diff options
| author | Daniel Colascione | 2018-06-11 14:58:09 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2018-06-11 16:10:34 -0700 |
| commit | 2f6c682061a281dc3e397ff4727a164880e86e7b (patch) | |
| tree | f5990303d483f7d80e1aa1e80a19dc64a6325b66 /doc | |
| parent | a20fe5a7e3577f9b9ad5e88006962966240d9b0c (diff) | |
| download | emacs-2f6c682061a281dc3e397ff4727a164880e86e7b.tar.gz emacs-2f6c682061a281dc3e397ff4727a164880e86e7b.zip | |
New focus management interface
focus-in-hook and focus-out-hook don't accurately reflect actual
user-visible focus states. Add a new focus interface and mark the old
one obsolete.
* doc/lispref/frames.texi (Input Focus): Document new focus
functions. Remove references to the now-obsolete focus hooks.
* lisp/frame.el (frame-focus-state): New function.
(after-focus-change-function): New variable.
(focus-in-hook, focus-out-hook): Move to lisp from C;
mark obsolete.
* lisp/term/xterm.el (xterm-translate-focus-in)
(xterm-translate-focus-out): Track tty focus in `tty-focus-state'
terminal parameter; call `after-focus-change-function'.
(xterm--suspend-tty-function): New function.
* src/frame.c (Fhandle_switch_frame): Update docstring; don't call
focus hooks.
(focus-in-hook, focus-out-hook): Remove: moved to lisp.
(syms_of_frame): Remove unread_switch_frame; add
Vunread_switch_frame.
* src/keyboard.c:
(Finternal_handle_focus_in): New function.
(make_lispy_event): Always report focus events to lisp; don't
translate them to switch events sometimes. Lisp can take care of
creating synthetic switch-frame events via
`internal-handle-focus-in'.
* src/w32term.c (x_focus_changed): Remove switch-avoidance logic:
just directly report focus changes to lisp.
* src/xterm.c (x_focus_changed): Remove switch-avoidance logic:
just directly report focus changes to lisp.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/frames.texi | 102 |
1 files changed, 76 insertions, 26 deletions
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index 459f05cb1c9..3a97ec01384 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi | |||
| @@ -2702,14 +2702,22 @@ This function returns the selected frame. | |||
| 2702 | Some window systems and window managers direct keyboard input to the | 2702 | Some window systems and window managers direct keyboard input to the |
| 2703 | window object that the mouse is in; others require explicit clicks or | 2703 | window object that the mouse is in; others require explicit clicks or |
| 2704 | commands to @dfn{shift the focus} to various window objects. Either | 2704 | commands to @dfn{shift the focus} to various window objects. Either |
| 2705 | way, Emacs automatically keeps track of which frame has the focus. To | 2705 | way, Emacs automatically keeps track of which frames have focus. To |
| 2706 | explicitly switch to a different frame from a Lisp function, call | 2706 | explicitly switch to a different frame from a Lisp function, call |
| 2707 | @code{select-frame-set-input-focus}. | 2707 | @code{select-frame-set-input-focus}. |
| 2708 | 2708 | ||
| 2709 | Lisp programs can also switch frames temporarily by calling the | 2709 | The plural ``frames'' in the previous paragraph is deliberate: while |
| 2710 | function @code{select-frame}. This does not alter the window system's | 2710 | Emacs itself has only one selected frame, Emacs can have frames on |
| 2711 | concept of focus; rather, it escapes from the window manager's control | 2711 | many different terminals (recall that a connection to a window system |
| 2712 | until that control is somehow reasserted. | 2712 | counts as a terminal), and each terminal has its own idea of which |
| 2713 | frame has input focus. When you set the input focus to a frame, you | ||
| 2714 | set the focus for that frame's terminal, but frames on other terminals | ||
| 2715 | may still remain focused. | ||
| 2716 | |||
| 2717 | Lisp programs can switch frames temporarily by calling the function | ||
| 2718 | @code{select-frame}. This does not alter the window system's concept | ||
| 2719 | of focus; rather, it escapes from the window manager's control until | ||
| 2720 | that control is somehow reasserted. | ||
| 2713 | 2721 | ||
| 2714 | When using a text terminal, only one frame can be displayed at a time | 2722 | When using a text terminal, only one frame can be displayed at a time |
| 2715 | on the terminal, so after a call to @code{select-frame}, the next | 2723 | on the terminal, so after a call to @code{select-frame}, the next |
| @@ -2720,11 +2728,11 @@ before the buffer name (@pxref{Mode Line Variables}). | |||
| 2720 | 2728 | ||
| 2721 | @defun select-frame-set-input-focus frame &optional norecord | 2729 | @defun select-frame-set-input-focus frame &optional norecord |
| 2722 | This function selects @var{frame}, raises it (should it happen to be | 2730 | This function selects @var{frame}, raises it (should it happen to be |
| 2723 | obscured by other frames) and tries to give it the X server's focus. | 2731 | obscured by other frames) and tries to give it the window system's |
| 2724 | On a text terminal, the next redisplay displays the new frame on the | 2732 | focus. On a text terminal, the next redisplay displays the new frame |
| 2725 | entire terminal screen. The optional argument @var{norecord} has the | 2733 | on the entire terminal screen. The optional argument @var{norecord} |
| 2726 | same meaning as for @code{select-frame} (see below). The return value | 2734 | has the same meaning as for @code{select-frame} (see below). |
| 2727 | of this function is not significant. | 2735 | The return value of this function is not significant. |
| 2728 | @end defun | 2736 | @end defun |
| 2729 | 2737 | ||
| 2730 | Ideally, the function described next should focus a frame without also | 2738 | Ideally, the function described next should focus a frame without also |
| @@ -2772,17 +2780,31 @@ could switch to a different terminal without switching back when | |||
| 2772 | you're done. | 2780 | you're done. |
| 2773 | @end deffn | 2781 | @end deffn |
| 2774 | 2782 | ||
| 2775 | Emacs cooperates with the window system by arranging to select frames as | 2783 | Emacs cooperates with the window system by arranging to select frames |
| 2776 | the server and window manager request. It does so by generating a | 2784 | as the server and window manager request. When a window system |
| 2777 | special kind of input event, called a @dfn{focus} event, when | 2785 | informs Emacs that one of its frames has been selected, Emacs |
| 2778 | appropriate. The command loop handles a focus event by calling | 2786 | internally generates a @dfn{focus-in} event. Focus events are |
| 2779 | @code{handle-switch-frame}. @xref{Focus Events}. | 2787 | normally handled by @code{handle-focus-in}. |
| 2788 | |||
| 2789 | @deffn Command handle-focus-in event | ||
| 2790 | This function handles focus-in events from window systems and | ||
| 2791 | terminals that support explicit focus notifications. It updates the | ||
| 2792 | per-frame focus flags that @code{frame-focus-state} queries and calls | ||
| 2793 | @code{after-focus-change-function}. In addition, it generates a | ||
| 2794 | @code{switch-frame} event in order to switch the Emacs notion of the | ||
| 2795 | selected frame to the frame most recently focused in some terminal. | ||
| 2796 | It's important to note that this switching of the Emacs selected frame | ||
| 2797 | to the most recently focused frame does not mean that other frames do | ||
| 2798 | not continue to have the focus in their respective terminals. Do not | ||
| 2799 | invoke this function yourself: instead, attach logic to | ||
| 2800 | @code{after-focus-change-function}. | ||
| 2801 | @end deffn | ||
| 2780 | 2802 | ||
| 2781 | @deffn Command handle-switch-frame frame | 2803 | @deffn Command handle-switch-frame frame |
| 2782 | This function handles a focus event by selecting frame @var{frame}. | 2804 | This function handles a switch-frame event, which Emacs generates for |
| 2783 | 2805 | itself upon focus notification or under various other circumstances | |
| 2784 | Focus events normally do their job by invoking this command. | 2806 | involving an input event arriving at a different frame from the last |
| 2785 | Don't call it for any other reason. | 2807 | event. Do not invoke this function yourself. |
| 2786 | @end deffn | 2808 | @end deffn |
| 2787 | 2809 | ||
| 2788 | @defun redirect-frame-focus frame &optional focus-frame | 2810 | @defun redirect-frame-focus frame &optional focus-frame |
| @@ -2816,14 +2838,42 @@ The redirection lasts until @code{redirect-frame-focus} is called to | |||
| 2816 | change it. | 2838 | change it. |
| 2817 | @end defun | 2839 | @end defun |
| 2818 | 2840 | ||
| 2819 | @defvar focus-in-hook | 2841 | @defun frame-focus-state frame |
| 2820 | This is a normal hook run when an Emacs frame gains input focus. The | 2842 | This function retrieves the last known focus state of @var{frame}. |
| 2821 | frame gaining focus is selected when this hook is run. | 2843 | |
| 2822 | @end defvar | 2844 | It returns @code{nil} if the frame is known not to be focused, |
| 2845 | @code{t} if the frame is known to be focused, or @code{unknown} if | ||
| 2846 | Emacs does not know the focus state of the frame. (You may see this | ||
| 2847 | last state in TTY frames running on terminals that do not support | ||
| 2848 | explicit focus notifications.) | ||
| 2849 | @end defun | ||
| 2823 | 2850 | ||
| 2824 | @defvar focus-out-hook | 2851 | @defvar after-focus-change-function |
| 2825 | This is a normal hook run when an Emacs frame has lost input focus and | 2852 | This function is an extension point that code can use to receive a |
| 2826 | no other Emacs frame has gained input focus instead. | 2853 | notification that focus has changed. |
| 2854 | |||
| 2855 | This function is called with no arguments when Emacs notices that the | ||
| 2856 | set of focused frames may have changed. Code wanting to do something | ||
| 2857 | when frame focus changes should use @code{add-function} to add a | ||
| 2858 | function to this one, and in this added function, re-scan the set of | ||
| 2859 | focused frames, calling @code{frame-focus-state} to retrieve the last | ||
| 2860 | known focus state of each frame. Focus events are delivered | ||
| 2861 | asynchronously, and frame input focus according to an external system | ||
| 2862 | may not correspond to the notion of the Emacs selected frame. | ||
| 2863 | Multiple frames may appear to have input focus simultaneously due to | ||
| 2864 | focus event delivery differences, the presence of multiple Emacs | ||
| 2865 | terminals, and other factors, and code should be robust in the face of | ||
| 2866 | this situation. | ||
| 2867 | |||
| 2868 | Depending on window system, focus events may also be delivered | ||
| 2869 | repeatedly and with different focus states before settling to the | ||
| 2870 | expected values. Code relying on focus notifications should | ||
| 2871 | ``debounce'' any user-visible updates arising from focus changes, | ||
| 2872 | perhaps by deferring work until redisplay. | ||
| 2873 | |||
| 2874 | This function may be called in arbitrary contexts, including from | ||
| 2875 | inside @code{read-event}, so take the same care as you might when | ||
| 2876 | writing a process filter. | ||
| 2827 | @end defvar | 2877 | @end defvar |
| 2828 | 2878 | ||
| 2829 | @defopt focus-follows-mouse | 2879 | @defopt focus-follows-mouse |