XLib Lock Mouse position (Mouse wrap)

拜拜、爱过 提交于 2019-12-10 19:43:50

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4124446/xlib-lock-mouse-position-mouse-wrap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!