Fixed Windows relative mouse coordinates when capturing the mouse over RDP
authorSam Lantinga <slouken@libsdl.org>
Mon, 26 Aug 2019 17:43:01 -0700
changeset 13038b5f5c317e652
parent 13037 d465f3a64af6
child 13039 bfed06214c2a
Fixed Windows relative mouse coordinates when capturing the mouse over RDP
src/video/windows/SDL_windowsevents.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Mon Aug 26 18:49:04 2019 -0300
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Aug 26 17:43:01 2019 -0700
     1.3 @@ -586,16 +586,22 @@
     1.4                          SDL_SendMouseMotion(data->window, 0, 1, (int)rawmouse->lLastX, (int)rawmouse->lLastY);
     1.5                      } else {
     1.6                          /* synthesize relative moves from the abs position */
     1.7 -                        static SDL_Point initialMousePoint;
     1.8 -                        if (initialMousePoint.x == 0 && initialMousePoint.y == 0) {
     1.9 -                            initialMousePoint.x = rawmouse->lLastX;
    1.10 -                            initialMousePoint.y = rawmouse->lLastY;
    1.11 +                        static SDL_Point lastMousePoint;
    1.12 +                        SDL_bool virtual_desktop = (rawmouse->usFlags & MOUSE_VIRTUAL_DESKTOP) ? SDL_TRUE : SDL_FALSE;
    1.13 +                        int w = GetSystemMetrics(virtual_desktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN);
    1.14 +                        int h = GetSystemMetrics(virtual_desktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN);
    1.15 +                        int x = (int)(((float)rawmouse->lLastX / 65535.0f) * w);
    1.16 +                        int y = (int)(((float)rawmouse->lLastY / 65535.0f) * h);
    1.17 +
    1.18 +                        if (lastMousePoint.x == 0 && lastMousePoint.y == 0) {
    1.19 +                            lastMousePoint.x = x;
    1.20 +                            lastMousePoint.y = y;
    1.21                          }
    1.22  
    1.23 -                        SDL_SendMouseMotion(data->window, 0, 1, (int)(rawmouse->lLastX-initialMousePoint.x), (int)(rawmouse->lLastY-initialMousePoint.y));
    1.24 +                        SDL_SendMouseMotion(data->window, 0, 1, (int)(x-lastMousePoint.x), (int)(y-lastMousePoint.y));
    1.25  
    1.26 -                        initialMousePoint.x = rawmouse->lLastX;
    1.27 -                        initialMousePoint.y = rawmouse->lLastY;
    1.28 +                        lastMousePoint.x = x;
    1.29 +                        lastMousePoint.y = y;
    1.30                      }
    1.31                      WIN_CheckRawMouseButtons(rawmouse->usButtonFlags, data);
    1.32                  } else if (isCapture) {