about summary refs log tree commit diff
path: root/exwm-manage.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2016-02-03T04·12+0800
committerChris Feng <chris.w.feng@gmail.com>2016-02-03T04·12+0800
commit9c95c03e18f6d5cf78bcd54bf00f8055a3863336 (patch)
tree1733a55d18719fd8eba91055cacfd6de5c63bcad /exwm-manage.el
parent07921a3731c3b951d7d5ecc35b808c40d1d15bd4 (diff)
Rework the X windows hierarchy model
This commit add workspace and X window containers support to avoid using
Emacs frames as the parents of X windows.  This should make it easier to
set input focus.

* exwm-core.el (exwm--container, exwm--floating-frame-position): New file
local variables.
(exwm--floating-frame-geometry): Removed file local variable.
* exwm-floating.el (exwm-floating--set-floating)
(exwm-floating--unset-floating, exwm-floating--do-moveresize)
(exwm-floating-move): Use container.
(exwm-floating--fit-frame-to-window): No longer adjust stacking order.
(exwm-floating--fit-frame-to-window): The first member is changed to
buffer.
(exwm-floating--start-moveresize): Use container.  Correctly set input
focus.
* exwm-input.el (exwm-input--redirected, exwm-input--on-focus-in): Removed.
(exwm-input--on-buffer-list-update): Remove the restriction on floating
frames which is no longer valid.
(exwm-input--update-focus): Adjust stacking order.
(exwm-input--on-minibuffer-setup): New function for setting focus on the
Emacs frame when entering minibuffer.
(exwm-input--on-KeyPress-line-mode): No longer compensate FocusOut event.
(exwm-input--grab-keyboard, exwm-input--release-keyboard): Local keys are
now grabbed on the X window container.
(exwm-input--init): Add `exwm-input--on-minibuffer-setup' to
`minibuffer-setup-hook'.
* exwm-layout.el (exwm-layout--resize-container): New function to
resize/reposition both the X window and its container.
(exwm-layout--show, exwm-layout--hide): Use container.
(exwm-layout-set-fullscreen): Use container.  No longer save width and
height.
(exwm-layout-unset-fullscreen, exwm-layout--set-frame-fullscreen): Use
container.
(exwm-layout--refresh): Update a frame parameter.  Remove dead code.
* exwm-manage.el (exwm-manage--manage-window): Reparent unmanaged X windows
to the workspace.  Create X window container as the parent of the X window.
(exwm-manage--unmanage-window): Unmap/destroy container when appropriate.
Use the position of container.
(exwm-manage--unmanage-window): Destroy the container.
* exwm-randr.el (exwm-randr--refresh): Resize workspace using container.
* exwm-workspace.el (exwm-workspace-switch): Raise workspace.
Correctly set input focus.
(exwm-workspace--on-focus-in): Removed.
(exwm-workspace-move-window): Reparent to workspace container.
(exwm-workspace--init): Create workspace frames as visible.
Create workspace containers.
Remove exwm-workspace--on-focus-in from focus-in-hook.
Update _NET_VIRTUAL_ROOTS.
* exwm.el (exwm-init): No longer disable hourglass window.
Initialize workspace module before input.

* exwm-core.el (exwm--debug): New macro for setting debug forms.

* exwm-floating.el (exwm-floating--set-floating): No longer do `exwm--lock'
and `exwm--unlock' since `make-frame' is already adviced to take care of
everything.  Correctly set input focus to the newly created floating
X window.

* exwm-core.el (exwm--floating-edges): Removed file local variable.
* exwm-floating.el (exwm-floating--set-floating)
(exwm-floating--unset-floating):
* exwm-layout.el (exwm-layout--show, exwm-layout-enlarge-window):
* exwm-manage.el (exwm-manage--on-ConfigureRequest):
No longer use floating geometry.

* exwm-input.el (exwm-input--update-global-prefix-keys): Grab global keys
on workspaces containers instead of the root window (or input focus would
transfer to the workspace containing the pointer when the grab is active).
* exwm-workspace.el (exwm-workspace-switch): No longer move mouse.
Diffstat (limited to 'exwm-manage.el')
-rw-r--r--exwm-manage.el140
1 files changed, 87 insertions, 53 deletions
diff --git a/exwm-manage.el b/exwm-manage.el
index 5b562ed52f..d8f91f3517 100644
--- a/exwm-manage.el
+++ b/exwm-manage.el
@@ -120,7 +120,7 @@ corresponding buffer.")
                 (make-instance 'xcb:ReparentWindow
                                :window id
                                :parent (frame-parameter exwm-workspace--current
-                                                        'exwm-window-id)
+                                                        'exwm-workspace)
                                :x x :y y)))
           ;; Center window of type _NET_WM_WINDOW_TYPE_SPLASH
           (when (memq xcb:Atom:_NET_WM_WINDOW_TYPE_SPLASH exwm-window-type)
@@ -145,10 +145,34 @@ corresponding buffer.")
         (throw 'return 'ignored))
       ;; Manage the window
       (exwm--log "Manage #x%x" id)
