Discussion:
XWarpPointer breaks raw mouse input.
Mad Fish The One
2010-09-06 15:52:09 UTC
Permalink
I'm writing a game, and I want raw mouse input to control camera (so no
additional acceleration by X server) and don't want mouse to escape the
window (for obvious reasons).
I'm using XI_RawMotion events for raw mouse input, and XWarpPointer to not
allow mouse escape the window.
Well, the problem is, when XWarpPointer is called, XI_RawMotion is posted
with coordinates of XWarpPointer's target point in screen coordinates. But
it shouldn't - isn't it RAW input?
How to do it right?

Minimal test case: http://pastebin.com/WFJULnYk
(captures RawMotion events, and sends XWarpPointer sometimes).
Compile as: "gcc warptest.c -o warptest -lX11 -lXi"
You will see a series of normal events, and then a strange event generated
by XWarpPointer.

Anyway, is there a better method of containing pointer in a window without
breaking Alt+Tab (that's what XGrabPointer does)?
Can you also recommend some general best practices with X input for games?

P.S. Currently using X server 1.8.2 on Arch Linux.
Peter Hutterer
2010-09-09 23:00:13 UTC
Permalink
Post by Mad Fish The One
I'm writing a game, and I want raw mouse input to control camera (so no
additional acceleration by X server) and don't want mouse to escape the
window (for obvious reasons).
I'm using XI_RawMotion events for raw mouse input, and XWarpPointer to not
allow mouse escape the window.
Well, the problem is, when XWarpPointer is called, XI_RawMotion is posted
with coordinates of XWarpPointer's target point in screen coordinates. But
it shouldn't - isn't it RAW input?
How to do it right?
WarpPointer must generate normal motion events, that's a core protocol spec
requirement and labeled so in the XI2 specs as well.
we don't need raw events though.
A quick peek at the code seems we need something like a POINTER_WARP or
POINTER_NO_RAW flag to be passed into GPE to skip the creation of raw
events. that should be enough.

patches welcome of course. don't hold your breath that I'll get to
implementing it myself anytime soon, sorry.
Post by Mad Fish The One
Minimal test case: http://pastebin.com/WFJULnYk
(captures RawMotion events, and sends XWarpPointer sometimes).
Compile as: "gcc warptest.c -o warptest -lX11 -lXi"
You will see a series of normal events, and then a strange event generated
by XWarpPointer.
Anyway, is there a better method of containing pointer in a window without
breaking Alt+Tab (that's what XGrabPointer does)?
no, there unfortunately isn't yet.

if you're not using the cursor itself because you're e.g. rendering your own
or it's not needed by the application, you can grab the slave devices
directly and detach them. in that case you don't have to worry about warp
pointer at all.

Cheers,
Peter
Post by Mad Fish The One
Can you also recommend some general best practices with X input for games?
P.S. Currently using X server 1.8.2 on Arch Linux.
Loading...