diff options
author | Chris Feng <chris.w.feng@gmail.com> | 2017-03-04T17·10+0800 |
---|---|---|
committer | Chris Feng <chris.w.feng@gmail.com> | 2017-03-04T17·10+0800 |
commit | 52dc2616240d43b8c15e10edfdd34b1e0039a10f (patch) | |
tree | e3b20ed9a5e32155923efc5e63ce9342b94ca1a0 /exwm-workspace.el | |
parent | eebf764edd1eebcd40c71dc61ab08f8ddb9e517f (diff) |
Manually run `focus-in-hook' and `focus-out-hook'
; Since X windows are managed by EXWM, the current Emacs frame should always be considered focused logically. * exwm-workspace.el (exwm-workspace-switch): Manually run `focus-in-hook' and `focus-out-hook'. (exwm-workspace--handle-focus-in, exwm-workspace--handle-focus-out): New functions for overriding `handle-focus-in' and `handle-focus-out'. (exwm-workspace--init, exwm-workspace--exit): Override `handle-focus-in' and `handle-focus-out'
Diffstat (limited to 'exwm-workspace.el')
-rw-r--r-- | exwm-workspace.el | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el index 66865989dd22..1b904d4f11d3 100644 --- a/exwm-workspace.el +++ b/exwm-workspace.el @@ -451,6 +451,7 @@ The optional FORCE option is for internal use only." (exwm-workspace--prompt-delete-allowed t)) (exwm-workspace--prompt-for-workspace "Switch to [+/-]: "))))) (let* ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index)) + (old-frame exwm-workspace--current) (index (exwm-workspace--position frame)) (workspace (frame-parameter frame 'exwm-workspace)) (window (frame-parameter frame 'exwm-selected-window))) @@ -510,6 +511,10 @@ The optional FORCE option is for internal use only." (make-instance 'xcb:ewmh:set-_NET_CURRENT_DESKTOP :window exwm--root :data index)) (xcb:flush exwm--connection)) + (when (frame-live-p old-frame) + (with-selected-frame old-frame + (run-hooks 'focus-out-hook))) + (run-hooks 'focus-in-hook) (run-hooks 'exwm-workspace-switch-hook))) (defvar exwm-workspace-switch-create-limit 10 @@ -1348,6 +1353,14 @@ applied to all subsequently created X frames." (setf (cdr x-parameters) (append new-x-parameters (cdr x-parameters))))) +(defun exwm-workspace--handle-focus-in (_orig-func _event) + "Replacement for `handle-focus-in'." + (interactive "e")) + +(defun exwm-workspace--handle-focus-out (_orig-func _event) + "Replacement for `handle-focus-out'." + (interactive "e")) + (defun exwm-workspace--init () "Initialize workspace module." ;; Prevent unexpected exit @@ -1463,6 +1476,10 @@ applied to all subsequently created X frames." (xcb:flush exwm--connection) ;; We have to advice `x-create-frame' or every call to it would hang EXWM (advice-add 'x-create-frame :around #'exwm-workspace--x-create-frame) + ;; We have to manually handle focus-in and focus-out events for Emacs + ;; frames. + (advice-add 'handle-focus-in :around #'exwm-workspace--handle-focus-in) + (advice-add 'handle-focus-out :around #'exwm-workspace--handle-focus-out) ;; Make new frames create new workspaces. (add-hook 'after-make-frame-functions #'exwm-workspace--add-frame-as-workspace) @@ -1494,6 +1511,8 @@ applied to all subsequently created X frames." (cl-delete '(exwm-workspace--display-buffer) display-buffer-alist :test #'equal)) (advice-remove 'x-create-frame #'exwm-workspace--x-create-frame) + (advice-remove 'handle-focus-in #'exwm-workspace--handle-focus-in) + (advice-remove 'handle-focus-out #'exwm-workspace--handle-focus-out) (remove-hook 'after-make-frame-functions #'exwm-workspace--add-frame-as-workspace) (remove-hook 'delete-frame-functions |