Add major mode menu

* exwm-core.el (exwm--keyboard-grabbed): New buffer-local variable for
recoding grabbing state.
(exwm-mode-menu, exwm-mode-map): Add major mode menu.
* exwm-input.el (exwm-input-set-key): Update prefix keys when a global
binding is interactively set.
(exwm-input-grab-keyboard, exwm-input-release-keyboard): Update grabbing
state.
This commit is contained in:
Chris Feng 2016-07-17 12:46:19 +08:00
parent 4ac71a7ddc
commit 2195316821
2 changed files with 73 additions and 1 deletions

View file

@ -90,6 +90,7 @@
(defvar-local exwm--fullscreen nil) ;used in fullscreen (defvar-local exwm--fullscreen nil) ;used in fullscreen
(defvar-local exwm--floating-frame-position nil) ;used in fullscreen (defvar-local exwm--floating-frame-position nil) ;used in fullscreen
(defvar-local exwm--fixed-size nil) ;fixed size (defvar-local exwm--fixed-size nil) ;fixed size
(defvar-local exwm--keyboard-grabbed nil) ;Keyboard grabbed.
(defvar-local exwm--on-KeyPress ;KeyPress event handler (defvar-local exwm--on-KeyPress ;KeyPress event handler
#'exwm-input--on-KeyPress-line-mode) #'exwm-input--on-KeyPress-line-mode)
;; Properties ;; Properties
@ -130,6 +131,73 @@
map) map)
"Keymap for `exwm-mode'.") "Keymap for `exwm-mode'.")
;; 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]
["Enter fullscreen" exwm-layout-set-fullscreen (not exwm--fullscreen)]
["Leave fullscreen" exwm-reset exwm--fullscreen]
["Hide window" exwm-floating-hide exwm--floating-frame]
"---"
"*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*"
"---"
["Capture keyboard" exwm-input-release-keyboard exwm--keyboard-grabbed]
;; It's recommended to use `exwm-reset' rather than
;; `exwm-input-grab-keyboard' to release keyboard (enter line-mode).
["Release keyboard" exwm-reset (not exwm--keyboard-grabbed)]
["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*"
"---"
["Move window to" exwm-workspace-move-window :keys "C-c C-m"]
["Switch to buffer" exwm-workspace-switch-to-buffer]
["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)])
(number-sequence 0 (1- exwm-workspace-number)))))))
(declare-function exwm-manage--kill-buffer-query-function "exwm-manage.el") (declare-function exwm-manage--kill-buffer-query-function "exwm-manage.el")
(define-derived-mode exwm-mode nil "EXWM" (define-derived-mode exwm-mode nil "EXWM"

View file

@ -285,7 +285,9 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
"Set a global key binding." "Set a global key binding."
(interactive "KSet key globally: \nCSet key %s to command: ") (interactive "KSet key globally: \nCSet key %s to command: ")
(global-set-key key command) (global-set-key key command)
(cl-pushnew key exwm-input--global-keys)) (cl-pushnew key exwm-input--global-keys)
(when (called-interactively-p 'any)
(exwm-input--update-global-prefix-keys)))
;; FIXME: Putting (t . EVENT) into `unread-command-events' does not really work ;; FIXME: Putting (t . EVENT) into `unread-command-events' does not really work
;; as documented in Emacs 24. Since inserting a conventional EVENT does ;; as documented in Emacs 24. Since inserting a conventional EVENT does
@ -421,6 +423,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(when id (when id
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(exwm-input--grab-keyboard id) (exwm-input--grab-keyboard id)
(setq exwm--keyboard-grabbed t)
(exwm-input--update-mode-line id) (exwm-input--update-mode-line id)
(force-mode-line-update)))) (force-mode-line-update))))
@ -431,6 +434,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(when id (when id
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(exwm-input--release-keyboard id) (exwm-input--release-keyboard id)
(setq exwm--keyboard-grabbed nil)
(exwm-input--update-mode-line id) (exwm-input--update-mode-line id)
(force-mode-line-update)))) (force-mode-line-update))))