I'm running two fullscreen apps on two monitors on Ubuntu 16.10. app1 needs the pointer and must be focused all time, so I need to lock the pointer in app1.
I had written a tool to grab the pointer like this:
#include <stdio.h>
#include <X11/Xlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
Display *display;
XEvent xevent;
Window window;
int x,y;
void setPos(int x,int y){
XWarpPointer(display,None,window,0,0,0,0,x,y);
XFlush(display);
}
int main(int argc, char **argv){
if( (display = XOpenDisplay(NULL)) == NULL )
return -1;
window = DefaultRootWindow(display);
XAllowEvents(display, AsyncBoth, CurrentTime);
XGrabPointer(display,window,0,PointerMotionMask,GrabModeAsync,GrabModeAsync,None,None,CurrentTime);
while(1) {
XNextEvent(display, &xevent);
switch (xevent.type) {
case MotionNotify:
if(xevent.xmotion.x_root>1920){
setPos(1920,xevent.xmotion.y_root);
}
break;
}
}
return 0;
}
This tool can capture the pointer's event and limit the pointer stay in app1, but the pointer can't operate anything in app1. All pointer event except motion are not working. Is there any suggestion to the codes? Or any other idea to finish the work?