aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorDaniel Colascione2018-06-11 14:58:09 -0700
committerDaniel Colascione2018-06-11 16:10:34 -0700
commit2f6c682061a281dc3e397ff4727a164880e86e7b (patch)
treef5990303d483f7d80e1aa1e80a19dc64a6325b66 /doc
parenta20fe5a7e3577f9b9ad5e88006962966240d9b0c (diff)
downloademacs-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.texi102
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.
2702Some window systems and window managers direct keyboard input to the 2702Some window systems and window managers direct keyboard input to the
2703window object that the mouse is in; others require explicit clicks or 2703window object that the mouse is in; others require explicit clicks or
2704commands to @dfn{shift the focus} to various window objects. Either 2704commands to @dfn{shift the focus} to various window objects. Either
2705way, Emacs automatically keeps track of which frame has the focus. To 2705way, Emacs automatically keeps track of which frames have focus. To
2706explicitly switch to a different frame from a Lisp function, call 2706explicitly 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
2709Lisp programs can also switch frames temporarily by calling the 2709The plural ``frames'' in the previous paragraph is deliberate: while
2710function @code{select-frame}. This does not alter the window system's 2710Emacs itself has only one selected frame, Emacs can have frames on
2711concept of focus; rather, it escapes from the window manager's control 2711many different terminals (recall that a connection to a window system
2712until that control is somehow reasserted. 2712counts as a terminal), and each terminal has its own idea of which
2713frame has input focus. When you set the input focus to a frame, you
2714set the focus for that frame's terminal, but frames on other terminals
2715may still remain focused.
2716
2717Lisp programs can switch frames temporarily by calling the function
2718@code{select-frame}. This does not alter the window system's concept
2719of focus; rather, it escapes from the window manager's control until
2720that control is somehow reasserted.
2713 2721
2714When using a text terminal, only one frame can be displayed at a time 2722When using a text terminal, only one frame can be displayed at a time
2715on the terminal, so after a call to @code{select-frame}, the next 2723on 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
2722This function selects @var{frame}, raises it (should it happen to be 2730This function selects @var{frame}, raises it (should it happen to be
2723obscured by other frames) and tries to give it the X server's focus. 2731obscured by other frames) and tries to give it the window system's
2724On a text terminal, the next redisplay displays the new frame on the 2732focus. On a text terminal, the next redisplay displays the new frame
2725entire terminal screen. The optional argument @var{norecord} has the 2733on the entire terminal screen. The optional argument @var{norecord}
2726same meaning as for @code{select-frame} (see below). The return value 2734has the same meaning as for @code{select-frame} (see below).
2727of this function is not significant. 2735The return value of this function is not significant.
2728@end defun 2736@end defun
2729 2737
2730Ideally, the function described next should focus a frame without also 2738Ideally, the function described next should focus a frame without also
@@ -2772,17 +2780,31 @@ could switch to a different terminal without switching back when
2772you're done. 2780you're done.
2773@end deffn 2781@end deffn
2774 2782
2775Emacs cooperates with the window system by arranging to select frames as 2783Emacs cooperates with the window system by arranging to select frames
2776the server and window manager request. It does so by generating a 2784as the server and window manager request. When a window system
2777special kind of input event, called a @dfn{focus} event, when 2785informs Emacs that one of its frames has been selected, Emacs
2778appropriate. The command loop handles a focus event by calling 2786internally generates a @dfn{focus-in} event. Focus events are
2779@code{handle-switch-frame}. @xref{Focus Events}. 2787normally handled by @code{handle-focus-in}.
2788
2789@deffn Command handle-focus-in event
2790This function handles focus-in events from window systems and
2791terminals that support explicit focus notifications. It updates the
2792per-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
2795selected frame to the frame most recently focused in some terminal.
2796It's important to note that this switching of the Emacs selected frame
2797to the most recently focused frame does not mean that other frames do
2798not continue to have the focus in their respective terminals. Do not
2799invoke 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
2782This function handles a focus event by selecting frame @var{frame}. 2804This function handles a switch-frame event, which Emacs generates for
2783 2805itself upon focus notification or under various other circumstances
2784Focus events normally do their job by invoking this command. 2806involving an input event arriving at a different frame from the last
2785Don't call it for any other reason. 2807event. 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
2816change it. 2838change it.
2817@end defun 2839@end defun
2818 2840
2819@defvar focus-in-hook 2841@defun frame-focus-state frame
2820This is a normal hook run when an Emacs frame gains input focus. The 2842This function retrieves the last known focus state of @var{frame}.
2821frame gaining focus is selected when this hook is run. 2843
2822@end defvar 2844It 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
2846Emacs does not know the focus state of the frame. (You may see this
2847last state in TTY frames running on terminals that do not support
2848explicit focus notifications.)
2849@end defun
2823 2850
2824@defvar focus-out-hook 2851@defvar after-focus-change-function
2825This is a normal hook run when an Emacs frame has lost input focus and 2852This function is an extension point that code can use to receive a
2826no other Emacs frame has gained input focus instead. 2853notification that focus has changed.
2854
2855This function is called with no arguments when Emacs notices that the
2856set of focused frames may have changed. Code wanting to do something
2857when frame focus changes should use @code{add-function} to add a
2858function to this one, and in this added function, re-scan the set of
2859focused frames, calling @code{frame-focus-state} to retrieve the last
2860known focus state of each frame. Focus events are delivered
2861asynchronously, and frame input focus according to an external system
2862may not correspond to the notion of the Emacs selected frame.
2863Multiple frames may appear to have input focus simultaneously due to
2864focus event delivery differences, the presence of multiple Emacs
2865terminals, and other factors, and code should be robust in the face of
2866this situation.
2867
2868Depending on window system, focus events may also be delivered
2869repeatedly and with different focus states before settling to the
2870expected values. Code relying on focus notifications should
2871``debounce'' any user-visible updates arising from focus changes,
2872perhaps by deferring work until redisplay.
2873
2874This function may be called in arbitrary contexts, including from
2875inside @code{read-event}, so take the same care as you might when
2876writing a process filter.
2827@end defvar 2877@end defvar
2828 2878
2829@defopt focus-follows-mouse 2879@defopt focus-follows-mouse