Fix #3747: make enlargen/maximize workspace-aware

Otherwise, doom/enlargen-window and doom/window-maximize-buffer could
restore the window configuration of other workspaces.
This commit is contained in:
Henrik Lissner 2020-08-14 02:12:10 -04:00
parent 14d9786360
commit 702fb6e95d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -113,34 +113,62 @@ See `display-line-numbers' for what these values mean."
(delete-frame))
(save-buffers-kill-emacs)))
(defvar doom--maximize-last-wconf nil)
;;;###autoload
(defun doom/window-maximize-buffer ()
"Close other windows to focus on this one. Activate again to undo this. If the
window changes before then, the undo expires.
Alternatively, use `doom/window-enlargen'."
(interactive)
(setq doom--maximize-last-wconf
(if (and (null (cdr (cl-remove-if #'window-dedicated-p (window-list))))
doom--maximize-last-wconf)
(ignore (set-window-configuration doom--maximize-last-wconf))
(defun doom--enlargened-forget-last-wconf-h ()
(set-frame-parameter nil 'doom--maximize-last-wconf nil)
(set-frame-parameter nil 'doom--enlargen-last-wconf nil)
(remove-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h))
;;;###autoload
(defun doom/window-maximize-buffer (&optional arg)
"Close other windows to focus on this one.
Activate again to undo this. If prefix ARG is non-nil, don't restore the last
window configuration and re-maximize the current window. Alternatively, use
`doom/window-enlargen'."
(interactive "P")
(let ((param 'doom--maximize-last-wconf))
(cl-destructuring-bind (window . wconf)
(or (frame-parameter nil param)
(cons nil nil))
(set-frame-parameter
nil param
(if (and (equal window (selected-window))
(not arg)
(null (cdr (cl-remove-if #'window-dedicated-p (window-list))))
wconf)
(ignore
(let ((source-window (selected-window)))
(set-window-configuration wconf)
(when (window-live-p source-window)
(select-window source-window))))
(when (and (bound-and-true-p +popup-mode)
(+popup-window-p))
(user-error "Cannot maximize a popup, use `+popup/raise' first or use `doom/window-enlargen' instead"))
(prog1 (current-window-configuration)
(delete-other-windows)))))
(prog1 (cons (selected-window) (or wconf (current-window-configuration)))
(delete-other-windows)
(add-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h)))))))
(defvar doom--enlargen-last-wconf nil)
;;;###autoload
(defun doom/window-enlargen ()
(defun doom/window-enlargen (&optional arg)
"Enlargen the current window to focus on this one. Does not close other
windows (unlike `doom/window-maximize-buffer'). Activate again to undo."
(interactive)
(setq doom--enlargen-last-wconf
(if doom--enlargen-last-wconf
(ignore (set-window-configuration doom--enlargen-last-wconf))
(prog1 (current-window-configuration)
(interactive "P")
(let ((param 'doom--enlargen-last-wconf))
(cl-destructuring-bind (window . wconf)
(or (frame-parameter nil param)
(cons nil nil))
(set-frame-parameter
nil param
(if (and (equal window (selected-window))
(not arg)
wconf)
(ignore
(let ((source-window (selected-window)))
(set-window-configuration wconf)
(when (window-live-p source-window)
(select-window source-window))))
(prog1 (cons (selected-window) (or wconf (current-window-configuration)))
(let* ((window (selected-window))
(dedicated-p (window-dedicated-p window))
(preserved-p (window-parameter window 'window-preserved-size))
@ -154,7 +182,8 @@ windows (unlike `doom/window-maximize-buffer'). Activate again to undo."
(maximize-window window))
(set-window-dedicated-p window dedicated-p)
(when preserved-p
(set-window-parameter window 'window-preserved-size preserved-p))))))))
(set-window-parameter window 'window-preserved-size preserved-p))
(add-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h)))))))))
;;;###autoload
(defun doom/window-maximize-horizontally ()