Locking mouse pointer using xGrabPointer in Linux

允我心安 提交于 2019-12-24 06:45:08

问题


I am using X11 to get mouse position when the mouse button is pressed in a application which runs on terminal without any window.

Getting Mouse Position :

Display *dpy;
Window root, child;
int rootX, rootY, winX, winY;
unsigned int mask;
dpy = XOpenDisplay(NULL);
XQueryPointer(dpy,DefaultRootWindow(dpy),&root,&child,
             &rootX,&rootY,&winX,&winY,&mask);

Now I want to use XGrabPointer() to lock the mouse so that it does not interact with objects(windows , icons and docks ) present on desktop . here is the documentation of XGrabPointer , but I don't seem to understand how to use it and what arguments to pass .


回答1:


This is the correct format that seems to work for me .

int g=XGrabPointer(dpy,DefaultRootWindow(dpy), true, ButtonPressMask |
                 ButtonReleaseMask |
                 PointerMotionMask |
                 FocusChangeMask |
                EnterWindowMask |
                  LeaveWindowMask,GrabModeAsync,GrabModeAsync, None, None, CurrentTime);


来源:https://stackoverflow.com/questions/12072886/locking-mouse-pointer-using-xgrabpointer-in-linux

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