I've been looking through the available hooks, but none of them seems to be firing when you switch windows.
What I'm trying to do, is activating a minor mode for the selected window:
(defvar active-window (frame-selected-window))
(defun active-window-switch (&rest _)
(when active-window
(with-selected-window active-window
(active-window-mode nil)))
(setq active-window (frame-selected-window))
(active-window-mode t))
(define-minor-mode active-window-mode
"Minor mode to distinguish the selected window."
:global nil :group 'active-window :init-value nil :lighter " Active")
(add-hook 'window-configuration-change-hook #'active-window-switch)
(provide 'active-window)
What hook or function to advice can I use instead of window-configuration-change-hook
(which only fires when I create or quit windows)?
You can try advising select-window:
or, if you want to un-do your settings in the window you are leaving first:
select-window
is an operation used internally in many cases, potentially thousands of times in a single command. You don't really care about the selected window all the time, but only when not running a command. So the better place to hook yourself is inpost-command-hook
.