btzy / circuit-sandbox

GNU General Public License v3.0
3 stars 1 forks source link

Various mouse-related bugs caused by window switching #35

Open xsot opened 6 years ago

xsot commented 6 years ago
  1. It is possible to change the cursor position without triggering mousemotion events by switching windows. This breaks several mousedown/mouseup events that depend on mousemotion updating the cursor position and functions like processMouseHover().
  2. Mouseup events can be missed if the window loses focus from switching.
btzy commented 6 years ago

Perhaps we can fire a mouse hover event when our window regains focus.

btzy commented 6 years ago

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.