From 9cf2d9fa869a0ad051fbcc1e1e0925b18a90ae09 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 23 Nov 2025 14:49:37 +0500 Subject: [PATCH] engine: platform: sdl2: set up DPI awawareness on Windows through SDL hint --- engine/platform/sdl2/sys_sdl2.c | 9 ++--- engine/platform/sdl2/vid_sdl2.c | 65 +-------------------------------- 2 files changed, 5 insertions(+), 69 deletions(-) diff --git a/engine/platform/sdl2/sys_sdl2.c b/engine/platform/sdl2/sys_sdl2.c index 99aedda1..c07be703 100644 --- a/engine/platform/sdl2/sys_sdl2.c +++ b/engine/platform/sdl2/sys_sdl2.c @@ -106,16 +106,12 @@ void SDLash_Init( const char *basedir ) else SDL_LogSetAllPriority( SDL_LOG_PRIORITY_ERROR ); -#ifndef SDL_INIT_EVENTS -#define SDL_INIT_EVENTS 0 -#endif if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) ) { Sys_Warn( "SDL_Init failed: %s", SDL_GetError() ); host.type = HOST_DEDICATED; } -#if SDL_MAJOR_VERSION >= 2 SDL_SetHint( SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0" ); #ifdef SDL_HINT_MOUSE_TOUCH_EVENTS @@ -123,8 +119,11 @@ void SDLash_Init( const char *basedir ) #endif // SDL_HINT_MOUSE_TOUCH_EVENTS SDL_SetHint( SDL_HINT_TOUCH_MOUSE_EVENTS, "0" ); +#if XASH_WIN32 + SDL_SetHint( SDL_HINT_WINDOWS_DPI_AWARENESS, "permonitorv2" ); +#endif // XASH_WIN32 + SDL_StopTextInput(); -#endif // XASH_SDL == 2 SDLash_InitCursors(); } diff --git a/engine/platform/sdl2/vid_sdl2.c b/engine/platform/sdl2/vid_sdl2.c index 5b9c6640..a233931e 100644 --- a/engine/platform/sdl2/vid_sdl2.c +++ b/engine/platform/sdl2/vid_sdl2.c @@ -314,66 +314,6 @@ static void R_FreeVideoModes( void ) } #if XASH_WIN32 -typedef enum _XASH_DPI_AWARENESS -{ - XASH_DPI_UNAWARE = 0, - XASH_SYSTEM_DPI_AWARE = 1, - XASH_PER_MONITOR_DPI_AWARE = 2 -} XASH_DPI_AWARENESS; - -static void WIN_SetDPIAwareness( void ) -{ - HMODULE hModule; - HRESULT ( __stdcall *pSetProcessDpiAwareness )( XASH_DPI_AWARENESS ); - BOOL ( __stdcall *pSetProcessDPIAware )( void ); - BOOL bSuccess = FALSE; - - if( ( hModule = LoadLibraryW( L"shcore.dll" ) ) ) - { - if( ( pSetProcessDpiAwareness = (void*)GetProcAddress( hModule, "SetProcessDpiAwareness" ) ) ) - { - // I hope SDL don't handle WM_DPICHANGED message - HRESULT hResult = pSetProcessDpiAwareness( XASH_SYSTEM_DPI_AWARE ); - - if( hResult == S_OK ) - { - Con_Reportf( "%s: Success\n", __func__ ); - bSuccess = TRUE; - } - else if( hResult == E_INVALIDARG ) Con_Reportf( "%s: Invalid argument\n", __func__ ); - else if( hResult == E_ACCESSDENIED ) Con_Reportf( "%s: Access Denied\n", __func__ ); - } - else Con_Reportf( "%s: Can't get SetProcessDpiAwareness\n", __func__ ); - FreeLibrary( hModule ); - } - else Con_Reportf( "%s: Can't load shcore.dll\n", __func__ ); - - - if( !bSuccess ) - { - Con_Reportf( "%s: Trying SetProcessDPIAware...\n", __func__ ); - - if( ( hModule = LoadLibraryW( L"user32.dll" ) ) ) - { - if( ( pSetProcessDPIAware = ( void* )GetProcAddress( hModule, "SetProcessDPIAware" ) ) ) - { - // I hope SDL don't handle WM_DPICHANGED message - BOOL hResult = pSetProcessDPIAware(); - - if( hResult ) - { - Con_Reportf( "%s: Success\n", __func__ ); - bSuccess = TRUE; - } - else Con_Reportf( "%s: fail\n", __func__ ); - } - else Con_Reportf( "%s: Can't get SetProcessDPIAware\n", __func__ ); - FreeLibrary( hModule ); - } - else Con_Reportf( "%s: Can't load user32.dll\n", __func__ ); - } -} - static qboolean WIN_SetWindowIcon( HICON ico ) { SDL_SysWMinfo wminfo; @@ -957,6 +897,7 @@ qboolean R_Init_Video( const int type ) #else int displayIndex = 0; #endif + SDL_GetCurrentDisplayMode( displayIndex, &displayMode ); refState.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format ); @@ -978,10 +919,6 @@ qboolean R_Init_Video( const int type ) SDL_SetHint( "SDL_VIDEO_X11_XVIDMODE", "1" ); #endif // !XASH_WIN32 - // must be initialized before creating window -#if XASH_WIN32 - WIN_SetDPIAwareness(); -#endif switch( type ) {