Skip to content

Commit cd92f4d

Browse files
committed
appframework: Mouse scaling should use only drawable screen area
See nillerusr/source-engine#456
1 parent 3236b1c commit cd92f4d

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

appframework/sdlmgr.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,9 +1303,6 @@ void CSDLMgr::SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight )
13031303
}
13041304

13051305
mode.format = (Uint32)SDL_PIXELFORMAT_RGBX8888;
1306-
1307-
m_flMouseXScale = ( float )nWidth / ( float )mode.w;
1308-
m_flMouseYScale = ( float )nHeight / ( float )mode.h;
13091306
}
13101307
else
13111308
{
@@ -1314,8 +1311,6 @@ void CSDLMgr::SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight )
13141311
mode.w = nWidth;
13151312
mode.h = nHeight;
13161313
mode.driverdata = 0;
1317-
m_flMouseXScale = 1.0f;
1318-
m_flMouseYScale = 1.0f;
13191314
}
13201315

13211316
SDL_SetWindowDisplayMode( m_Window, &mode );
@@ -1362,6 +1357,33 @@ void CSDLMgr::SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight )
13621357

13631358
m_bFullScreen = bFullScreen;
13641359
}
1360+
1361+
// dimhotepus: Mouse scaling should account camera notch on Macs
1362+
if (bFullScreen)
1363+
{
1364+
int drawableW, drawableH;
1365+
SDL_GL_GetDrawableSize(m_Window, &drawableW, &drawableH);
1366+
1367+
if ( drawableW > 0 && drawableH > 0 )
1368+
{
1369+
// Use drawable size for accurate mouse scaling, including macOS devices
1370+
// with camera notch
1371+
m_flMouseXScale = (float)nWidth / (float)drawableW;
1372+
m_flMouseYScale = (float)nHeight / (float)drawableH;
1373+
}
1374+
else
1375+
{
1376+
// Fallback to mode dimensions if drawable size unavailable
1377+
m_flMouseXScale = (float)nWidth / (float)mode.w;
1378+
m_flMouseYScale = (float)nHeight / (float)mode.h;
1379+
}
1380+
}
1381+
else
1382+
{
1383+
// Use 1:1 scaling for windowed mode
1384+
m_flMouseXScale = 1.0f;
1385+
m_flMouseYScale = 1.0f;
1386+
}
13651387
}
13661388

13671389

0 commit comments

Comments
 (0)