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)
This commit is contained in:
Chris Feng 2015-08-11 09:18:21 +08:00
parent 24b964bb4a
commit b755296f54
4 changed files with 45 additions and 61 deletions

View file

@ -39,7 +39,6 @@
(defun exwm-floating--set-floating (id) (defun exwm-floating--set-floating (id)
"Make window ID floating." "Make window ID floating."
(interactive) (interactive)
(setq exwm-input--focus-lock t)
(when (get-buffer-window (exwm--id->buffer id)) ;window in non-floating state (when (get-buffer-window (exwm--id->buffer id)) ;window in non-floating state
(set-window-buffer (selected-window) (other-buffer))) ;hide it first (set-window-buffer (selected-window) (other-buffer))) ;hide it first
(let* ((original-frame (let* ((original-frame
@ -167,13 +166,11 @@
;; FIXME: other conditions? ;; FIXME: other conditions?
(unless (memq xcb:Atom:_NET_WM_WINDOW_TYPE_UTILITY exwm-window-type) (unless (memq xcb:Atom:_NET_WM_WINDOW_TYPE_UTILITY exwm-window-type)
(x-focus-frame exwm--floating-frame) (x-focus-frame exwm--floating-frame)
(exwm-input--set-focus id))) (exwm-input--set-focus id)))))
(setq exwm-input--focus-lock nil)))
(defun exwm-floating--unset-floating (id) (defun exwm-floating--unset-floating (id)
"Make window ID non-floating." "Make window ID non-floating."
(interactive) (interactive)
(setq exwm-input--focus-lock t)
(let ((buffer (exwm--id->buffer id))) (let ((buffer (exwm--id->buffer id)))
;; Reparent to workspace frame ;; Reparent to workspace frame
(xcb:+request exwm--connection (xcb:+request exwm--connection
@ -201,8 +198,7 @@
exwm--frame exwm-workspace--current)) exwm--frame exwm-workspace--current))
(select-frame exwm-workspace--current t) (select-frame exwm-workspace--current t)
(set-window-buffer nil buffer) (set-window-buffer nil buffer)
(exwm-input--set-focus id)) (exwm-input--set-focus id)))
(setq exwm-input--focus-lock nil))
(defun exwm-floating-toggle-floating () (defun exwm-floating-toggle-floating ()
"Toggle the current window between floating and non-floating states." "Toggle the current window between floating and non-floating states."

View file

@ -81,15 +81,12 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(defvar exwm-input--focus-id xcb:Window:None (defvar exwm-input--focus-id xcb:Window:None
"The window that is theoretically focused.") "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 () (defun exwm-input--update-focus ()
"Update input 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 (when (and (frame-parameter nil 'exwm-window-id) ;e.g. emacsclient frame
(eq (current-buffer) (window-buffer))) ;e.g. `with-temp-buffer' (eq (current-buffer) (window-buffer))) ;e.g. `with-temp-buffer'
(exwm--log "EXWM-INPUT--UPDATE-FOCUS")
(if (eq major-mode 'exwm-mode) (if (eq major-mode 'exwm-mode)
(progn (exwm--log "Set focus ID to #x%x" exwm--id) (progn (exwm--log "Set focus ID to #x%x" exwm--id)
(setq exwm-input--focus-id exwm--id) (setq exwm-input--focus-id exwm--id)
@ -108,22 +105,20 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(when (exwm--id->buffer exwm-input--focus-id) (when (exwm--id->buffer exwm-input--focus-id)
(exwm-input--set-focus exwm-input--focus-id))) (exwm-input--set-focus exwm-input--focus-id)))
(let ((buffer (exwm--id->buffer exwm-input--focus-id))) (let ((buffer (exwm--id->buffer exwm-input--focus-id)))
(when buffer (when (and buffer (eq (selected-frame) exwm-workspace--current))
(with-current-buffer buffer (with-current-buffer buffer
(exwm--log "Set focus ID to #x%x" xcb:Window:None) (exwm--log "Set focus ID to #x%x" xcb:Window:None)
(setq exwm-input--focus-id xcb:Window:None) (setq exwm-input--focus-id xcb:Window:None)
(let ((frame (selected-frame)))
(if exwm--floating-frame (if exwm--floating-frame
(unless (or (eq frame exwm--floating-frame) (unless (active-minibuffer-window)
(active-minibuffer-window))
;; Redirect input focus to the workspace frame ;; Redirect input focus to the workspace frame
(exwm--log "Redirect input focus (%s => %s)" (exwm--log "Redirect input focus (%s => %s)"
exwm--floating-frame frame) exwm--floating-frame exwm-workspace--current)
(redirect-frame-focus exwm--floating-frame frame)) (redirect-frame-focus exwm--floating-frame
exwm-workspace--current))
;; Focus the workspace frame ;; Focus the workspace frame
(exwm--log "Focus on workspace %s" frame) (exwm--log "Focus on workspace %s" exwm-workspace--current)
(x-focus-frame frame)))))))) (x-focus-frame exwm-workspace--current))))))))
(setq exwm-input--focus-lock nil)))
(defun exwm-input--finish-key-sequence () (defun exwm-input--finish-key-sequence ()
"Mark the end of a key sequence (with the aid of `pre-command-hook')." "Mark the end of a key sequence (with the aid of `pre-command-hook')."

View file

@ -45,7 +45,6 @@ corresponding buffer.")
(defun exwm-manage--manage-window (id) (defun exwm-manage--manage-window (id)
"Manage window ID." "Manage window ID."
(exwm--log "Try to manage #x%x" id) (exwm--log "Try to manage #x%x" id)
(setq exwm-input--focus-lock t)
(catch 'return (catch 'return
;; Ensure it's not managed ;; Ensure it's not managed
(when (assoc id exwm--id-buffer-alist) (when (assoc id exwm--id-buffer-alist)
@ -136,10 +135,8 @@ corresponding buffer.")
(exwm-floating--unset-floating id)) (exwm-floating--unset-floating id))
(exwm-input-grab-keyboard id) (exwm-input-grab-keyboard id)
(exwm-workspace--update-switch-history) (exwm-workspace--update-switch-history)
(setq exwm-input--focus-lock nil) ;unlocked in advance
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(run-hooks 'exwm-manage-finish-hook)))) (run-hooks 'exwm-manage-finish-hook)))))
(setq exwm-input--focus-lock nil))
(defun exwm-manage--unmanage-window (id &optional withdraw-only) (defun exwm-manage--unmanage-window (id &optional withdraw-only)
"Unmanage window ID." "Unmanage window ID."

View file

@ -90,7 +90,6 @@
(defvar exwm-workspace--current nil "Current active workspace.") (defvar exwm-workspace--current nil "Current active workspace.")
(defvar exwm-workspace-current-index 0 "Index of 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) (defun exwm-workspace-switch (index &optional force)
"Switch to workspace INDEX. Query for INDEX if it's not specified. "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 `(exwm-workspace--switch-history
. ,(1+ exwm-workspace-current-index))))) . ,(1+ exwm-workspace-current-index)))))
(cl-position idx exwm-workspace--switch-history :test 'equal))))) (cl-position idx exwm-workspace--switch-history :test 'equal)))))
(unless (or exwm-workspace--switch-lock (not index)) (when index
(setq exwm-workspace--switch-lock t)
(unless (and (<= 0 index) (< index exwm-workspace-number)) (unless (and (<= 0 index) (< index exwm-workspace-number))
(user-error "[EXWM] Workspace index out of range: %d" index)) (user-error "[EXWM] Workspace index out of range: %d" index))
(when (or force (/= exwm-workspace-current-index 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 (xcb:+request exwm--connection
(make-instance 'xcb:ewmh:set-_NET_CURRENT_DESKTOP (make-instance 'xcb:ewmh:set-_NET_CURRENT_DESKTOP
:window exwm--root :data index)) :window exwm--root :data index))
(xcb:flush exwm--connection))) (xcb:flush exwm--connection)))))
(setq exwm-workspace--switch-lock nil)))
(defun exwm-workspace--on-focus-in () (defun exwm-workspace--on-focus-in ()
"Fix unexpected frame switch." "Fix unexpected frame switch."
(unless exwm-workspace--switch-lock
(let ((index (cl-position (selected-frame) exwm-workspace--list))) (let ((index (cl-position (selected-frame) exwm-workspace--list)))
(exwm--log "Focus on workspace %s" index) (exwm--log "Focus on workspace %s" index)
(when (and index (/= index exwm-workspace-current-index)) (when (and index (/= index exwm-workspace-current-index))
(exwm--log "Workspace was switched unexpectedly") (exwm--log "Workspace was switched unexpectedly")
(exwm-workspace-switch index))))) (exwm-workspace-switch index))))
(defun exwm-workspace-move-window (index &optional id) (defun exwm-workspace-move-window (index &optional id)
"Move window ID to workspace INDEX." "Move window ID to workspace INDEX."