Fix bad mouse

Thomas Jaeger thjaeger at
Sat Aug 23 22:53:55 PDT 2008

Haoyu Bai wrote:
> My question is, how to implement such a feature in X? One possible way
> is to hack the mouse driver, but this could made this feature
> unportable, because there are many mouse drivers. The second way is to
> write a X11 client program which grab all button events, and then
> block false events and resend the true events. I tried the second way,
> but encountered some problem: I use XGrabButton() to grab events, and
> then ungrab, then resend them using the XTest extension, but finally I
> received the event I was sent, and that usually caused an infinite
> loop.
If you supply GrabModeSync as the pointer_mode argument in XGrabButton,
then whenever a button is pressed event processing will be frozen until
you call XAllowEvents: an event_mode of ReplayPointer will pass the
event (and all the following events until all buttons are released) to
the application, if event_mode is AsyncPointer or SyncPointer the event
will only be reported to your application.  See for details.

If you really want (or need) to resend events the sequence "Fake
ButtonRelease - Wait for Release - Ungrab - Fake ButtonPress - Grab"
will also work -- but there is potential for race conditions.

The basic limitation is that you once you pass control to another
application, you won't receive any subsequent ButtonPresse or
ButtonRelease events until all the buttons are up again.


More information about the xorg mailing list