src/video/x11/SDL_x11mouse.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/video/x11/SDL_x11mouse.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/video/x11/SDL_x11mouse.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -39,21 +39,21 @@
     1.4  
     1.5  
     1.6  void
     1.7 -X11_FreeWMCursor (_THIS, WMcursor * cursor)
     1.8 +X11_FreeWMCursor(_THIS, WMcursor * cursor)
     1.9  {
    1.10      if (SDL_Display != NULL) {
    1.11 -        SDL_Lock_EventThread ();
    1.12 -        XFreeCursor (SDL_Display, cursor->x_cursor);
    1.13 -        XSync (SDL_Display, False);
    1.14 -        SDL_Unlock_EventThread ();
    1.15 +        SDL_Lock_EventThread();
    1.16 +        XFreeCursor(SDL_Display, cursor->x_cursor);
    1.17 +        XSync(SDL_Display, False);
    1.18 +        SDL_Unlock_EventThread();
    1.19      }
    1.20 -    SDL_free (cursor);
    1.21 +    SDL_free(cursor);
    1.22  }
    1.23  
    1.24  WMcursor *
    1.25 -X11_CreateWMCursor (_THIS,
    1.26 -                    Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
    1.27 -                    int hot_y)
    1.28 +X11_CreateWMCursor(_THIS,
    1.29 +                   Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
    1.30 +                   int hot_y)
    1.31  {
    1.32      WMcursor *cursor;
    1.33      XGCValues GCvalues;
    1.34 @@ -66,25 +66,25 @@
    1.35      static XColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
    1.36  
    1.37      /* Allocate the cursor memory */
    1.38 -    cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor));
    1.39 +    cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
    1.40      if (cursor == NULL) {
    1.41 -        SDL_OutOfMemory ();
    1.42 +        SDL_OutOfMemory();
    1.43          return (NULL);
    1.44      }
    1.45  
    1.46      /* Mix the mask and the data */
    1.47      clen = (w / 8) * h;
    1.48 -    x_data = (char *) SDL_malloc (clen);
    1.49 +    x_data = (char *) SDL_malloc(clen);
    1.50      if (x_data == NULL) {
    1.51 -        SDL_free (cursor);
    1.52 -        SDL_OutOfMemory ();
    1.53 +        SDL_free(cursor);
    1.54 +        SDL_OutOfMemory();
    1.55          return (NULL);
    1.56      }
    1.57 -    x_mask = (char *) SDL_malloc (clen);
    1.58 +    x_mask = (char *) SDL_malloc(clen);
    1.59      if (x_mask == NULL) {
    1.60 -        SDL_free (cursor);
    1.61 -        SDL_free (x_data);
    1.62 -        SDL_OutOfMemory ();
    1.63 +        SDL_free(cursor);
    1.64 +        SDL_free(x_data);
    1.65 +        SDL_OutOfMemory();
    1.66          return (NULL);
    1.67      }
    1.68      for (i = 0; i < clen; ++i) {
    1.69 @@ -97,59 +97,59 @@
    1.70      }
    1.71  
    1.72      /* Prevent the event thread from running while we use the X server */
    1.73 -    SDL_Lock_EventThread ();
    1.74 +    SDL_Lock_EventThread();
    1.75  
    1.76      /* Create the data image */
    1.77 -    data_image = XCreateImage (SDL_Display,
    1.78 -                               DefaultVisual (SDL_Display, SDL_Screen),
    1.79 -                               1, XYBitmap, 0, x_data, w, h, 8, w / 8);
    1.80 +    data_image = XCreateImage(SDL_Display,
    1.81 +                              DefaultVisual(SDL_Display, SDL_Screen),
    1.82 +                              1, XYBitmap, 0, x_data, w, h, 8, w / 8);
    1.83      data_image->byte_order = MSBFirst;
    1.84      data_image->bitmap_bit_order = MSBFirst;
    1.85 -    data_pixmap = XCreatePixmap (SDL_Display, SDL_Root, w, h, 1);
    1.86 +    data_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
    1.87  
    1.88      /* Create the data mask */
    1.89 -    mask_image = XCreateImage (SDL_Display,
    1.90 -                               DefaultVisual (SDL_Display, SDL_Screen),
    1.91 -                               1, XYBitmap, 0, x_mask, w, h, 8, w / 8);
    1.92 +    mask_image = XCreateImage(SDL_Display,
    1.93 +                              DefaultVisual(SDL_Display, SDL_Screen),
    1.94 +                              1, XYBitmap, 0, x_mask, w, h, 8, w / 8);
    1.95      mask_image->byte_order = MSBFirst;
    1.96      mask_image->bitmap_bit_order = MSBFirst;
    1.97 -    mask_pixmap = XCreatePixmap (SDL_Display, SDL_Root, w, h, 1);
    1.98 +    mask_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
    1.99  
   1.100      /* Create the graphics context */
   1.101      GCvalues.function = GXcopy;
   1.102      GCvalues.foreground = ~0;
   1.103      GCvalues.background = 0;
   1.104      GCvalues.plane_mask = AllPlanes;
   1.105 -    GCcursor = XCreateGC (SDL_Display, data_pixmap,
   1.106 -                          (GCFunction | GCForeground | GCBackground |
   1.107 -                           GCPlaneMask), &GCvalues);
   1.108 +    GCcursor = XCreateGC(SDL_Display, data_pixmap,
   1.109 +                         (GCFunction | GCForeground | GCBackground |
   1.110 +                          GCPlaneMask), &GCvalues);
   1.111  
   1.112      /* Blit the images to the pixmaps */
   1.113 -    XPutImage (SDL_Display, data_pixmap, GCcursor, data_image,
   1.114 -               0, 0, 0, 0, w, h);
   1.115 -    XPutImage (SDL_Display, mask_pixmap, GCcursor, mask_image,
   1.116 -               0, 0, 0, 0, w, h);
   1.117 -    XFreeGC (SDL_Display, GCcursor);
   1.118 +    XPutImage(SDL_Display, data_pixmap, GCcursor, data_image,
   1.119 +              0, 0, 0, 0, w, h);
   1.120 +    XPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image,
   1.121 +              0, 0, 0, 0, w, h);
   1.122 +    XFreeGC(SDL_Display, GCcursor);
   1.123      /* These free the x_data and x_mask memory pointers */
   1.124 -    XDestroyImage (data_image);
   1.125 -    XDestroyImage (mask_image);
   1.126 +    XDestroyImage(data_image);
   1.127 +    XDestroyImage(mask_image);
   1.128  
   1.129      /* Create the cursor */
   1.130 -    cursor->x_cursor = XCreatePixmapCursor (SDL_Display, data_pixmap,
   1.131 -                                            mask_pixmap, &black, &white,
   1.132 -                                            hot_x, hot_y);
   1.133 -    XFreePixmap (SDL_Display, data_pixmap);
   1.134 -    XFreePixmap (SDL_Display, mask_pixmap);
   1.135 +    cursor->x_cursor = XCreatePixmapCursor(SDL_Display, data_pixmap,
   1.136 +                                           mask_pixmap, &black, &white,
   1.137 +                                           hot_x, hot_y);
   1.138 +    XFreePixmap(SDL_Display, data_pixmap);
   1.139 +    XFreePixmap(SDL_Display, mask_pixmap);
   1.140  
   1.141      /* Release the event thread */
   1.142 -    XSync (SDL_Display, False);
   1.143 -    SDL_Unlock_EventThread ();
   1.144 +    XSync(SDL_Display, False);
   1.145 +    SDL_Unlock_EventThread();
   1.146  
   1.147      return (cursor);
   1.148  }
   1.149  
   1.150  int
   1.151 -X11_ShowWMCursor (_THIS, WMcursor * cursor)
   1.152 +X11_ShowWMCursor(_THIS, WMcursor * cursor)
   1.153  {
   1.154      /* Don't do anything if the display is gone */
   1.155      if (SDL_Display == NULL) {
   1.156 @@ -158,36 +158,36 @@
   1.157  
   1.158      /* Set the X11 cursor cursor, or blank if cursor is NULL */
   1.159      if (SDL_Window) {
   1.160 -        SDL_Lock_EventThread ();
   1.161 +        SDL_Lock_EventThread();
   1.162          if (cursor == NULL) {
   1.163              if (SDL_BlankCursor != NULL) {
   1.164 -                XDefineCursor (SDL_Display, SDL_Window,
   1.165 -                               SDL_BlankCursor->x_cursor);
   1.166 +                XDefineCursor(SDL_Display, SDL_Window,
   1.167 +                              SDL_BlankCursor->x_cursor);
   1.168              }
   1.169          } else {
   1.170 -            XDefineCursor (SDL_Display, SDL_Window, cursor->x_cursor);
   1.171 +            XDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor);
   1.172          }
   1.173 -        XSync (SDL_Display, False);
   1.174 -        SDL_Unlock_EventThread ();
   1.175 +        XSync(SDL_Display, False);
   1.176 +        SDL_Unlock_EventThread();
   1.177      }
   1.178      return (1);
   1.179  }
   1.180  
   1.181  void
   1.182 -X11_WarpWMCursor (_THIS, Uint16 x, Uint16 y)
   1.183 +X11_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
   1.184  {
   1.185      if (using_dga & DGA_MOUSE) {
   1.186 -        SDL_PrivateMouseMotion (0, 0, x, y);
   1.187 +        SDL_PrivateMouseMotion(0, 0, x, y);
   1.188      } else if (mouse_relative) {
   1.189          /*      RJR: March 28, 2000
   1.190             leave physical cursor at center of screen if
   1.191             mouse hidden and grabbed */
   1.192 -        SDL_PrivateMouseMotion (0, 0, x, y);
   1.193 +        SDL_PrivateMouseMotion(0, 0, x, y);
   1.194      } else {
   1.195 -        SDL_Lock_EventThread ();
   1.196 -        XWarpPointer (SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y);
   1.197 -        XSync (SDL_Display, False);
   1.198 -        SDL_Unlock_EventThread ();
   1.199 +        SDL_Lock_EventThread();
   1.200 +        XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y);
   1.201 +        XSync(SDL_Display, False);
   1.202 +        SDL_Unlock_EventThread();
   1.203      }
   1.204  }
   1.205  
   1.206 @@ -197,27 +197,27 @@
   1.207     denumenator and threshold.
   1.208  */
   1.209  static void
   1.210 -SetMouseAccel (_THIS, const char *accel_param)
   1.211 +SetMouseAccel(_THIS, const char *accel_param)
   1.212  {
   1.213      int i;
   1.214      size_t len;
   1.215      int accel_value[3];
   1.216      char *mouse_param, *mouse_param_buf, *pin;
   1.217  
   1.218 -    len = SDL_strlen (accel_param) + 1;
   1.219 -    mouse_param_buf = SDL_stack_alloc (char, len);
   1.220 +    len = SDL_strlen(accel_param) + 1;
   1.221 +    mouse_param_buf = SDL_stack_alloc(char, len);
   1.222      if (!mouse_param_buf) {
   1.223          return;
   1.224      }
   1.225 -    SDL_strlcpy (mouse_param_buf, accel_param, len);
   1.226 +    SDL_strlcpy(mouse_param_buf, accel_param, len);
   1.227      mouse_param = mouse_param_buf;
   1.228  
   1.229      for (i = 0; (i < 3) && mouse_param; ++i) {
   1.230 -        pin = SDL_strchr (mouse_param, '/');
   1.231 +        pin = SDL_strchr(mouse_param, '/');
   1.232          if (pin) {
   1.233              *pin = '\0';
   1.234          }
   1.235 -        accel_value[i] = atoi (mouse_param);
   1.236 +        accel_value[i] = atoi(mouse_param);
   1.237          if (pin) {
   1.238              mouse_param = pin + 1;
   1.239          } else {
   1.240 @@ -225,16 +225,15 @@
   1.241          }
   1.242      }
   1.243      if (mouse_param_buf) {
   1.244 -        XChangePointerControl (SDL_Display, True, True,
   1.245 -                               accel_value[0], accel_value[1],
   1.246 -                               accel_value[2]);
   1.247 -        SDL_free (mouse_param_buf);
   1.248 +        XChangePointerControl(SDL_Display, True, True,
   1.249 +                              accel_value[0], accel_value[1], accel_value[2]);
   1.250 +        SDL_free(mouse_param_buf);
   1.251      }
   1.252  }
   1.253  
   1.254  /* Check to see if we need to enter or leave mouse relative mode */
   1.255  void
   1.256 -X11_CheckMouseModeNoLock (_THIS)
   1.257 +X11_CheckMouseModeNoLock(_THIS)
   1.258  {
   1.259      const Uint8 full_focus =
   1.260          (SDL_APPACTIVE | SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS);
   1.261 @@ -245,30 +244,30 @@
   1.262         They almost never want to do this, as it seriously affects
   1.263         applications that rely on continuous relative mouse motion.
   1.264       */
   1.265 -    env_override = SDL_getenv ("SDL_MOUSE_RELATIVE");
   1.266 +    env_override = SDL_getenv("SDL_MOUSE_RELATIVE");
   1.267      if (env_override) {
   1.268 -        enable_relative = atoi (env_override);
   1.269 +        enable_relative = atoi(env_override);
   1.270      }
   1.271  
   1.272      /* If the mouse is hidden and input is grabbed, we use relative mode */
   1.273      if (enable_relative &&
   1.274          !(SDL_cursorstate & CURSOR_VISIBLE) &&
   1.275          (SDL_CurrentWindow.input_grab != SDL_GRAB_OFF) &&
   1.276 -        (SDL_GetAppState () & full_focus) == full_focus) {
   1.277 +        (SDL_GetAppState() & full_focus) == full_focus) {
   1.278          if (!mouse_relative) {
   1.279 -            X11_EnableDGAMouse (this);
   1.280 +            X11_EnableDGAMouse(this);
   1.281              if (!(using_dga & DGA_MOUSE)) {
   1.282                  char *xmouse_accel;
   1.283  
   1.284 -                SDL_GetMouseState (&mouse_last.x, &mouse_last.y);
   1.285 +                SDL_GetMouseState(&mouse_last.x, &mouse_last.y);
   1.286                  /* Use as raw mouse mickeys as possible */
   1.287 -                XGetPointerControl (SDL_Display,
   1.288 -                                    &mouse_accel.numerator,
   1.289 -                                    &mouse_accel.denominator,
   1.290 -                                    &mouse_accel.threshold);
   1.291 -                xmouse_accel = SDL_getenv ("SDL_VIDEO_X11_MOUSEACCEL");
   1.292 +                XGetPointerControl(SDL_Display,
   1.293 +                                   &mouse_accel.numerator,
   1.294 +                                   &mouse_accel.denominator,
   1.295 +                                   &mouse_accel.threshold);
   1.296 +                xmouse_accel = SDL_getenv("SDL_VIDEO_X11_MOUSEACCEL");
   1.297                  if (xmouse_accel) {
   1.298 -                    SetMouseAccel (this, xmouse_accel);
   1.299 +                    SetMouseAccel(this, xmouse_accel);
   1.300                  }
   1.301              }
   1.302              mouse_relative = 1;
   1.303 @@ -276,23 +275,23 @@
   1.304      } else {
   1.305          if (mouse_relative) {
   1.306              if (using_dga & DGA_MOUSE) {
   1.307 -                X11_DisableDGAMouse (this);
   1.308 +                X11_DisableDGAMouse(this);
   1.309              } else {
   1.310 -                XChangePointerControl (SDL_Display, True, True,
   1.311 -                                       mouse_accel.numerator,
   1.312 -                                       mouse_accel.denominator,
   1.313 -                                       mouse_accel.threshold);
   1.314 +                XChangePointerControl(SDL_Display, True, True,
   1.315 +                                      mouse_accel.numerator,
   1.316 +                                      mouse_accel.denominator,
   1.317 +                                      mouse_accel.threshold);
   1.318              }
   1.319              mouse_relative = 0;
   1.320          }
   1.321      }
   1.322  }
   1.323  void
   1.324 -X11_CheckMouseMode (_THIS)
   1.325 +X11_CheckMouseMode(_THIS)
   1.326  {
   1.327 -    SDL_Lock_EventThread ();
   1.328 -    X11_CheckMouseModeNoLock (this);
   1.329 -    SDL_Unlock_EventThread ();
   1.330 +    SDL_Lock_EventThread();
   1.331 +    X11_CheckMouseModeNoLock(this);
   1.332 +    SDL_Unlock_EventThread();
   1.333  }
   1.334  
   1.335  /* vi: set ts=4 sw=4 expandtab: */