Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <X11/Xlib.h>
  5. #include <array>
  6.  
  7. std::array<int, 2> getScreenSize(Display* p_display)
  8. {
  9.     std::array<int, 2> screen_size{ { -1, -1 } };
  10.     Screen* pscr = NULL;
  11.  
  12.  
  13.     pscr = DefaultScreenOfDisplay( p_display );
  14.     if ( !pscr ) {
  15.         fprintf(stderr, "Failed to obtain the default screen of given display.\n");
  16.         return screen_size;
  17.     }
  18.  
  19.     screen_size[0] = pscr->width;
  20.     screen_size[1] = pscr->height;
  21.    
  22.     return screen_size;
  23. }
  24.  
  25. int main(){
  26.     std::array<int, 2> screen_size;
  27.     std::array<int, 2> cursor_pos;
  28.    
  29.     Display *dpy;
  30.     Window root;
  31.     Window ret_root;
  32.     Window ret_child;
  33.     unsigned int mask;
  34.     int empty;
  35.    
  36.     dpy = XOpenDisplay(NULL);
  37.     root = XDefaultRootWindow(dpy);
  38.     screen_size = getScreenSize(dpy);
  39.    
  40.    
  41.     if(XQueryPointer(dpy, root, &ret_root, &ret_child, &cursor_pos[0], &cursor_pos[1],&empty, &empty, &mask)){
  42.         printf("+%d+%d\n", cursor_pos[0], cursor_pos[1]);
  43.         usleep(499999);
  44.     }
  45.     else{
  46.         printf("CO DO LUJA?!");
  47.     }
  48.    
  49.  
  50.     printf (" Screen:  width = %d, height = %d \n", screen_size[0], screen_size[1]);
  51.     if(XQueryPointer(dpy, root, &ret_root, &ret_child, &cursor_pos[0], &cursor_pos[1],&empty, &empty, &mask)){
  52.         printf("+%d+%d\n", cursor_pos[0], cursor_pos[1]);
  53.         usleep(499999);
  54.     }
  55.    
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement