mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
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:
parent
05578787e9
commit
c0efc3bc9a
1 changed files with 10 additions and 6 deletions
|
@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static qboolean windowhasfocus = true; //just in case sdl fails to tell us...
|
||||||
static qboolean textmode;
|
static qboolean textmode;
|
||||||
extern qboolean bind_grab; //from the menu code, so that we regrab the mouse in order to pass inputs through
|
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 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);
|
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);
|
freemouse = wantcursor && (modestate == MS_WINDOWED || gamecodecursor);
|
||||||
needevents = (!wantcursor) || key_dest == key_game;
|
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)
|
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[0] = wx;
|
||||||
vid.cursorpos[1] = wy;
|
vid.cursorpos[1] = wy;
|
||||||
if (key_dest == key_menu && cls.menu_qcvm.extfuncs.Menu_InputEvent)
|
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_PARM2, wy, 0, 0); //y
|
||||||
G_VECTORSET(OFS_PARM3, 0, 0, 0); //devid
|
G_VECTORSET(OFS_PARM3, 0, 0, 0); //devid
|
||||||
}
|
}
|
||||||
else
|
else if (dx||dy)
|
||||||
{
|
{
|
||||||
G_FLOAT(OFS_PARM0) = CSIE_MOUSEDELTA;
|
G_FLOAT(OFS_PARM0) = CSIE_MOUSEDELTA;
|
||||||
G_VECTORSET(OFS_PARM1, dx, dy, 0); //x
|
G_VECTORSET(OFS_PARM1, dx, dy, 0); //x
|
||||||
|
@ -1171,9 +1174,9 @@ void IN_SendKeyEvents (void)
|
||||||
#if defined(USE_SDL2)
|
#if defined(USE_SDL2)
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
||||||
S_UnblockSound();
|
windowhasfocus=true, S_UnblockSound();
|
||||||
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
||||||
S_BlockSound();
|
windowhasfocus=false, S_BlockSound();
|
||||||
else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
{
|
{
|
||||||
vid.width = event.window.data1;
|
vid.width = event.window.data1;
|
||||||
|
@ -1186,8 +1189,9 @@ void IN_SendKeyEvents (void)
|
||||||
if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE))
|
if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE))
|
||||||
{
|
{
|
||||||
if (event.active.gain)
|
if (event.active.gain)
|
||||||
S_UnblockSound();
|
windowhasfocus=true, S_UnblockSound();
|
||||||
else S_BlockSound();
|
else
|
||||||
|
windowhasfocus=false, S_BlockSound();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue