From bf4aff823f5d172a510346e25e56ea7ea69a7e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Mon, 19 Feb 2024 19:32:24 +0100 Subject: [PATCH] window: Fall back to main window monitor for highest scale monitor MetaWindow always tries to have a main monitor: If the frame rect is empty and the window has not been positioned, in meta_window_constructed() we fall back to asking the backend for the current monitor, and in meta_window_wayland_update_main_monitor() we fall back to meta_window_find_monitor_from_id(), which then falls back to the primary monitor. In general this means that window->monitor is always set as long as there is a monitor around. For getting the highest-scale-monitor the window is on, we currently rely completely on the frame rect. If the frame rect is empty, we set the highest-scale-monitor to NULL. Since we usually know though which monitor the window is, or will be on, and window->monitor is even set to that, we can just fall back to window->monitor for the highest-scale-monitor. This makes sure ::highest-scale-monitor-changed is emitted right after the window is created, and it's set to the correct monitor that the window will be on. This in turn means that we can send a correct wp_fractional_scale fraction_scale event to clients right away. https://gitlab.gnome.org/GNOME/mutter/-/issues/3262 Part-of: --- src/core/window.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/window.c b/src/core/window.c index c86431756..04bba58ec 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -1112,12 +1112,16 @@ meta_window_constructed (GObject *object) window->compositor_private = NULL; if (window->rect.width > 0 && window->rect.height > 0) - window->monitor = meta_window_find_monitor_from_frame_rect (window); + { + window->monitor = meta_window_find_monitor_from_frame_rect (window); + window->highest_scale_monitor = + meta_window_find_highest_scale_monitor_from_frame_rect (window); + } else - window->monitor = meta_backend_get_current_logical_monitor (backend); - - window->highest_scale_monitor = - meta_window_find_highest_scale_monitor_from_frame_rect (window); + { + window->monitor = meta_backend_get_current_logical_monitor (backend); + window->highest_scale_monitor = window->monitor; + } if (window->monitor) window->preferred_output_winsys_id = window->monitor->winsys_id; @@ -3725,8 +3729,11 @@ meta_window_update_monitor (MetaWindow *window, } old_highest_scale = window->highest_scale_monitor; - window->highest_scale_monitor = - meta_window_find_highest_scale_monitor_from_frame_rect (window); + + window->highest_scale_monitor = window->rect.width > 0 && window->rect.height > 0 + ? meta_window_find_highest_scale_monitor_from_frame_rect (window) + : window->monitor; + if (old_highest_scale != window->highest_scale_monitor) g_signal_emit (window, window_signals[HIGHEST_SCALE_MONITOR_CHANGED], 0); }