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,48 +113,77 @@ See `display-line-numbers' for what these values mean."
(delete-frame)) (delete-frame))
(save-buffers-kill-emacs))) (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'." (defun doom--enlargened-forget-last-wconf-h ()
(interactive) (set-frame-parameter nil 'doom--maximize-last-wconf nil)
(setq doom--maximize-last-wconf (set-frame-parameter nil 'doom--enlargen-last-wconf nil)
(if (and (null (cdr (cl-remove-if #'window-dedicated-p (window-list)))) (remove-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h))
doom--maximize-last-wconf)
(ignore (set-window-configuration doom--maximize-last-wconf))
(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)))))
(defvar doom--enlargen-last-wconf nil)
;;;###autoload ;;;###autoload
(defun doom/window-enlargen () (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 (cons (selected-window) (or wconf (current-window-configuration)))
(delete-other-windows)
(add-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h)))))))
;;;###autoload
(defun doom/window-enlargen (&optional arg)
"Enlargen the current window to focus on this one. Does not close other "Enlargen the current window to focus on this one. Does not close other
windows (unlike `doom/window-maximize-buffer'). Activate again to undo." windows (unlike `doom/window-maximize-buffer'). Activate again to undo."
(interactive) (interactive "P")
(setq doom--enlargen-last-wconf (let ((param 'doom--enlargen-last-wconf))
(if doom--enlargen-last-wconf (cl-destructuring-bind (window . wconf)
(ignore (set-window-configuration doom--enlargen-last-wconf)) (or (frame-parameter nil param)
(prog1 (current-window-configuration) (cons nil nil))
(let* ((window (selected-window)) (set-frame-parameter
(dedicated-p (window-dedicated-p window)) nil param
(preserved-p (window-parameter window 'window-preserved-size)) (if (and (equal window (selected-window))
(ignore-window-parameters t)) (not arg)
(unwind-protect wconf)
(progn (ignore
(when dedicated-p (let ((source-window (selected-window)))
(set-window-dedicated-p window nil)) (set-window-configuration wconf)
(when preserved-p (when (window-live-p source-window)
(set-window-parameter window 'window-preserved-size nil)) (select-window source-window))))
(maximize-window window)) (prog1 (cons (selected-window) (or wconf (current-window-configuration)))
(set-window-dedicated-p window dedicated-p) (let* ((window (selected-window))
(when preserved-p (dedicated-p (window-dedicated-p window))
(set-window-parameter window 'window-preserved-size preserved-p)))))))) (preserved-p (window-parameter window 'window-preserved-size))
(ignore-window-parameters t))
(unwind-protect
(progn
(when dedicated-p
(set-window-dedicated-p window nil))
(when preserved-p
(set-window-parameter window 'window-preserved-size nil))
(maximize-window window))
(set-window-dedicated-p window dedicated-p)
(when preserved-p
(set-window-parameter window 'window-preserved-size preserved-p))
(add-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h)))))))))
;;;###autoload ;;;###autoload
(defun doom/window-maximize-horizontally () (defun doom/window-maximize-horizontally ()