+      ;; Create a new container as the parent of this X window
+      (setq exwm--container (xcb:generate-id exwm--connection))
+      (xcb:+request exwm--connection
+          (make-instance 'xcb:CreateWindow
+                         :depth 0 :wid exwm--container
+                         :parent (frame-parameter exwm-workspace--current
+                                                  'exwm-workspace)
+                         :x 0 :y 0 :width 1 :height 1 :border-width 0
+                         :class xcb:WindowClass:CopyFromParent
+                         :visual 0      ;CopyFromParent
+                         :value-mask (logior xcb:CW:OverrideRedirect
+                                             xcb:CW:EventMask)
+                         :override-redirect 1
+                         :event-mask xcb:EventMask:SubstructureRedirect))
+      (exwm--debug
+       (xcb:+request exwm--connection
+           (make-instance 'xcb:ewmh:set-_NET_WM_NAME
+                          :window exwm--container
+                          :data (format "EXWM container for 0x%x" id))))
+      (xcb:+request exwm--connection
+          (make-instance 'xcb:ReparentWindow
+                         :window id :parent exwm--container :x 0 :y 0))
       (xcb:+request exwm--connection    ;remove border
           (make-instance 'xcb:ConfigureWindow
                          :window id :value-mask xcb:ConfigWindow:BorderWidth
                          :border-width 0))
+      ;; (xcb:+request exwm--connection    ;map the window
+      ;;     (make-instance 'xcb:MapWindow :window id))
       (dolist (button       ;grab buttons to set focus / move / resize
                (list xcb:ButtonIndex:1 xcb:ButtonIndex:2 xcb:ButtonIndex:3))
         (xcb:+request-checked+request-check exwm--connection
@@ -190,9 +214,8 @@ corresponding buffer.")
     (xcb:flush exwm--connection)
     (when (buffer-live-p buffer)
       (with-current-buffer buffer
-        (when exwm--floating-frame
-          (make-frame-invisible exwm--floating-frame)
-          (redisplay))
+        (xcb:+request exwm--connection
+            (make-instance 'xcb:UnmapWindow :window exwm--container))
         (setq exwm-workspace--switch-history-outdated t)
         ;;
         (when withdraw-only
@@ -207,9 +230,7 @@ corresponding buffer.")
               (setq geometry-parent
                     (xcb:+request-unchecked+reply exwm--connection
                         (make-instance 'xcb:GetGeometry
-                                       :drawable
-                                       (frame-parameter exwm--floating-frame
-                                                        'exwm-outer-id)))
+                                       :drawable exwm--container))
                     geometry (xcb:+request-unchecked+reply exwm--connection
                                  (make-instance 'xcb:GetGeometry
                                                 :drawable id)))
@@ -227,6 +248,13 @@ corresponding buffer.")
               (make-instance 'xcb:DeleteProperty
                              :window id :property xcb:Atom:WM_STATE))
           (xcb:flush exwm--connection))
+        ;; Destroy the container (it seems it has to be delayed).
+        (run-with-idle-timer 0 nil
+                             `(lambda ()
+                                (xcb:+request exwm--connection
+                                    ,(make-instance 'xcb:DestroyWindow
+                                                    :window exwm--container))
+                                (xcb:flush exwm--connection)))
         (let ((kill-buffer-query-functions nil)
               (floating exwm--floating-frame))
           (kill-buffer)
@@ -252,55 +280,62 @@ corresponding buffer.")
 ;;;###autoload
 (defun exwm-manage--close-window (id &optional buffer)
   "Close window ID in a proper way."
-  (catch 'return
-    (unless (exwm--id->buffer id)
-      (throw 'return t))
-    (unless buffer (setq buffer (exwm--id->buffer id)))
-    ;; Destroy the client window if it does not support WM_DELETE_WINDOW
-    (unless (and (buffer-live-p buffer)
-                 (with-current-buffer buffer
-                   (memq xcb:Atom:WM_DELETE_WINDOW exwm--protocols)))
-      (xcb:+request exwm--connection
-          (make-instance 'xcb:DestroyWindow :window id))
-      (xcb:flush exwm--connection)
-      (throw 'return nil))
-    ;; Try to close the window with WM_DELETE_WINDOW client message
-    (xcb:+request exwm--connection
-        (make-instance 'xcb:icccm:SendEvent
-                       :destination id
-                       :event (xcb:marshal
-                               (make-instance 'xcb:icccm:WM_DELETE_WINDOW
-                                              :window id)
-                               exwm--connection)))
-    (xcb:flush exwm--connection)
-    ;; Try to determine if the client stop responding
-    (with-current-buffer buffer
-      (unless (memq xcb:Atom:_NET_WM_PING exwm--protocols)
-        ;; Ensure it's dead
-        (run-with-timer exwm-manage-ping-timeout nil
-                        `(lambda () (exwm-manage--kill-client ,id)))
+  (let (container)
+    (catch 'return
+      (unless (exwm--id->buffer id)
+        (throw 'return t))
+      (unless buffer (setq buffer (exwm--id->buffer id)))
+      (when (buffer-live-p buffer)
+        (setq container exwm--container))
+      ;; Destroy the client window if it does not support WM_DELETE_WINDOW
+      (unless (and (buffer-live-p buffer)
+                   (with-current-buffer buffer
+                     (memq xcb:Atom:WM_DELETE_WINDOW exwm--protocols)))
+        (xcb:+request exwm--connection
+            (make-instance 'xcb:DestroyWindow :window id))
+        (xcb:flush exwm--connection)
         (throw 'return nil))
-      (setq exwm-manage--ping-lock t)
+      ;; Try to close the window with WM_DELETE_WINDOW client message
       (xcb:+request exwm--connection
-          (make-instance 'xcb:SendEvent
-                         :propagate 0 :destination id
-                         :event-mask xcb:EventMask:NoEvent
+          (make-instance 'xcb:icccm:SendEvent
+                         :destination id
                          :event (xcb:marshal
-                                 (make-instance 'xcb:ewmh:_NET_WM_PING
-                                                :window id :timestamp 0
-                                                :client-window id)
+                                 (make-instance 'xcb:icccm:WM_DELETE_WINDOW
+                                                :window id)
                                  exwm--connection)))
       (xcb:flush exwm--connection)
-      (with-timeout (exwm-manage-ping-timeout
-                     (if (yes-or-no-p (format "`%s' is not responding. \
+      ;; Try to determine if the client stop responding
+      (with-current-buffer buffer
+        (unless (memq xcb:Atom:_NET_WM_PING exwm--protocols)
+          ;; Ensure it's dead
+          (run-with-timer exwm-manage-ping-timeout nil
+                          `(lambda () (exwm-manage--kill-client ,id)))
+          (throw 'return nil))
+        (setq exwm-manage--ping-lock t)
+        (xcb:+request exwm--connection
+            (make-instance 'xcb:SendEvent
+                           :propagate 0 :destination id
+                           :event-mask xcb:EventMask:NoEvent
+                           :event (xcb:marshal
+                                   (make-instance 'xcb:ewmh:_NET_WM_PING
+                                                  :window id :timestamp 0
+                                                  :client-window id)
+                                   exwm--connection)))
+        (xcb:flush exwm--connection)
+        (with-timeout (exwm-manage-ping-timeout
+                       (if (yes-or-no-p (format "`%s' is not responding. \
 Would you like to kill it? "
-                                              (buffer-name buffer)))
-                         (progn (exwm-manage--kill-client id)
-                                (throw 'return nil))
-                       (throw 'return nil)))
-        (while (and exwm-manage--ping-lock
-                    (exwm--id->buffer id)) ;may have been destroyed
-          (accept-process-output nil 0.1))))))
+                                                (buffer-name buffer)))
+                           (progn (exwm-manage--kill-client id)
+                                  (throw 'return nil))
+                         (throw 'return nil)))
+          (while (and exwm-manage--ping-lock
+                      (exwm--id->buffer id)) ;may have been destroyed
+            (accept-process-output nil 0.1)))))
+    ;; Finally destroy the container
+    (xcb:+request exwm--connection
+        (make-instance 'xcb:DestroyWindow :window container))
+    (xcb:flush exwm--connection)))
 
 (defun exwm-manage--kill-client (&optional id)
   "Kill an X client."
@@ -338,9 +373,8 @@ Would you like to kill it? "
                       (list 0 0
                             (frame-pixel-width exwm-workspace--current)
                             (frame-pixel-height exwm-workspace--current))
-                    (or exwm--floating-edges
-                        (window-inside-absolute-pixel-edges
-                         (get-buffer-window buffer t)))))
+                    (window-inside-absolute-pixel-edges
+                     (get-buffer-window buffer t))))
             (exwm--log "Reply with ConfigureNotify (edges): %s" edges)
             (xcb:+request exwm--connection
                 (make-instance 'xcb:SendEvent