Use the 'exwm-randr-output' frame parameter to determine the output

* exwm-randr.el (exwm-randr--refresh): Always set the name of primary
output.

* exwm-workspace.el (exwm-workspace-switch)
(exwm-workspace-move-window): Use 'exwm-randr-output' frame parameter
to check if two frames are on the same output.
This commit is contained in:
Chris Feng 2018-02-20 22:17:22 +08:00
parent bfa35c0e38
commit c821f76dfe
2 changed files with 35 additions and 42 deletions

View file

@ -89,7 +89,7 @@ the first one in result being the primary output."
(defun exwm-randr--refresh () (defun exwm-randr--refresh ()
"Refresh workspaces according to the updated RandR info." "Refresh workspaces according to the updated RandR info."
(let (output-name geometry output-plist default-geometry) (let (output-name geometry output-plist primary-output default-geometry)
;; Query all outputs ;; Query all outputs
(with-slots (config-timestamp outputs) (with-slots (config-timestamp outputs)
(xcb:+request-unchecked+reply exwm--connection (xcb:+request-unchecked+reply exwm--connection
@ -115,8 +115,9 @@ the first one in result being the primary output."
:x x :y y :x x :y y
:width width :height height) :width width :height height)
output-plist (plist-put output-plist output-name geometry)) output-plist (plist-put output-plist output-name geometry))
(unless default-geometry ;assume the first output as primary (unless primary-output
(setq default-geometry geometry))))))) (setq primary-output output-name
default-geometry geometry)))))))
(exwm--log "(randr) outputs: %s" output-plist) (exwm--log "(randr) outputs: %s" output-plist)
(when output-plist (when output-plist
(when exwm-workspace--fullscreen-frame-count (when exwm-workspace--fullscreen-frame-count
@ -128,7 +129,7 @@ the first one in result being the primary output."
(frame (elt exwm-workspace--list i))) (frame (elt exwm-workspace--list i)))
(unless geometry (unless geometry
(setq geometry default-geometry (setq geometry default-geometry
output nil)) output primary-output))
(set-frame-parameter frame 'exwm-randr-output output) (set-frame-parameter frame 'exwm-randr-output output)
(set-frame-parameter frame 'exwm-geometry geometry))) (set-frame-parameter frame 'exwm-geometry geometry)))
;; Update workareas. ;; Update workareas.

View file

@ -528,18 +528,14 @@ for internal use only."
;; Set a default minibuffer frame. ;; Set a default minibuffer frame.
(setq default-minibuffer-frame frame)) (setq default-minibuffer-frame frame))
;; Show/Hide X windows. ;; Show/Hide X windows.
(let ((hide-x-windows-on-old-frame (let ((hide-old-workspace
(with-slots ((x1 x) (and old-frame
(y1 y)) (eq (frame-parameter old-frame 'exwm-randr-output)
(exwm-workspace--get-geometry frame) (frame-parameter frame 'exwm-randr-output)))))
(with-slots ((x2 x)
(y2 y))
(exwm-workspace--get-geometry old-frame)
(and (= x1 x2) (= y1 y2))))))
(dolist (i exwm--id-buffer-alist) (dolist (i exwm--id-buffer-alist)
(with-current-buffer (cdr i) (with-current-buffer (cdr i)
(if (eq old-frame exwm--frame) (if (eq old-frame exwm--frame)
(when hide-x-windows-on-old-frame (when hide-old-workspace
(exwm-layout--hide exwm--id)) (exwm-layout--hide exwm--id))
(when (eq frame exwm--frame) (when (eq frame exwm--frame)
(let ((window (get-buffer-window nil t))) (let ((window (get-buffer-window nil t)))
@ -703,7 +699,7 @@ INDEX must not exceed the current number of workspaces."
(exwm-workspace--prompt-delete-allowed t)) (exwm-workspace--prompt-delete-allowed t))
(exwm-workspace--prompt-for-workspace "Move to [+/-]: ")))) (exwm-workspace--prompt-for-workspace "Move to [+/-]: "))))
(let ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index)) (let ((frame (exwm-workspace--workspace-from-frame-or-index frame-or-index))
x-old y-old x-new y-new should-hide old-frame container) should-hide old-frame container)
(unless id (setq id (exwm--buffer->id (window-buffer)))) (unless id (setq id (exwm--buffer->id (window-buffer))))
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(unless (eq exwm--frame frame) (unless (eq exwm--frame frame)
@ -715,32 +711,22 @@ INDEX must not exceed the current number of workspaces."
(concat " " name))))) (concat " " name)))))
(setq old-frame exwm--frame (setq old-frame exwm--frame
exwm--frame frame) exwm--frame frame)
;; Save the positions of new & old frames. (if (eq (frame-parameter old-frame 'exwm-randr-output)
(with-slots ((x1 x) (frame-parameter frame 'exwm-randr-output))
(y1 y))
(exwm-workspace--get-geometry old-frame)
(with-slots ((x2 x)
(y2 y))
(exwm-workspace--get-geometry frame)
(setq x-old x1
y-old y1
x-new x2
y-new y2)))
(if (and (= x-old x-new)
(= y-old y-new))
;; Switch to a workspace on the same output. ;; Switch to a workspace on the same output.
(setq should-hide t) (setq should-hide t)
;; Check if this frame has the largest timestamp of that output. ;; Check if this frame has the largest timestamp of that output.
(let ((timestamp (frame-parameter frame 'exwm-timestamp)) (let* ((timestamp (frame-parameter frame 'exwm-timestamp))
(output (frame-parameter frame 'exwm-randr-output))
(timestamp-active (timestamp-active
(apply #'max (apply #'max
(mapcar (lambda (w) (mapcar
(with-slots (x y) (lambda (w)
(exwm-workspace--get-geometry w) (or (when (eq output
(if (and (= x x-new) (frame-parameter w
(= y y-new)) 'exwm-randr-output))
(frame-parameter w 'exwm-timestamp) (frame-parameter w 'exwm-timestamp))
-1))) -1))
exwm-workspace--list)))) exwm-workspace--list))))
(when (< timestamp timestamp-active) (when (< timestamp timestamp-active)
;; Switch to a workspace not active on another output. ;; Switch to a workspace not active on another output.
@ -762,14 +748,20 @@ INDEX must not exceed the current number of workspaces."
;; Floating. ;; Floating.
(setq container (frame-parameter exwm--floating-frame (setq container (frame-parameter exwm--floating-frame
'exwm-container)) 'exwm-container))
(unless (and (= x-old x-new) (unless (eq (frame-parameter old-frame 'exwm-randr-output)
(= y-old y-new)) (frame-parameter frame 'exwm-randr-output))
(with-slots (x y) (with-slots (x y)
(xcb:+request-unchecked+reply exwm--connection (xcb:+request-unchecked+reply exwm--connection
(make-instance 'xcb:GetGeometry (make-instance 'xcb:GetGeometry
:drawable container)) :drawable container))
(setq x (+ x (- x-new x-old)) (with-slots ((x1 x)
y (+ y (- y-new y-old))) (y1 y))
(exwm-workspace--get-geometry old-frame)
(with-slots ((x2 x)
(y2 y))
(exwm-workspace--get-geometry frame)
(setq x (+ x (- x2 x1))
y (+ y (- y2 y1)))))
(exwm--set-geometry id x y nil nil) (exwm--set-geometry id x y nil nil)
(exwm--set-geometry container x y nil nil))) (exwm--set-geometry container x y nil nil)))
(if (exwm-workspace--minibuffer-own-frame-p) (if (exwm-workspace--minibuffer-own-frame-p)