about summary refs log tree commit diff
path: root/exwm-input.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2015-08-10T06·23+0800
committerChris Feng <chris.w.feng@gmail.com>2015-08-10T06·23+0800
commit048994c7948528630b5c13f56dd22a9b2972e09c (patch)
tree5c5732fde3c9a09bda4995a63c05c6e60f48120f /exwm-input.el
parent2d4104a0eceb7d043ed1cd6bdd1bda1db4f91a73 (diff)
Remove redundant code caused by the concurrency of events (continued)
Remove `exwm--with-current-id`, which was introduced to as a wrapper to
`with-current-buffer` to do extra checks. Note that in functions run as hooks,
the validation of window ID is still required as they are not synchronized with
events.
Diffstat (limited to 'exwm-input.el')
-rw-r--r--exwm-input.el37
1 files changed, 20 insertions, 17 deletions
diff --git a/exwm-input.el b/exwm-input.el
index 97dfd53e3640..24aa94abdaee 100644
--- a/exwm-input.el
+++ b/exwm-input.el
@@ -56,7 +56,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
 
 (defun exwm-input--set-focus (id)
   "Set input focus to window ID in a proper way."
-  (exwm--with-current-id id
+  (with-current-buffer (exwm--id->buffer id)
     (exwm--log "Set focus ID to #x%x" id)
     (setq exwm-input--focus-id id)
     (if (and (not exwm--hints-input)
@@ -105,21 +105,24 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
                                 exwm--floating-frame)
                      (x-focus-frame exwm--floating-frame)))
                  ;; Finally focus the window
-                 (exwm-input--set-focus exwm-input--focus-id))
-        (exwm--with-current-id exwm-input--focus-id
-          (exwm--log "Set focus ID to #x%x" xcb:Window:None)
-          (setq exwm-input--focus-id xcb:Window:None)
-          (let ((frame (selected-frame)))
-            (if exwm--floating-frame
-                (unless (or (eq frame exwm--floating-frame)
-                            (active-minibuffer-window))
-                  ;; Redirect input focus to the workspace frame
-                  (exwm--log "Redirect input focus (%s => %s)"
-                             exwm--floating-frame frame)
-                  (redirect-frame-focus exwm--floating-frame frame))
-              ;; Focus the workspace frame
-              (exwm--log "Focus on workspace %s" frame)
-              (x-focus-frame frame))))))
+                 (when (exwm--id->buffer exwm-input--focus-id)
+                   (exwm-input--set-focus exwm-input--focus-id)))
+        (let ((buffer (exwm--id->buffer exwm-input--focus-id)))
+          (when buffer
+            (with-current-buffer buffer
+              (exwm--log "Set focus ID to #x%x" xcb:Window:None)
+              (setq exwm-input--focus-id xcb:Window:None)
+              (let ((frame (selected-frame)))
+                (if exwm--floating-frame
+                    (unless (or (eq frame exwm--floating-frame)
+                                (active-minibuffer-window))
+                      ;; Redirect input focus to the workspace frame
+                      (exwm--log "Redirect input focus (%s => %s)"
+                                 exwm--floating-frame frame)
+                      (redirect-frame-focus exwm--floating-frame frame))
+                  ;; Focus the workspace frame
+                  (exwm--log "Focus on workspace %s" frame)
+                  (x-focus-frame frame))))))))
     (setq exwm-input--focus-lock nil)))
 
 (defun exwm-input--finish-key-sequence ()
@@ -163,7 +166,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
             (t
              ;; Click to focus
              (unless (and (boundp 'exwm--id) (= event exwm--id))
-               (exwm--with-current-id event
+               (with-current-buffer (exwm--id->buffer event)
                  (select-frame-set-input-focus (or exwm--floating-frame
                                                    exwm--frame))
                  (select-window (get-buffer-window nil 'visible))))