From bd2ab9bffd035a9b9a6ce5cef5f4c26d8677f665 Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Tue, 3 Nov 2009 20:29:43 +0000 Subject: [PATCH] - implement r_noborder, inspired by patch from ensiform (#4289) - Add Sys_SetEnv for portable setting of environment variables - Default ioquake3 to appear on the center of the screen if running in windowed mode. --- README | 2 ++ code/renderer/tr_init.c | 2 ++ code/renderer/tr_local.h | 1 + code/sdl/sdl_glimp.c | 21 ++++++++++++++------- code/sys/sys_unix.c | 16 ++++++++++++++++ code/sys/sys_win32.c | 13 +++++++++++++ 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/README b/README index 18ab581b..c78f27ed 100644 --- a/README +++ b/README @@ -192,6 +192,8 @@ New cvars intend to use this. r_sdlDriver - read only, indicates the SDL driver backend being used + r_noborder - Remove window decoration from window + managers, like borders and titlebar. New commands video [filename] - start video capture (use with demo command) diff --git a/code/renderer/tr_init.c b/code/renderer/tr_init.c index 7670770d..edcf48b8 100644 --- a/code/renderer/tr_init.c +++ b/code/renderer/tr_init.c @@ -135,6 +135,7 @@ cvar_t *r_subdivisions; cvar_t *r_lodCurveError; cvar_t *r_fullscreen; +cvar_t *r_noborder; cvar_t *r_customwidth; cvar_t *r_customheight; @@ -909,6 +910,7 @@ void R_Register( void ) r_ignorehwgamma = ri.Cvar_Get( "r_ignorehwgamma", "0", CVAR_ARCHIVE | CVAR_LATCH); r_mode = ri.Cvar_Get( "r_mode", "3", CVAR_ARCHIVE | CVAR_LATCH ); r_fullscreen = ri.Cvar_Get( "r_fullscreen", "1", CVAR_ARCHIVE ); + r_noborder = Cvar_Get("r_noborder", "0", CVAR_ARCHIVE); r_customwidth = ri.Cvar_Get( "r_customwidth", "1600", CVAR_ARCHIVE | CVAR_LATCH ); r_customheight = ri.Cvar_Get( "r_customheight", "1024", CVAR_ARCHIVE | CVAR_LATCH ); r_customPixelAspect = ri.Cvar_Get( "r_customPixelAspect", "1", CVAR_ARCHIVE | CVAR_LATCH ); diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index 1a2cdae7..f5a3846c 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -1043,6 +1043,7 @@ extern cvar_t *r_showcluster; extern cvar_t *r_mode; // video mode extern cvar_t *r_fullscreen; +extern cvar_t *r_noborder; extern cvar_t *r_gamma; extern cvar_t *r_displayRefresh; // optional display refresh option extern cvar_t *r_ignorehwgamma; // overrides hardware gamma capabilities diff --git a/code/sdl/sdl_glimp.c b/code/sdl/sdl_glimp.c index 04690108..e312f9ff 100644 --- a/code/sdl/sdl_glimp.c +++ b/code/sdl/sdl_glimp.c @@ -188,7 +188,7 @@ static void GLimp_DetectAvailableModes(void) GLimp_SetMode =============== */ -static int GLimp_SetMode( int mode, qboolean fullscreen ) +static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder) { const char* glstring; int sdlcolorbits; @@ -249,7 +249,12 @@ static int GLimp_SetMode( int mode, qboolean fullscreen ) glConfig.isFullscreen = qtrue; } else + { + if (noborder) + flags |= SDL_NOFRAME; + glConfig.isFullscreen = qfalse; + } colorbits = r_colorbits->value; if ((!colorbits) || (colorbits >= 32)) @@ -428,7 +433,7 @@ static int GLimp_SetMode( int mode, qboolean fullscreen ) GLimp_StartDriverAndSetMode =============== */ -static qboolean GLimp_StartDriverAndSetMode( int mode, qboolean fullscreen ) +static qboolean GLimp_StartDriverAndSetMode(int mode, qboolean fullscreen, qboolean noborder) { rserr_t err; @@ -455,8 +460,8 @@ static qboolean GLimp_StartDriverAndSetMode( int mode, qboolean fullscreen ) r_fullscreen->modified = qfalse; fullscreen = qfalse; } - - err = GLimp_SetMode( mode, fullscreen ); + + err = GLimp_SetMode(mode, fullscreen, noborder); switch ( err ) { @@ -666,16 +671,18 @@ void GLimp_Init( void ) r_sdlDriver = ri.Cvar_Get( "r_sdlDriver", "", CVAR_ROM ); r_allowResize = ri.Cvar_Get( "r_allowResize", "0", CVAR_ARCHIVE ); + Sys_SetEnv("SDL_VIDEO_CENTERED", "1"); + Sys_GLimpInit( ); // Create the window and set up the context - if( GLimp_StartDriverAndSetMode( r_mode->integer, r_fullscreen->integer ) ) + if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, r_noborder->integer)) goto success; // Try again, this time in a platform specific "safe mode" Sys_GLimpSafeInit( ); - if( GLimp_StartDriverAndSetMode( r_mode->integer, r_fullscreen->integer ) ) + if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, qfalse)) goto success; // Finally, try the default screen resolution @@ -684,7 +691,7 @@ void GLimp_Init( void ) ri.Printf( PRINT_ALL, "Setting r_mode %d failed, falling back on r_mode %d\n", r_mode->integer, R_MODE_FALLBACK ); - if( GLimp_StartDriverAndSetMode( R_MODE_FALLBACK, r_fullscreen->integer ) ) + if(GLimp_StartDriverAndSetMode(R_MODE_FALLBACK, r_fullscreen->integer, qfalse)) goto success; } diff --git a/code/sys/sys_unix.c b/code/sys/sys_unix.c index 5ed0721c..d1131922 100644 --- a/code/sys/sys_unix.c +++ b/code/sys/sys_unix.c @@ -583,3 +583,19 @@ void Sys_PlatformInit( void ) signal( SIGIOT, Sys_SigHandler ); signal( SIGBUS, Sys_SigHandler ); } + +/* +============== +Sys_SetEnv + +set/unset environment variables (empty value removes it) +============== +*/ + +void Sys_SetEnv(const char *name, const char *value) +{ + if(value && *value) + setenv(name, value, 1); + else + unsetenv(name); +} diff --git a/code/sys/sys_win32.c b/code/sys/sys_win32.c index b3d21670..d478f0f2 100644 --- a/code/sys/sys_win32.c +++ b/code/sys/sys_win32.c @@ -652,3 +652,16 @@ void Sys_PlatformInit( void ) SDL_VIDEODRIVER_externallySet = qfalse; #endif } + +/* +============== +Sys_SetEnv + +set/unset environment variables (empty value removes it) +============== +*/ + +void Sys_SetEnv(const char *name, const char *value) +{ + _putenv(va("%s=%s", name, value); +}