Skip to content

Commit 4bed374

Browse files
committed
Unscale the window size on resize if we are doing automatic HighDPI scaling.
1 parent b80250b commit 4bed374

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/platforms/rcore_desktop_glfw.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1753,8 +1753,14 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
17531753

17541754
if (IsWindowFullscreen()) return;
17551755

1756-
// Set current screen size
1756+
// if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale
1757+
if (IsWindowState(FLAG_WINDOW_HIGHDPI))
1758+
{
1759+
width = (int)(width / GetWindowScaleDPI().x);
1760+
height = (int)(height / GetWindowScaleDPI().y);
1761+
}
17571762

1763+
// Set current screen size
17581764
CORE.Window.screen.width = width;
17591765
CORE.Window.screen.height = height;
17601766

src/platforms/rcore_desktop_rgfw.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,19 @@ void PollInputEvents(void)
10331033
case RGFW_windowResized:
10341034
{
10351035
SetupViewport(platform.window->r.w, platform.window->r.h);
1036-
CORE.Window.screen.width = platform.window->r.w;
1037-
CORE.Window.screen.height = platform.window->r.h;
1036+
1037+
// if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale
1038+
if (IsWindowState(FLAG_WINDOW_HIGHDPI))
1039+
{
1040+
CORE.Window.screen.width = (int)(platform.window->r.w / GetWindowScaleDPI().x);
1041+
CORE.Window.screen.height = (int)(platform.window->r.h / GetWindowScaleDPI().y);
1042+
}
1043+
else
1044+
{
1045+
CORE.Window.screen.width = platform.window->r.w;
1046+
CORE.Window.screen.height = platform.window->r.h;
1047+
}
1048+
10381049
CORE.Window.currentFbo.width = platform.window->r.w;
10391050
CORE.Window.currentFbo.height = platform.window->r.h;
10401051
CORE.Window.resizedLastFrame = true;

src/platforms/rcore_desktop_sdl.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,17 @@ void PollInputEvents(void)
14511451
const int width = event.window.data1;
14521452
const int height = event.window.data2;
14531453
SetupViewport(width, height);
1454-
CORE.Window.screen.width = width;
1455-
CORE.Window.screen.height = height;
1454+
// if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale
1455+
if (IsWindowState(FLAG_WINDOW_HIGHDPI))
1456+
{
1457+
CORE.Window.screen.width = (int)(width / GetWindowScaleDPI().x);
1458+
CORE.Window.screen.height = (int)(height / GetWindowScaleDPI().y);
1459+
}
1460+
else
1461+
{
1462+
CORE.Window.screen.width = width;
1463+
CORE.Window.screen.height = height;
1464+
}
14561465
CORE.Window.currentFbo.width = width;
14571466
CORE.Window.currentFbo.height = height;
14581467
CORE.Window.resizedLastFrame = true;

0 commit comments

Comments
 (0)