Skip to content
Snippets Groups Projects
Commit 9f116c7c authored by LJ Sonic's avatar LJ Sonic
Browse files

Fix mouse events not being fired when the mouse is ungrabbed

parent 4196252e
Branches
Tags
2 merge requests!2355fix newer versions of mixerx,!2178Fix mouse events not being fired when the mouse is ungrabbed
Pipeline #885 passed
...@@ -382,10 +382,8 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) ...@@ -382,10 +382,8 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code)
return 0; return 0;
} }
static boolean IgnoreMouse(void) static boolean ShouldIgnoreMouse(void)
{ {
if (cv_alwaysgrabmouse.value)
return false;
if (menuactive) if (menuactive)
return !M_MouseNeeded(); return !M_MouseNeeded();
if (paused || con_destlines || chat_on) if (paused || con_destlines || chat_on)
...@@ -393,9 +391,18 @@ static boolean IgnoreMouse(void) ...@@ -393,9 +391,18 @@ static boolean IgnoreMouse(void)
if (gamestate != GS_LEVEL && gamestate != GS_INTERMISSION && if (gamestate != GS_LEVEL && gamestate != GS_INTERMISSION &&
gamestate != GS_CONTINUING && gamestate != GS_CUTSCENE) gamestate != GS_CONTINUING && gamestate != GS_CUTSCENE)
return true; return true;
if (!mousegrabbedbylua) return false;
}
static boolean ShouldGrabMouse(void)
{
if (cv_alwaysgrabmouse.value)
return true; return true;
if (ShouldIgnoreMouse())
return false; return false;
if (!mousegrabbedbylua)
return false;
return true;
} }
static void SDLdoGrabMouse(void) static void SDLdoGrabMouse(void)
...@@ -424,7 +431,7 @@ void I_UpdateMouseGrab(void) ...@@ -424,7 +431,7 @@ void I_UpdateMouseGrab(void)
{ {
if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO && window != NULL if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO && window != NULL
&& SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window && SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window
&& USE_MOUSEINPUT && !IgnoreMouse()) && USE_MOUSEINPUT && ShouldGrabMouse())
SDLdoGrabMouse(); SDLdoGrabMouse();
} }
...@@ -640,7 +647,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) ...@@ -640,7 +647,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
} }
//else firsttimeonmouse = SDL_FALSE; //else firsttimeonmouse = SDL_FALSE;
if (USE_MOUSEINPUT && !IgnoreMouse()) if (USE_MOUSEINPUT && ShouldGrabMouse())
SDLdoGrabMouse(); SDLdoGrabMouse();
} }
else if (!mousefocus && !kbfocus) else if (!mousefocus && !kbfocus)
...@@ -692,7 +699,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) ...@@ -692,7 +699,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
if (USE_MOUSEINPUT) if (USE_MOUSEINPUT)
{ {
if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window) || (IgnoreMouse() && !firstmove)) if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window) || (!ShouldGrabMouse() && !firstmove))
{ {
SDLdoUngrabMouse(); SDLdoUngrabMouse();
firstmove = false; firstmove = false;
...@@ -745,7 +752,7 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) ...@@ -745,7 +752,7 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
// this apparently makes a mouse button down event but not a mouse button up event, // this apparently makes a mouse button down event but not a mouse button up event,
// resulting in whatever key was pressed down getting "stuck" if we don't ignore it. // resulting in whatever key was pressed down getting "stuck" if we don't ignore it.
// -- Monster Iestyn (28/05/18) // -- Monster Iestyn (28/05/18)
if (SDL_GetMouseFocus() != window || IgnoreMouse()) if (SDL_GetMouseFocus() != window || ShouldIgnoreMouse())
return; return;
/// \todo inputEvent.button.which /// \todo inputEvent.button.which
...@@ -1127,7 +1134,7 @@ void I_StartupMouse(void) ...@@ -1127,7 +1134,7 @@ void I_StartupMouse(void)
} }
else else
firsttimeonmouse = SDL_FALSE; firsttimeonmouse = SDL_FALSE;
if (cv_usemouse.value && !IgnoreMouse()) if (cv_usemouse.value && ShouldGrabMouse())
SDLdoGrabMouse(); SDLdoGrabMouse();
else else
SDLdoUngrabMouse(); SDLdoUngrabMouse();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment