diff options
| -rw-r--r-- | doc/lispref/frames.texi | 30 |
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 |
| 3000 | This function is an extension point that code can use to receive a | 3000 | This function is called with no arguments when Emacs notices that a |
| 3001 | notification that focus has changed. | 3001 | frame may have gotten or lost focus. Focus events are delivered |
| 3002 | 3002 | asynchronously, and may not be delivered in the expected order, so | |
| 3003 | This function is called with no arguments when Emacs notices that the | 3003 | code that wants to do something depending on the state of focused |
| 3004 | set of focused frames may have changed. Code wanting to do something | 3004 | frames have go through all the frames and check. |
| 3005 | when frame focus changes should use @code{add-function} to add a | 3005 | |
| 3006 | function to this one, and in this added function, re-scan the set of | 3006 | For instance, here's a simple example function that sets the |
| 3007 | focused frames, calling @code{frame-focus-state} to retrieve the last | 3007 | background color based on whether the frame has focus or not: |
| 3008 | known focus state of each frame. Focus events are delivered | 3008 | |
| 3009 | asynchronously, and frame input focus according to an external system | 3009 | @lisp |
| 3010 | may 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 | |||
| 3011 | Multiple frames may appear to have input focus simultaneously due to | 3019 | Multiple frames may appear to have input focus simultaneously due to |
| 3012 | focus event delivery differences, the presence of multiple Emacs | 3020 | focus event delivery differences, the presence of multiple Emacs |
| 3013 | terminals, and other factors, and code should be robust in the face of | 3021 | terminals, and other factors, and code should be robust in the face of |