about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2015-08-11T01·18+0800
committerChris Feng <chris.w.feng@gmail.com>2015-08-11T01·18+0800
commitb755296f547938d0f97d6aa49b8cb0d726de9eb9 (patch)
tree25d07bc390ca2d47ca0f00af17b0fdc90082681b
parent24b964bb4af100b959a33215cc91b9c896c9359e (diff)
Remove redundant code caused by the concurrency of events (contd, 2)
* Remove locks that are no longer required
* Also fix #20 (inactive workspace frame steals input focus)
-rw-r--r--exwm-floating.el8
-rw-r--r--exwm-input.el75
-rw-r--r--exwm-manage.el5
-rw-r--r--exwm-workspace.el18
4 files changed, 45 insertions, 61 deletions
diff --git a/exwm-floating.el b/exwm-floating.el
index bc7ee338466b..3971fa48126b 100644
--- a/exwm-floating.el
+++ b/exwm-floating.el
@@ -39,7 +39,6 @@
 (defun exwm-floating--set-floating (id)
   "Make window ID floating."
   (interactive)
-  (setq exwm-input--focus-lock t)
   (when (get-buffer-window (exwm--id->buffer id)) ;window in non-floating state
     (set-window-buffer (selected-window) (other-buffer))) ;hide it first
   (let* ((original-frame
@@ -167,13 +166,11 @@
       ;; FIXME: other conditions?
       (unless (memq xcb:Atom:_NET_WM_WINDOW_TYPE_UTILITY exwm-window-type)
         (x-focus-frame exwm--floating-frame)
-        (exwm-input--set-focus id)))
-    (setq exwm-input--focus-lock nil)))
+        (exwm-input--set-focus id)))))
 
 (defun exwm-floating--unset-floating (id)
   "Make window ID non-floating."
   (interactive)
-  (setq exwm-input--focus-lock t)
   (let ((buffer (exwm--id->buffer id)))
     ;; Reparent to workspace frame
     (xcb:+request exwm--connection
@@ -201,8 +198,7 @@
             exwm--frame exwm-workspace--current))
     (select-frame exwm-workspace--current t)
     (set-window-buffer nil buffer)
-    (exwm-input--set-focus id))
-  (setq exwm-input--focus-lock nil))
+    (exwm-input--set-focus id)))
 
 (defun exwm-floating-toggle-floating ()
   "Toggle the current window between floating and non-floating states."
diff --git a/exwm-input.el b/exwm-input.el
index 293fd670478f..a19331431dc2 100644
--- a/exwm-input.el
+++ b/exwm-input.el
@@ -81,49 +81,44 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
 
 (defvar exwm-input--focus-id xcb:Window:None
   "The window that is theoretically focused.")
-(defvar exwm-input--focus-lock nil
-  "Non-nil when input focus should stay unchanged.")
 
 (defun exwm-input--update-focus ()
   "Update input focus."
-  (unless exwm-input--focus-lock
-    (setq exwm-input--focus-lock t)
-    (when (and (frame-parameter nil 'exwm-window-id) ;e.g. emacsclient frame
-               (eq (current-buffer) (window-buffer))) ;e.g. `with-temp-buffer'
-      (if (eq major-mode 'exwm-mode)
-          (progn (exwm--log "Set focus ID to #x%x" exwm--id)
-                 (setq exwm-input--focus-id exwm--id)
-                 (when exwm--floating-frame
-                   (if (eq (selected-frame) exwm--floating-frame)
-                       ;; Cancel the possible input focus redirection
-                       (progn
-                         (exwm--log "Cancel input focus redirection on %s"
-                                    exwm--floating-frame)
-                         (redirect-frame-focus exwm--floating-frame nil))
-                     ;; Focus the floating frame
-                     (exwm--log "Focus on floating frame %s"
-                                exwm--floating-frame)
-                     (x-focus-frame exwm--floating-frame)))
-                 ;; Finally focus the window
-                 (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)))
+  (when (and (frame-parameter nil 'exwm-window-id) ;e.g. emacsclient frame
+             (eq (current-buffer) (window-buffer))) ;e.g. `with-temp-buffer'
+    (exwm--log "EXWM-INPUT--UPDATE-FOCUS")
+    (if (eq major-mode 'exwm-mode)
+        (progn (exwm--log "Set focus ID to #x%x" exwm--id)
+               (setq exwm-input--focus-id exwm--id)
+               (when exwm--floating-frame
+                 (if (eq (selected-frame) exwm--floating-frame)
+                     ;; Cancel the possible input focus redirection
+                     (progn
+                       (exwm--log "Cancel input focus redirection on %s"
+                                  exwm--floating-frame)
+                       (redirect-frame-focus exwm--floating-frame nil))
+                   ;; Focus the floating frame
+                   (exwm--log "Focus on floating frame %s"
+                              exwm--floating-frame)
+                   (x-focus-frame exwm--floating-frame)))
+               ;; Finally focus the window
+               (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 (and buffer (eq (selected-frame) exwm-workspace--current))
+          (with-current-buffer buffer
+            (exwm--log "Set focus ID to #x%x" xcb:Window:None)
+            (setq exwm-input--focus-id xcb:Window:None)
+            (if exwm--floating-frame
+                (unless (active-minibuffer-window)
+                  ;; Redirect input focus to the workspace frame
+                  (exwm--log "Redirect input focus (%s => %s)"
+                             exwm--floating-frame exwm-workspace--current)
+                  (redirect-frame-focus exwm--floating-frame
+                                        exwm-workspace--current))
+              ;; Focus the workspace frame
+              (exwm--log "Focus on workspace %s" exwm-workspace--current)
+              (x-focus-frame exwm-workspace--current))))))))
 
 (defun exwm-input--finish-key-sequence ()
   "Mark the end of a key sequence (with the aid of `pre-command-hook')."
diff --git a/exwm-manage.el b/exwm-manage.el
index 9d9860789874..79cff221e0bf 100644
--- a/exwm-manage.el
+++ b/exwm-manage.el
@@ -45,7 +45,6 @@ corresponding buffer.")
 (defun exwm-manage--manage-window (id)
   "Manage window ID."
   (exwm--log "Try to manage #x%x" id)
-  (setq exwm-input--focus-lock t)
   (catch 'return
     ;; Ensure it's not managed
     (when (assoc id exwm--id-buffer-alist)
@@ -136,10 +135,8 @@ corresponding buffer.")
         (exwm-floating--unset-floating id))
       (exwm-input-grab-keyboard id)
       (exwm-workspace--update-switch-history)
-      (setq exwm-input--focus-lock nil) ;unlocked in advance
       (with-current-buffer (exwm--id->buffer id)
-        (run-hooks 'exwm-manage-finish-hook))))
-  (setq exwm-input--focus-lock nil))
+        (run-hooks 'exwm-manage-finish-hook)))))
 
 (defun exwm-manage--unmanage-window (id &optional withdraw-only)
   "Unmanage window ID."
diff --git a/exwm-workspace.el b/exwm-workspace.el
index 148ff36c5955..bcac91702317 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -90,7 +90,6 @@
 
 (defvar exwm-workspace--current nil "Current active workspace.")
 (defvar exwm-workspace-current-index 0 "Index of current active workspace.")
-(defvar exwm-workspace--switch-lock nil "Non-nil to prevent workspace switch.")
 
 (defun exwm-workspace-switch (index &optional force)
   "Switch to workspace INDEX. Query for INDEX if it's not specified.
@@ -107,8 +106,7 @@ The optional FORCE option is for internal use only."
                    `(exwm-workspace--switch-history
                      . ,(1+ exwm-workspace-current-index)))))
         (cl-position idx exwm-workspace--switch-history :test 'equal)))))
-  (unless (or exwm-workspace--switch-lock (not index))
-    (setq exwm-workspace--switch-lock t)
+  (when index
     (unless (and (<= 0 index) (< index exwm-workspace-number))
       (user-error "[EXWM] Workspace index out of range: %d" index))
     (when (or force (/= exwm-workspace-current-index index))
@@ -145,17 +143,15 @@ The optional FORCE option is for internal use only."
         (xcb:+request exwm--connection
             (make-instance 'xcb:ewmh:set-_NET_CURRENT_DESKTOP
                            :window exwm--root :data index))
-        (xcb:flush exwm--connection)))
-    (setq exwm-workspace--switch-lock nil)))
+        (xcb:flush exwm--connection)))))
 
 (defun exwm-workspace--on-focus-in ()
   "Fix unexpected frame switch."
-  (unless exwm-workspace--switch-lock
-    (let ((index (cl-position (selected-frame) exwm-workspace--list)))
-      (exwm--log "Focus on workspace %s" index)
-      (when (and index (/= index exwm-workspace-current-index))
-        (exwm--log "Workspace was switched unexpectedly")
-        (exwm-workspace-switch index)))))
+  (let ((index (cl-position (selected-frame) exwm-workspace--list)))
+    (exwm--log "Focus on workspace %s" index)
+    (when (and index (/= index exwm-workspace-current-index))
+      (exwm--log "Workspace was switched unexpectedly")
+      (exwm-workspace-switch index))))
 
 (defun exwm-workspace-move-window (index &optional id)
   "Move window ID to workspace INDEX."