From 98d88266a6f5c51239e050c6fe35d8a3b769ab74 Mon Sep 17 00:00:00 2001 From: Sheridan Kane Rathbun Date: Fri, 23 Feb 2024 09:54:17 -0800 Subject: [PATCH] engine: platform: sdl: fix incorrect mouse cursor positioning on high-dpi displays (#1623) Signed-off-by: SheridanR --- engine/platform/sdl/in_sdl.c | 11 +++++++++++ engine/platform/sdl/vid_sdl.c | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/engine/platform/sdl/in_sdl.c b/engine/platform/sdl/in_sdl.c index 24dabc0e..7231a626 100644 --- a/engine/platform/sdl/in_sdl.c +++ b/engine/platform/sdl/in_sdl.c @@ -43,7 +43,18 @@ Platform_GetMousePos */ void GAME_EXPORT Platform_GetMousePos( int *x, int *y ) { + float factorX; + float factorY; + { + int w1, w2, h1, h2; + SDL_GL_GetDrawableSize( host.hWnd, &w1, &h1 ); + SDL_GetWindowSize( host.hWnd, &w2, &h2 ); + factorX = (float)w1 / w2; + factorY = (float)h1 / h2; + } SDL_GetMouseState( x, y ); + *x = *x * factorX; + *y = *y * factorY; } /* diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 1d097d42..737c1d6d 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -576,10 +576,8 @@ static qboolean VID_SetScreenResolution( int width, int height, window_mode_t wi SDL_DisplayMode got; Uint32 wndFlags = 0; -#if !XASH_APPLE if( vid_highdpi.value ) SetBits( wndFlags, SDL_WINDOW_ALLOW_HIGHDPI ); -#endif SDL_SetWindowBordered( host.hWnd, SDL_FALSE );