From dd1d86c289c483258cd38069b50ae1d372ad7975 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 18 Jan 2023 19:28:16 +0300 Subject: [PATCH] engine: platform: sdl: check usable display rect before creating window --- engine/platform/sdl/vid_sdl.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index e9dd87e3..e63f7589 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -639,11 +639,33 @@ qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) if( !fullscreen ) { + SDL_Rect r; + wndFlags |= SDL_WINDOW_RESIZABLE; - xpos = Cvar_VariableInteger( "_window_xpos" ); - ypos = Cvar_VariableInteger( "_window_ypos" ); - if( xpos < 0 ) xpos = SDL_WINDOWPOS_CENTERED; - if( ypos < 0 ) ypos = SDL_WINDOWPOS_CENTERED; + +#if SDL_VERSION_ATLEAST( 2, 0, 5 ) + if( SDL_GetDisplayUsableBounds( 0, &r ) < 0 && + SDL_GetDisplayBounds( 0, &r ) < 0 ) +#else + if( SDL_GetDisplayBounds( 0, &r ) < 0 ) +#endif + { + Con_Reportf( S_ERROR "VID_CreateWindow: SDL_GetDisplayBounds failed: %s\n", SDL_GetError( )); + xpos = SDL_WINDOWPOS_CENTERED; + ypos = SDL_WINDOWPOS_CENTERED; + } + else + { + xpos = Cvar_VariableInteger( "_window_xpos" ); + ypos = Cvar_VariableInteger( "_window_ypos" ); + + // don't create window outside of usable display space + if( xpos < r.x || xpos + width > r.x + r.w ) + xpos = SDL_WINDOWPOS_CENTERED; + + if( ypos < r.y || ypos + height > r.y + r.h ) + ypos = SDL_WINDOWPOS_CENTERED; + } } else {