Skip to content

Commit

Permalink
Respond to mouse cursor positions but not relative motions when the w…
Browse files Browse the repository at this point in the history
…indow is not focused, no more looking around when tabbed out.
  • Loading branch information
Shpoike committed Jul 10, 2023
1 parent 0557878 commit c0efc3b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit c0efc3b

Please sign in to comment.