[mutter/gnome-42] window: Add monitor finder using stored IDs



commit ab1adc28fe11d59dc0c5ad69142ba1c98963286e
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Aug 3 22:59:16 2022 +0200

    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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2554>

 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 fce2a4727e..4f269ff37a 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 70a6bf557a..e7278e48c2 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -3646,6 +3646,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
@@ -3668,17 +3693,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)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]