Question

I am trying to create a a mouse wrap within X11 for openGL games/content. The approach I was trying to take is to hide the cursor (which I can do just fine), lock the mouse position in the center of the window and then use the mouse delta positions to detect movement. I cannot find any way however to lock the mouse position other then to keep moving it back to the center every frame.

In windows this can be done with ClipCursor() and in OSX mouse wrap can be done using CGWarpMouseCursorPosition. Does anything similar exist within the XLib libraries?

Was it helpful?

Solution

libSDL does almost exactly that and the source code of this might be a good starting point for your own implementation. Alternatively if the goal is cross-platform fullscreen application then just using SDL directly might save you reinventing the wheel here.

The file in question for X11 seems to be src/video/x11/SDL_x11mouse.c, in particular the implementation of X11_WarpWMCursor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top