about summary refs log tree commit diff
path: root/exwm-input.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2017-11-19T06·51+0800
committerChris Feng <chris.w.feng@gmail.com>2017-11-19T06·51+0800
commit71a39840b239a51eed7455877517ebe612892eff (patch)
treec1320b3e7c7778e9027d0e2bc7e502d5ee7418bd /exwm-input.el
parent55626530f4a523cccd1d24c8819f7e80543e0276 (diff)
Fix various input focus issues
* exwm-input.el (exwm-input--on-buffer-list-update): Cancel the frame
redirection introduced by 421c0512f7.

* exwm-input.el (exwm-input--on-buffer-list-update): Only ignore temp
buffers just switched from.

* exwm-input.el (exwm-input--update-focus-commit): New function for
ensuring the input focus lock can always be released.
(exwm-input--update-focus-defer, exwm-input--update-focus): Use it.

* exwm-input.el (exwm-input--update-focus): No need to select frames;
only transfer X input focus.

* exwm-core.el (exwm--defer): New macro for correcting the use of
`run-with-idle-timer' by taking `current-idle-time' into account.
* exwm-input.el (exwm-input--update-focus-defer)
(exwm-input--update-focus):
* exwm-layout.el (exwm-layout--on-minibuffer-setup)
(exwm-layout--on-echo-area-change):
* exwm-manage.el (exwm-manage--unmanage-window)
(exwm-workspace--prompt-delete):
* exwm-workspace.el (exwm-workspace-switch)
(exwm-workspace--add-frame-as-workspace):
Use it.
Diffstat (limited to 'exwm-input.el')
-rw-r--r--exwm-input.el37
1 files changed, 19 insertions, 18 deletions
diff --git a/exwm-input.el b/exwm-input.el
index 3a817be4cd6e..6a60ac35d082 100644
--- a/exwm-input.el
+++ b/exwm-input.el
@@ -158,7 +158,9 @@ This value should always be overwritten.")
              ;; The following conditions filter out events relating to temp
              ;; buffers.
              (eq (current-buffer) (window-buffer))
-             (not (get-buffer " *temp*")))
+             (not (string-prefix-p " *temp*"
+                                   (buffer-name (car (last (buffer-list)))))))
+    (redirect-frame-focus (selected-frame) nil)
     (setq exwm-input--update-focus-window (selected-window))
     (exwm-input--update-focus-defer)))
 
@@ -186,15 +188,14 @@ This value should always be overwritten.")
     (cancel-timer exwm-input--update-focus-defer-timer))
   (if exwm-input--update-focus-lock
       (setq exwm-input--update-focus-defer-timer
-            (run-with-idle-timer 0 nil
-                                 #'exwm-input--update-focus-defer))
+            (exwm--defer 0 #'exwm-input--update-focus-defer))
     (setq exwm-input--update-focus-defer-timer nil)
     (when exwm-input--update-focus-timer
       (cancel-timer exwm-input--update-focus-timer))
     (setq exwm-input--update-focus-timer
-          (run-with-idle-timer exwm-input--update-focus-interval nil
-                               #'exwm-input--update-focus
-                               exwm-input--update-focus-window))))
+          (exwm--defer exwm-input--update-focus-interval
+                       #'exwm-input--update-focus-commit
+                       exwm-input--update-focus-window))))
 
 (declare-function exwm-layout--iconic-state-p "exwm-layout.el" (&optional id))
 (declare-function exwm-layout--set-state "exwm-layout.el" (id state))
@@ -203,17 +204,22 @@ This value should always be overwritten.")
                   (frame-or-index &optional force))
 (declare-function exwm-workspace--workspace-p "exwm-workspace.el" (workspace))
 
+(defun exwm-input--update-focus-commit (window)
+  "Commit updating input focus."
+  (setq exwm-input--update-focus-lock t)
+  (unwind-protect
+      (exwm-input--update-focus window)
+    (setq exwm-input--update-focus-lock nil)))
+
 (defun exwm-input--update-focus (window)
   "Update input focus."
-  (setq exwm-input--update-focus-lock t)
   (when (window-live-p window)
     (with-current-buffer (window-buffer window)
       (if (eq major-mode 'exwm-mode)
           (if (not (eq exwm--frame exwm-workspace--current))
               (progn
                 (set-frame-parameter exwm--frame 'exwm-selected-window window)
-                (run-with-idle-timer 0 nil #'exwm-workspace-switch
-                                     exwm--frame))
+                (exwm--defer 0 #'exwm-workspace-switch exwm--frame))
             (exwm--log "Set focus on #x%x" exwm--id)
             (exwm-input--set-focus exwm--id)
             (when exwm--floating-frame
@@ -237,21 +243,16 @@ This value should always be overwritten.")
               (progn
                 (set-frame-parameter (selected-frame) 'exwm-selected-window
                                      window)
-                (run-with-idle-timer 0 nil #'exwm-workspace-switch
-                                     (selected-frame)))
+                (exwm--defer 0 #'exwm-workspace-switch (selected-frame)))
             ;; The focus is still on the current workspace.
             (if (not (and (exwm-workspace--minibuffer-own-frame-p)
                           (minibufferp)))
-                (select-frame-set-input-focus (window-frame window) t)
+                (x-focus-frame (window-frame window))
               ;; X input focus should be set on the previously selected
               ;; frame.
-              (select-frame-set-input-focus (window-frame
-                                             (minibuffer-selected-window))
-                                            t)
-              (select-frame (window-frame window) t))
+              (x-focus-frame (window-frame (minibuffer-selected-window))))
             (exwm-input--set-active-window)
-            (xcb:flush exwm--connection))))))
-  (setq exwm-input--update-focus-lock nil))
+            (xcb:flush exwm--connection)))))))
 
 (defun exwm-input--on-minibuffer-setup ()
   "Run in `minibuffer-setup-hook' to set input focus."