Center floating windows by default

This commit makes a floating window centered to its leading window if it has
a valid WM_TRANSIENT_FOR property set. Other it's placed at the center of the
screen.
This commit is contained in:
Chris Feng 2015-08-11 15:06:11 +08:00
parent 801185c7cc
commit 1ce18afd05
3 changed files with 26 additions and 2 deletions

View file

@ -67,6 +67,7 @@
(y (slot-value exwm--geometry 'y)) (y (slot-value exwm--geometry 'y))
(width (slot-value exwm--geometry 'width)) (width (slot-value exwm--geometry 'width))
(height (slot-value exwm--geometry 'height))) (height (slot-value exwm--geometry 'height)))
(exwm--log "Floating geometry (original): %dx%d%+d%+d" width height x y)
;; Save window IDs ;; Save window IDs
(set-frame-parameter frame 'exwm-window-id frame-id) (set-frame-parameter frame 'exwm-window-id frame-id)
(set-frame-parameter frame 'exwm-outer-id outer-id) (set-frame-parameter frame 'exwm-outer-id outer-id)
@ -102,7 +103,24 @@
(when (= 0 height) (setq height (/ display-height 2))) (when (= 0 height) (setq height (/ display-height 2)))
;; Completely outside ;; Completely outside
(when (or (> y display-height) (> 0 (+ y display-height))) (when (or (> y display-height) (> 0 (+ y display-height)))
(setq y (/ (- display-height height) 2))))) (setq y (/ (- display-height height) 2))))
;; Center floating windows
(when (and (= x 0) (= y 0))
(let ((buffer (exwm--id->buffer exwm-transient-for))
window edges)
(when (and buffer (setq window (get-buffer-window buffer)))
(setq edges (window-inside-absolute-pixel-edges window))
(unless (and (<= width (- (elt edges 2) (elt edges 0)))
(<= height (- (elt edges 3) (elt edges 1))))
(setq edges nil)))
(if edges
;; Put at the center of leading window
(setq x (/ (- (+ (elt edges 2) (elt edges 0)) width) 2)
y (/ (- (+ (elt edges 3) (elt edges 1)) height) 2))
;; Put at the center of screen
(setq x (/ (- display-width width) 2)
y (/ (- display-height height) 2))))))
(exwm--log "Floating geometry (corrected): %dx%d%+d%+d" width height x y)
;; Set OverrideRedirect on this frame ;; Set OverrideRedirect on this frame
(xcb:+request exwm--connection (xcb:+request exwm--connection
(make-instance 'xcb:ChangeWindowAttributes (make-instance 'xcb:ChangeWindowAttributes

View file

@ -86,7 +86,6 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
"Update input focus." "Update input focus."
(when (and (frame-parameter nil 'exwm-window-id) ;e.g. emacsclient frame (when (and (frame-parameter nil 'exwm-window-id) ;e.g. emacsclient frame
(eq (current-buffer) (window-buffer))) ;e.g. `with-temp-buffer' (eq (current-buffer) (window-buffer))) ;e.g. `with-temp-buffer'
(exwm--log "EXWM-INPUT--UPDATE-FOCUS")
(if (eq major-mode 'exwm-mode) (if (eq major-mode 'exwm-mode)
(progn (exwm--log "Set focus ID to #x%x" exwm--id) (progn (exwm--log "Set focus ID to #x%x" exwm--id)
(setq exwm-input--focus-id exwm--id) (setq exwm-input--focus-id exwm--id)

View file

@ -276,6 +276,8 @@ corresponding buffer.")
buffer edges) buffer edges)
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(with-slots (window x y width height border-width) obj (with-slots (window x y width height border-width) obj
(exwm--log "ConfigureRequest from #x%x @%dx%d%+d%+d, border: %d"
window width height x y border-width)
(if (setq buffer (exwm--id->buffer window)) (if (setq buffer (exwm--id->buffer window))
;; Send client message for managed windows ;; Send client message for managed windows
(with-current-buffer buffer (with-current-buffer buffer
@ -286,6 +288,7 @@ corresponding buffer.")
(or exwm--floating-edges (or exwm--floating-edges
(window-inside-absolute-pixel-edges (window-inside-absolute-pixel-edges
(get-buffer-window))))) (get-buffer-window)))))
(exwm--log "Reply with ConfigureNotify (edges): %s" edges)
(xcb:+request exwm--connection (xcb:+request exwm--connection
(make-instance 'xcb:SendEvent (make-instance 'xcb:SendEvent
:propagate 0 :destination window :propagate 0 :destination window
@ -300,6 +303,7 @@ corresponding buffer.")
:height (- (elt edges 3) (elt edges 1)) :height (- (elt edges 3) (elt edges 1))
:border-width 0 :override-redirect 0) :border-width 0 :override-redirect 0)
exwm--connection)))) exwm--connection))))
(exwm--log "ConfigureWindow (preserve geometry)")
;; Configure unmanaged windows ;; Configure unmanaged windows
(xcb:+request exwm--connection (xcb:+request exwm--connection
(make-instance 'xcb:ConfigureWindow (make-instance 'xcb:ConfigureWindow
@ -317,6 +321,7 @@ corresponding buffer.")
"Handle MapRequest event." "Handle MapRequest event."
(let ((obj (make-instance 'xcb:MapRequest))) (let ((obj (make-instance 'xcb:MapRequest)))
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(exwm--log "MapRequest from #x%x" (slot-value obj 'window))
(exwm-manage--manage-window (slot-value obj 'window)))) (exwm-manage--manage-window (slot-value obj 'window))))
(defun exwm-manage--on-UnmapNotify (data synthetic) (defun exwm-manage--on-UnmapNotify (data synthetic)
@ -324,6 +329,7 @@ corresponding buffer.")
(unless synthetic (unless synthetic
(let ((obj (make-instance 'xcb:UnmapNotify))) (let ((obj (make-instance 'xcb:UnmapNotify)))
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(exwm--log "UnmapNotify from #x%x" (slot-value obj 'window))
(exwm-manage--unmanage-window (slot-value obj 'window) t)))) (exwm-manage--unmanage-window (slot-value obj 'window) t))))
(defun exwm-manage--on-DestroyNotify (data synthetic) (defun exwm-manage--on-DestroyNotify (data synthetic)
@ -331,6 +337,7 @@ corresponding buffer.")
(unless synthetic (unless synthetic
(let ((obj (make-instance 'xcb:DestroyNotify))) (let ((obj (make-instance 'xcb:DestroyNotify)))
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(exwm--log "DestroyNotify from #x%x" (slot-value obj 'window))
(exwm-manage--unmanage-window (slot-value obj 'window))))) (exwm-manage--unmanage-window (slot-value obj 'window)))))
(defun exwm-manage--init () (defun exwm-manage--init ()