home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / xgalaga-2_0_tar.gz / xgalaga-2_0_tar / xgalaga-2.0 / libsprite / mouse.c < prev    next >
C/C++ Source or Header  |  1998-04-12  |  2KB  |  101 lines

  1. #include "allincludes.h"
  2.  
  3. static void
  4. findMouse(x, y)
  5.     int    *x, *y;
  6. {
  7.     Window  theRoot, theChild;
  8.     int     wX, wY, rootX, rootY, ErrorVal;
  9.     unsigned int wButtons;
  10.  
  11.     ErrorVal = XQueryPointer(W_Display, W_Root, &theRoot, &theChild, &rootX, &rootY, &wX, &wY, &wButtons);
  12.     if (ErrorVal == True) {
  13.     *x = wX;
  14.     *y = wY;
  15.     } else {
  16.     *x = 0;
  17.     *y = 0;
  18.     }
  19. }
  20.  
  21. void
  22. W_WarpPointer(window, x, y)
  23.     W_Window window;
  24.     int     x, y;
  25. {
  26.     static int warped_from_x = 0, warped_from_y = 0;
  27.  
  28.     if (window == NULL) {
  29.     if (W_in_message) {
  30.         XWarpPointer(W_Display, None, W_Root, 0, 0, 0, 0, warped_from_x, warped_from_y);
  31.         W_in_message = 0;
  32.     }
  33.     } else {
  34.     findMouse(&warped_from_x, &warped_from_y);
  35.     XWarpPointer(W_Display, None, W_Void2Window(window)->window, 0, 0, 0, 0, 0, 0);
  36.     W_in_message = 1;
  37.     }
  38. }
  39.  
  40. int
  41. findMouseInWin(x, y, window)
  42.     int    *x, *y;
  43.     W_Window window;
  44. {
  45.     Window  theRoot, theChild;
  46.     int     wX, wY, rootX, rootY, ErrorVal;
  47.     unsigned int wButtons;
  48.     struct window *win = W_Void2Window(window);
  49.     Window  thisWin = win->window;
  50.  
  51.     ErrorVal = XQueryPointer(W_Display, thisWin, &theRoot, &theChild,
  52.                &rootX, &rootY, &wX, &wY, &wButtons);
  53.     if (ErrorVal == True) {
  54.     /*
  55.        if it's in the window we specified then the values returned should
  56.        be within the with and height of the window
  57.     */
  58.     if (wX <= win->width && wY <= win->height) {
  59.         *x = wX;
  60.         *y = wY;
  61.         return 1;
  62.     }
  63.     }
  64.     *x = 0;
  65.     *y = 0;
  66.     return 0;
  67. }
  68.  
  69. void
  70. W_GetMouse(window, x, y, but)
  71.      W_Window window;
  72.      int *x, *y, *but;
  73. {
  74.     struct window *win = W_Void2Window(window);
  75.     Window QueryRoot, QueryChild;
  76.     int AbsoluteX, AbsoluteY;
  77.     unsigned int            ModKeyMask;
  78.  
  79.     XQueryPointer( W_Display, win->window, &QueryRoot, &QueryChild, &AbsoluteX, &AbsoluteY, x, y, &ModKeyMask );
  80.  
  81.     if(ModKeyMask & Button1Mask)
  82.     *but = W_LBUTTON;
  83.     else
  84.     *but = 0;
  85. }
  86.  
  87. void
  88. W_GrabPointer(window)
  89.      W_Window window;
  90. {
  91.     struct window *win = W_Void2Window(window);
  92.  
  93.     XGrabPointer(W_Display, win->window, True, 0, GrabModeAsync, GrabModeAsync, win->window, None, CurrentTime);
  94. }
  95.  
  96. void
  97. W_UngrabPointer()
  98. {
  99.     XUngrabPointer(W_Display, CurrentTime);
  100. }
  101.