Skip to content

Commit

Permalink
Merge pull request #881 from Homo-carbonis/main
Browse files Browse the repository at this point in the history
Set last focused window in switch-to-window.
  • Loading branch information
cxxxr authored Jul 26, 2023
2 parents 2dfb4f1 + ffb69a9 commit 531074d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
23 changes: 8 additions & 15 deletions src/commands/window.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
Expand Down
1 change: 1 addition & 0 deletions src/internal-packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
:window-use-modeline-p
:window-redraw
:current-window
:last-focused-window
:window-list
:compute-window-list
:one-window-p
Expand Down
8 changes: 7 additions & 1 deletion src/window.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 531074d

Please sign in to comment.