diff --git a/src/commands/window.lisp b/src/commands/window.lisp index 476bbf6e2..67f23efd8 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 @@ -164,32 +158,31 @@ (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))))) - (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..b4b3074ba 100644 --- a/src/internal-packages.lisp +++ b/src/internal-packages.lisp @@ -226,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 363abe2ea..7ccc42f44 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) @@ -178,9 +180,13 @@ (%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))) + (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)))