about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2016-03-08T05·03+0800
committerChris Feng <chris.w.feng@gmail.com>2016-03-08T05·03+0800
commite217533642c864053a2e8add7c48dc2668edf17a (patch)
tree7136287b2fc872335dfd7ecf1af5e302a4ef198d
parenta50e6bd384d2157cb5070f138eb64d23496cf7ac (diff)
parentac3f8098c7b8d87225a34e85fcac8996404d1d8d (diff)
Merge branch 'medranocalvo/fix-input-target' into externals/exwm
-rw-r--r--exwm-input.el72
1 files changed, 44 insertions, 28 deletions
diff --git a/exwm-input.el b/exwm-input.el
index 31125a25c694..dc7f2b54ef0a 100644
--- a/exwm-input.el
+++ b/exwm-input.el
@@ -318,6 +318,34 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
                      :time xcb:Time:CurrentTime))
   (xcb:flush exwm--connection))
 
+(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)
+       (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)
+       (setq mode "char"
+             help-echo "mouse-1: Switch to line-mode"
+             cmd `(lambda ()
+                    (interactive)
+                    (exwm-input-grab-keyboard ,id)))))
+    (with-current-buffer (exwm--id->buffer id)
+      (setq mode-line-process
+            `(": "
+              (:propertize ,mode
+                           help-echo ,help-echo
+                           mouse-face mode-line-highlight
+                           local-map
+                           (keymap
+                            (mode-line
+                             keymap
+                             (down-mouse-1 . ,cmd)))))))))
+
 (defun exwm-input--grab-keyboard (&optional id)
   "Grab all key events on window ID."
   (unless id (setq id (exwm--buffer->id (window-buffer))))
@@ -331,7 +359,8 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
                              :pointer-mode xcb:GrabMode:Async
                              :keyboard-mode xcb:GrabMode:Sync))
       (exwm--log "Failed to grab keyboard for #x%x" id))
-    (setq exwm--on-KeyPress #'exwm-input--on-KeyPress-line-mode)))
+    (with-current-buffer (exwm--id->buffer id)
+      (setq exwm--on-KeyPress #'exwm-input--on-KeyPress-line-mode))))
 
 (defun exwm-input--release-keyboard (&optional id)
   "Ungrab all key events on window ID."
@@ -343,41 +372,28 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
                              :grab-window id
                              :modifiers xcb:ModMask:Any))
       (exwm--log "Failed to release keyboard for #x%x" id))
-    (setq exwm--on-KeyPress #'exwm-input--on-KeyPress-char-mode)))
+    (with-current-buffer (exwm--id->buffer id)
+      (setq exwm--on-KeyPress #'exwm-input--on-KeyPress-char-mode))))
 
 ;;;###autoload
 (defun exwm-input-grab-keyboard (&optional id)
   "Switch to line-mode."
-  (interactive)
-  (exwm-input--grab-keyboard id)
-  (setq mode-line-process
-        '(": "
-          (:propertize "line"
-                       help-echo "mouse-1: Switch to char-mode"
-                       mouse-face mode-line-highlight
-                       local-map
-                       (keymap
-                        (mode-line
-                         keymap
-                         (down-mouse-1 . exwm-input-release-keyboard))))))
-  (force-mode-line-update))
+  (interactive (list (exwm--buffer->id (window-buffer))))
+  (when id
+    (with-current-buffer (exwm--id->buffer id)
+      (exwm-input--grab-keyboard id)
+      (exwm-input--update-mode-line id)
+      (force-mode-line-update))))
 
 ;;;###autoload
 (defun exwm-input-release-keyboard (&optional id)
   "Switch to char-mode."
-  (interactive)
-  (exwm-input--release-keyboard id)
-  (setq mode-line-process
-        '(": "
-          (:propertize "char"
-                       help-echo "mouse-1: Switch to line-mode"
-                       mouse-face mode-line-highlight
-                       local-map
-                       (keymap
-                        (mode-line
-                         keymap
-                         (down-mouse-1 . exwm-input-grab-keyboard))))))
-  (force-mode-line-update))
+  (interactive (list (exwm--buffer->id (window-buffer))))
+  (when id
+    (with-current-buffer (exwm--id->buffer id)
+      (exwm-input--release-keyboard id)
+      (exwm-input--update-mode-line id)
+      (force-mode-line-update))))
 
 (defun exwm-input--fake-key (event)
   "Fake a key event equivalent to Emacs event EVENT."