]> git.eshelyaron.com Git - emacs.git/commitdiff
Attempt to clarify Input Focus documentation
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 20 Sep 2022 14:47:21 +0000 (16:47 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 20 Sep 2022 15:12:28 +0000 (17:12 +0200)
* doc/lispref/frames.texi (Input Focus): Try to clarify the
documentation (bug#51862).

doc/lispref/frames.texi

index 262b86672da92b1bfceb9c08e1db175a34cf3ec6..e38a81d3e7eaff178657206ada53de188209e788 100644 (file)
@@ -2997,17 +2997,25 @@ explicit focus notifications.)
 @end defun
 
 @defvar after-focus-change-function
-This function is an extension point that code can use to receive a
-notification that focus has 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 @code{add-function} to add a
-function to this one, and in this added function, re-scan the set of
-focused frames, calling @code{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.
+This function is called with no arguments when Emacs notices that a
+frame may have gotten or lost focus.  Focus events are delivered
+asynchronously, and may not be delivered in the expected order, so
+code that wants to do something depending on the state of focused
+frames have go through all the frames and check.
+
+For instance, here's a simple example function that sets the
+background color based on whether the frame has focus or not:
+
+@lisp
+(add-function :after after-focus-change-function
+              #'my-change-background)
+(defun my-change-background ()
+  (dolist (frame (frame-list))
+    (pcase (frame-focus-state frame)
+      (`t (set-face-background 'default "black" frame))
+      (`nil (set-face-background 'default "#404040" frame)))))
+@end lisp
+
 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