mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-13 08:38:59 +00:00
engine: client: restore window maximized state after engine restart
This commit is contained in:
parent
73fcb84b62
commit
cb19fa2f6d
@ -549,7 +549,7 @@ static void SetWidthAndHeightFromCommandLine( void )
|
||||
return;
|
||||
}
|
||||
|
||||
R_SaveVideoMode( width, height, width, height );
|
||||
R_SaveVideoMode( width, height, width, height, false );
|
||||
}
|
||||
|
||||
static void SetFullscreenModeFromCommandLine( void )
|
||||
|
@ -29,7 +29,8 @@ static CVAR_DEFINE_AUTO( vid_rotate, "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "sc
|
||||
static CVAR_DEFINE_AUTO( vid_scale, "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "pixel scale" );
|
||||
|
||||
CVAR_DEFINE_AUTO( vid_highdpi, "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" );
|
||||
CVAR_DEFINE( vid_fullscreen, "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" );
|
||||
CVAR_DEFINE_AUTO( vid_maximized, "0", FCVAR_RENDERINFO, "window maximized state, read-only" );
|
||||
CVAR_DEFINE( vid_fullscreen, "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscren mode" );
|
||||
CVAR_DEFINE( window_xpos, "_window_xpos", "-1", FCVAR_RENDERINFO, "window position by horizontal" );
|
||||
CVAR_DEFINE( window_ypos, "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" );
|
||||
|
||||
@ -66,7 +67,7 @@ void VID_InitDefaultResolution( void )
|
||||
R_SaveVideoMode
|
||||
=================
|
||||
*/
|
||||
void R_SaveVideoMode( int w, int h, int render_w, int render_h )
|
||||
void R_SaveVideoMode( int w, int h, int render_w, int render_h, qboolean maximized )
|
||||
{
|
||||
if( !w || !h || !render_w || !render_h )
|
||||
{
|
||||
@ -79,6 +80,7 @@ void R_SaveVideoMode( int w, int h, int render_w, int render_h )
|
||||
|
||||
Cvar_SetValue( "width", w );
|
||||
Cvar_SetValue( "height", h );
|
||||
Cvar_DirectSet( &vid_maximized, maximized ? "1" : "0" );
|
||||
|
||||
// immediately drop changed state or we may trigger
|
||||
// video subsystem to reapply settings
|
||||
@ -221,6 +223,7 @@ void VID_Init( void )
|
||||
Cvar_RegisterVariable( &vid_rotate );
|
||||
Cvar_RegisterVariable( &vid_scale );
|
||||
Cvar_RegisterVariable( &vid_fullscreen );
|
||||
Cvar_RegisterVariable( &vid_maximized );
|
||||
Cvar_RegisterVariable( &vid_brightness );
|
||||
Cvar_RegisterVariable( &vid_gamma );
|
||||
Cvar_RegisterVariable( &window_xpos );
|
||||
|
@ -31,12 +31,13 @@ extern glwstate_t glw_state;
|
||||
#define VID_MIN_WIDTH 320
|
||||
|
||||
extern convar_t vid_fullscreen;
|
||||
extern convar_t vid_maximized;
|
||||
extern convar_t vid_highdpi;
|
||||
extern convar_t window_xpos;
|
||||
extern convar_t window_ypos;
|
||||
extern convar_t gl_msaa_samples;
|
||||
|
||||
void R_SaveVideoMode( int w, int h, int render_w, int render_h );
|
||||
void R_SaveVideoMode( int w, int h, int render_w, int render_h, qboolean maximized );
|
||||
void VID_SetDisplayTransform( int *render_w, int *render_h );
|
||||
void VID_CheckChanges( void );
|
||||
const char *VID_GetModeString( int vid_mode );
|
||||
|
@ -631,15 +631,19 @@ static void SDLash_EventFilter( SDL_Event *event )
|
||||
|
||||
Q_snprintf( val, sizeof( val ), "%d", event->window.data2 );
|
||||
Cvar_DirectSet( &window_ypos, val );
|
||||
|
||||
Cvar_DirectSet( &vid_maximized, "0" );
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
host.status = HOST_SLEEP;
|
||||
Cvar_DirectSet( &vid_maximized, "0" );
|
||||
VID_RestoreScreenResolution( );
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESTORED:
|
||||
host.status = HOST_FRAME;
|
||||
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
|
||||
Cvar_DirectSet( &vid_maximized, "0" );
|
||||
if( vid_fullscreen.value )
|
||||
VID_SetMode();
|
||||
break;
|
||||
@ -651,12 +655,18 @@ static void SDLash_EventFilter( SDL_Event *event )
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
{
|
||||
SDL_Window *wnd = SDL_GetWindowFromID( event->window.windowID );
|
||||
|
||||
if( vid_fullscreen.value )
|
||||
break;
|
||||
|
||||
VID_SaveWindowSize( event->window.data1, event->window.data2 );
|
||||
VID_SaveWindowSize( event->window.data1, event->window.data2,
|
||||
FBitSet( SDL_GetWindowFlags( wnd ), SDL_WINDOW_MAXIMIZED ) != 0 );
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
Cvar_DirectSet( &vid_maximized, "1" );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen );
|
||||
void VID_DestroyWindow( void );
|
||||
void GL_InitExtensions( void );
|
||||
qboolean GL_DeleteContext( void );
|
||||
void VID_SaveWindowSize( int width, int height );
|
||||
void VID_SaveWindowSize( int width, int height, qboolean maximized );
|
||||
|
||||
// joystick events
|
||||
extern SDL_Joystick *g_joy;
|
||||
|
@ -520,7 +520,7 @@ static qboolean GL_UpdateContext( void )
|
||||
return true;
|
||||
}
|
||||
|
||||
void VID_SaveWindowSize( int width, int height )
|
||||
void VID_SaveWindowSize( int width, int height, qboolean maximized )
|
||||
{
|
||||
int render_w = width, render_h = height;
|
||||
|
||||
@ -532,7 +532,7 @@ void VID_SaveWindowSize( int width, int height )
|
||||
#endif
|
||||
|
||||
VID_SetDisplayTransform( &render_w, &render_h );
|
||||
R_SaveVideoMode( width, height, render_w, render_h );
|
||||
R_SaveVideoMode( width, height, render_w, render_h, maximized );
|
||||
}
|
||||
|
||||
static qboolean VID_SetScreenResolution( int width, int height )
|
||||
@ -568,9 +568,9 @@ static qboolean VID_SetScreenResolution( int width, int height )
|
||||
//SDL_SetWindowPosition( host.hWnd, 0, 0 );
|
||||
SDL_SetWindowSize( host.hWnd, got.w, got.h );
|
||||
|
||||
VID_SaveWindowSize( got.w, got.h );
|
||||
VID_SaveWindowSize( got.w, got.h, true );
|
||||
#else
|
||||
VID_SaveWindowSize( width, height );
|
||||
VID_SaveWindowSize( width, height, true );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@ -622,6 +622,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
|
||||
char iconpath[MAX_STRING];
|
||||
int xpos, ypos;
|
||||
const char *localIcoPath;
|
||||
qboolean maximized = vid_maximized.value != 0.0f;
|
||||
|
||||
if( vid_highdpi.value ) wndFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
Q_strncpy( wndname, GI->title, sizeof( wndname ));
|
||||
@ -634,6 +635,8 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
|
||||
SDL_Rect r;
|
||||
|
||||
wndFlags |= SDL_WINDOW_RESIZABLE;
|
||||
if( maximized )
|
||||
wndFlags |= SDL_WINDOW_MAXIMIZED;
|
||||
|
||||
#if SDL_VERSION_ATLEAST( 2, 0, 5 )
|
||||
if( SDL_GetDisplayUsableBounds( 0, &r ) < 0 &&
|
||||
@ -691,9 +694,11 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
|
||||
|
||||
// window creation has failed...
|
||||
if( glw_state.safe >= SAFE_LAST )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// update window size if it was maximized, just in case
|
||||
if( FBitSet( SDL_GetWindowFlags( host.hWnd ), SDL_WINDOW_MAXIMIZED ) != 0 )
|
||||
SDL_GetWindowSize( host.hWnd, &width, &height );
|
||||
|
||||
#if !XASH_MOBILE_PLATFORM
|
||||
if( fullscreen )
|
||||
@ -840,7 +845,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
|
||||
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
|
||||
VID_SaveWindowSize( width, height );
|
||||
VID_SaveWindowSize( width, height, maximized );
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1094,7 +1099,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
|
||||
SDL_SetWindowSize( host.hWnd, width, height );
|
||||
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
VID_SaveWindowSize( width, height );
|
||||
VID_SaveWindowSize( width, height, true );
|
||||
}
|
||||
|
||||
return rserr_ok;
|
||||
@ -1136,7 +1141,7 @@ qboolean VID_SetMode( void )
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
}
|
||||
|
||||
if( !FBitSet( vid_fullscreen.flags, FCVAR_CHANGED ) )
|
||||
if( !FBitSet( vid_fullscreen.flags, FCVAR_CHANGED ))
|
||||
Cvar_DirectSet( &vid_fullscreen, DEFAULT_FULLSCREEN );
|
||||
else
|
||||
ClearBits( vid_fullscreen.flags, FCVAR_CHANGED );
|
||||
@ -1167,11 +1172,12 @@ qboolean VID_SetMode( void )
|
||||
// try setting it back to something safe
|
||||
if(( err = R_ChangeDisplaySettings( sdlState.prev_width, sdlState.prev_height, false )) != rserr_ok )
|
||||
{
|
||||
Con_Reportf( S_ERROR "VID_SetMode: could not revert to safe mode\n" );
|
||||
Con_Reportf( S_ERROR "VID_SetMode: could not revert to safe mode\n" );
|
||||
Sys_Warn("could not revert to safe mode!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user