Add doom-after-switch-frame-hook; fix over-eager switch-window hooks
Switch-window hooks would fire too frequently; like when switching to the same window, clicking in windows, or from the minibuffer (e.g. during ivy sessions).
This commit is contained in:
parent
1282072db3
commit
f3b99779c9
2 changed files with 18 additions and 6 deletions
|
@ -301,16 +301,27 @@ with `doom//reload-theme').")
|
|||
"Hook run before `switch-to-buffer' and `display-buffer' are called. See
|
||||
`doom-before-switch-buffer-hook'.")
|
||||
|
||||
(defun doom*switch-window-hooks (orig-fn &rest args)
|
||||
(run-hook-with-args 'doom-before-switch-window-hook)
|
||||
(prog1 (apply orig-fn args)
|
||||
(run-hook-with-args 'doom-after-switch-window-hook)))
|
||||
(defun doom*switch-frame-hooks (orig-fn frame &optional norecord)
|
||||
(if (eq frame (selected-frame))
|
||||
(funcall orig-fn frame norecord)
|
||||
(run-hook-with-args 'doom-before-switch-frame-hook)
|
||||
(prog1 (funcall orig-fn frame norecord)
|
||||
(run-hook-with-args 'doom-after-switch-frame-hook))))
|
||||
(defun doom*switch-window-hooks (orig-fn window &optional norecord)
|
||||
(if (or (eq window (selected-window))
|
||||
(memq this-command '(mouse-set-point evil-mouse-drag-region))
|
||||
(window-minibuffer-p)
|
||||
(window-minibuffer-p window))
|
||||
(funcall orig-fn window norecord)
|
||||
(run-hook-with-args 'doom-before-switch-window-hook)
|
||||
(prog1 (funcall orig-fn window norecord)
|
||||
(run-hook-with-args 'doom-after-switch-window-hook))))
|
||||
(defun doom*switch-buffer-hooks (orig-fn &rest args)
|
||||
(run-hook-with-args 'doom-before-switch-buffer-hook)
|
||||
(prog1 (apply orig-fn args)
|
||||
(run-hook-with-args 'doom-after-switch-buffer-hook)))
|
||||
|
||||
(advice-add #'select-frame :around #'doom*switch-window-hooks)
|
||||
(advice-add #'select-frame :around #'doom*switch-frame-hooks)
|
||||
(advice-add #'select-window :around #'doom*switch-window-hooks)
|
||||
(advice-add #'switch-to-buffer :around #'doom*switch-buffer-hooks)
|
||||
(advice-add #'display-buffer :around #'doom*switch-buffer-hooks)
|
||||
|
|
|
@ -49,9 +49,10 @@
|
|||
(force-mode-line-update))
|
||||
|
||||
(add-hook 'window-configuration-change-hook #'+doom-modeline|set-selected-window)
|
||||
(add-hook 'focus-in-hook #'+doom-modeline|set-selected-window)
|
||||
(add-hook 'focus-in-hook #'+doom-modeline|set-selected-window)
|
||||
(add-hook 'focus-out-hook #'+doom-modeline|unset-selected-window)
|
||||
(add-hook 'doom-after-switch-window-hook #'+doom-modeline|set-selected-window)
|
||||
(add-hook 'doom-after-switch-frame-hook #'+doom-modeline|set-selected-window)
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue