From 4ed965375758ac48887b887b80128730170c8a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 3 Aug 2022 22:59:16 +0200 Subject: [PATCH] window: Add monitor finder using stored IDs This will be used to find new monitors on e.g. "winsys ID" of previous monitors. Part-of: --- src/core/window-private.h | 2 ++ src/core/window.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/core/window-private.h b/src/core/window-private.h index fce2a4727..4f269ff37 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -851,6 +851,8 @@ void meta_window_activate_full (MetaWindow *window, META_EXPORT_TEST MetaLogicalMonitor * meta_window_find_monitor_from_frame_rect (MetaWindow *window); +MetaLogicalMonitor * meta_window_find_monitor_from_id (MetaWindow *window); + MetaLogicalMonitor * meta_window_get_main_logical_monitor (MetaWindow *window); void meta_window_update_monitor (MetaWindow *window, MetaWindowUpdateMonitorFlags flags); diff --git a/src/core/window.c b/src/core/window.c index 621abd9a5..0a1a97547 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -3647,6 +3647,31 @@ find_monitor_by_winsys_id (MetaWindow *window, return NULL; } +MetaLogicalMonitor * +meta_window_find_monitor_from_id (MetaWindow *window) +{ + MetaContext *context = meta_display_get_context (window->display); + MetaBackend *backend = meta_context_get_backend (context); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaLogicalMonitor *old_monitor = window->monitor; + MetaLogicalMonitor *new_monitor; + + new_monitor = find_monitor_by_winsys_id (window, + window->preferred_output_winsys_id); + + if (old_monitor && !new_monitor) + new_monitor = find_monitor_by_winsys_id (window, old_monitor->winsys_id); + + if (!new_monitor) + { + new_monitor = + meta_monitor_manager_get_primary_logical_monitor (monitor_manager); + } + + return new_monitor; +} + /* This is called when the monitor setup has changed. The window->monitor * reference is still "valid", but refer to the previous monitor setup */ void @@ -3669,17 +3694,7 @@ meta_window_update_for_monitors_changed (MetaWindow *window) } old = window->monitor; - - /* Try the preferred output first */ - new = find_monitor_by_winsys_id (window, window->preferred_output_winsys_id); - - /* Otherwise, try to find the old output on a new monitor */ - if (old && !new) - new = find_monitor_by_winsys_id (window, old->winsys_id); - - /* Fall back to primary if everything else failed */ - if (!new) - new = meta_monitor_manager_get_primary_logical_monitor (monitor_manager); + new = meta_window_find_monitor_from_id (window); if (window->tile_mode != META_TILE_NONE) {