2015-09-04 03:09:59 +02:00
|
|
|
|
;;; exwm-core.el --- Core definitions -*- lexical-binding: t -*-
|
|
|
|
|
|
2017-02-05 10:49:42 +01:00
|
|
|
|
;; Copyright (C) 2015-2017 Free Software Foundation, Inc.
|
2015-09-04 03:09:59 +02:00
|
|
|
|
|
|
|
|
|
;; Author: Chris Feng <chris.w.feng@gmail.com>
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; This module includes core definitions of variables, macros, functions, etc
|
|
|
|
|
;; shared by various other modules.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2016-09-22 13:10:38 +02:00
|
|
|
|
(require 'kmacro)
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(require 'xcb)
|
|
|
|
|
(require 'xcb-icccm)
|
|
|
|
|
(require 'xcb-ewmh)
|
|
|
|
|
|
|
|
|
|
(eval-and-compile
|
|
|
|
|
(defvar exwm-debug-on nil "Non-nil to turn on debug for EXWM."))
|
|
|
|
|
|
|
|
|
|
(defmacro exwm--log (format-string &rest args)
|
|
|
|
|
"Print debug message."
|
|
|
|
|
(when exwm-debug-on
|
|
|
|
|
`(message (concat "[EXWM] " ,format-string) ,@args)))
|
|
|
|
|
|
2016-02-03 05:12:24 +01:00
|
|
|
|
(defmacro exwm--debug (&rest forms)
|
|
|
|
|
(when exwm-debug-on `(progn ,@forms)))
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defvar exwm--connection nil "X connection.")
|
|
|
|
|
(defvar exwm--root nil "Root window.")
|
|
|
|
|
(defvar exwm--id-buffer-alist nil "Alist of (<X window ID> . <Emacs buffer>).")
|
|
|
|
|
|
|
|
|
|
(defsubst exwm--id->buffer (id)
|
|
|
|
|
"X window ID => Emacs buffer."
|
|
|
|
|
(cdr (assoc id exwm--id-buffer-alist)))
|
|
|
|
|
|
|
|
|
|
(defsubst exwm--buffer->id (buffer)
|
|
|
|
|
"Emacs buffer BUFFER => X window ID."
|
|
|
|
|
(car (rassoc buffer exwm--id-buffer-alist)))
|
|
|
|
|
|
|
|
|
|
(defun exwm--lock (&rest _args)
|
|
|
|
|
"Lock (disable all events)."
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ChangeWindowAttributes
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:value-mask xcb:CW:EventMask
|
|
|
|
|
:event-mask xcb:EventMask:NoEvent))
|
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
|
|
|
|
|
(defun exwm--unlock (&rest _args)
|
|
|
|
|
"Unlock (enable all events)."
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ChangeWindowAttributes
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:value-mask xcb:CW:EventMask
|
2015-09-27 13:31:00 +02:00
|
|
|
|
:event-mask (eval-when-compile
|
|
|
|
|
(logior xcb:EventMask:SubstructureRedirect
|
|
|
|
|
xcb:EventMask:StructureNotify))))
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
|
|
|
|
|
(defconst exwm--client-event-mask
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(eval-when-compile
|
|
|
|
|
(logior xcb:EventMask:StructureNotify xcb:EventMask:PropertyChange))
|
2015-09-04 03:09:59 +02:00
|
|
|
|
"Event mask set on all managed windows.")
|
|
|
|
|
|
2016-09-22 13:10:38 +02:00
|
|
|
|
(defvar exwm-input--during-key-sequence)
|
|
|
|
|
(defvar exwm-input--global-prefix-keys)
|
|
|
|
|
(defvar exwm-input-prefix-keys)
|
|
|
|
|
(defvar exwm-input--simulation-prefix-keys)
|
|
|
|
|
|
|
|
|
|
(declare-function exwm-input--fake-key "exwm-input.el" (event))
|
2016-02-19 10:12:43 +01:00
|
|
|
|
(declare-function exwm-input--on-KeyPress-line-mode "exwm-input.el"
|
2016-07-29 11:05:09 +02:00
|
|
|
|
(key-press raw-data))
|
2016-02-19 10:12:43 +01:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; Internal variables
|
2016-02-07 03:45:59 +01:00
|
|
|
|
(defvar-local exwm--id nil) ;window ID
|
|
|
|
|
(defvar-local exwm--container nil) ;container
|
|
|
|
|
(defvar-local exwm--frame nil) ;workspace frame
|
|
|
|
|
(defvar-local exwm--floating-frame nil) ;floating frame
|
|
|
|
|
(defvar-local exwm--mode-line-format nil) ;save mode-line-format
|
|
|
|
|
(defvar-local exwm--floating-frame-position nil) ;used in fullscreen
|
|
|
|
|
(defvar-local exwm--fixed-size nil) ;fixed size
|
2016-07-17 06:46:19 +02:00
|
|
|
|
(defvar-local exwm--keyboard-grabbed nil) ;Keyboard grabbed.
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defvar-local exwm--on-KeyPress ;KeyPress event handler
|
|
|
|
|
#'exwm-input--on-KeyPress-line-mode)
|
|
|
|
|
;; Properties
|
|
|
|
|
(defvar-local exwm-window-type nil "_NET_WM_WINDOW_TYPE.")
|
|
|
|
|
(defvar-local exwm--geometry nil)
|
|
|
|
|
(defvar-local exwm-class-name nil "Class name in WM_CLASS.")
|
|
|
|
|
(defvar-local exwm-instance-name nil "Instance name in WM_CLASS.")
|
|
|
|
|
(defvar-local exwm-title nil "Window title (either _NET_WM_NAME or WM_NAME)")
|
|
|
|
|
(defvar-local exwm--title-is-utf8 nil)
|
|
|
|
|
(defvar-local exwm-transient-for nil "WM_TRANSIENT_FOR.")
|
|
|
|
|
(defvar-local exwm--protocols nil)
|
2016-07-13 12:51:32 +02:00
|
|
|
|
(defvar-local exwm-state xcb:icccm:WM_STATE:NormalState "WM_STATE.")
|
2016-08-12 13:27:26 +02:00
|
|
|
|
(defvar-local exwm--ewmh-state nil "_NET_WM_STATE.")
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; _NET_WM_NORMAL_HINTS
|
|
|
|
|
(defvar-local exwm--normal-hints-x nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-y nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-width nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-height nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-min-width nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-min-height nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-max-width nil)
|
|
|
|
|
(defvar-local exwm--normal-hints-max-height nil)
|
|
|
|
|
;; (defvar-local exwm--normal-hints-win-gravity nil)
|
|
|
|
|
;; WM_HINTS
|
2016-02-19 10:12:43 +01:00
|
|
|
|
(defvar-local exwm--hints-input nil)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defvar-local exwm--hints-urgency nil)
|
2015-09-19 10:46:08 +02:00
|
|
|
|
;; _MOTIF_WM_HINTS
|
2016-05-24 06:30:53 +02:00
|
|
|
|
(defvar-local exwm--mwm-hints-decorations t)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
|
2016-07-17 14:00:00 +02:00
|
|
|
|
(declare-function exwm-floating-hide "exwm-floating.el")
|
|
|
|
|
(declare-function exwm-floating-toggle-floating "exwm-floating.el")
|
|
|
|
|
(declare-function exwm-input-release-keyboard "exwm-input.el")
|
|
|
|
|
(declare-function exwm-input-send-next-key "exwm-input.el" (times))
|
|
|
|
|
(declare-function exwm-layout-set-fullscreen "exwm-layout.el" (&optional id))
|
|
|
|
|
(declare-function exwm-layout-toggle-mode-line "exwm-layout.el")
|
|
|
|
|
(declare-function exwm-workspace-move-window "exwm-workspace.el"
|
2016-07-17 14:00:00 +02:00
|
|
|
|
(frame-or-index &optional id))
|
2016-07-17 14:00:00 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defvar exwm-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2016-02-20 03:02:11 +01:00
|
|
|
|
(define-key map "\C-c\C-f" #'exwm-layout-set-fullscreen)
|
2016-02-25 05:41:35 +01:00
|
|
|
|
(define-key map "\C-c\C-h" #'exwm-floating-hide)
|
2016-02-20 03:02:11 +01:00
|
|
|
|
(define-key map "\C-c\C-k" #'exwm-input-release-keyboard)
|
|
|
|
|
(define-key map "\C-c\C-m" #'exwm-workspace-move-window)
|
|
|
|
|
(define-key map "\C-c\C-q" #'exwm-input-send-next-key)
|
|
|
|
|
(define-key map "\C-c\C-t\C-f" #'exwm-floating-toggle-floating)
|
|
|
|
|
(define-key map "\C-c\C-t\C-m" #'exwm-layout-toggle-mode-line)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
map)
|
|
|
|
|
"Keymap for `exwm-mode'.")
|
|
|
|
|
|
2016-09-22 13:10:38 +02:00
|
|
|
|
(defvar exwm--kmacro-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map [t]
|
|
|
|
|
(lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(cond
|
|
|
|
|
((or exwm-input--during-key-sequence
|
|
|
|
|
;; Do not test `exwm-input--during-command'.
|
|
|
|
|
(active-minibuffer-window)
|
|
|
|
|
(memq last-input-event exwm-input--global-prefix-keys)
|
|
|
|
|
(memq last-input-event exwm-input-prefix-keys)
|
|
|
|
|
(memq last-input-event exwm-input--simulation-prefix-keys))
|
|
|
|
|
(set-transient-map (make-composed-keymap (list exwm-mode-map
|
|
|
|
|
global-map)))
|
|
|
|
|
(push last-input-event unread-command-events))
|
|
|
|
|
(t
|
|
|
|
|
(exwm-input--fake-key last-input-event)))))
|
|
|
|
|
map)
|
|
|
|
|
"Keymap used when executing keyboard macros.")
|
|
|
|
|
|
2016-07-17 06:46:19 +02:00
|
|
|
|
;; This menu mainly acts as an reminder for users. Thus it should be as
|
|
|
|
|
;; detailed as possible, even some entries do not make much sense here.
|
|
|
|
|
;; Also, inactive entries should be disabled rather than hidden.
|
|
|
|
|
(easy-menu-define exwm-mode-menu exwm-mode-map
|
|
|
|
|
"Menu for `exwm-mode'."
|
|
|
|
|
'("EXWM"
|
|
|
|
|
"---"
|
|
|
|
|
"*General*"
|
|
|
|
|
"---"
|
|
|
|
|
["Toggle floating" exwm-floating-toggle-floating]
|
2016-08-24 13:21:17 +02:00
|
|
|
|
["Toggle fullscreen mode" exwm-layout-toggle-fullscreen]
|
2016-07-17 06:46:19 +02:00
|
|
|
|
["Hide window" exwm-floating-hide exwm--floating-frame]
|
2017-02-05 10:51:43 +01:00
|
|
|
|
["Close window" (kill-buffer (current-buffer))]
|
2016-07-17 06:46:19 +02:00
|
|
|
|
|
|
|
|
|
"---"
|
|
|
|
|
"*Resizing*"
|
|
|
|
|
"---"
|
|
|
|
|
["Toggle mode-line" exwm-layout-toggle-mode-line :keys "C-c C-t C-m"]
|
|
|
|
|
["Enlarge window vertically" exwm-layout-enlarge-window]
|
|
|
|
|
["Enlarge window horizontally" exwm-layout-enlarge-window-horizontally]
|
|
|
|
|
["Shrink window vertically" exwm-layout-shrink-window]
|
|
|
|
|
["Shrink window horizontally" exwm-layout-shrink-window-horizontally]
|
|
|
|
|
|
|
|
|
|
"---"
|
|
|
|
|
"*Keyboard*"
|
|
|
|
|
"---"
|
2016-08-24 13:21:17 +02:00
|
|
|
|
["Toggle keyboard mode" exwm-input-toggle-keyboard]
|
2016-07-17 06:46:19 +02:00
|
|
|
|
["Send key" exwm-input-send-next-key exwm--keyboard-grabbed]
|
|
|
|
|
;; This is merely a reference.
|
|
|
|
|
("Send simulation key" :filter
|
|
|
|
|
(lambda (&rest _args)
|
|
|
|
|
(mapcar (lambda (i)
|
|
|
|
|
(let ((keys (cdr i)))
|
|
|
|
|
(if (vectorp keys)
|
|
|
|
|
(setq keys (append keys))
|
|
|
|
|
(unless (sequencep keys)
|
|
|
|
|
(setq keys (list keys))))
|
|
|
|
|
(vector (key-description keys)
|
|
|
|
|
`(lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(dolist (key ',keys)
|
|
|
|
|
(exwm-input--fake-key key)))
|
|
|
|
|
:keys (key-description (car i)))))
|
|
|
|
|
exwm-input--simulation-keys)))
|
|
|
|
|
|
|
|
|
|
["Define global binding" exwm-input-set-key]
|
|
|
|
|
|
|
|
|
|
"---"
|
|
|
|
|
"*Workspace*"
|
|
|
|
|
"---"
|
2016-07-19 04:36:14 +02:00
|
|
|
|
["Add workspace" exwm-workspace-add]
|
|
|
|
|
["Delete current workspace" exwm-workspace-delete]
|
|
|
|
|
["Move workspace to" exwm-workspace-move]
|
|
|
|
|
["Swap workspaces" exwm-workspace-swap]
|
|
|
|
|
["Move X window to" exwm-workspace-move-window :keys "C-c C-m"]
|
|
|
|
|
["Move X window from" exwm-workspace-switch-to-buffer]
|
2016-07-22 06:26:29 +02:00
|
|
|
|
["Toggle minibuffer" exwm-workspace-toggle-minibuffer]
|
2016-07-17 06:46:19 +02:00
|
|
|
|
["Switch workspace" exwm-workspace-switch]
|
|
|
|
|
;; Place this entry at bottom to avoid selecting others by accident.
|
|
|
|
|
("Switch to" :filter
|
|
|
|
|
(lambda (&rest _args)
|
|
|
|
|
(mapcar (lambda (i)
|
|
|
|
|
`[,(format "workspace %d" i)
|
|
|
|
|
(lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(exwm-workspace-switch ,i))
|
|
|
|
|
(/= ,i exwm-workspace-current-index)])
|
2016-07-19 04:24:23 +02:00
|
|
|
|
(number-sequence 0 (1- (exwm-workspace--count))))))))
|
2016-07-17 06:46:19 +02:00
|
|
|
|
|
2016-02-19 10:12:43 +01:00
|
|
|
|
(declare-function exwm-manage--kill-buffer-query-function "exwm-manage.el")
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(define-derived-mode exwm-mode nil "EXWM"
|
|
|
|
|
"Major mode for managing X windows.
|
|
|
|
|
|
|
|
|
|
\\{exwm-mode-map}"
|
|
|
|
|
;;
|
|
|
|
|
(setq mode-name
|
|
|
|
|
'(:eval (propertize "EXWM" 'face
|
|
|
|
|
(when (cl-some (lambda (i)
|
2016-07-21 06:41:51 +02:00
|
|
|
|
(frame-parameter i 'exwm-urgency))
|
2015-09-04 03:09:59 +02:00
|
|
|
|
exwm-workspace--list)
|
|
|
|
|
'font-lock-warning-face))))
|
|
|
|
|
;; Change major-mode is not allowed
|
|
|
|
|
(add-hook 'change-major-mode-hook #'kill-buffer nil t)
|
|
|
|
|
;; Kill buffer -> close window
|
|
|
|
|
(add-hook 'kill-buffer-query-functions
|
2016-02-18 12:56:01 +01:00
|
|
|
|
#'exwm-manage--kill-buffer-query-function nil t)
|
2016-09-22 13:10:38 +02:00
|
|
|
|
;; Redirect events when executing keyboard macros.
|
|
|
|
|
(push `(executing-kbd-macro . ,exwm--kmacro-map)
|
|
|
|
|
minor-mode-overriding-map-alist)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(setq buffer-read-only t
|
|
|
|
|
left-margin-width nil
|
|
|
|
|
right-margin-width nil
|
|
|
|
|
left-fringe-width 0
|
|
|
|
|
right-fringe-width 0
|
|
|
|
|
vertical-scroll-bar nil))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'exwm-core)
|
|
|
|
|
|
|
|
|
|
;;; exwm-core.el ends here
|