Respond to mouse cursor positions but not relative motions when the window is not focused, no more looking around when tabbed out.

This commit is contained in:
Shpoike 2023-07-10 03:08:57 +01:00
parent 05578787e9
commit c0efc3bc9a

View file

@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "SDL.h"
#endif
static qboolean windowhasfocus = true; //just in case sdl fails to tell us...
static qboolean textmode;
extern qboolean bind_grab; //from the menu code, so that we regrab the mouse in order to pass inputs through
@ -302,7 +303,7 @@ static void IN_UpdateGrabs_Internal(qboolean forecerelease)
qboolean needevents; //whether we want to receive events still
qboolean gamecodecursor = (key_dest == key_game && cl.qcvm.cursorforced) || (key_dest == key_menu && cls.menu_qcvm.cursorforced);
wantcursor = (key_dest == key_console || (key_dest == key_menu&&!bind_grab)) || gamecodecursor;
wantcursor = (key_dest == key_console || (key_dest == key_menu&&!bind_grab)) || gamecodecursor || !windowhasfocus;
freemouse = wantcursor && (modestate == MS_WINDOWED || gamecodecursor);
needevents = (!wantcursor) || key_dest == key_game;
@ -503,6 +504,8 @@ extern cvar_t cl_minpitch; /* johnfitz -- variable pitch clamping */
void IN_MouseMotion(int dx, int dy, int wx, int wy)
{
if (!windowhasfocus)
dx = dy = 0; //don't change view angles etc while unfocused.
vid.cursorpos[0] = wx;
vid.cursorpos[1] = wy;
if (key_dest == key_menu && cls.menu_qcvm.extfuncs.Menu_InputEvent)
@ -521,7 +524,7 @@ void IN_MouseMotion(int dx, int dy, int wx, int wy)
G_VECTORSET(OFS_PARM2, wy, 0, 0); //y
G_VECTORSET(OFS_PARM3, 0, 0, 0); //devid
}
else
else if (dx||dy)
{
G_FLOAT(OFS_PARM0) = CSIE_MOUSEDELTA;
G_VECTORSET(OFS_PARM1, dx, dy, 0); //x
@ -1171,9 +1174,9 @@ void IN_SendKeyEvents (void)
#if defined(USE_SDL2)
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
S_UnblockSound();
windowhasfocus=true, S_UnblockSound();
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
S_BlockSound();
windowhasfocus=false, S_BlockSound();
else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
vid.width = event.window.data1;
@ -1186,8 +1189,9 @@ void IN_SendKeyEvents (void)
if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE))
{
if (event.active.gain)
S_UnblockSound();
else S_BlockSound();
windowhasfocus=true, S_UnblockSound();
else
windowhasfocus=false, S_BlockSound();
}
break;
#endif