From 2799ab75e03ccb088706944e0ab1fe2b4fca4bf8 Mon Sep 17 00:00:00 2001 From: Homo-carbonis Date: Tue, 25 Jul 2023 20:24:37 +0100 Subject: [PATCH 1/2] Set last focused window in switch-to-window. --- src/commands/window.lisp | 17 +++++------------ src/internal-packages.lisp | 1 + src/window.lisp | 5 ++++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/commands/window.lisp b/src/commands/window.lisp index 476bbf6e2..a29c00a89 100644 --- a/src/commands/window.lisp +++ b/src/commands/window.lisp @@ -144,18 +144,12 @@ (unless n (maybe-balance-windows))) -(defvar *last-focused-window* nil) - -(defun update-last-focused-window () - (setf *last-focused-window* (current-window))) - (define-command other-window (&optional (n 1)) ("p") "Go to the next window." (let ((window-list (compute-window-list (current-window)))) (when (minusp n) (setf n (- (length window-list) (abs n)))) - (update-last-focused-window) (let ((window (current-window))) (dotimes (_ n t) (setf window @@ -168,28 +162,27 @@ (not (deleted-window-p *last-focused-window*)) *last-focused-window*) (get-next-window (current-window))))) - (update-last-focused-window) - (setf (current-window) window))) + (switch-to-window window))) (define-command window-move-down () () "Go to the window on the down." (alexandria:when-let ((window (down-window (current-window)))) - (setf (current-window) window))) + (switch-to-window window))) (define-command window-move-up () () "Go to the window on the up." (alexandria:when-let ((window (up-window (current-window)))) - (setf (current-window) window))) + (switch-to-window window))) (define-command window-move-right () () "Go to the window on the right." (alexandria:when-let ((window (right-window (current-window)))) - (setf (current-window) window))) + (switch-to-window window))) (define-command window-move-left () () "Go to the window on the left." (alexandria:when-let ((window (left-window (current-window)))) - (setf (current-window) window))) + (switch-to-window window))) (define-command delete-other-windows () () "Delete all other windows." diff --git a/src/internal-packages.lisp b/src/internal-packages.lisp index 9cee0152f..14cf01266 100644 --- a/src/internal-packages.lisp +++ b/src/internal-packages.lisp @@ -203,6 +203,7 @@ :*window-scroll-functions* :*window-size-change-functions* :*window-show-buffer-functions* + :*last-focused-window* :window-parent :scroll :window-view-point diff --git a/src/window.lisp b/src/window.lisp index 363abe2ea..623a2c17d 100644 --- a/src/window.lisp +++ b/src/window.lisp @@ -12,6 +12,8 @@ (defparameter *use-new-vertical-move-function* t) (defparameter *use-cursor-movement-workaround* t) +(defvar *last-focused-window* nil) + (defgeneric %delete-window (window)) (defgeneric window-parent (window) (:method (window) @@ -180,7 +182,8 @@ (defun switch-to-window (new-window) (unless (eq (current-window) new-window) - (run-hooks (window-leave-hook (current-window)) (current-window))) + (run-hooks (window-leave-hook (current-window)) (current-window)) + (setf *last-focused-window* (current-window))) (setf (current-window) new-window)) (defun window-list (&optional (frame (current-frame))) From ffb69a94287626db3e1d225b1985cecf52ed4d41 Mon Sep 17 00:00:00 2001 From: Homo-carbonis Date: Wed, 26 Jul 2023 13:37:46 +0100 Subject: [PATCH 2/2] Encapsulate *last-focused-window* --- src/commands/window.lisp | 6 +++--- src/internal-packages.lisp | 2 +- src/window.lisp | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/commands/window.lisp b/src/commands/window.lisp index a29c00a89..67f23efd8 100644 --- a/src/commands/window.lisp +++ b/src/commands/window.lisp @@ -158,9 +158,9 @@ (define-command switch-to-last-focused-window () () "Go to the window that was last in focus." - (let ((window (or (and (not (null *last-focused-window*)) - (not (deleted-window-p *last-focused-window*)) - *last-focused-window*) + (let ((window (or (and (not (null (last-focused-window))) + (not (deleted-window-p (last-focused-window))) + (last-focused-window)) (get-next-window (current-window))))) (switch-to-window window))) diff --git a/src/internal-packages.lisp b/src/internal-packages.lisp index 14cf01266..b4b3074ba 100644 --- a/src/internal-packages.lisp +++ b/src/internal-packages.lisp @@ -203,7 +203,6 @@ :*window-scroll-functions* :*window-size-change-functions* :*window-show-buffer-functions* - :*last-focused-window* :window-parent :scroll :window-view-point @@ -227,6 +226,7 @@ :window-use-modeline-p :window-redraw :current-window + :last-focused-window :window-list :compute-window-list :one-window-p diff --git a/src/window.lisp b/src/window.lisp index 623a2c17d..7ccc42f44 100644 --- a/src/window.lisp +++ b/src/window.lisp @@ -180,6 +180,9 @@ (%window-point new-window))) (setf (frame-current-window frame) new-window))) +(defun last-focused-window () + *last-focused-window*) + (defun switch-to-window (new-window) (unless (eq (current-window) new-window) (run-hooks (window-leave-hook (current-window)) (current-window))