aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/frames.texi30
1 files changed, 19 insertions, 11 deletions
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index 262b86672da..e38a81d3e7e 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -2997,17 +2997,25 @@ explicit focus notifications.)
2997@end defun 2997@end defun
2998 2998
2999@defvar after-focus-change-function 2999@defvar after-focus-change-function
3000This function is an extension point that code can use to receive a 3000This function is called with no arguments when Emacs notices that a
3001notification that focus has changed. 3001frame may have gotten or lost focus. Focus events are delivered
3002 3002asynchronously, and may not be delivered in the expected order, so
3003This function is called with no arguments when Emacs notices that the 3003code that wants to do something depending on the state of focused
3004set of focused frames may have changed. Code wanting to do something 3004frames have go through all the frames and check.
3005when frame focus changes should use @code{add-function} to add a 3005
3006function to this one, and in this added function, re-scan the set of 3006For instance, here's a simple example function that sets the
3007focused frames, calling @code{frame-focus-state} to retrieve the last 3007background color based on whether the frame has focus or not:
3008known focus state of each frame. Focus events are delivered 3008
3009asynchronously, and frame input focus according to an external system 3009@lisp
3010may not correspond to the notion of the Emacs selected frame. 3010(add-function :after after-focus-change-function
3011 #'my-change-background)
3012(defun my-change-background ()
3013 (dolist (frame (frame-list))
3014 (pcase (frame-focus-state frame)
3015 (`t (set-face-background 'default "black" frame))
3016 (`nil (set-face-background 'default "#404040" frame)))))
3017@end lisp
3018
3011Multiple frames may appear to have input focus simultaneously due to 3019Multiple frames may appear to have input focus simultaneously due to
3012focus event delivery differences, the presence of multiple Emacs 3020focus event delivery differences, the presence of multiple Emacs
3013terminals, and other factors, and code should be robust in the face of 3021terminals, and other factors, and code should be robust in the face of