问题
with following code:
XGrabPointer(d, root, False, ButtonPressMask
, GrabModeAsync, GrabModeAsync, None,
None, CurrentTime);
I just specify with button press event, but when running other applications can't get any other mouse event such as mouse move. Is it what this function designed to be? or with something I made wrong understanding. like parameter owner_events, I can't understand well.
If owner_events is False, all generated pointer events are reported with respect to grab_window and are reported only if selected by event_mask. If owner_events is True and if a generated pointer event would normally be reported to this client, it is reported as usual. Otherwise, the event is reported with respect to the grab_window and is reported only if selected by event_mask. For either value of owner_events, unreported events are discarded.
with explaination of owner_event, it looks like I need to register two event type: ButtonPressMask|PointerMotionMask and owner_events True? but that doesn't work either.
回答1:
The key is in the last sentence of the description you posted:
For either value of owner_events, unreported events are discarded.
I.e. it doesn't matter if owner_events is True or False, events that are not handled are discarded. The subtelty of owner_events is to which window the events are delivered: if owner_events == False all pointer events matching the mask are sent to the grabbing window, even if the event is in other windows that belong to you application (Client in X parlance); coordinates are relative to the grabbing window too. If owner_events == True events are reported to any window of your application, but not to other applications.
XGrabPointer really grabs all pointer events, and this is very strong. It is normally only used for transient (temporary) windows like popups, expanding dropdown windows, etc. The reason is to keep track of clicks outside of the window so you can close the transient. I've used in a color selector popup: when the users clicks on the "choose color" button a popup appears, I do a XGrabPointer (..False..), so I get all click events. If a user clicks outside of my popup window I close the window as if the user did not make a selection. Without XGrabPointer I would not know this happened and the popup would remain open until the user clicked in it. The XGrabPointer is immediately removed when the popup closes.
来源:https://stackoverflow.com/questions/32122360/x11-will-xgrabpointer-prevent-other-apps-from-any-mouse-event