about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdrián Medraño Calvo <adrian@medranocalvo.com>2018-10-08T12·00+0000
committerAdrián Medraño Calvo <adrian@medranocalvo.com>2018-10-08T12·00+0000
commitdff1ef6a3c36fd7d8b3a3bafbd66a91b8e576b26 (patch)
tree3cee64b88e0658c8e0d8a57297c875fe169fcb8a
parent472f7cb82b67b98843f10c12e6bda9b8ae7262bc (diff)
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.
-rw-r--r--exwm-core.el6
-rw-r--r--exwm-input.el50
-rw-r--r--exwm-layout.el3
3 files changed, 33 insertions, 26 deletions
diff --git a/exwm-core.el b/exwm-core.el
index 66eb98cf905f..612a26f59fde 100644
--- a/exwm-core.el
+++ b/exwm-core.el
@@ -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)
diff --git a/exwm-input.el b/exwm-input.el
index 57fed2d4b88e..d9ad3d3c66c0 100644
--- a/exwm-input.el
+++ b/exwm-input.el
@@ -428,9 +428,13 @@ ARGS are additional arguments to CALLBACK."
   (let ((obj (make-instance 'xcb:KeyPress)))
     (xcb:unmarshal obj data)
     (exwm--log "major-mode=%s buffer=%s"
-	       major-mode (buffer-name (current-buffer)))
+               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--grab-keyboard id)
+    (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--release-keyboard id)
+    (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."
diff --git a/exwm-layout.el b/exwm-layout.el
index 56faadd99209..90988faae07f 100644
--- a/exwm-layout.el
+++ b/exwm-layout.el
@@ -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