Open xsot opened 6 years ago
Perhaps we can fire a mouse hover event when our window regains focus.
When the mouse is captured (SDL_CaptureMouse(true)
) on Windows, SDL continues to dispatch mouse motion events even when the our window doesn't have focus. So bug 2 never happens, and bug 1 can only happen if the mouse is not pressed (so we don't capture the mouse).
On Windows, bug 1 can manifest in this form:
1) Move mouse in the window -> SDL_MOUSEMOTION is received as we move the mouse, so processMouseHover()
is called. (Good)
2) Alt-Tab to switch windows without moving the mouse -> SDL_WINDOWEVENT_LEAVE is received upon switching to the other window, so processMouseLeave()
is called. (Good)
3) Move mouse while in the other window -> No events received because mouse is not captured. (As expected)
4) Alt-Tab to switch back to our window -> SDL_WINDOWEVENT_ENTER is received, but we don't do anything. (Bad)
We probably want to call processMouseHover()
when we get SDL_WINDOWEVENT_ENTER if the mouse is inside the window. This should fix bug 1 for both Windows and Linux.
Bug 2 might need a Linux-specific fix.
Note that on Windows, we don't immediately get SDL_WINDOWEVENT_LEAVE if mouse capture is on and we switch windows. We will only get the SDL_WINDOWEVENT_LEAVE once SDL_CaptureMouse(false)
is called (which, for us, is when the user lifts up the mouse button). So code that calls SDL_CaptureMouse(false)
after receiving SDL_WINDOWEVENT_LEAVE will not do anything on Windows.
processMouseHover()
.