How can I lock the cursor to the inside of a window on Linux?

久未见 提交于 2019-12-06 10:28:07

问题


I'm trying to put together a game for Linux which involves a lot of fast action and flinging around of the mouse cursor. If the user wants to play in windowed mode, I'd quite like to lock the cursor to the inside of the window to avoid accidentally changing programs in the heat of battle (obviously this will cancel itself if the user changes programs or hits escape for the pause menu.)

On Windows, this can be accomplished easily with ClipCursor(). I can't find an equivalent on Linux. Is there one?

I plan to do this in pure X code, but obviously if anyone knows of a way to do this in any Linux windowing library then I can just read the source code and figure out how to duplicate it in X.


回答1:


int XGrabPointer(Display *display, Window grab_window, Bool owner_events, unsigned int event_mask, int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor, Time time);

confine_to
        Specifies the window to confine the pointer in or None.



来源:https://stackoverflow.com/questions/4642867/how-can-i-lock-the-cursor-to-the-inside-of-a-window-on-linux

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