Name

ButtonPress,ButtonRelease — (generated event).

When Generated

There are two types of pointer button events: ButtonPress and ButtonRelease. Both contain the same information.

Select With

May be selected separately, using ButtonPressMask and ButtonReleaseMask.

XEvent Structure Name

typedef union _XEvent {
   ...
   XButtonEvent xbutton;
   ...
} XEvent;

Event Structure

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 occurred under */
Window subwindow;         /* child window */
Time time;                /* when event occurred, in milliseconds */
int x, y;                 /* pointer coordinates relative to receiving                                    * window */
int x_root, y_root;       /* coordinates relative to root */
unsigned int state;       /* mask of all buttons and modifier keys */
unsigned int button;      /* button that triggered event */
Bool same_screen;         /* same screen flag */
} XButtonEvent;
typedef XButtonEvent XButtonPressedEvent;
typedef XButtonEvent XButtonReleasedEvent;

Event Structure Members

subwindow 

If the source window is the child of the receiving window, then the subwindow member is set to the ID of that child.

time 

The server time when the button event occurred, in milliseconds. Time is declared as unsigned long, so it wraps around when it reaches the maximum value of a 32-bit number (every 49.7 days).

x, y 

If the receiving window is on the same screen as the root window specified by root, then x and y are the pointer coordinates relative to the receiving window's origin. Otherwise, x and y are zero. When active button grabs and pointer grabs are in effect (see 9.4 of Volume One), the coordinates relative to the receiving window may not be within the window (they may be negative or greater than window height or width).

x_root, y_root 

The pointer coordinates relative to the root window which is an ancestor of the event window. If the pointer was on a different screen, these are zero.

state 

The state of all the buttons and modifier keys just before the event, represented by a mask of the button and modifier key symbols: Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask, ControlMask, LockMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask, and ShiftMask. If a modifier key is pressed and released when no other modifier keys are held, the ButtonPress will have a state member of 0 and the ButtonRelease will have a non-zero state member indicating that itself was held just before the event.

button 

A value indicating which button changed state to trigger this event. One of the constants: Button1, Button2, Button3, Button4, or Button5.

same_screen 

Indicates whether the pointer is currently on the same screen as this window. This is always True unless the pointer was actively grabbed before the automatic grab could take place.

Notes

Unless an active grab already exists or a passive grab on the button combination that was pressed already exists at a higher level in the hierarchy than where the ButtonPress occurred, an automatic active grab of the pointer takes place when a ButtonPress occurs. Because of the automatic grab, the matching ButtonRelease is sent to the same application that received the ButtonPress event. If OwnerGrabButtonMask has been selected, the ButtonRelease event is delivered to the window which contained the pointer when the button was released, as long as that window belongs to the same client as the window in which the ButtonPress event occurred. If the ButtonRelease occurs outside of the client's windows or OwnerGrabButtonMask was not selected, the ButtonRelease is delivered to the window in which the ButtonPress occurred. The grab is terminated when all buttons are released. During the grab, the cursor associated with the grabbing window will track the pointer anywhere on the screen.

If the application has invoked a passive button grab on an ancestor of the window in which the ButtonPress event occurs, then that grab takes precedence over the automatic grab, and the ButtonRelease will go to that window, or it will be handled normally by that client depending on the owner_events flag in the XGrabButton call.