branch: externals/window-commander commit dc96f7173210a7af1280ef43c443459b8e40cb45 Author: Daniel Semyonov <dan...@dsemy.com> Commit: Daniel Semyonov <dan...@dsemy.com>
Update window information when switching frames * swsw.el (swsw--current-frame): New variable holding the last frame from which 'swsw--update' was called. (swsw--update-frame): New function which calls 'swsw--update' if 'swsw--current-frame' differs from the selected frame and 'swsw-scope' isn't t. (swsw--update): Set 'swsw--current-frame'. (swsw-mode): Hook 'swsw--update-frame' to run through 'window-state-change-hook'. --- NEWS | 3 +++ swsw.el | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 136d065a0b..3383649328 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,9 @@ See the end of the file for an explanation of the versioning scheme. * 2.1.0 +** Update window information when switching frames. +This fixes several issues when 'swsw-scope' isn't t. + ** Make 'swsw-select' and 'swsw-delete' respect 'swsw-scope'. Previously, 'swsw-select' and 'swsw-delete' would not select/delete the only other window if it was on a different frame and 'swsw-scope' diff --git a/swsw.el b/swsw.el index a777746ed2..65fc6aeac3 100644 --- a/swsw.el +++ b/swsw.el @@ -154,6 +154,10 @@ If set to `lighter', use a mode line lighter." "Amount of windows that have been assigned an ID.") (put 'swsw-window-count 'risky-local-variable t) +(defvar swsw--current-frame nil + "Current frame (set by `swsw--update'), used to detect frame changes.") +(put 'swsw--current-frame 'risky-local-variable t) + (defun swsw--get-scope () "Return the current scope in which windows should be tracked." (if (eq swsw-scope 'current) @@ -203,12 +207,21 @@ If set to `lighter', use a mode line lighter." (set-window-parameter window 'swsw-id id) (setq swsw-window-count (1+ swsw-window-count)))) +(defun swsw--update-frame () + "Run `swsw--update' if the current frame isn't `swsw--current-frame'. +This check is skipped (and this function does nothing) if `swsw-scope' +is t." + (unless (or (eq (swsw--get-scope) t) + (eq swsw--current-frame (selected-frame))) + (swsw--update))) + (defun swsw--update (&optional _frame) "Update information for all windows." (setq swsw--id-map (make-sparse-keymap)) (set-keymap-parent swsw--id-map swsw-command-map) (setq swsw--id-counter nil - swsw-window-count 0) + swsw-window-count 0 + swsw--current-frame (selected-frame)) ;; Clear and resize `swsw--id-counter' according to the ID length. (dotimes (_var (swsw--get-id-length)) (push 0 swsw--id-counter)) @@ -351,12 +364,14 @@ selection: (unless (eq swsw-display-function 'lighter) (funcall swsw-display-function t)) (add-hook 'window-configuration-change-hook #'swsw--update) + (add-hook 'window-state-change-hook #'swsw--update-frame) (add-hook 'minibuffer-setup-hook #'swsw--update) (add-hook 'minibuffer-exit-hook #'swsw--update) (add-hook 'after-delete-frame-functions #'swsw--update)) (unless (eq swsw-display-function 'lighter) (funcall swsw-display-function nil)) (remove-hook 'window-configuration-change-hook #'swsw--update) + (remove-hook 'window-state-change-hook #'swsw--update-frame) (remove-hook 'minibuffer-setup-hook #'swsw--update) (remove-hook 'minibuffer-exit-hook #'swsw--update) (remove-hook 'after-delete-frame-functions #'swsw--update)))