If a key on the server keyboard is pressed or part of a window is uncovered
the server can inform the client which is effected by sending events.
Events are usually delivered to windows and each window has to
tell the server which events it is interested in. It does this using the
XSelectInput
call. If an event hasn't been selected then it will either be
discarded or be passed on to another window, depending on how the
window's do_not_propagate_mask
has been set up.
It is possible for a window to hijack all events from the keyboard or the mouse. This is not to be encouraged and has been relegated to a later chapter.
These events are queued by the window system and subroutines are listed
below which show how to ask if events are waiting for you and remove them
from the queue.
In order to find out what an event means it is necessary
to be able to read the event structure.
An XEvent
structure always has type
as the first entry. This
uniquely identifies what kind of event it is. The second entry
is always a pointer to the display the event was read from.
The third entry is always a window of one type or another, (except
for keymap events, which have no window.)
The pointer to the generic event must be cast before use to
access any other information in the structure.
<X11/Xlib.h>
contains all the event structures with enough explanation
for all but FocusIn
, FocusOut
, EnterNotify
and LeaveNotify
events.
For precise details of these, you should consult the manual.
XEvent
is the union of all Event Structures, one of which is:-
typedef struct { int type; /* of event */ Display *display; /* Display the event was read from */ Window window; /* window it is reported relative to */ Window root; /* root window that the event occured on */ Window subwindow; /* child window */ unsigned long time; /* milliseconds */ int x, y; /* pointer coordinates in event window */ int x_root, y_root; /* coordinates relative to root */ unsigned int state; /* key or button mask */ unsigned int keycode; /* detail */ Bool same_screen; /* same screen flag */ } XKeyEvent; typedef XKeyEvent XKeyPressedEvent; typedef XKeyEvent XKeyReleasedEvent;Another useful event deals with button presses.
typedef struct { int type; /* of event */ unsigned long serial; /* # of last request processed by server */ Bool send_event; /* true if this came from a SendEvent request */ Display *display; /* Display the event was read from */ Window window; /* "event" window it is reported relative to */ Window root; /* root window that the event occured on */ Window subwindow; /* child window */ Time time; /* milliseconds */ int x, y; /* pointer x, y coordinates in event window */ int x_root, y_root; /* coordinates relative to root */ unsigned int state; /* key or button mask */ unsigned int button; /* detail */ Bool same_screen; /* same screen flag */ } XButtonEvent; typedef XButtonEvent XButtonPressedEvent; typedef XButtonEvent XButtonReleasedEvent;