diff --git a/exwm-input.el b/exwm-input.el index 0b5ce98..0da0558 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -73,7 +73,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.") (exwm--log "Focus on #x%x with SetInputFocus" id) (xcb:+request exwm--connection (make-instance 'xcb:SetInputFocus - :revert-to xcb:InputFocus:PointerRoot + :revert-to xcb:InputFocus:Parent :focus id :time xcb:Time:CurrentTime))) (exwm-input--set-active-window id) @@ -169,9 +169,15 @@ This value should always be overwritten.") (xcb:flush exwm--connection))) (when (eq (selected-window) window) (exwm--log "Focus on %s" window) - (select-frame-set-input-focus (window-frame window) t) - (exwm-input--set-active-window) - (xcb:flush exwm--connection))))) + (if (and (exwm-workspace--workspace-p (selected-frame)) + (not (eq (selected-frame) exwm-workspace--current))) + ;; The focus is on another workspace (e.g. it got clicked) + ;; so switch to it. + (exwm-workspace-switch (selected-frame)) + ;; The focus is still on the current workspace. + (select-frame-set-input-focus (window-frame window) t) + (exwm-input--set-active-window) + (xcb:flush exwm--connection)))))) (setq exwm-input--update-focus-lock nil)) (defun exwm-input--on-minibuffer-setup () diff --git a/exwm-workspace.el b/exwm-workspace.el index 3a4a5a8..b2a0cab 100644 --- a/exwm-workspace.el +++ b/exwm-workspace.el @@ -610,16 +610,6 @@ INDEX must not exceed the current number of workspaces." (exwm-workspace--workspace-from-frame-or-index frame-or-index) exwm-workspace--current)))) -(defun exwm-workspace--on-focus-in () - "Handle unexpected frame switch." - ;; `focus-in-hook' is run by `handle-switch-frame'. - (unless (eq this-command #'handle-switch-frame) - (let ((index (exwm-workspace--position (selected-frame)))) - (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--set-desktop (id) "Set _NET_WM_DESKTOP for X window ID." (with-current-buffer (exwm--id->buffer id) @@ -1374,8 +1364,6 @@ applied to all subsequently created X frames." ;; `minibuffer-completion-help') is not correct here. (cl-pushnew '(exwm-workspace--display-buffer) display-buffer-alist :test #'equal)) - ;; Handle unexpected frame switch. - (add-hook 'focus-in-hook #'exwm-workspace--on-focus-in) ;; Prevent `other-buffer' from selecting already displayed EXWM buffers. (modify-all-frames-parameters '((buffer-predicate . exwm-layout--other-buffer-predicate))) @@ -1413,7 +1401,6 @@ applied to all subsequently created X frames." (setq display-buffer-alist (cl-delete '(exwm-workspace--display-buffer) display-buffer-alist :test #'equal)) - (remove-hook 'focus-in-hook #'exwm-workspace--on-focus-in) (advice-remove 'x-create-frame #'exwm-workspace--x-create-frame) (remove-hook 'after-make-frame-functions #'exwm-workspace--add-frame-as-workspace)