//para compilar //g++ -I /usr/X11/include -L /usr/X11/lib -o sal x1.cc -lX11 //sal es el nombre del ejecutable #include #include enum { _NET_WM_STATE_REMOVE =0, _NET_WM_STATE_ADD = 1, _NET_WM_STATE_TOGGLE =2 }; void fuul(Display *,Window ); void drawCroshair(Display *, Window, int, int, int); int main() { Display * pDisplay = XOpenDisplay(NULL); int screen = DefaultScreen(pDisplay); int calibration=0; int posX,posY; int screenWidth=DisplayWidth(pDisplay,screen); int screenHeight=DisplayHeight(pDisplay,screen); XSetWindowAttributes attr; attr.border_pixel = 0; attr.background_pixel = WhitePixel(pDisplay,screen); attr.event_mask = ExposureMask | StructureNotifyMask; Window parentWindow = RootWindow(pDisplay, screen); Window window = XCreateWindow(pDisplay, parentWindow, 0,0, //left top 640, 480, 0, 0, InputOutput, CopyFromParent, CWBackPixel | CWBorderPixel | CWEventMask, &attr); XWarpPointer(pDisplay, None, window, 0, 0, 0, 0, 100, 100); XGrabKeyboard(pDisplay, window, True, GrabModeAsync, GrabModeAsync,CurrentTime); XGrabPointer(pDisplay, window, True, None, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XMapRaised(pDisplay, window); XSelectInput(pDisplay, window, KeyPressMask | ButtonPressMask | PointerMotionMask); //bool fullScreen = true; fuul(pDisplay, window); printf("calibration %i \n",calibration); drawCroshair(pDisplay, window, calibration, screenWidth, screenHeight); bool run = true; while (run) { XEvent event; //KeySym keySym; while (XPending(pDisplay) > 0) { XNextEvent(pDisplay, &event); switch(event.type) { case KeyPress: { printf("Recalibracion \n"); //limpiarPantalla(); XClearWindow(pDisplay,window); XFlush(pDisplay); calibration=0; drawCroshair(pDisplay, window, calibration, screenWidth, screenHeight); break; } case ButtonPress: { printf("click %i\n",calibration+1); printf("posicion: %i,%i \n",posX,posY); calibration++; drawCroshair(pDisplay, window, calibration, screenWidth, screenHeight); if(calibration>3){ printf("fin calibration \n"); drawCroshair(pDisplay, window, -1, screenWidth, screenHeight); run = false; } if(calibration==4) { run=false; } break; } case 6: { //=====================================================Capturar el IR, en vez del raton //printf("%i,%i \n",event.xmotion.x, event.xmotion.y); posX=event.xmotion.x; posY=event.xmotion.y; break; } default: { //printf("%i \n",event.type); break; } } } } XCloseDisplay(pDisplay); } void drawCroshair(Display* pDisplay, Window window, int num, int screenWidth, int screenHeight){ int size=100; float calibrationMargin=0.1; int x=0; int y=0; GC gc = XCreateGC(pDisplay, window, 0, NULL); XSetForeground(pDisplay, gc, BlackPixel(pDisplay, DefaultScreen(pDisplay))); //printf("case %i \n",num); switch (num){ case 0: { //limpiar la pantalla XClearWindow(pDisplay,window); XFlush(pDisplay); //dibujar la marca x = (int)(screenWidth * calibrationMargin); y = (int)(screenHeight * calibrationMargin); XDrawLine(pDisplay, window, gc, x-(size/2), y, x+(size/2), y); XDrawLine(pDisplay, window, gc, x, y-(size/2), x, y+(size/2)); XFlush(pDisplay); //capturar el click break; } case 1: { //limpiar la pantalla XClearWindow(pDisplay,window); XFlush(pDisplay); //dibujar la marca x = (int)screenWidth -(int)(screenWidth * calibrationMargin); y = (int)(screenHeight * calibrationMargin); XDrawLine(pDisplay, window, gc, x-(size/2), y, x+(size/2), y); XDrawLine(pDisplay, window, gc, x, y-(size/2), x, y+(size/2)); XFlush(pDisplay); //capturar el click break; } case 2: { //limpiar la pantalla XClearWindow(pDisplay,window); XFlush(pDisplay); //dibujar la marca x = (int)(screenWidth * calibrationMargin); y = (int)screenHeight-(int)(screenHeight * calibrationMargin); XDrawLine(pDisplay, window, gc, x-(size/2), y, x+(size/2), y); XDrawLine(pDisplay, window, gc, x, y-(size/2), x, y+(size/2)); XFlush(pDisplay); //capturar el click break; } case 3: { //limpiar la pantalla XClearWindow(pDisplay,window); XFlush(pDisplay); //dibujar la marca x = (int)screenWidth -(int)(screenWidth * calibrationMargin); y = (int)screenHeight-(int)(screenHeight * calibrationMargin); XDrawLine(pDisplay, window, gc, x-(size/2), y, x+(size/2), y); XDrawLine(pDisplay, window, gc, x, y-(size/2), x, y+(size/2)); XFlush(pDisplay); //capturar el click break; } default: { break; } } }; void fuul(Display *pDisplay,Window window){ Atom wmState = XInternAtom(pDisplay, "_NET_WM_STATE", False); Atom afullScreen = XInternAtom(pDisplay,"_NET_WM_STATE_FULLSCREEN", False); XEvent xev; xev.xclient.type=ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event=True; xev.xclient.window=window; xev.xclient.message_type=wmState; xev.xclient.format=32; xev.xclient.data.l[0] = (afullScreen ? _NET_WM_STATE_ADD :_NET_WM_STATE_REMOVE); xev.xclient.data.l[1] = afullScreen; xev.xclient.data.l[2] = 0; XSendEvent(pDisplay, DefaultRootWindow(pDisplay), False, SubstructureRedirectMask | SubstructureNotifyMask,&xev); }