We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4165 - Invalid mouse state after losing focus with a captured mouse
Summary: Invalid mouse state after losing focus with a captured mouse
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.5
Hardware: x86 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-11 20:17 UTC by sycobob
Modified: 2018-05-11 20:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sycobob 2018-05-11 20:17:02 UTC
When mouse capture is enabled, clicking off of a window then back onto the window will send mouse down, but not mouse up. This leads to a couple of strange effects:

1) Moving the mouse off the window sends mouse up, or
2) The next mouse click does not send a mouse down, but sends a mouse up

When holding a keyboard button and clicking off of the window key up events are sent to release all buttons. Given this, I assume the mouse should do the same thing and clicking off the window should send mouse down and mouse up.

The repro is straight forward:

    SDL_Event sdl;
    while (SDL_PollEvent(&sdl) != 0) {
        switch(sdl.type) {
            case SDL_MOUSEBUTTONDOWN:
                Print("Mouse Down");
                break;
            case SDL_MOUSEBUTTONUP:
                Print("Mouse Up");
                break;

            case SDL_WINDOWEVENT: {
                if (sdl.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
                    Print("Focus Gained");
                    SDL_CaptureMouse(SDL_TRUE);
                }
                if (sdl.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
                    Print("Focus Gained");
                    SDL_CaptureMouse(SDL_TRUE);
                }
                break;
            }
        }
    }

With the above code:
1) Click off the window to lose focus (receive mouse down and focus lost)
2) Click the window to regain focus (receive focus gained)
3) Move the mouse off the window without clicking (receive mouse up)

I believe the core issue is that mouse up is not sent during step 1.