about summary refs log tree commit diff
path: root/exwm-input.el
diff options
context:
space:
mode:
Diffstat (limited to 'exwm-input.el')
-rw-r--r--exwm-input.el50
1 files changed, 29 insertions, 21 deletions
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."