window/wayland: Always update the monitor when updating

If the window didn't have a size, it would still have a monitor, and
when we are asked to update, we must update, as the old monitor might
not be kept around, leaving us vulnerable to use after free.

Avoid not updating the monitor by using the stored IDs (preferred, or
previous) to find suitable logical monitors, with the primary monitor
being the last fallback unless we're completely headless.

This fixes the assert

  !window->monitor ||
  g_list_find (meta_monitor_manager_get_logical_monitors (monitor_manager),
               window->monitor)

in meta_window_update_for_monitors_changed() being hit when a Wayland
window has been created, but not mapped, when a hotplug happens.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2554>
This commit is contained in:
Jonas Ådahl 2022-08-03 23:01:00 +02:00 committed by Marge Bot
parent 4ed9653757
commit 5f96194e9e

View File

@ -490,7 +490,10 @@ meta_window_wayland_update_main_monitor (MetaWindow *window,
}
if (window->rect.width == 0 || window->rect.height == 0)
{
window->monitor = meta_window_find_monitor_from_id (window);
return;
}
/* Require both the current and the new monitor would be the new main monitor,
* even given the resulting scale the window would end up having. This is