From 1bb8199342fc40e00145ff06a634c3389f1ba0d6 Mon Sep 17 00:00:00 2001 From: Riteo Date: Sat, 16 Mar 2024 14:48:11 +0100 Subject: Wayland: Workaround API limitation in screen/UI scale logic Mainly, this fixes auto UI scaling with _single-monitor_ fractional setups (see the comment in `display_server_wayland.cpp` for more info). This is the result of a bunch of current limitations, mainly the fact that the UI scale is static (it's probed at startup) and the fact that Wayland exposes fractional scales only at the window-level, by design. The `screen_get_scale` special case should help in 99% of cases, while the auto UI scale part will unfortunately only help with single-screen situations, as multi-screen fractional scaling requires dynamic UI scale changing. --- platform/linuxbsd/wayland/display_server_wayland.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'platform/linuxbsd/wayland/display_server_wayland.cpp') diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp index 1c3cae0435..f7995472d0 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.cpp +++ b/platform/linuxbsd/wayland/display_server_wayland.cpp @@ -550,7 +550,15 @@ float DisplayServerWayland::screen_get_scale(int p_screen) const { MutexLock mutex_lock(wayland_thread.mutex); if (p_screen == SCREEN_OF_MAIN_WINDOW) { - p_screen = window_get_current_screen(); + // Wayland does not expose fractional scale factors at the screen-level, but + // some code relies on it. Since this special screen is the default and a lot + // of code relies on it, we'll return the window's scale, which is what we + // really care about. After all, we have very little use of the actual screen + // enumeration APIs and we're (for now) in single-window mode anyways. + struct wl_surface *wl_surface = wayland_thread.window_get_wl_surface(MAIN_WINDOW_ID); + WaylandThread::WindowState *ws = wayland_thread.wl_surface_get_window_state(wl_surface); + + return wayland_thread.window_state_get_scale_factor(ws); } return wayland_thread.screen_get_data(p_screen).scale; -- cgit v1.2.3