* src/xterm.c: Add a small writeup on input handling on X.

Hopefully I will extend this section with details about more
aspects of X11 support in the future.
This commit is contained in:
Po Lu 2022-01-14 19:47:35 +08:00
parent 85299991e4
commit 30dbdecd4a

View file

@ -20,6 +20,72 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
/* New display code by Gerd Moellmann <gerd@gnu.org>. */
/* Xt features made by Fred Pierresteguy. */
/* X window system support for GNU Emacs
This file is part of the X window system support for GNU Emacs. It
contains subroutines comprising the redisplay interface, setting up
scroll bars and widgets, and handling input.
INPUT
Emacs handles input by running pselect in a loop, which returns
whenever there is input available on the connection to the X
server. On some systems, Emacs also arranges for any new input on
that connection to send an asynchronous signal. Whenever pselect
returns, or such a signal is received and input is not blocked,
XTread_socket is called and translates X11 events read by Xlib into
struct input_events, which are then stored in the keyboard buffer,
to be processed and acted upon at some later time. The function
handle_one_xevent is responsible for handling core events after
they are filtered, and filtering X Input Extension events. It also
performs actions on some special events, such as updating the
dimensions of a frame after a ConfigureNotify is sent by the X
server to inform us that it changed.
Before such events are translated, an Emacs build with
internationalization enabled (the default since X11R6) will filter
events through an X Input Method (XIM) or GTK, which might decide
to intercept the event and send a different one in its place, for
reasons such as enabling the user to insert international
characters that aren't on his keyboard by typing a sequence of
characters which are. See the function x_filter_event and its
callers for more details.
Events that cause Emacs to quit are treated specially by the code
that stores them in the keyboard buffer and generally cause an
immediate interrupt. Such an interrupt can lead to a longjmp from
the code that stored the keyboard event, which isn't safe inside
XTread_socket. To avoid this problem, XTread_socket is provided a
special event buffer named hold_quit. When a quit event is
encountered, it is stored inside this special buffer, which will
cause the keyboard code that called XTread_socket to store it at a
later time when it is safe to do so.
handle_one_xevent will generally have to determine which frame an
event should be attributed to. This is not easy, because events
can come from multiple X windows, and a frame can also have
multiple windows. handle_one_xevent usually calls the function
x_any_window_to_frame, which searches for a frame by toplevel
window and widget windows. There are also some other functions for
searching by specific types of window, such as
x_top_window_to_frame (which only searches for frames by toplevel
window), and x_menubar_window_to_frame (which will only search
through frame menu bars).
INPUT FOCUS
Under X, the window where keyboard input is sent is not always
explictly defined. When there is a focus window, it receives what
is referred to as "explicit focus", but when there is none, it
receives "implicit focus" whenever the pointer enters it, and loses
that focus when the pointer leaves. When the toplevel window of a
frame receives an explicit focus event (FocusIn or FocusOut), we
treat that frame as having the current input focus, but when there
is no focus window, we treat each frame as having the input focus
whenever the pointer enters it, and undo that treatment when the
pointer leaves it. See the callers of x_detect_focus_change for
more details. */
#include <config.h>
#include <stdlib.h>
#include <math.h>