reacting on mouse pointer events
The mouse (pointer) generates events when it moves, when it crosses window borders and when buttons are pressed.
When one wants to obtain the final pointer position XQueryPointer() is a good function to call.
ButtonPress and ButtonRelease events are fired when the pointer buttons are presses and released. A mouse (pointing device) can have many buttons, these buttons are mapped on a bit mask that can be changed by XSetPointerMapping(); one can read this mapping by the XGetPointerMapping() function call.
The System automatically grabs the pointer between the ButtonPress and ButtonRelease events and presents it to the client window where the button was pressed. So the client always receives two button events (press, release). Only one client can select this button events.
The distribution of the ButtonRelease events can be controlled by XSelectInput calls where one can select OwnerGrabButtonMask. This will cause the ButtonRelease event to be send to the same application where the presses event took place.
unsigned int button;
display = XOpenDisplay(...
screen = DefaultScreen( display...
XSelectInput(display, RootWindow(display, screen), ButtonPressMask | ButtonReleaseMask | ExpousureMask,
gc = XCreateGC( display
XNextEvent(display, &event) // trap any event
button = event.xbutton.button;
...XCheckTypedEvent(display, ButtonPress, event)
// process other button pressed events..
XMskEvent(display ButtonReleaseMask, &event)
if( event.xbutton.button == button)
// process released event
For details please also take a look into O'Reilly's XLib Programming Manual. Here you can find a detailed description with some examples.