SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL doesn't receive SDL_EVENT_MOUSE_BUTTON_UP when SDL_EVENT_MOUSE_BUTTON_DOWN was done before SDLWindow created

Open beki007 opened this issue 3 weeks ago • 2 comments

Description: We have an application where when user click, we will create SDL_Window and implement event loop there. Basically, the window creation is triggered by WM_LBUTTONDOWN event. After that we create an event loop and we are expected WM_LBUTTONUP event should come. SDL's window procedure function WIN_WindowProc receive this event, but it is not sent to our event loop - no SDL_EVENT_MOUSE_BUTTON_UP event received.

Expected result: If WIN_WindowProc receive WM_LBUTTONUP event, SDL_EVENT_MOUSE_BUTTON_UP should be send.

Root cause: SDL's event handling logic in WIN_CheckWParamMouseButton only sends SDL_EVENT_MOUSE_BUTTON_UP if SDL's internal state thinks the button was pressed. Since the mouse button DOWN happened BEFORE SDL window was created, SDL's internal buttonstate (mouseFlags) is 0, so when WM_LBUTTONUP arrives, the condition to send the UP event fails:

else if (!bwParamMousePressed && (mouseFlags & SDL_BUTTON_MASK(button))) 
{
    SDL_SendMouseButton(..., button, false);  // This is not reached!
}

I created very simple MFC app, where you can reproduce it: https://github.com/beki007/MFC_SDL3_app, just left click and it should create window, which doesn't receive SDL_EVENT_MOUSE_BUTTON_UP event.

beki007 avatar Dec 05 '25 09:12 beki007

This is intentional. We had issues with applications getting key up and mouse button up events when they hadn't gotten the corresponding down events. Do you have a specific use case here where that causes problems?

slouken avatar Dec 05 '25 16:12 slouken

Yes, we have an application where full click (mouse button down + up) should show menu. We create SDL_Window when mouse button down and expecting mouse button up to display menu. When mouse button up doesn't arrive, we expect user hold button which means user try to use gesture to select item in menu and show submenu (we track mouse move events). To receive this event is critical for us, since it decide which mode user want to use - clasic (mouse click) or gesture (mouse move).

beki007 avatar Dec 08 '25 07:12 beki007