Simplify input handling

No functional change.

* exwm-input.el (exwm-input--current-input-mode): New function
indicating keyboard input mode.
(exwm-input--on-KeyPress, exwm-input--update-mode-line): Use
`exwm-input--current-input-mode'.
(exwm-input-grab-keyboard, exwm-input-release-keyboard)
(exwm-input--update-mode-line): Simplify.

* exwh-core.el (exwm--on-KeyPress): Remove variable, use
`exwm--keyboard-grabbed' and `exwm-input--current-input-mode'
instead.
This commit is contained in:
Adrián Medraño Calvo 2018-10-08 12:00:00 +00:00
parent 472f7cb82b
commit dff1ef6a3c
3 changed files with 33 additions and 26 deletions

View file

@ -158,9 +158,7 @@ least SECS seconds later."
(defvar-local exwm--mode-line-format nil) ;save mode-line-format
(defvar-local exwm--floating-frame-position nil) ;set when hidden.
(defvar-local exwm--fixed-size nil) ;fixed size
(defvar-local exwm--keyboard-grabbed nil) ;Keyboard grabbed.
(defvar-local exwm--on-KeyPress ;KeyPress event handler
#'exwm-input--on-KeyPress-line-mode)
(defvar-local exwm--input-mode 'line-mode) ;Keyboard grabbed.
;; Properties
(defvar-local exwm--desktop nil "_NET_WM_DESKTOP.")
(defvar-local exwm-window-type nil "_NET_WM_WINDOW_TYPE.")
@ -252,7 +250,7 @@ least SECS seconds later."
"*Keyboard*"
"---"
["Toggle keyboard mode" exwm-input-toggle-keyboard]
["Send key" exwm-input-send-next-key exwm--keyboard-grabbed]
["Send key" exwm-input-send-next-key (eq exwm--input-mode 'line-mode)]
;; This is merely a reference.
("Send simulation key" :filter
(lambda (&rest _args)

View file

@ -430,7 +430,11 @@ ARGS are additional arguments to CALLBACK."
(exwm--log "major-mode=%s buffer=%s"
major-mode (buffer-name (current-buffer)))
(if (derived-mode-p 'exwm-mode)
(funcall exwm--on-KeyPress obj data)
(cl-case (exwm-input--current-input-mode)
(line-mode
(exwm-input--on-KeyPress-line-mode obj data))
(char-mode
(exwm-input--on-KeyPress-char-mode obj data)))
(exwm-input--on-KeyPress-char-mode obj))))
(defun exwm-input--on-CreateNotify (data _synthetic)
@ -654,17 +658,24 @@ instead."
:time xcb:Time:CurrentTime))
(xcb:flush exwm--connection))
(defun exwm-input--current-input-mode ()
"Return current input mode.
The return value is one of the symbols \\='line-mode or \\=`char-mode.
Current buffer must be an `exwm-mode' buffer."
exwm--input-mode)
(defun exwm-input--update-mode-line (id)
"Update the propertized `mode-line-process' for window ID."
(let (help-echo cmd mode)
(cl-case exwm--on-KeyPress
((exwm-input--on-KeyPress-line-mode)
(cl-case (exwm-input--current-input-mode)
(line-mode
(setq mode "line"
help-echo "mouse-1: Switch to char-mode"
cmd `(lambda ()
(interactive)
(exwm-input-release-keyboard ,id))))
((exwm-input--on-KeyPress-char-mode)
(char-mode
(setq mode "char"
help-echo "mouse-1: Switch to line-mode"
cmd `(lambda ()
@ -680,7 +691,8 @@ instead."
(keymap
(mode-line
keymap
(down-mouse-1 . ,cmd)))))))))
(down-mouse-1 . ,cmd))))))
(force-mode-line-update))))
(defun exwm-input--grab-keyboard (&optional id)
"Grab all key events on window ID."
@ -697,7 +709,7 @@ instead."
:keyboard-mode xcb:GrabMode:Sync))
(exwm--log "Failed to grab keyboard for #x%x" id))
(with-current-buffer (exwm--id->buffer id)
(setq exwm--on-KeyPress #'exwm-input--on-KeyPress-line-mode))))
(setq exwm--input-mode 'line-mode))))
(defun exwm-input--release-keyboard (&optional id)
"Ungrab all key events on window ID."
@ -712,7 +724,7 @@ instead."
(exwm--log "Failed to release keyboard for #x%x" id))
(exwm-input--grab-global-prefix-keys id)
(with-current-buffer (exwm--id->buffer id)
(setq exwm--on-KeyPress #'exwm-input--on-KeyPress-char-mode))))
(setq exwm--input-mode 'char-mode))))
;;;###autoload
(defun exwm-input-grab-keyboard (&optional id)
@ -721,11 +733,8 @@ instead."
(exwm--buffer->id (window-buffer)))))
(when id
(exwm--log "id=#x%x" id)
(with-current-buffer (exwm--id->buffer id)
(exwm-input--grab-keyboard id)
(setq exwm--keyboard-grabbed t)
(exwm-input--update-mode-line id)
(force-mode-line-update))))
(exwm-input--update-mode-line id)))
;;;###autoload
(defun exwm-input-release-keyboard (&optional id)
@ -734,11 +743,8 @@ instead."
(exwm--buffer->id (window-buffer)))))
(when id
(exwm--log "id=#x%x" id)
(with-current-buffer (exwm--id->buffer id)
(exwm-input--release-keyboard id)
(setq exwm--keyboard-grabbed nil)
(exwm-input--update-mode-line id)
(force-mode-line-update))))
(exwm-input--update-mode-line id)))
;;;###autoload
(defun exwm-input-toggle-keyboard (&optional id)
@ -748,9 +754,11 @@ instead."
(when id
(exwm--log "id=#x%x" id)
(with-current-buffer (exwm--id->buffer id)
(if exwm--keyboard-grabbed
(exwm-input-release-keyboard id)
(exwm-reset)))))
(cl-case (exwm-input--current-input-mode)
(line-mode
(exwm-input-release-keyboard id))
(char-mode
(exwm-reset))))))
(defun exwm-input--fake-key (event)
"Fake a key event equivalent to Emacs event EVENT."

View file

@ -45,6 +45,7 @@
(defvar exwm-layout--timer nil "Timer used to track echo area changes.")
(defvar exwm-workspace--current)
(declare-function exwm-input--current-input-mode "exwm-input.el")
(declare-function exwm-input--release-keyboard "exwm-input.el")
(declare-function exwm-input--grab-keyboard "exwm-input.el")
(declare-function exwm-input-grab-keyboard "exwm-input.el")
@ -199,7 +200,7 @@
(make-instance 'xcb:ewmh:set-_NET_WM_STATE :window exwm--id :data []))
(xcb:flush exwm--connection)
(set-window-dedicated-p (get-buffer-window) nil)
(when exwm--keyboard-grabbed
(when (eq 'line-mode (exwm-input--current-input-mode))
(exwm-input--grab-keyboard exwm--id))))
;;;###autoload