about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--exwm-workspace.el19
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