[gnome-flashback] monitor-manager: only derive global scales supported by all monitors



commit 10cf38b31b02667b8a88b3b51c4fd242eb7bb67a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Sep 12 23:10:04 2021 +0300

    monitor-manager: only derive global scales supported by all monitors
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/4ca5a97ea80a

 backends/gf-monitor-manager.c | 65 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 54 insertions(+), 11 deletions(-)
---
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 0bf9593..dee146f 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -208,12 +208,6 @@ find_monitor (GfMonitorManager *monitor_manager,
   return NULL;
 }
 
-static GfMonitor *
-get_active_monitor (GfMonitorManager *manager)
-{
-  return find_monitor (manager, gf_monitor_is_active);
-}
-
 static gboolean
 is_global_scale_matching_in_config (GfMonitorsConfig *config,
                                     float             scale)
@@ -385,20 +379,69 @@ calculate_monitor_scale (GfMonitorManager *manager,
                                                           monitor_mode);
 }
 
+static gboolean
+is_scale_supported_by_other_monitors (GfMonitorManager *manager,
+                                      GfMonitor        *not_this_one,
+                                      float             scale)
+{
+  GList *l;
+
+  for (l = manager->monitors; l; l = l->next)
+    {
+      GfMonitor *monitor = l->data;
+      GfMonitorMode *mode;
+
+      if (monitor == not_this_one || !gf_monitor_is_active (monitor))
+        continue;
+
+      mode = gf_monitor_get_current_mode (monitor);
+      if (!gf_monitor_manager_is_scale_supported (manager,
+                                                  manager->layout_mode,
+                                                  monitor,
+                                                  mode,
+                                                  scale))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 static gfloat
 derive_calculated_global_scale (GfMonitorManager *manager)
 {
   GfMonitor *monitor;
+  float scale;
+  GList *l;
 
   monitor = gf_monitor_manager_get_primary_monitor (manager);
+  scale = 1.0f;
 
-  if (!monitor || !gf_monitor_is_active (monitor))
-    monitor = get_active_monitor (manager);
+  if (monitor != NULL && gf_monitor_is_active (monitor))
+    {
+      scale = calculate_monitor_scale (manager, monitor);
+      if (is_scale_supported_by_other_monitors (manager, monitor, scale))
+        return scale;
+    }
 
-  if (!monitor)
-    return 1.0;
+  for (l = manager->monitors; l; l = l->next)
+    {
+      GfMonitor *other_monitor;
+      float monitor_scale;
+
+      other_monitor = l->data;
+
+      if (other_monitor == monitor || !gf_monitor_is_active (other_monitor))
+        continue;
+
+      monitor_scale = calculate_monitor_scale (manager, other_monitor);
+
+      if (is_scale_supported_by_other_monitors (manager,
+                                                other_monitor,
+                                                monitor_scale))
+        scale = MAX (scale, monitor_scale);
+    }
 
-  return calculate_monitor_scale (manager, monitor);
+  return scale;
 }
 
 static GfLogicalMonitor *


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