Index: code/sdl/sdl_input.c =================================================================== --- code/sdl/sdl_input.c (revision 1183) +++ code/sdl/sdl_input.c (working copy) @@ -62,6 +62,8 @@ static cvar_t *in_joystickDebug = NULL; static cvar_t *in_joystickThreshold = NULL; +extern qboolean fullscreen_minimized; + /* =============== IN_TranslateSDLToQ3Key @@ -667,6 +669,40 @@ { switch (e.type) { + case SDL_ACTIVEEVENT: + if( e.active.state & SDL_APPACTIVE ) + { + if( e.active.gain ) + { + Sys_EnableAltTab( ( cl_altTab->integer == 1 ) ); + if( fullscreen_minimized ) + { + Cvar_Set( "r_fullscreen", "1" ); + fullscreen_minimized = qfalse; + } + } + else + { + Sys_EnableAltTab( qtrue ); + } + } + + if( e.active.state & SDL_APPINPUTFOCUS ) + { + if( e.active.gain ) + { + SDL_ShowCursor(0); + SDL_WM_GrabInput(SDL_GRAB_ON); + } + else + { + SDL_ShowCursor(1); + SDL_WM_GrabInput(SDL_GRAB_OFF); + + } + } + break; + case SDL_KEYDOWN: IN_PrintKey(&e); p = IN_TranslateSDLToQ3Key(&e.key.keysym, &key); Index: code/sdl/sdl_glimp.c =================================================================== --- code/sdl/sdl_glimp.c (revision 1183) +++ code/sdl/sdl_glimp.c (working copy) @@ -54,6 +54,8 @@ #define GLimp_SetCurrentContext(ctx) #endif +qboolean fullscreen_minimized = qfalse; + static QGLContext opengl_context; typedef enum @@ -540,6 +542,38 @@ SDL_GL_SwapBuffers(); } + if( r_minimize && r_minimize->integer ) + { + SDL_Surface *s = SDL_GetVideoSurface( ); + qboolean fullscreen = qfalse; + qboolean isMinimized = qfalse; + + fullscreen = ( s && ( s->flags & SDL_FULLSCREEN ) ); + isMinimized = ( SDL_WM_IconifyWindow( ) != 0 ); + if( isMinimized ) + { + // success + if( fullscreen ) + fullscreen_minimized = qtrue; + + Cvar_Set( "r_minimize", "0" ); + } + else if( fullscreen && r_fullscreen && r_fullscreen->integer ) + { + // if SDL_WM_IconifyWindow() fails because of + // fullscreen, switch to windowed mode and try again + fullscreen_minimized = qtrue; + Cvar_Set( "r_fullscreen", "0" ); + } + else if( fullscreen ) + { + // SDL_WM_IconfiyWindow is totally broken, set + // fullscreen mode back + Cvar_Set( "r_fullscreen", "1" ); + fullscreen_minimized = qfalse; + } + } + if( r_fullscreen->modified ) { qboolean fullscreen; @@ -567,6 +601,14 @@ r_fullscreen->modified = qfalse; } + + + if( cl_altTab->modified ) + { + Sys_EnableAltTab( ( cl_altTab->integer == 1 ) ); + cl_altTab->modified = qfalse; + } + } Index: code/renderer/tr_local.h =================================================================== --- code/renderer/tr_local.h (revision 1183) +++ code/renderer/tr_local.h (working copy) @@ -1035,6 +1035,7 @@ extern cvar_t *r_mode; // video mode extern cvar_t *r_fullscreen; +extern cvar_t *r_minimize; extern cvar_t *r_gamma; extern cvar_t *r_displayRefresh; // optional display refresh option extern cvar_t *r_ignorehwgamma; // overrides hardware gamma capabilities Index: code/renderer/tr_init.c =================================================================== --- code/renderer/tr_init.c (revision 1183) +++ code/renderer/tr_init.c (working copy) @@ -127,6 +127,7 @@ cvar_t *r_lodCurveError; cvar_t *r_fullscreen; +cvar_t *r_minimize; cvar_t *r_customwidth; cvar_t *r_customheight; @@ -922,6 +923,7 @@ 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_minimize = ri.Cvar_Get( "r_minimize", "0", 0 ); 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 ); Index: code/qcommon/qcommon.h =================================================================== --- code/qcommon/qcommon.h (revision 1183) +++ code/qcommon/qcommon.h (working copy) @@ -1031,6 +1031,7 @@ char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs ); void Sys_FreeFileList( char **list ); void Sys_Sleep(int msec); +void Sys_EnableAltTab(qboolean enable); qboolean Sys_LowPhysicalMemory( void ); Index: code/client/client.h =================================================================== --- code/client/client.h (revision 1183) +++ code/client/client.h (working copy) @@ -378,6 +378,8 @@ extern cvar_t *cl_lanForcePackets; extern cvar_t *cl_autoRecordDemo; +extern cvar_t *cl_altTab; + //================================================= // Index: code/client/cl_main.c =================================================================== --- code/client/cl_main.c (revision 1183) +++ code/client/cl_main.c (working copy) @@ -77,6 +77,8 @@ cvar_t *cl_guidServerUniq; +cvar_t *cl_altTab; + clientActive_t cl; clientConnection_t clc; clientStatic_t cls; @@ -2735,6 +2737,8 @@ cl_guidServerUniq = Cvar_Get ("cl_guidServerUniq", "1", CVAR_ARCHIVE); + cl_altTab = Cvar_Get ("cl_altTab", "1", CVAR_ARCHIVE); + // userinfo Cvar_Get ("name", "UnnamedPlayer", CVAR_USERINFO | CVAR_ARCHIVE ); Cvar_Get ("rate", "3000", CVAR_USERINFO | CVAR_ARCHIVE ); Index: code/client/cl_keys.c =================================================================== --- code/client/cl_keys.c (revision 1183) +++ code/client/cl_keys.c (working copy) @@ -1161,6 +1161,14 @@ } } + // on win32 Alt-Tab is handled by the OS, see Sys_EnableAltTab() + if( cl_altTab->integer && key == K_TAB && down && keys[K_ALT].down ) + { + Key_ClearStates(); + Cvar_SetValue( "r_minimize", 1 ); + return; + } + // console key is hardcoded, so the user can never unbind it if (key == '`' || key == '~' || ( key == K_ESCAPE && keys[K_SHIFT].down ) ) { Index: code/sys/sys_win32.c =================================================================== --- code/sys/sys_win32.c (revision 1183) +++ code/sys/sys_win32.c (working copy) @@ -525,3 +525,32 @@ WaitForSingleObject( GetStdHandle( STD_INPUT_HANDLE ), msec ); } +/* +=============== +Sys_EnableAltTab +=============== +*/ +void Sys_EnableAltTab( qboolean enable ) +{ + OSVERSIONINFO osinfo; + + osinfo.dwOSVersionInfoSize = sizeof( osinfo ); + if( !GetVersionEx( &osinfo ) ) + return; + + if( osinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) + { + BOOL old; + + SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, !enable, + &old, 0 ); + } + else + { + if( enable ) + UnregisterHotKey( NULL, 0 ); + else + RegisterHotKey( NULL, 0, MOD_ALT, VK_TAB ); + } +} + Index: code/sys/sys_unix.c =================================================================== --- code/sys/sys_unix.c (revision 1183) +++ code/sys/sys_unix.c (working copy) @@ -476,3 +476,12 @@ select((fileno(stdin) + 1), &fdset, NULL, NULL, &timeout); } } + +/* +=============== +Sys_EnableAltTab +=============== +*/ +void Sys_EnableAltTab( qboolean enable ) +{ +}