Setting the mouse in relative mode implies grabbing the mouse.
authorSam Lantinga <slouken@libsdl.org>
Mon, 23 Dec 2013 17:55:06 -0800
changeset 80729d8865351afd
parent 8071 1ac2db4abe11
child 8073 ccbeeb164979
Setting the mouse in relative mode implies grabbing the mouse.
This fixes getting mouse button events in raw input relative mode on X11.
src/video/SDL_video.c
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
     1.1 --- a/src/video/SDL_video.c	Mon Dec 23 17:37:22 2013 -0800
     1.2 +++ b/src/video/SDL_video.c	Mon Dec 23 17:55:06 2013 -0800
     1.3 @@ -2055,9 +2055,8 @@
     1.4  {
     1.5      if (_this->SetWindowGrab) {
     1.6          SDL_bool grabbed;
     1.7 -        if (SDL_GetMouse()->relative_mode_warp ||
     1.8 -            ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
     1.9 -             (window->flags & SDL_WINDOW_INPUT_FOCUS))) {
    1.10 +        if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
    1.11 +             (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    1.12              grabbed = SDL_TRUE;
    1.13          } else {
    1.14              grabbed = SDL_FALSE;
     2.1 --- a/src/video/windows/SDL_windowsevents.c	Mon Dec 23 17:37:22 2013 -0800
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Dec 23 17:55:06 2013 -0800
     2.3 @@ -286,47 +286,6 @@
     2.4      return SDL_TRUE;
     2.5  }
     2.6  
     2.7 -static void
     2.8 -WIN_UpdateClipCursor(SDL_Window *window)
     2.9 -{
    2.10 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.11 -    SDL_Mouse *mouse = SDL_GetMouse();
    2.12 -
    2.13 -    /* Don't clip the cursor while we're in the modal resize or move loop */
    2.14 -    if (data->in_modal_loop) {
    2.15 -        ClipCursor(NULL);
    2.16 -        return;
    2.17 -    }
    2.18 -        
    2.19 -    if (mouse->relative_mode && !mouse->relative_mode_warp) {
    2.20 -        LONG cx, cy;
    2.21 -        RECT rect;
    2.22 -        GetWindowRect(data->hwnd, &rect);
    2.23 -
    2.24 -        cx = (rect.left + rect.right) / 2;
    2.25 -        cy = (rect.top + rect.bottom) / 2;
    2.26 -
    2.27 -        /* Make an absurdly small clip rect */
    2.28 -        rect.left = cx-1;
    2.29 -        rect.right = cx+1;
    2.30 -        rect.top = cy-1;
    2.31 -        rect.bottom = cy+1;
    2.32 -
    2.33 -        ClipCursor(&rect);
    2.34 -    } else if (mouse->relative_mode_warp ||
    2.35 -               ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
    2.36 -                (window->flags & SDL_WINDOW_INPUT_FOCUS))) {
    2.37 -        RECT rect;
    2.38 -        if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
    2.39 -            ClientToScreen(data->hwnd, (LPPOINT) & rect);
    2.40 -            ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
    2.41 -            ClipCursor(&rect);
    2.42 -        }
    2.43 -    } else {
    2.44 -        ClipCursor(NULL);
    2.45 -    }
    2.46 -}
    2.47 -
    2.48  LRESULT CALLBACK
    2.49  WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    2.50  {
     3.1 --- a/src/video/windows/SDL_windowswindow.c	Mon Dec 23 17:37:22 2013 -0800
     3.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Dec 23 17:55:06 2013 -0800
     3.3 @@ -28,6 +28,7 @@
     3.4  #include "../SDL_sysvideo.h"
     3.5  #include "../SDL_pixels_c.h"
     3.6  #include "../../events/SDL_keyboard_c.h"
     3.7 +#include "../../events/SDL_mouse_c.h"
     3.8  
     3.9  #include "SDL_windowsvideo.h"
    3.10  #include "SDL_windowswindow.h"
    3.11 @@ -571,17 +572,7 @@
    3.12  void
    3.13  WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
    3.14  {
    3.15 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    3.16 -
    3.17 -    if (grabbed) {
    3.18 -        RECT rect;
    3.19 -        GetClientRect(hwnd, &rect);
    3.20 -        ClientToScreen(hwnd, (LPPOINT) & rect);
    3.21 -        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
    3.22 -        ClipCursor(&rect);
    3.23 -    } else {
    3.24 -        ClipCursor(NULL);
    3.25 -    }
    3.26 +    WIN_UpdateClipCursor(window);
    3.27  
    3.28      if (window->flags & SDL_WINDOW_FULLSCREEN) {
    3.29          UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
    3.30 @@ -722,6 +713,48 @@
    3.31  #endif /* WM_MOUSELEAVE */
    3.32  }
    3.33  
    3.34 +void
    3.35 +WIN_UpdateClipCursor(SDL_Window *window)
    3.36 +{
    3.37 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    3.38 +    SDL_Mouse *mouse = SDL_GetMouse();
    3.39 +
    3.40 +    /* Don't clip the cursor while we're in the modal resize or move loop */
    3.41 +    if (data->in_modal_loop) {
    3.42 +        ClipCursor(NULL);
    3.43 +        return;
    3.44 +    }
    3.45 +
    3.46 +    if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
    3.47 +        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    3.48 +        if (mouse->relative_mode && !mouse->relative_mode_warp) {
    3.49 +            LONG cx, cy;
    3.50 +            RECT rect;
    3.51 +            GetWindowRect(data->hwnd, &rect);
    3.52 +
    3.53 +            cx = (rect.left + rect.right) / 2;
    3.54 +            cy = (rect.top + rect.bottom) / 2;
    3.55 +
    3.56 +            /* Make an absurdly small clip rect */
    3.57 +            rect.left = cx - 1;
    3.58 +            rect.right = cx + 1;
    3.59 +            rect.top = cy - 1;
    3.60 +            rect.bottom = cy + 1;
    3.61 +
    3.62 +            ClipCursor(&rect);
    3.63 +        } else {
    3.64 +            RECT rect;
    3.65 +            if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
    3.66 +                ClientToScreen(data->hwnd, (LPPOINT) & rect);
    3.67 +                ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
    3.68 +                ClipCursor(&rect);
    3.69 +            }
    3.70 +        }
    3.71 +    } else {
    3.72 +        ClipCursor(NULL);
    3.73 +    }
    3.74 +}
    3.75 +
    3.76  #endif /* SDL_VIDEO_DRIVER_WINDOWS */
    3.77  
    3.78  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/windows/SDL_windowswindow.h	Mon Dec 23 17:37:22 2013 -0800
     4.2 +++ b/src/video/windows/SDL_windowswindow.h	Mon Dec 23 17:55:06 2013 -0800
     4.3 @@ -66,6 +66,7 @@
     4.4  extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
     4.5                                      struct SDL_SysWMinfo *info);
     4.6  extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
     4.7 +extern void WIN_UpdateClipCursor(SDL_Window *window);
     4.8  
     4.9  #endif /* _SDL_windowswindow_h */
    4.10