SDL/src/video/windows
Sam Lantinga 50203d58b3 Fixed bug 5329 - SDL_SetWindowGrab(SDL_FALSE) fails to unlock cursor if window is partially offscreen
Ivan Mogilko

With SDL 2.0.12 under MS Windows, if the window is partially offscreen calling SDL_SetWindowGrab(w, SDL_TRUE) works, but subsequent call to SDL_SetWindowGrab(w, SDL_FALSE) does not work.

I tested this in both real program, and a small test app, where unlocking cursor worked perfectly while window is fully in desktop bounds, but did not work if it was at least few pixels outside.

For the reference, following code is enough to reproduce the issue:

#include <windows.h>
#include <SDL.h>

int WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpCmdLine,
    int       nShowCmd)
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* w = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 400, 0);

    bool grabbed = false;
    bool want_quit = false;
    while (!want_quit)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT: want_quit = true; break;
            case SDL_KEYDOWN:
                if (event.key.keysym.scancode == SDL_SCANCODE_SPACE)
                {
                    SDL_SetWindowGrab(w, static_cast<SDL_bool>(!grabbed));
                    grabbed = !grabbed;
                }
            }
        }
    }

    SDL_DestroyWindow(w);
    SDL_Quit();
    return 0;
}
2020-12-08 22:00:06 -08:00
..
SDL_msctf.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_vkeys.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsclipboard.c Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsclipboard.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsevents.c windows: Fix numpad arrow key scancodes with numlock off 2020-08-27 17:54:52 -07:00
SDL_windowsevents.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsframebuffer.c Fixed whitespace 2020-06-09 21:43:00 -07:00
SDL_windowsframebuffer.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowskeyboard.c Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowskeyboard.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsmessagebox.c SIZE_MAX need not be defined in limits.h 2020-11-11 12:33:55 +03:00
SDL_windowsmessagebox.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsmodes.c video: Refresh Windows display list on WM_DISPLAYCHANGE 2020-10-13 21:08:20 -07:00
SDL_windowsmodes.h video: Refresh Windows display list on WM_DISPLAYCHANGE 2020-10-13 21:08:20 -07:00
SDL_windowsmouse.c windows: Fix handling of swapped mouse buttons 2020-08-25 21:22:00 -07:00
SDL_windowsmouse.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsopengl.c Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsopengl.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsopengles.c Patched to compile. 2020-07-16 13:28:59 -04:00
SDL_windowsopengles.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsshape.c Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsshape.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowstaskdialog.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsvideo.c Merge VideoBootStrap::available into VideoBootStrap::create 2020-07-12 19:11:15 -04:00
SDL_windowsvideo.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsvulkan.c Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowsvulkan.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
SDL_windowswindow.c Fixed bug 5329 - SDL_SetWindowGrab(SDL_FALSE) fails to unlock cursor if window is partially offscreen 2020-12-08 22:00:06 -08:00
SDL_windowswindow.h Fixed bug 5171 - PollEvent impacts performance in 2.0.12 2020-06-09 21:47:41 -07:00
wmmsg.h Updated copyright date for 2020 2020-01-16 20:49:25 -08:00