]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
input: stop capturing mouse movement if window is hidden without first losing focus
authorbones_was_here <bones_was_here@xonotic.au>
Thu, 5 Oct 2023 18:44:37 +0000 (04:44 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 8 Nov 2023 17:26:26 +0000 (03:26 +1000)
Fixes players looking all around after they alt+tabbed.

Moves the logic for selecting the mouse mode out of screen drawing and
into SDL event handling where it's unaffected if we early-out of drawing
the frame.

Prevents mouse "grab" (raw/relative mode + cursor hiding) in a few
"loading" situations.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cl_screen.c
vid.h
vid_null.c
vid_sdl.c

index e4ba43d90301a49d84a77c15c2b7776409deadd1..6435b576fd3efc680a1d88a8fc6c0ac6e4b33fc3 100644 (file)
@@ -100,7 +100,7 @@ int jpeg_supported = false;
 
 qbool  scr_initialized;                // ready to draw
 
-static qbool scr_loading = false;  // we are in a loading screen
+qbool scr_loading = false;  // we are in a loading screen
 
 unsigned int        scr_con_current;
 static unsigned int scr_con_margin_bottom;
@@ -2325,14 +2325,6 @@ void CL_UpdateScreen(void)
 #endif
 
        qglFlush(); // ensure that the commands are submitted to the GPU before we do other things
-
-       if (!vid_activewindow || key_consoleactive)
-               VID_SetMouse(false, false);
-       else if (key_dest == key_menu || key_dest == key_menu_grabbed || scr_loading)
-               VID_SetMouse(vid_mouse.integer && !in_client_mouse && !vid_touchscreen.integer, !vid_touchscreen.integer);
-       else
-               VID_SetMouse(vid_mouse.integer && !cl.csqc_wantsmousemove && cl_prydoncursor.integer <= 0 && (!cls.demoplayback || cl_demo_mousegrab.integer) && !vid_touchscreen.integer, !vid_touchscreen.integer);
-
        VID_Finish();
 }
 
diff --git a/vid.h b/vid.h
index 816a6935ec041141fc46990e2ccd3fc97d8a1b95..cab749693ec3744dd6151752e3012f1b6e8c8f71 100644 (file)
--- a/vid.h
+++ b/vid.h
@@ -133,6 +133,9 @@ int VID_Shared_SetJoystick(int index);
 qbool VID_JoyBlockEmulatedKeys(int keycode);
 void VID_EnableJoystick(qbool enable);
 
+extern cvar_t cl_demo_mousegrab;
+extern qbool scr_loading;
+
 extern qbool vid_hidden;
 extern qbool vid_activewindow;
 extern qbool vid_supportrefreshrate;
@@ -231,7 +234,6 @@ qbool VID_HasScreenKeyboardSupport(void);
 void VID_ShowKeyboard(qbool show);
 qbool VID_ShowingKeyboard(void);
 
-void VID_SetMouse(qbool relative, qbool hidecursor);
 void VID_Finish (void);
 
 void VID_Restart_f(struct cmd_state_s *cmd);
index 5b2d869c9da8e77c16016b4b13b7632585036652..fb3cba08bdeeaf2f06f584a7f20561caea9cd6bc 100644 (file)
@@ -51,10 +51,6 @@ static void InitSig(void)
 }
 #endif
 
-void VID_SetMouse(qbool relative, qbool hidecursor)
-{
-}
-
 void VID_Finish (void)
 {
 }
index 7f33a50f77062ab5a2f7e843f97f3594c57c906d..5c7721a9687d17218ada1be6ae443cfeb70d2955 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -368,7 +368,7 @@ qbool VID_ShowingKeyboard(void)
        return SDL_IsTextInputActive() != 0;
 }
 
-void VID_SetMouse(qbool relative, qbool hidecursor)
+static void VID_SetMouse(qbool relative, qbool hidecursor)
 {
 #ifndef DP_MOBILETOUCH
 #ifdef MACOSX
@@ -1013,6 +1013,8 @@ void IN_Move( void )
                in_windowmouse_y = y;
        }
 
+       //Con_Printf("Mouse position: in_mouse %f %f in_windowmouse %f %f\n", in_mouse_x, in_mouse_y, in_windowmouse_x, in_windowmouse_y);
+
        VID_BuildJoyState(&joystate);
        VID_ApplyJoyState(&joystate);
 }
@@ -1348,8 +1350,10 @@ void Sys_SDL_HandleEvents(void)
                                break;
                }
 
+       vid_activewindow = !vid_hidden && vid_hasfocus;
+
        // enable/disable sound on focus gain/loss
-       if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
+       if (vid_activewindow || !snd_mutewhenidle.integer)
        {
                if (!sound_active)
                {
@@ -1365,6 +1369,13 @@ void Sys_SDL_HandleEvents(void)
                        sound_active = false;
                }
        }
+
+       if (!vid_activewindow || key_consoleactive || scr_loading)
+               VID_SetMouse(false, false);
+       else if (key_dest == key_menu || key_dest == key_menu_grabbed)
+               VID_SetMouse(vid_mouse.integer && !in_client_mouse && !vid_touchscreen.integer, !vid_touchscreen.integer);
+       else
+               VID_SetMouse(vid_mouse.integer && !cl.csqc_wantsmousemove && cl_prydoncursor.integer <= 0 && (!cls.demoplayback || cl_demo_mousegrab.integer) && !vid_touchscreen.integer, !vid_touchscreen.integer);
 }
 
 /////////////////
@@ -1825,8 +1836,6 @@ void VID_Shutdown (void)
 
 void VID_Finish (void)
 {
-       vid_activewindow = !vid_hidden && vid_hasfocus;
-
        VID_UpdateGamma();
 
        if (!vid_hidden)