From 2ffca576293de1b60019ba3e14ea34cc0d757eeb Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:45:08 +0200 Subject: [PATCH] `GetWindowScaleDPI()` return `{1,1}` if HDPI or fullscreen modes --- src/platforms/rcore_desktop_glfw.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index e42125630..dddf586fb 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1024,8 +1024,23 @@ Vector2 GetWindowPosition(void) // Get window scale DPI factor for current monitor Vector2 GetWindowScaleDPI(void) { - Vector2 scale = {0}; - glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y); + Vector2 scale = {1.0, 1.0}; + + // On platforms, like Wayland, the window and its frameBuffer are automatically rescaled + // according to the current DPI scale of the display on which the window is visible, + // `glfwGetWindowContentScale()` will always return `{1.0, 1.0}`, because there is no need + // for the applciation to apply any DPI rescaling by itself. + // So, to keep consistency among all supported platforms, if `FLAG_WINDOW_HIGHDPI` is enabled + // we ignore the value returned by `glfwGetWindowContentScale()` and return `{1.0, 1.0}` instead. + // Same if we are in an hardware/exclusive fullscreen mode. + + if (!IsWindowState(FLAG_WINDOW_HIGHDPI) && !CORE.Window.fullscreen) + { + // We only need to know the DPI scale of the display if we want to rescale our UI and texts manually by code. + + glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y); + } + return scale; }