Sign in to follow this  
InetRoadkill

Raw mouse input on X11/Linux

Recommended Posts

I need raw mouse movements (delta x,y) from the mouse on X11. I have Xinput2 working, except it stops sending events whenever a mouse button is down. From my understanding, this has to do with implied window grabbing. Is there a way around this? (The WarpMouse trick won't work here.)

Share this post


Link to post
Share on other sites

I'm not a Linux developer, but I do know that windows in X11 have attributes, so I searched for "xwindow attributes", and found this: http://tronche.com/gui/x/xlib/window/attributes/override-redirect.html . Of course, if you are using a library (maybe SDL), it should've (probably?) already applied the correct window attributes for you.

Edited by tonemgub

Share this post


Link to post
Share on other sites

Yes, this can be made to work. Make sure you have the correct events selected.

 

A complete working example can be found here: OpenTK/Platform/X11/XI2MouseKeyboard.cs. This has been tested and is working on both X.org and XQuartz.

 

The source code is in C#, but most of it should be trivial to port to C or C++. Feel free to ask if you have any questions.

 

Edit: raw input has been pulled from SDL2 for some reason, which is rather unfortunate. You can only use regular input events (single mouse with pointer acceleration etc.)

 

Edit 2: do not use WarpMouse unless you really hate your users. That was necessary back in the core X11 days, due to the lack of relative motion events, but this is no longer necessary with XInput2. Do note that some devices, such as the VMware mouse driver, do not report relative motion events. Actual mice do not have this problem.

Edited by Fiddler

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this