about summary refs log tree commit diff
path: root/exwm.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2016-05-23T11·13+0800
committerChris Feng <chris.w.feng@gmail.com>2016-05-23T11·13+0800
commit1b2ae3749e98b83f94cc19cef8830ce823c63367 (patch)
treec12da35ab83e429eb5ff1980778181e55c43fd8c /exwm.el
parentdc0c0f5131296f31b02019d1d928a0a17f085818 (diff)
Add cleanup codes for Emacs daemon
* exwm-floating.el (exwm-floating--exit):
* exwm-input.el (exwm-input--exit):
* exwm-layout.el (exwm-layout--exit):
* exwm-manage.el (exwm-manage--exit):
* exwm-randr.el (exwm-randr--exit):
* exwm-systemtray.el (exwm-systemtray--exit):
* exwm-workspace.el (exwm-workspace--exit):
New functions for cleanup each module.

* exwm-input.el (exwm-input--on-pre-command, exwm-input--on-post-command)
(exwm-input--init): Name lambda functions.

* exwm-layout.el (exwm-layout--timer, exwm-layout--init): Save timer.

* exwm-randr.el (exwm-randr-enable): Register the cleanup function.

* exwm-systemtray.el (exwm-systemtray--init): Force refresh atoms in XEMBED
and system tray protocols.
(exwm-systemtray-enable): Register the cleanup function.

* exwm-workspace.el (exwm-workspace--client): Save the server process.
(exwm-workspace--confirm-kill-emacs): Add emacsclient-specific
cleanup codes.
(exwm-workspace--timer): Save the timer.
(exwm-workspace--init): Save the server process and timer;
fix problems with emacsclient frames.

* exwm.el (exwm-init): Always select the newly created frame;
force refresh ICCCM & EWMH atoms.
(exwm-exit-hook): New hook for holding cleanup codes.
(exwm--exit): Run `exwm-exit-hook', execute cleanup codes for
each module and reset the environment.
Diffstat (limited to 'exwm.el')
-rw-r--r--exwm.el30
1 files changed, 27 insertions, 3 deletions
diff --git a/exwm.el b/exwm.el
index c9dc6cd0ebb0..0bc27d71d80a 100644
--- a/exwm.el
+++ b/exwm.el
@@ -477,7 +477,11 @@
 
 (defun exwm-init (&optional frame)
   "Initialize EXWM."
-  (if (not (eq 'x (framep (or frame (selected-frame)))))
+  (if frame
+      ;; The frame might not be selected if it's created by emacslicnet.
+      (select-frame-set-input-focus frame)
+    (setq frame (selected-frame)))
+  (if (not (eq 'x (framep frame)))
       (exwm--log "Not running under X environment")
     (unless exwm--connection
       (exwm-enable 'undo)               ;never initialize again
@@ -499,8 +503,8 @@
         ;; Disable some features not working well with EXWM
         (setq use-dialog-box nil)
         ;; Initialize ICCCM/EWMH support
-        ;; (xcb:icccm:init exwm--connection)
-        (xcb:ewmh:init exwm--connection)
+        (xcb:icccm:init exwm--connection t)
+        (xcb:ewmh:init exwm--connection t)
         (exwm--lock)
         (exwm--init-icccm-ewmh)
         (exwm-layout--init)
@@ -514,6 +518,26 @@
         (exwm-manage--scan)
         (run-hooks 'exwm-init-hook)))))
 
+(defvar exwm-exit-hook nil
+  "Normal hook run just before EXWM is about to exit.
+
+This hook is only run when EXWM is started with emacsclient.")
+
+(defun exwm--exit ()
+  "Exit EXWM."
+  (run-hooks 'exwm-exit-hook)
+  ;; Exit modules.
+  (exwm-input--exit)
+  (exwm-workspace--exit)
+  (exwm-manage--exit)
+  (exwm-floating--exit)
+  (exwm-layout--exit)
+  ;; Reset several import variables.
+  (setq exwm--connection nil
+        exwm--root nil
+        exwm--id-buffer-alist nil)
+  (exwm-enable))
+
 (defvar exwm-blocking-subrs '(x-file-dialog x-popup-dialog x-select-font)
   "Subrs (primitives) that would normally block EXWM.")