9.4 Grabbing the Keyboard and Pointer
There are times when a program might want to bypass the normal
keyboard or pointer event propagation path in order to get input
independent of the position of the pointer. This is the purpose of
grabbing the keyboard and pointer. There are routines to grab the
XGrabKeyboard()) or the pointer
XGrabPointer()), or to arrange that they become
grabbed when a certain combination of keys and/or buttons is pressed
are corresponding calls to ungrab (
XUngrabPointer()), and there is one call to change
the characteristics of a pointer grab
One of the most common situations where grabbing takes place is
with button events. Most applications want both a
ButtonPress and a
so that they can compare the two positions. Since this is such a common
desire, the server automatically grabs the pointer
ButtonRelease if both are selected, so that you do
not have to make an explicit grab.
One reason for grabbing a device is so that you can handle a series of events contiguously without fear of intervening events. But when you grab a device, no other application can receive input from that device. Therefore, it is something to do only when absolutely necessary.
The routines that grab take several arguments that tailor the input response in these ways:
When the pointer is grabbed, the cursor may be confined ...