about summary refs log tree commit diff
path: root/exwm-layout.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2018-12-30T00·00+0000
committerChris Feng <chris.w.feng@gmail.com>2018-12-30T00·00+0000
commit404c94568d581fb66fca5e2524c908d631883884 (patch)
tree0ce1900d36125f34871069cea8ba1564bc2d70d5 /exwm-layout.el
parent2efd7495d9755e12a611dbf27dac6057287cd590 (diff)
Automatically iconify floating X windows
* exwm-layout.el (exwm-layout-auto-iconify): New user option to
specify whether to automatically iconify X windows.
(exwm-layout--auto-iconify): Automatically iconify floating X windows
when its main X window (if any) is iconified.
(exwm-layout--show, exwm-layout--hide): Use it.
Diffstat (limited to 'exwm-layout.el')
-rw-r--r--exwm-layout.el22
1 files changed, 21 insertions, 1 deletions
diff --git a/exwm-layout.el b/exwm-layout.el
index 8b2fc2ae0d2f..6c9f0ff7d824 100644
--- a/exwm-layout.el
+++ b/exwm-layout.el
@@ -32,6 +32,10 @@
   :version "25.3"
   :group 'exwm)
 
+(defcustom exwm-layout-auto-iconify t
+  "Non-nil to automatically iconify unused X windows when possible."
+  :type 'boolean)
+
 (defcustom exwm-layout-show-all-buffers nil
   "Non-nil to allow switching to buffers on other workspaces."
   :type 'boolean)
@@ -76,6 +80,20 @@
   (when (derived-mode-p 'exwm-mode)
     (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state)))
 
+(defun exwm-layout--auto-iconify ()
+  (when (and exwm-layout-auto-iconify
+             (not exwm-transient-for))
+    (let ((xwin exwm--id)
+          (state exwm-state))
+      (dolist (pair exwm--id-buffer-alist)
+        (with-current-buffer (cdr pair)
+          (when (and exwm--floating-frame
+                     (eq exwm-transient-for xwin)
+                     (not (eq exwm-state state)))
+            (if (eq state xcb:icccm:WM_STATE:NormalState)
+                (exwm-layout--refresh-floating exwm--floating-frame)
+              (exwm-layout--hide exwm--id))))))))
+
 (defun exwm-layout--show (id &optional window)
   "Show window ID exactly fit in the Emacs window WINDOW."
   (exwm--log "Show #x%x in %s" id window)
@@ -111,7 +129,8 @@
                 height height*)))
       (exwm--set-geometry id x y width height)
       (xcb:+request exwm--connection (make-instance 'xcb:MapWindow :window id))
-      (exwm-layout--set-state id xcb:icccm:WM_STATE:NormalState)))
+      (exwm-layout--set-state id xcb:icccm:WM_STATE:NormalState)
+      (exwm-layout--auto-iconify)))
   (xcb:flush exwm--connection))
 
 (defun exwm-layout--hide (id)
@@ -141,6 +160,7 @@
                          :window id :value-mask xcb:CW:EventMask
                          :event-mask exwm--client-event-mask))
       (exwm-layout--set-state id xcb:icccm:WM_STATE:IconicState)
+      (exwm-layout--auto-iconify)
       (xcb:flush exwm--connection))))
 
 ;;;###autoload