about summary refs log tree commit diff
path: root/exwm-workspace.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-workspace.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-workspace.el')
-rw-r--r--exwm-workspace.el93
1 files changed, 43 insertions, 50 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el
index d1fe6cf38161..eb7b2466bd40 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -122,22 +122,16 @@ The optional FORCE option is for internal use only."
     (unless (and (<= 0 index) (< index exwm-workspace-number))
       (user-error "[EXWM] Workspace index out of range: %d" index))
     (when (or force (/= exwm-workspace-current-index index))
-      (let ((frame (elt exwm-workspace--list index)))
+      (let* ((frame (elt exwm-workspace--list index))
+             (workspace (frame-parameter frame 'exwm-workspace)))
+        (xcb:+request exwm--connection
+            (make-instance 'xcb:ConfigureWindow
+                           :window workspace
+                           :value-mask xcb:ConfigWindow:StackMode
+                           :stack-mode xcb:StackMode:Above))
         (setq exwm-workspace--current frame
               exwm-workspace-current-index index)
-        (select-frame-set-input-focus frame)
-        ;; Move mouse when necessary
-        (let ((position (mouse-pixel-position))
-              x y w h)
-          (unless (eq frame (car position))
-            (setq x (cadr position)
-                  y (cddr position)
-                  w (frame-pixel-width frame)
-                  h (frame-pixel-height frame))
-            (when (or (> x w) (> y h))
-              (setq x (/ w 2)
-                    y (/ h 2)))
-            (set-mouse-pixel-position frame x y)))
+        (select-window (frame-selected-window frame))
         ;; Close the (possible) active minibuffer
         (when (active-minibuffer-window)
           (run-with-idle-timer 0 nil (lambda () (abort-recursive-edit))))
@@ -161,16 +155,6 @@ The optional FORCE option is for internal use only."
                            :window exwm--root :data index))
         (xcb:flush exwm--connection)))))
 
-(defun exwm-workspace--on-focus-in ()
-  "Fix unexpected frame switch."
-  ;; `focus-in-hook' is run by `handle-switch-frame'
-  (unless (eq this-command 'handle-switch-frame)
-    (let ((index (cl-position (selected-frame) exwm-workspace--list)))
-      (exwm--log "Focus on workspace %s" index)
-      (when (and index (/= index exwm-workspace-current-index))
-        (exwm--log "Workspace was switched unexpectedly")
-        (exwm-workspace-switch index)))))
-
 ;;;###autoload
 (defun exwm-workspace-move-window (index &optional id)
   "Move window ID to workspace INDEX."
@@ -204,10 +188,9 @@ The optional FORCE option is for internal use only."
             (progn
               (xcb:+request exwm--connection
                   (make-instance 'xcb:ReparentWindow
-                                 :window (frame-parameter exwm--floating-frame
-                                                          'exwm-outer-id)
-                                 :parent (frame-parameter frame
-                                                          'exwm-window-id)
+                                 :window exwm--container
+                                 :parent
+                                 (frame-parameter frame 'exwm-workspace)
                                  :x 0 :y 0))
               (xcb:flush exwm--connection))
           ;; Move the window itself
@@ -222,8 +205,10 @@ The optional FORCE option is for internal use only."
           (exwm-layout--hide id)
           (xcb:+request exwm--connection
               (make-instance 'xcb:ReparentWindow
-                             :window id
-                             :parent (frame-parameter frame 'exwm-window-id)
+                             ;; (current-buffer) is changed.
+                             :window (with-current-buffer (exwm--id->buffer id)
+                                       exwm--container)
+                             :parent (frame-parameter frame 'exwm-workspace)
                              :x 0 :y 0))
           (xcb:flush exwm--connection)
           (set-window-buffer (frame-selected-window frame)
@@ -303,50 +288,58 @@ The optional FORCE option is for internal use only."
     (set-frame-parameter (car exwm-workspace--list) 'client nil))
   ;; Create remaining frames
   (dotimes (_ (1- exwm-workspace-number))
-    (nconc exwm-workspace--list
-           (list (make-frame '((window-system . x)
-                               (visibility . nil))))))
+    (nconc exwm-workspace--list (list (make-frame '((window-system . x))))))
   ;; Configure workspaces
   (dolist (i exwm-workspace--list)
-    (let ((window-id (string-to-number (frame-parameter i 'window-id)))
-          (outer-id (string-to-number (frame-parameter i 'outer-window-id))))
+    (let ((outer-id (string-to-number (frame-parameter i 'outer-window-id)))
+          (workspace (xcb:generate-id exwm--connection)))
       ;; Save window IDs
-      (set-frame-parameter i 'exwm-window-id window-id)
       (set-frame-parameter i 'exwm-outer-id outer-id)
+      (set-frame-parameter i 'exwm-workspace workspace)
       ;; Set OverrideRedirect on all frames
       (xcb:+request exwm--connection
           (make-instance 'xcb:ChangeWindowAttributes
                          :window outer-id :value-mask xcb:CW:OverrideRedirect
                          :override-redirect 1))
-      ;; Select events on all virtual roots
       (xcb:+request exwm--connection
-          (make-instance 'xcb:ChangeWindowAttributes
-                         :window window-id :value-mask xcb:CW:EventMask
-                         :event-mask xcb:EventMask:SubstructureRedirect))))
+          (make-instance 'xcb:CreateWindow
+                         :depth 0 :wid workspace :parent exwm--root
+                         :x 0 :y 0
+                         :width (x-display-pixel-width)
+                         :height (x-display-pixel-height)
+                         :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 workspace
+                          :data
+                          (format "EXWM workspace %d"
+                                  (cl-position i exwm-workspace--list)))))
+      (xcb:+request exwm--connection
+          (make-instance 'xcb:ReparentWindow
+                         :window outer-id :parent workspace :x 0 :y 0))
+      (xcb:+request exwm--connection
+          (make-instance 'xcb:MapWindow :window workspace))))
   (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 delay making the frame visible until the
-  ;; override-redirect flag has been set.
-  (select-frame-set-input-focus (car exwm-workspace--list))
-  (dolist (i exwm-workspace--list)
-    (set-frame-parameter i 'visibility t)
-    (lower-frame i))
   ;; Delay making the workspaces fullscreen until Emacs becomes idle
   (run-with-idle-timer 0 nil
                        (lambda ()
                          (dolist (i exwm-workspace--list)
                            (set-frame-parameter i 'fullscreen 'fullboth))))
-  (raise-frame (car exwm-workspace--list))
-  ;; Handle unexpected frame switch
-  (add-hook 'focus-in-hook #'exwm-workspace--on-focus-in)
   ;; Set _NET_VIRTUAL_ROOTS
   (xcb:+request exwm--connection
       (make-instance 'xcb:ewmh:set-_NET_VIRTUAL_ROOTS
                      :window exwm--root
                      :data (vconcat (mapcar
                                      (lambda (i)
-                                       (frame-parameter i 'exwm-window-id))
+                                       (frame-parameter i 'exwm-workspace))
                                      exwm-workspace--list))))
   ;; Switch to the first workspace
   (exwm-workspace-switch 0 t))