From e6cfd1c970eba8487d5847d1c0fcee0cf9ee9543 Mon Sep 17 00:00:00 2001 From: Tris Date: Fri, 5 Dec 2025 14:36:23 +0100 Subject: [PATCH] Fixed y mouse offset issue on macOS devices with camera notch. --- appframework/sdlmgr.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/appframework/sdlmgr.cpp b/appframework/sdlmgr.cpp index 53ca92d5f5..a7dd240b1a 100644 --- a/appframework/sdlmgr.cpp +++ b/appframework/sdlmgr.cpp @@ -1472,9 +1472,6 @@ void CSDLMgr::SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight ) } mode.format = (Uint32)SDL_PIXELFORMAT_RGBX8888; - - m_flMouseXScale = ( float )nWidth / ( float )mode.w; - m_flMouseYScale = ( float )nHeight / ( float )mode.h; } else { @@ -1483,8 +1480,6 @@ void CSDLMgr::SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight ) mode.w = nWidth; mode.h = nHeight; mode.driverdata = 0; - m_flMouseXScale = 1.0f; - m_flMouseYScale = 1.0f; } SDL_SetWindowDisplayMode( m_Window, &mode ); @@ -1531,6 +1526,31 @@ void CSDLMgr::SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight ) m_bFullScreen = bFullScreen; } + + if (bFullScreen) + { + int drawableW, drawableH; + SDL_GL_GetDrawableSize(m_Window, &drawableW, &drawableH); + + if ( drawableW > 0 && drawableH > 0 ) + { + // Use drawable size for accurate mouse scaling, including macOS devices + // with camera notch + m_flMouseXScale = (float)nWidth / (float)drawableW; + m_flMouseYScale = (float)nHeight / (float)drawableH; + } + else { + // Fallback to mode dimensions if drawable size unavailable + m_flMouseXScale = (float)nWidth / (float)mode.w; + m_flMouseYScale = (float)nHeight / (float)mode.h; + } + } + else + { + // Use 1:1 scaling for windowed mode + m_flMouseXScale = 1.0f; + m_flMouseYScale = 1.0f; + } }