src/events/SDL_mouse.c
changeset 4465 3e69e077cb95
parent 4429 faa9fc8e7f67
child 4484 9322f7db8603
     1.1 --- a/src/events/SDL_mouse.c	Sun May 09 19:55:28 2010 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Sun May 09 20:47:22 2010 -0700
     1.3 @@ -29,9 +29,44 @@
     1.4  #include "../video/SDL_sysvideo.h"
     1.5  
     1.6  
     1.7 -static int SDL_num_mice = 0;
     1.8 -static int SDL_current_mouse = -1;
     1.9 -static SDL_Mouse **SDL_mice = NULL;
    1.10 +/* Global mouse information */
    1.11 +
    1.12 +typedef struct SDL_Mouse SDL_Mouse;
    1.13 +
    1.14 +struct SDL_Mouse
    1.15 +{
    1.16 +    /* Create a cursor from a surface */
    1.17 +    SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
    1.18 +
    1.19 +    /* Show the specified cursor, or hide if cursor is NULL */
    1.20 +    int (*ShowCursor) (SDL_Cursor * cursor);
    1.21 +
    1.22 +    /* This is called when a mouse motion event occurs */
    1.23 +    void (*MoveCursor) (SDL_Cursor * cursor);
    1.24 +
    1.25 +    /* Free a window manager cursor */
    1.26 +    void (*FreeCursor) (SDL_Cursor * cursor);
    1.27 +
    1.28 +    /* Warp the mouse to (x,y) */
    1.29 +    void (*WarpMouse) (SDL_Mouse * mouse, SDL_Window * window, int x, int y);
    1.30 +
    1.31 +    /* Data common to all mice */
    1.32 +    SDL_Window *focus;
    1.33 +    int x;
    1.34 +    int y;
    1.35 +    int xdelta;
    1.36 +    int ydelta;
    1.37 +    int last_x, last_y;         /* the last reported x and y coordinates */
    1.38 +    Uint8 buttonstate;
    1.39 +    SDL_bool relative_mode;
    1.40 +
    1.41 +    SDL_Cursor *cursors;
    1.42 +    SDL_Cursor *def_cursor;
    1.43 +    SDL_Cursor *cur_cursor;
    1.44 +    SDL_bool cursor_shown;
    1.45 +};
    1.46 +
    1.47 +static SDL_Mouse SDL_mouse;
    1.48  
    1.49  
    1.50  /* Public functions */
    1.51 @@ -41,370 +76,50 @@
    1.52      return (0);
    1.53  }
    1.54  
    1.55 -SDL_Mouse *
    1.56 -SDL_GetMouse(int index)
    1.57 +void
    1.58 +SDL_ResetMouse(void)
    1.59  {
    1.60 -    if (index < 0 || index >= SDL_num_mice) {
    1.61 -        return NULL;
    1.62 -    }
    1.63 -    return SDL_mice[index];
    1.64 -}
    1.65 -
    1.66 -static int
    1.67 -SDL_GetMouseIndexId(int id)
    1.68 -{
    1.69 -    int index;
    1.70 -    SDL_Mouse *mouse;
    1.71 -
    1.72 -    for (index = 0; index < SDL_num_mice; ++index) {
    1.73 -        mouse = SDL_GetMouse(index);
    1.74 -        if (mouse->id == id) {
    1.75 -            return index;
    1.76 -        }
    1.77 -    }
    1.78 -    return -1;
    1.79 +    /* FIXME */
    1.80  }
    1.81  
    1.82 -int
    1.83 -SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max,
    1.84 -             int pressure_min, int ends)
    1.85 +SDL_Window *
    1.86 +SDL_GetMouseFocus(void)
    1.87  {
    1.88 -    SDL_Mouse **mice;
    1.89 -    int selected_mouse;
    1.90 -    int index;
    1.91 -    size_t length;
    1.92 -
    1.93 -    if (SDL_GetMouseIndexId(mouse->id) != -1) {
    1.94 -        SDL_SetError("Mouse ID already in use");
    1.95 -    }
    1.96 -
    1.97 -    /* Add the mouse to the list of mice */
    1.98 -    mice = (SDL_Mouse **) SDL_realloc(SDL_mice,
    1.99 -                                      (SDL_num_mice + 1) * sizeof(*mice));
   1.100 -    if (!mice) {
   1.101 -        SDL_OutOfMemory();
   1.102 -        return -1;
   1.103 -    }
   1.104 -
   1.105 -    SDL_mice = mice;
   1.106 -    index = SDL_num_mice++;
   1.107 -
   1.108 -    SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
   1.109 -    if (!SDL_mice[index]) {
   1.110 -        SDL_OutOfMemory();
   1.111 -        return -1;
   1.112 -    }
   1.113 -    *SDL_mice[index] = *mouse;
   1.114 +    SDL_Mouse *mouse = &SDL_mouse;
   1.115  
   1.116 -    /* we're setting the mouse properties */
   1.117 -    length = 0;
   1.118 -    length = SDL_strlen(name);
   1.119 -    SDL_mice[index]->focus = 0;
   1.120 -    SDL_mice[index]->name = SDL_malloc((length + 2) * sizeof(char));
   1.121 -    SDL_strlcpy(SDL_mice[index]->name, name, length + 1);
   1.122 -    SDL_mice[index]->pressure_max = pressure_max;
   1.123 -    SDL_mice[index]->pressure_min = pressure_min;
   1.124 -    SDL_mice[index]->cursor_shown = SDL_TRUE;
   1.125 -    selected_mouse = SDL_SelectMouse(index);
   1.126 -    SDL_mice[index]->cur_cursor = NULL;
   1.127 -    SDL_mice[index]->def_cursor =
   1.128 -        SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
   1.129 -                         DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
   1.130 -    SDL_SetCursor(SDL_mice[index]->def_cursor);
   1.131 -    /* we're assuming that all mice are in the computer sensing zone */
   1.132 -    SDL_mice[index]->proximity = SDL_TRUE;
   1.133 -    /* we're assuming that all mice are working in the absolute position mode
   1.134 -       thanx to that, the users that don't want to use many mice don't have to
   1.135 -       worry about anything */
   1.136 -    SDL_mice[index]->relative_mode = SDL_FALSE;
   1.137 -    SDL_mice[index]->current_end = 0;
   1.138 -    SDL_mice[index]->total_ends = ends;
   1.139 -    SDL_SelectMouse(selected_mouse);
   1.140 -
   1.141 -    return index;
   1.142 -}
   1.143 -
   1.144 -void
   1.145 -SDL_DelMouse(int index)
   1.146 -{
   1.147 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.148 -
   1.149 -    if (!mouse) {
   1.150 -        return;
   1.151 -    }
   1.152 -
   1.153 -    mouse->def_cursor = NULL;
   1.154 -    SDL_free(mouse->name);
   1.155 -    while (mouse->cursors) {
   1.156 -        SDL_FreeCursor(mouse->cursors);
   1.157 -    }
   1.158 -
   1.159 -    if (mouse->FreeMouse) {
   1.160 -        mouse->FreeMouse(mouse);
   1.161 -    }
   1.162 -    SDL_free(mouse);
   1.163 -
   1.164 -    SDL_mice[index] = NULL;
   1.165 -}
   1.166 -
   1.167 -void
   1.168 -SDL_ResetMouse(int index)
   1.169 -{
   1.170 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.171 -
   1.172 -    if (!mouse) {
   1.173 -        return;
   1.174 -    }
   1.175 -
   1.176 -    /* FIXME */
   1.177 +    return mouse->focus;
   1.178  }
   1.179  
   1.180  void
   1.181 -SDL_MouseQuit(void)
   1.182 -{
   1.183 -    int i;
   1.184 -
   1.185 -    for (i = 0; i < SDL_num_mice; ++i) {
   1.186 -        SDL_DelMouse(i);
   1.187 -    }
   1.188 -    SDL_num_mice = 0;
   1.189 -    SDL_current_mouse = -1;
   1.190 -
   1.191 -    if (SDL_mice) {
   1.192 -        SDL_free(SDL_mice);
   1.193 -        SDL_mice = NULL;
   1.194 -    }
   1.195 -}
   1.196 -
   1.197 -int
   1.198 -SDL_GetNumMice(void)
   1.199 -{
   1.200 -    return SDL_num_mice;
   1.201 -}
   1.202 -
   1.203 -int
   1.204 -SDL_SelectMouse(int index)
   1.205 -{
   1.206 -    if (index >= 0 && index < SDL_num_mice) {
   1.207 -        SDL_current_mouse = index;
   1.208 -    }
   1.209 -    return SDL_current_mouse;
   1.210 -}
   1.211 -
   1.212 -SDL_Window *
   1.213 -SDL_GetMouseFocusWindow(int index)
   1.214 +SDL_SetMouseFocus(SDL_Window * window)
   1.215  {
   1.216 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.217 -
   1.218 -    if (!mouse) {
   1.219 -        return 0;
   1.220 -    }
   1.221 -    return mouse->focus;
   1.222 -}
   1.223 -
   1.224 -static int SDLCALL
   1.225 -FlushMouseMotion(void *param, SDL_Event * event)
   1.226 -{
   1.227 -    if (event->type == SDL_MOUSEMOTION
   1.228 -        && event->motion.which == (Uint8) SDL_current_mouse) {
   1.229 -        return 0;
   1.230 -    } else {
   1.231 -        return 1;
   1.232 -    }
   1.233 -}
   1.234 -
   1.235 -int
   1.236 -SDL_SetRelativeMouseMode(int index, SDL_bool enabled)
   1.237 -{
   1.238 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.239 -
   1.240 -    if (!mouse) {
   1.241 -        return -1;
   1.242 -    }
   1.243 -
   1.244 -    /* Flush pending mouse motion */
   1.245 -    mouse->flush_motion = SDL_TRUE;
   1.246 -    SDL_PumpEvents();
   1.247 -    mouse->flush_motion = SDL_FALSE;
   1.248 -    SDL_FilterEvents(FlushMouseMotion, mouse);
   1.249 -
   1.250 -    /* Set the relative mode */
   1.251 -    mouse->relative_mode = enabled;
   1.252 -
   1.253 -    /* Update cursor visibility */
   1.254 -    SDL_SetCursor(NULL);
   1.255 +    SDL_Mouse *mouse = &SDL_mouse;
   1.256  
   1.257 -    if (!enabled) {
   1.258 -        /* Restore the expected mouse position */
   1.259 -        SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
   1.260 -    }
   1.261 -    return 0;
   1.262 -}
   1.263 -
   1.264 -SDL_bool
   1.265 -SDL_GetRelativeMouseMode(int index)
   1.266 -{
   1.267 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.268 -
   1.269 -    if (!mouse) {
   1.270 -        return SDL_FALSE;
   1.271 -    }
   1.272 -    return mouse->relative_mode;
   1.273 -}
   1.274 -
   1.275 -Uint8
   1.276 -SDL_GetMouseState(int *x, int *y)
   1.277 -{
   1.278 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   1.279 -
   1.280 -    if (!mouse) {
   1.281 -        if (x) {
   1.282 -            *x = 0;
   1.283 -        }
   1.284 -        if (y) {
   1.285 -            *y = 0;
   1.286 -        }
   1.287 -        return 0;
   1.288 -    }
   1.289 -
   1.290 -    if (x) {
   1.291 -        *x = mouse->x;
   1.292 -    }
   1.293 -    if (y) {
   1.294 -        *y = mouse->y;
   1.295 -    }
   1.296 -    return mouse->buttonstate;
   1.297 -}
   1.298 -
   1.299 -Uint8
   1.300 -SDL_GetRelativeMouseState(int index, int *x, int *y)
   1.301 -{
   1.302 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.303 -
   1.304 -    if (!mouse) {
   1.305 -        if (x) {
   1.306 -            *x = 0;
   1.307 -        }
   1.308 -        if (y) {
   1.309 -            *y = 0;
   1.310 -        }
   1.311 -        return 0;
   1.312 -    }
   1.313 -
   1.314 -    if (x) {
   1.315 -        *x = mouse->xdelta;
   1.316 -    }
   1.317 -    if (y) {
   1.318 -        *y = mouse->ydelta;
   1.319 -    }
   1.320 -    mouse->xdelta = 0;
   1.321 -    mouse->ydelta = 0;
   1.322 -    return mouse->buttonstate;
   1.323 -}
   1.324 -
   1.325 -void
   1.326 -SDL_SetMouseFocus(int id, SDL_Window * window)
   1.327 -{
   1.328 -    int index = SDL_GetMouseIndexId(id);
   1.329 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.330 -    int i;
   1.331 -    SDL_bool focus;
   1.332 -
   1.333 -    if (!mouse || (mouse->focus == window)) {
   1.334 +    if (mouse->focus == window) {
   1.335          return;
   1.336      }
   1.337  
   1.338      /* See if the current window has lost focus */
   1.339      if (mouse->focus) {
   1.340 -        focus = SDL_FALSE;
   1.341 -        for (i = 0; i < SDL_num_mice; ++i) {
   1.342 -            SDL_Mouse *check;
   1.343 -            if (i != index) {
   1.344 -                check = SDL_GetMouse(i);
   1.345 -                if (check && check->focus == mouse->focus) {
   1.346 -                    focus = SDL_TRUE;
   1.347 -                    break;
   1.348 -                }
   1.349 -            }
   1.350 -        }
   1.351 -        if (!focus) {
   1.352 -            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
   1.353 -        }
   1.354 +        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
   1.355      }
   1.356  
   1.357      mouse->focus = window;
   1.358  
   1.359      if (mouse->focus) {
   1.360 -        focus = SDL_FALSE;
   1.361 -        for (i = 0; i < SDL_num_mice; ++i) {
   1.362 -            SDL_Mouse *check;
   1.363 -            if (i != index) {
   1.364 -                check = SDL_GetMouse(i);
   1.365 -                if (check && check->focus == mouse->focus) {
   1.366 -                    focus = SDL_TRUE;
   1.367 -                    break;
   1.368 -                }
   1.369 -            }
   1.370 -        }
   1.371 -        if (!focus) {
   1.372 -            SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
   1.373 -        }
   1.374 +        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
   1.375      }
   1.376  }
   1.377  
   1.378  int
   1.379 -SDL_SendProximity(int id, int x, int y, int type)
   1.380 +SDL_SendMouseMotion(int relative, int x, int y)
   1.381  {
   1.382 -    int index = SDL_GetMouseIndexId(id);
   1.383 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.384 -    int posted = 0;
   1.385 -
   1.386 -    if (!mouse) {
   1.387 -        return 0;
   1.388 -    }
   1.389 -
   1.390 -    mouse->last_x = x;
   1.391 -    mouse->last_y = y;
   1.392 -    if (SDL_GetEventState(type) == SDL_ENABLE) {
   1.393 -        SDL_Event event;
   1.394 -        event.proximity.which = (Uint8) index;
   1.395 -        event.proximity.x = x;
   1.396 -        event.proximity.y = y;
   1.397 -        event.proximity.cursor = mouse->current_end;
   1.398 -        event.proximity.type = type;
   1.399 -        /* FIXME: is this right? */
   1.400 -        event.proximity.windowID = mouse->focus ? mouse->focus->id : 0;
   1.401 -        posted = (SDL_PushEvent(&event) > 0);
   1.402 -        if (type == SDL_PROXIMITYIN) {
   1.403 -            mouse->proximity = SDL_TRUE;
   1.404 -        } else {
   1.405 -            mouse->proximity = SDL_FALSE;
   1.406 -        }
   1.407 -    }
   1.408 -    return posted;
   1.409 -}
   1.410 -
   1.411 -int
   1.412 -SDL_SendMouseMotion(int id, int relative, int x, int y, int pressure)
   1.413 -{
   1.414 -    int index = SDL_GetMouseIndexId(id);
   1.415 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.416 +    SDL_Mouse *mouse = &SDL_mouse;
   1.417      int posted;
   1.418      int xrel;
   1.419      int yrel;
   1.420      int x_max = 0, y_max = 0;
   1.421  
   1.422 -    if (!mouse || mouse->flush_motion) {
   1.423 -        return 0;
   1.424 -    }
   1.425 -
   1.426 -    /* if the mouse is out of proximity we don't to want to have any motion from it */
   1.427 -    if (mouse->proximity == SDL_FALSE) {
   1.428 -        mouse->last_x = x;
   1.429 -        mouse->last_y = y;
   1.430 -        return 0;
   1.431 -    }
   1.432 -
   1.433      /* the relative motion is calculated regarding the system cursor last position */
   1.434      if (relative) {
   1.435          xrel = x;
   1.436 @@ -451,35 +166,26 @@
   1.437  
   1.438      mouse->xdelta += xrel;
   1.439      mouse->ydelta += yrel;
   1.440 -    mouse->pressure = pressure;
   1.441  
   1.442 +#if 0 /* FIXME */
   1.443      /* Move the mouse cursor, if needed */
   1.444      if (mouse->cursor_shown && !mouse->relative_mode &&
   1.445          mouse->MoveCursor && mouse->cur_cursor) {
   1.446          mouse->MoveCursor(mouse->cur_cursor);
   1.447      }
   1.448 +#endif
   1.449  
   1.450      /* Post the event, if desired */
   1.451      posted = 0;
   1.452 -    if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE &&
   1.453 -        mouse->proximity == SDL_TRUE) {
   1.454 +    if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
   1.455          SDL_Event event;
   1.456          event.motion.type = SDL_MOUSEMOTION;
   1.457 -        event.motion.which = (Uint8) index;
   1.458 +        event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
   1.459          event.motion.state = mouse->buttonstate;
   1.460          event.motion.x = mouse->x;
   1.461          event.motion.y = mouse->y;
   1.462 -        event.motion.z = mouse->z;
   1.463 -        event.motion.pressure = mouse->pressure;
   1.464 -        event.motion.pressure_max = mouse->pressure_max;
   1.465 -        event.motion.pressure_min = mouse->pressure_min;
   1.466 -        event.motion.rotation = 0;
   1.467 -        event.motion.tilt_x = 0;
   1.468 -        event.motion.tilt_y = 0;
   1.469 -        event.motion.cursor = mouse->current_end;
   1.470          event.motion.xrel = xrel;
   1.471          event.motion.yrel = yrel;
   1.472 -        event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
   1.473          posted = (SDL_PushEvent(&event) > 0);
   1.474      }
   1.475      mouse->last_x = mouse->x;
   1.476 @@ -488,17 +194,12 @@
   1.477  }
   1.478  
   1.479  int
   1.480 -SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
   1.481 +SDL_SendMouseButton(Uint8 state, Uint8 button)
   1.482  {
   1.483 -    int index = SDL_GetMouseIndexId(id);
   1.484 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.485 +    SDL_Mouse *mouse = &SDL_mouse;
   1.486      int posted;
   1.487      Uint32 type;
   1.488  
   1.489 -    if (!mouse) {
   1.490 -        return 0;
   1.491 -    }
   1.492 -
   1.493      /* Figure out which event to perform */
   1.494      switch (state) {
   1.495      case SDL_PRESSED:
   1.496 @@ -527,7 +228,6 @@
   1.497      if (SDL_GetEventState(type) == SDL_ENABLE) {
   1.498          SDL_Event event;
   1.499          event.type = type;
   1.500 -        event.button.which = (Uint8) index;
   1.501          event.button.state = state;
   1.502          event.button.button = button;
   1.503          event.button.x = mouse->x;
   1.504 @@ -539,12 +239,12 @@
   1.505  }
   1.506  
   1.507  int
   1.508 -SDL_SendMouseWheel(int index, int x, int y)
   1.509 +SDL_SendMouseWheel(int x, int y)
   1.510  {
   1.511 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.512 +    SDL_Mouse *mouse = &SDL_mouse;
   1.513      int posted;
   1.514  
   1.515 -    if (!mouse || (!x && !y)) {
   1.516 +    if (!x && !y) {
   1.517          return 0;
   1.518      }
   1.519  
   1.520 @@ -553,53 +253,108 @@
   1.521      if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
   1.522          SDL_Event event;
   1.523          event.type = SDL_MOUSEWHEEL;
   1.524 -        event.wheel.which = (Uint8) index;
   1.525 +        event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
   1.526          event.wheel.x = x;
   1.527          event.wheel.y = y;
   1.528 -        event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
   1.529          posted = (SDL_PushEvent(&event) > 0);
   1.530      }
   1.531      return posted;
   1.532  }
   1.533  
   1.534  void
   1.535 +SDL_MouseQuit(void)
   1.536 +{
   1.537 +}
   1.538 +
   1.539 +Uint8
   1.540 +SDL_GetMouseState(int *x, int *y)
   1.541 +{
   1.542 +    SDL_Mouse *mouse = &SDL_mouse;
   1.543 +
   1.544 +    if (x) {
   1.545 +        *x = mouse->x;
   1.546 +    }
   1.547 +    if (y) {
   1.548 +        *y = mouse->y;
   1.549 +    }
   1.550 +    return mouse->buttonstate;
   1.551 +}
   1.552 +
   1.553 +Uint8
   1.554 +SDL_GetRelativeMouseState(int *x, int *y)
   1.555 +{
   1.556 +    SDL_Mouse *mouse = &SDL_mouse;
   1.557 +
   1.558 +    if (x) {
   1.559 +        *x = mouse->xdelta;
   1.560 +    }
   1.561 +    if (y) {
   1.562 +        *y = mouse->ydelta;
   1.563 +    }
   1.564 +    mouse->xdelta = 0;
   1.565 +    mouse->ydelta = 0;
   1.566 +    return mouse->buttonstate;
   1.567 +}
   1.568 +
   1.569 +void
   1.570  SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
   1.571  {
   1.572 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   1.573 -
   1.574 -    if (!mouse) {
   1.575 -        return;
   1.576 -    }
   1.577 +    SDL_Mouse *mouse = &SDL_mouse;
   1.578  
   1.579      if (mouse->WarpMouse) {
   1.580          mouse->WarpMouse(mouse, window, x, y);
   1.581      } else {
   1.582 -        SDL_SetMouseFocus(SDL_current_mouse, window);
   1.583 -        SDL_SendMouseMotion(SDL_current_mouse, 0, x, y, 0);
   1.584 +        SDL_SetMouseFocus(window);
   1.585 +        SDL_SendMouseMotion(0, x, y);
   1.586      }
   1.587  }
   1.588  
   1.589 +int
   1.590 +SDL_SetRelativeMouseMode(SDL_bool enabled)
   1.591 +{
   1.592 +    SDL_Mouse *mouse = &SDL_mouse;
   1.593 +
   1.594 +    /* Flush pending mouse motion */
   1.595 +    SDL_FlushEvent(SDL_MOUSEMOTION);
   1.596 +
   1.597 +    /* Set the relative mode */
   1.598 +    mouse->relative_mode = enabled;
   1.599 +
   1.600 +    if (!enabled) {
   1.601 +        /* Restore the expected mouse position */
   1.602 +        SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
   1.603 +    }
   1.604 +
   1.605 +    /* Update cursor visibility */
   1.606 +    SDL_SetCursor(NULL);
   1.607 +
   1.608 +    return 0;
   1.609 +}
   1.610 +
   1.611 +SDL_bool
   1.612 +SDL_GetRelativeMouseMode()
   1.613 +{
   1.614 +    SDL_Mouse *mouse = &SDL_mouse;
   1.615 +
   1.616 +    return mouse->relative_mode;
   1.617 +}
   1.618 +
   1.619  SDL_Cursor *
   1.620  SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
   1.621                   int w, int h, int hot_x, int hot_y)
   1.622  {
   1.623 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   1.624 +    SDL_Mouse *mouse = &SDL_mouse;
   1.625      SDL_Surface *surface;
   1.626      SDL_Cursor *cursor;
   1.627      int x, y;
   1.628      Uint32 *pixel;
   1.629 -    Uint8 datab, maskb;
   1.630 +    Uint8 datab = 0, maskb = 0;
   1.631      const Uint32 black = 0xFF000000;
   1.632      const Uint32 white = 0xFFFFFFFF;
   1.633      const Uint32 transparent = 0x00000000;
   1.634  
   1.635 -    if (!mouse) {
   1.636 -        SDL_SetError("No mice are initialized");
   1.637 -        return NULL;
   1.638 -    }
   1.639 -
   1.640      if (!mouse->CreateCursor) {
   1.641 -        SDL_SetError("Current mouse doesn't have cursor support");
   1.642 +        SDL_SetError("Cursors are not currently supported");
   1.643          return NULL;
   1.644      }
   1.645  
   1.646 @@ -638,7 +393,6 @@
   1.647  
   1.648      cursor = mouse->CreateCursor(surface, hot_x, hot_y);
   1.649      if (cursor) {
   1.650 -        cursor->mouse = mouse;
   1.651          cursor->next = mouse->cursors;
   1.652          mouse->cursors = cursor;
   1.653      }
   1.654 @@ -655,12 +409,7 @@
   1.655  void
   1.656  SDL_SetCursor(SDL_Cursor * cursor)
   1.657  {
   1.658 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   1.659 -
   1.660 -    if (!mouse) {
   1.661 -        SDL_SetError("No mice are initialized");
   1.662 -        return;
   1.663 -    }
   1.664 +    SDL_Mouse *mouse = &SDL_mouse;
   1.665  
   1.666      /* Set the new cursor */
   1.667      if (cursor) {
   1.668 @@ -694,7 +443,7 @@
   1.669  SDL_Cursor *
   1.670  SDL_GetCursor(void)
   1.671  {
   1.672 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   1.673 +    SDL_Mouse *mouse = &SDL_mouse;
   1.674  
   1.675      if (!mouse) {
   1.676          return NULL;
   1.677 @@ -705,13 +454,12 @@
   1.678  void
   1.679  SDL_FreeCursor(SDL_Cursor * cursor)
   1.680  {
   1.681 -    SDL_Mouse *mouse;
   1.682 +    SDL_Mouse *mouse = &SDL_mouse;
   1.683      SDL_Cursor *curr, *prev;
   1.684  
   1.685      if (!cursor) {
   1.686          return;
   1.687      }
   1.688 -    mouse = cursor->mouse;
   1.689  
   1.690      if (cursor == mouse->def_cursor) {
   1.691          return;
   1.692 @@ -740,7 +488,7 @@
   1.693  int
   1.694  SDL_ShowCursor(int toggle)
   1.695  {
   1.696 -    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   1.697 +    SDL_Mouse *mouse = &SDL_mouse;
   1.698      SDL_bool shown;
   1.699  
   1.700      if (!mouse) {
   1.701 @@ -761,47 +509,4 @@
   1.702      return shown;
   1.703  }
   1.704  
   1.705 -char *
   1.706 -SDL_GetMouseName(int index)
   1.707 -{
   1.708 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.709 -    if (!mouse) {
   1.710 -        return NULL;
   1.711 -    }
   1.712 -    return mouse->name;
   1.713 -}
   1.714 -
   1.715 -void
   1.716 -SDL_ChangeEnd(int id, int end)
   1.717 -{
   1.718 -    int index = SDL_GetMouseIndexId(id);
   1.719 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.720 -
   1.721 -    if (mouse) {
   1.722 -        mouse->current_end = end;
   1.723 -    }
   1.724 -}
   1.725 -
   1.726 -int
   1.727 -SDL_GetCursorsNumber(int index)
   1.728 -{
   1.729 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.730 -
   1.731 -    if (!mouse) {
   1.732 -        return -1;
   1.733 -    }
   1.734 -    return mouse->total_ends;
   1.735 -}
   1.736 -
   1.737 -int
   1.738 -SDL_GetCurrentCursor(int index)
   1.739 -{
   1.740 -    SDL_Mouse *mouse = SDL_GetMouse(index);
   1.741 -
   1.742 -    if (!mouse) {
   1.743 -        return -1;
   1.744 -    }
   1.745 -    return mouse->current_end;
   1.746 -}
   1.747 -
   1.748  /* vi: set ts=4 sw=4 expandtab: */