Chapter 8. Events
This chapter is another must-read. Events are central to X. The fundamental framework for handling events was given in Chapter 3, but this chapter gives much more detail, both on selecting events for a window and on handling them when they arrive. It discusses each of the masks used to select events; for a description of the event structures themselves, see Appendix E.
An event, to quote the Oxford English Dictionary, is an “incident of importance” or a “consequence, result, or outcome.” This definition holds for X. An event reports some device activity or is generated as a side effect of an Xlib routine.
From a programmer’s point of view, an event reports:
Something that your program needs to know about, such as user input or information available from other clients.
Something your program is doing that other clients need to know about, such as making text available for pasting to another client.
Something the window manager needs to know, such as a request by your program for a change to the layout of the screen by mapping a window.
Programming with events is quite different from traditional methods of programming for input. You cannot simply wait for a user to type something and expect nothing else to happen in the meantime. Other programs are running concurrently and sharing the same system resources including the screen. They can affect your program. What happens if another window is placed over yours in the middle of the instruction your user is typing? The program ...