Skip to content
Advertisement

Hook and block globally mouse in X11

I need to hook globally mouse clicks and block last click if delay between two clicks is less than was set.

I wrote it for windows using WM_MOUSE_LL hook. I was unable to find any solution for me. Is it even possible to globally block mouse click in X11 ?

Windows full code

Advertisement

Answer

As far as I know the standard X11 protocol doesn’t allow this. The XInput 2.0 extension might, but I doubt it.. while Windows assumes a single event queue that every program listens to, so that a program can intercept an event and prevent it from being sent down the queue to other listeners, every X11 client has its own independent queue and all clients that register interest in an event receive an independent copy of it in their queue. This means that under normal circumstances it’s impossible for an errant program to block other programs from running; but it also means that, for those times when a client must block other clients, it must do a server grab to prevent the server from processing events for any other client.

Which means you can either

  • use an X server proxy (won’t be hard, but will be pretty slower)

or

  • do it on the input device level. /dev/input/event<n> give you the input events. You can read off the keypresses there and decide if they should propagate further be consumed. Unfortunately there’s no real documentation for this, but the header file linux/include/input.h is quite self explanatory.
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement