Variable: after-focus-change-function

after-focus-change-function is a variable defined in frame.el.gz.

Value

ignore

Documentation

Function called after frame focus may have changed.

This function is called with no arguments when Emacs notices that the set of focused frames may have changed. Code wanting to do something when frame focus changes should use add-function to add a function to this one, and in this added function, re-scan the set of focused frames, calling frame-focus-state to retrieve the last known focus state of each frame. Focus events are delivered asynchronously, and frame input focus according to an external system may not correspond to the notion of the Emacs selected frame. Multiple frames may appear to have input focus simultaneously due to focus event delivery differences, the presence of multiple Emacs terminals, and other factors, and code should be robust in the face of this situation.

Depending on window system, focus events may also be delivered repeatedly and with different focus states before settling to the expected values. Code relying on focus notifications should
"debounce" any user-visible updates arising from focus changes,
perhaps by deferring work until redisplay.

This function may be called in arbitrary contexts, including from inside read-event, so take the same care as you might when writing a process filter.

View in manual

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/frame.el.gz
(defvar after-focus-change-function #'ignore
  "Function called after frame focus may have changed.

This function is called with no arguments when Emacs notices that
the set of focused frames may have changed.  Code wanting to do
something when frame focus changes should use `add-function' to
add a function to this one, and in this added function, re-scan
the set of focused frames, calling `frame-focus-state' to
retrieve the last known focus state of each frame.  Focus events
are delivered asynchronously, and frame input focus according to
an external system may not correspond to the notion of the Emacs
selected frame.  Multiple frames may appear to have input focus
simultaneously due to focus event delivery differences, the
presence of multiple Emacs terminals, and other factors, and code
should be robust in the face of this situation.

Depending on window system, focus events may also be delivered
repeatedly and with different focus states before settling to the
expected values.  Code relying on focus notifications should
\"debounce\" any user-visible updates arising from focus changes,
perhaps by deferring work until redisplay.

This function may be called in arbitrary contexts, including from
inside `read-event', so take the same care as you might when
writing a process filter.")