Fix mouse grab after toggling fullscreen

cls.glconfig.isFullscreen was not updated when changing r_fullscreen
without a vid_restart. Starting in fullscreen and switching to
windowed mode would not release the mouse.

Mods calling trap_GetGlconfig() after a fullscreen toggle now get
the correct value for isFullscreen. (Note: Mods already got the
correct value at start up and after vid_restart.)

Reported by Mickaël "mickael9" Thomas.
This commit is contained in:
Zack Middleton 2018-04-08 23:53:52 -05:00
parent e986384fde
commit 699cbed7c7

View file

@ -341,7 +341,7 @@ static void IN_GobbleMotionEvents( void )
IN_ActivateMouse IN_ActivateMouse
=============== ===============
*/ */
static void IN_ActivateMouse( void ) static void IN_ActivateMouse( qboolean isFullscreen )
{ {
if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) ) if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) )
return; return;
@ -355,7 +355,7 @@ static void IN_ActivateMouse( void )
} }
// in_nograb makes no sense in fullscreen mode // in_nograb makes no sense in fullscreen mode
if( !Cvar_VariableIntegerValue("r_fullscreen") ) if( !isFullscreen )
{ {
if( in_nograb->modified || !mouseActive ) if( in_nograb->modified || !mouseActive )
{ {
@ -379,15 +379,15 @@ static void IN_ActivateMouse( void )
IN_DeactivateMouse IN_DeactivateMouse
=============== ===============
*/ */
static void IN_DeactivateMouse( void ) static void IN_DeactivateMouse( qboolean isFullscreen )
{ {
if( !SDL_WasInit( SDL_INIT_VIDEO ) ) if( !SDL_WasInit( SDL_INIT_VIDEO ) )
return; return;
// Always show the cursor when the mouse is disabled, // Always show the cursor when the mouse is disabled,
// but not when fullscreen // but not when fullscreen
if( !Cvar_VariableIntegerValue("r_fullscreen") ) if( !isFullscreen )
SDL_ShowCursor( 1 ); SDL_ShowCursor( SDL_TRUE );
if( !mouseAvailable ) if( !mouseAvailable )
return; return;
@ -1174,23 +1174,26 @@ void IN_Frame( void )
// If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading // If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading
loading = ( clc.state != CA_DISCONNECTED && clc.state != CA_ACTIVE ); loading = ( clc.state != CA_DISCONNECTED && clc.state != CA_ACTIVE );
// update isFullscreen since it might of changed since the last vid_restart
cls.glconfig.isFullscreen = Cvar_VariableIntegerValue( "r_fullscreen" ) != 0;
if( !cls.glconfig.isFullscreen && ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ) if( !cls.glconfig.isFullscreen && ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) )
{ {
// Console is down in windowed mode // Console is down in windowed mode
IN_DeactivateMouse( ); IN_DeactivateMouse( cls.glconfig.isFullscreen );
} }
else if( !cls.glconfig.isFullscreen && loading ) else if( !cls.glconfig.isFullscreen && loading )
{ {
// Loading in windowed mode // Loading in windowed mode
IN_DeactivateMouse( ); IN_DeactivateMouse( cls.glconfig.isFullscreen );
} }
else if( !( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_INPUT_FOCUS ) ) else if( !( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_INPUT_FOCUS ) )
{ {
// Window not got focus // Window not got focus
IN_DeactivateMouse( ); IN_DeactivateMouse( cls.glconfig.isFullscreen );
} }
else else
IN_ActivateMouse( ); IN_ActivateMouse( cls.glconfig.isFullscreen );
IN_ProcessEvents( ); IN_ProcessEvents( );
@ -1236,7 +1239,7 @@ void IN_Init( void *windowData )
SDL_StartTextInput( ); SDL_StartTextInput( );
mouseAvailable = ( in_mouse->value != 0 ); mouseAvailable = ( in_mouse->value != 0 );
IN_DeactivateMouse( ); IN_DeactivateMouse( Cvar_VariableIntegerValue( "r_fullscreen" ) != 0 );
appState = SDL_GetWindowFlags( SDL_window ); appState = SDL_GetWindowFlags( SDL_window );
Cvar_SetValue( "com_unfocused", !( appState & SDL_WINDOW_INPUT_FOCUS ) ); Cvar_SetValue( "com_unfocused", !( appState & SDL_WINDOW_INPUT_FOCUS ) );
@ -1255,7 +1258,7 @@ void IN_Shutdown( void )
{ {
SDL_StopTextInput( ); SDL_StopTextInput( );
IN_DeactivateMouse( ); IN_DeactivateMouse( Cvar_VariableIntegerValue( "r_fullscreen" ) != 0 );
mouseAvailable = qfalse; mouseAvailable = qfalse;
IN_ShutdownJoystick( ); IN_ShutdownJoystick( );