From 0964fb11e45d99f5d840d455933a93f578cb890a Mon Sep 17 00:00:00 2001 From: a1batross Date: Thu, 29 Nov 2018 21:43:51 +0300 Subject: [PATCH] sdl: partially fix maximizing window on Windows --- engine/platform/sdl/events.c | 34 ++++++++++++++-------------------- engine/platform/sdl/events.h | 1 - engine/platform/sdl/vid_sdl.c | 26 +++++++------------------- mainui | 2 +- 4 files changed, 22 insertions(+), 41 deletions(-) diff --git a/engine/platform/sdl/events.c b/engine/platform/sdl/events.c index 421b8664..ee8523b0 100644 --- a/engine/platform/sdl/events.c +++ b/engine/platform/sdl/events.c @@ -380,9 +380,9 @@ static void SDLash_EventFilter( SDL_Event *event ) if( event->window.windowID != SDL_GetWindowID( host.hWnd ) ) return; - if( ( host.status == HOST_SHUTDOWN ) || - ( Host_IsDedicated() ) ) + if( host.status == HOST_SHUTDOWN || Host_IsDedicated() ) break; // no need to activate + switch( event->window.event ) { case SDL_WINDOWEVENT_MOVED: @@ -392,10 +392,14 @@ static void SDLash_EventFilter( SDL_Event *event ) Cvar_SetValue( "_window_ypos", (float)event->window.data1 ); } break; + case SDL_WINDOWEVENT_MINIMIZED: + host.status = HOST_SLEEP; + VID_RestoreScreenResolution( ); + break; case SDL_WINDOWEVENT_RESTORED: host.status = HOST_FRAME; host.force_draw_version = true; - host.force_draw_version_time = host.realtime + 2; + host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; if( vid_fullscreen->value ) VID_SetMode(); break; @@ -407,16 +411,11 @@ static void SDLash_EventFilter( SDL_Event *event ) S_Activate( true ); } host.force_draw_version = true; - host.force_draw_version_time = host.realtime + 2; + host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; if( vid_fullscreen->value ) VID_SetMode(); break; - case SDL_WINDOWEVENT_MINIMIZED: - host.status = HOST_SLEEP; - VID_RestoreScreenResolution(); - break; case SDL_WINDOWEVENT_FOCUS_LOST: - #if TARGET_OS_IPHONE { // Keep running if ftp server enabled @@ -431,24 +430,19 @@ static void SDLash_EventFilter( SDL_Event *event ) S_Activate( false ); } host.force_draw_version = true; - host.force_draw_version_time = host.realtime + 1; + host.force_draw_version_time = host.realtime + 2; VID_RestoreScreenResolution(); break; - case SDL_WINDOWEVENT_CLOSE: - Sys_Quit(); - break; case SDL_WINDOWEVENT_RESIZED: - if( vid_fullscreen->value ) break; - R_ChangeDisplaySettingsFast( event->window.data1, - event->window.data2 ); - break; case SDL_WINDOWEVENT_MAXIMIZED: { - int w, h; - if( vid_fullscreen->value ) break; + int w = VID_MIN_WIDTH, h = VID_MIN_HEIGHT; + if( vid_fullscreen->value ) + break; SDL_GL_GetDrawableSize( host.hWnd, &w, &h ); - R_ChangeDisplaySettingsFast( w, h ); + R_SaveVideoMode( w, h ); + SCR_VidInit(); // tell the client.dll what vid_mode has changed break; } default: diff --git a/engine/platform/sdl/events.h b/engine/platform/sdl/events.h index a1ab29b2..d5102331 100644 --- a/engine/platform/sdl/events.h +++ b/engine/platform/sdl/events.h @@ -22,7 +22,6 @@ GNU General Public License for more details. // window management void VID_RestoreScreenResolution( void ); -void R_ChangeDisplaySettingsFast( int width, int height ); // for fast resizing qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ); void VID_DestroyWindow( void ); void GL_InitExtensions( void ); diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 052db635..370da1c7 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -517,7 +517,7 @@ qboolean VID_SetScreenResolution( int width, int height ) SDL_GL_GetDrawableSize( host.hWnd, &got.w, &got.h ); - R_ChangeDisplaySettingsFast( got.w, got.h ); + R_SaveVideoMode( got.w, got.h ); return true; } @@ -571,8 +571,10 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) if( !fullscreen ) { wndFlags |= SDL_WINDOW_RESIZABLE; - xpos = max( 0, Cvar_VariableInteger( "_window_xpos" ) ); - ypos = max( 0, Cvar_VariableInteger( "_window_ypos" ) ); + xpos = Cvar_VariableInteger( "_window_xpos" ); + ypos = Cvar_VariableInteger( "_window_ypos" ); + if( xpos < 0 ) xpos = SDL_WINDOWPOS_CENTERED; + if( ypos < 0 ) ypos = SDL_WINDOWPOS_CENTERED; } else { @@ -675,7 +677,7 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) return false; SDL_GL_GetDrawableSize( host.hWnd, &width, &height ); - R_ChangeDisplaySettingsFast( width, height ); + R_SaveVideoMode( width, height ); return true; } @@ -1126,20 +1128,6 @@ void GL_InitExtensions( void ) glw_state.initialized = true; } -/* -================== -R_ChangeDisplaySettingsFast - -Change window size fastly to custom values, without setting vid mode -================== -*/ -void R_ChangeDisplaySettingsFast( int width, int height ) -{ - R_SaveVideoMode( width, height ); - - SCR_VidInit(); -} - rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) { SDL_DisplayMode displayMode; @@ -1177,7 +1165,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) SDL_SetWindowBordered( host.hWnd, true ); SDL_SetWindowSize( host.hWnd, width, height ); SDL_GL_GetDrawableSize( host.hWnd, &width, &height ); - R_ChangeDisplaySettingsFast( width, height ); + R_SaveVideoMode( width, height ); } return rserr_ok; diff --git a/mainui b/mainui index 4e061f6e..7af08ccb 160000 --- a/mainui +++ b/mainui @@ -1 +1 @@ -Subproject commit 4e061f6eb58884ca04b75aac2b0016cbe67132f5 +Subproject commit 7af08ccb66b5a74ec6cab298b63f4b829585fd12