Blame SOURCES/inherit-xrandr-metamodes.patch

657d8e
From 2fd3910c29d2af2a7c64b82f075cd3647d7e4bee Mon Sep 17 00:00:00 2001
657d8e
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
657d8e
Date: Mon, 18 Mar 2019 17:08:11 +0100
657d8e
Subject: [PATCH 1/2] monitor-config-manager: Use current mode when deriving
657d8e
 current config
657d8e
657d8e
Instead of overriding the existing mode with the preferred mode of the monitor,
657d8e
use the one already configured. Also use the MetaMonitor API for deriving the
657d8e
position of the monitor in the screen coordinate space.
657d8e
---
657d8e
 src/backends/meta-monitor-config-manager.c | 77 +++++++++++++---------
657d8e
 1 file changed, 47 insertions(+), 30 deletions(-)
657d8e
657d8e
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
657d8e
index c09edbe00..a3387aa0f 100644
657d8e
--- a/src/backends/meta-monitor-config-manager.c
657d8e
+++ b/src/backends/meta-monitor-config-manager.c
657d8e
@@ -592,20 +592,19 @@ create_monitor_config (MetaMonitor     *monitor,
657d8e
 }
657d8e
 
657d8e
 static MetaLogicalMonitorConfig *
657d8e
-create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_manager,
657d8e
-                                         MetaMonitor                 *monitor,
657d8e
-                                         int                          x,
657d8e
-                                         int                          y,
657d8e
-                                         MetaLogicalMonitorConfig    *primary_logical_monitor_config,
657d8e
-                                         MetaLogicalMonitorLayoutMode layout_mode)
657d8e
+create_logical_monitor_config (MetaMonitorManager           *monitor_manager,
657d8e
+                               MetaMonitor                  *monitor,
657d8e
+                               MetaMonitorMode              *mode,
657d8e
+                               int                           x,
657d8e
+                               int                           y,
657d8e
+                               MetaLogicalMonitorConfig     *primary_logical_monitor_config,
657d8e
+                               MetaLogicalMonitorLayoutMode  layout_mode)
657d8e
 {
657d8e
-  MetaMonitorMode *mode;
657d8e
   int width, height;
657d8e
   float scale;
657d8e
   MetaMonitorConfig *monitor_config;
657d8e
   MetaLogicalMonitorConfig *logical_monitor_config;
657d8e
 
657d8e
-  mode = meta_monitor_get_preferred_mode (monitor);
657d8e
   meta_monitor_mode_get_resolution (mode, &width, &height);
657d8e
 
657d8e
   if ((meta_monitor_manager_get_capabilities (monitor_manager) &
657d8e
@@ -645,22 +644,40 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
657d8e
 }
657d8e
 
657d8e
 static MetaLogicalMonitorConfig *
657d8e
-create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
657d8e
-                                           MetaMonitor                  *monitor,
657d8e
-                                           MetaLogicalMonitorConfig     *primary_logical_monitor_config,
657d8e
-                                           MetaLogicalMonitorLayoutMode  layout_mode)
657d8e
+create_preferred_logical_monitor_config (MetaMonitorManager           *monitor_manager,
657d8e
+                                         MetaMonitor                  *monitor,
657d8e
+                                         int                           x,
657d8e
+                                         int                           y,
657d8e
+                                         MetaLogicalMonitorConfig     *primary_logical_monitor_config,
657d8e
+                                         MetaLogicalMonitorLayoutMode  layout_mode)
657d8e
 {
657d8e
-    MetaOutput *output;
657d8e
-    MetaCrtc *crtc;
657d8e
+  return create_logical_monitor_config (monitor_manager,
657d8e
+                                        monitor,
657d8e
+                                        meta_monitor_get_preferred_mode (monitor),
657d8e
+                                        x, y,
657d8e
+                                        primary_logical_monitor_config,
657d8e
+                                        layout_mode);
657d8e
+}
657d8e
 
657d8e
-    output = meta_monitor_get_main_output (monitor);
657d8e
-    crtc = meta_output_get_assigned_crtc (output);
657d8e
-    return create_preferred_logical_monitor_config (monitor_manager,
657d8e
-                                                    monitor,
657d8e
-                                                    crtc->rect.x,
657d8e
-                                                    crtc->rect.y,
657d8e
-                                                    primary_logical_monitor_config,
657d8e
-                                                    layout_mode);
657d8e
+static MetaLogicalMonitorConfig *
657d8e
+create_logical_monitor_config_from_monitor (MetaMonitorManager           *monitor_manager,
657d8e
+                                            MetaMonitor                  *monitor,
657d8e
+                                            MetaLogicalMonitorConfig     *primary_logical_monitor_config,
657d8e
+                                            MetaLogicalMonitorLayoutMode  layout_mode)
657d8e
+{
657d8e
+  MetaRectangle monitor_layout;
657d8e
+  MetaMonitorMode *mode;
657d8e
+
657d8e
+  meta_monitor_derive_layout (monitor, &monitor_layout);
657d8e
+  mode = meta_monitor_get_current_mode (monitor);
657d8e
+
657d8e
+  return create_logical_monitor_config (monitor_manager,
657d8e
+                                        monitor,
657d8e
+                                        mode,
657d8e
+                                        monitor_layout.x,
657d8e
+                                        monitor_layout.y,
657d8e
+                                        primary_logical_monitor_config,
657d8e
+                                        layout_mode);
657d8e
 }
657d8e
 
657d8e
 MetaMonitorsConfig *
657d8e
@@ -688,10 +705,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
657d8e
   layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
657d8e
 
657d8e
   primary_logical_monitor_config =
657d8e
-    create_logical_monitor_config_from_output (monitor_manager,
657d8e
-                                               primary_monitor,
657d8e
-                                               NULL,
657d8e
-                                               layout_mode);
657d8e
+    create_logical_monitor_config_from_monitor (monitor_manager,
657d8e
+                                                primary_monitor,
657d8e
+                                                NULL,
657d8e
+                                                layout_mode);
657d8e
 
657d8e
   primary_logical_monitor_config->is_primary = TRUE;
657d8e
   logical_monitor_configs = g_list_append (NULL,
657d8e
@@ -710,10 +727,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
657d8e
         continue;
657d8e
 
657d8e
       logical_monitor_config =
657d8e
-        create_logical_monitor_config_from_output (monitor_manager,
657d8e
-                                                   monitor,
657d8e
-                                                   primary_logical_monitor_config,
657d8e
-                                                   layout_mode);
657d8e
+        create_logical_monitor_config_from_monitor (monitor_manager,
657d8e
+                                                    monitor,
657d8e
+                                                    primary_logical_monitor_config,
657d8e
+                                                    layout_mode);
657d8e
 
657d8e
       logical_monitor_configs = g_list_append (logical_monitor_configs,
657d8e
                                                logical_monitor_config);
657d8e
-- 
657d8e
2.21.0
657d8e
657d8e
657d8e
From d8c34e4cd7e500567e72e0f219295d7c2162dcf3 Mon Sep 17 00:00:00 2001
657d8e
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
657d8e
Date: Mon, 18 Mar 2019 17:10:37 +0100
657d8e
Subject: [PATCH 2/2] monitor-manager: Don't try to derive current config on
657d8e
 non-X11
657d8e
657d8e
This commit also reworks the initial config state reading some. Appart from
657d8e
avoiding trying to inherit from backends where it doesn't make sense, it does
657d8e
the following changes:
657d8e
657d8e
 * Replace the name "initial" with "inherited", as the initial config in the
657d8e
   context of monitor management is the one used initialization. E.g. if there is
657d8e
   a applicable configuration in monitors.xml, the initial config is taken from
657d8e
   there.
657d8e
657d8e
 * Don't make "_create_()" functions have side effects. Previously
657d8e
   meta_monitor_config_manager_create_initial() also set state on the config
657d8e
   manager object. Instead, add a meta_monitor_config_manager_ensure_inherited()
657d8e
   and meta_monitor_manager_get_inherited_config() function to make things more
657d8e
   explicit.
657d8e
657d8e
 * Don't recreate "is-applicable" logic, just use the existing helper.
657d8e
---
657d8e
 src/backends/meta-monitor-config-manager.c    | 39 +++++++++++--------
657d8e
 src/backends/meta-monitor-config-manager.h    |  5 +++
657d8e
 src/backends/meta-monitor-manager-private.h   |  4 +-
657d8e
 src/backends/meta-monitor-manager.c           | 32 ++++++++-------
657d8e
 .../x11/meta-monitor-manager-xrandr.c         |  3 +-
657d8e
 5 files changed, 49 insertions(+), 34 deletions(-)
657d8e
657d8e
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
657d8e
index a3387aa0f..bc1a39db8 100644
657d8e
--- a/src/backends/meta-monitor-config-manager.c
657d8e
+++ b/src/backends/meta-monitor-config-manager.c
657d8e
@@ -42,7 +42,7 @@ struct _MetaMonitorConfigManager
657d8e
   MetaMonitorConfigStore *config_store;
657d8e
 
657d8e
   MetaMonitorsConfig *current_config;
657d8e
-  MetaMonitorsConfig *initial_config;
657d8e
+  MetaMonitorsConfig *inherited_config;
657d8e
   GQueue config_history;
657d8e
 };
657d8e
 
657d8e
@@ -680,11 +680,10 @@ create_logical_monitor_config_from_monitor (MetaMonitorManager           *monito
657d8e
                                         layout_mode);
657d8e
 }
657d8e
 
657d8e
-MetaMonitorsConfig *
657d8e
-meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
657d8e
+static MetaMonitorsConfig *
657d8e
+meta_monitor_config_manager_derive_current (MetaMonitorConfigManager *config_manager)
657d8e
 {
657d8e
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
657d8e
-  MetaMonitorsConfig *initial_config;
657d8e
   GList *logical_monitor_configs;
657d8e
   MetaMonitor *primary_monitor;
657d8e
   MetaLogicalMonitorLayoutMode layout_mode;
657d8e
@@ -692,12 +691,6 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
657d8e
   GList *monitors;
657d8e
   GList *l;
657d8e
 
657d8e
-  if (config_manager->initial_config != NULL)
657d8e
-    return g_object_ref (config_manager->initial_config);
657d8e
-
657d8e
-  if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
657d8e
-    return NULL;
657d8e
-
657d8e
   primary_monitor = find_primary_monitor (monitor_manager);
657d8e
   if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
657d8e
     return NULL;
657d8e
@@ -736,14 +729,26 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
657d8e
                                                logical_monitor_config);
657d8e
     }
657d8e
 
657d8e
-  initial_config = meta_monitors_config_new (monitor_manager,
657d8e
-                                             logical_monitor_configs,
657d8e
-                                             layout_mode,
657d8e
-                                             META_MONITORS_CONFIG_FLAG_NONE);
657d8e
+  return meta_monitors_config_new (monitor_manager,
657d8e
+                                   logical_monitor_configs,
657d8e
+                                   layout_mode,
657d8e
+                                   META_MONITORS_CONFIG_FLAG_NONE);
657d8e
+}
657d8e
+
657d8e
+void
657d8e
+meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager)
657d8e
+{
657d8e
+  if (config_manager->inherited_config)
657d8e
+    return;
657d8e
 
657d8e
-  config_manager->initial_config = g_object_ref (initial_config);
657d8e
+  config_manager->inherited_config =
657d8e
+    meta_monitor_config_manager_derive_current (config_manager);
657d8e
+}
657d8e
 
657d8e
-  return initial_config;
657d8e
+MetaMonitorsConfig *
657d8e
+meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager)
657d8e
+{
657d8e
+  return config_manager->inherited_config;
657d8e
 }
657d8e
 
657d8e
 MetaMonitorsConfig *
657d8e
@@ -1282,7 +1287,7 @@ meta_monitor_config_manager_dispose (GObject *object)
657d8e
     META_MONITOR_CONFIG_MANAGER (object);
657d8e
 
657d8e
   g_clear_object (&config_manager->current_config);
657d8e
-  g_clear_object (&config_manager->initial_config);
657d8e
+  g_clear_object (&config_manager->inherited_config);
657d8e
   meta_monitor_config_manager_clear_history (config_manager);
657d8e
 
657d8e
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
657d8e
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
657d8e
index 409611bb0..bb847b96e 100644
657d8e
--- a/src/backends/meta-monitor-config-manager.h
657d8e
+++ b/src/backends/meta-monitor-config-manager.h
657d8e
@@ -96,6 +96,11 @@ MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigMa
657d8e
 
657d8e
 META_EXPORT_TEST
657d8e
 MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
657d8e
+
657d8e
+void meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager);
657d8e
+
657d8e
+MetaMonitorsConfig * meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager);
657d8e
+
657d8e
 META_EXPORT_TEST
657d8e
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
657d8e
 
657d8e
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
657d8e
index cdb8f4209..223b5dfbd 100644
657d8e
--- a/src/backends/meta-monitor-manager-private.h
657d8e
+++ b/src/backends/meta-monitor-manager-private.h
657d8e
@@ -44,7 +44,8 @@ typedef enum _MetaMonitorManagerCapability
657d8e
   META_MONITOR_MANAGER_CAPABILITY_NONE = 0,
657d8e
   META_MONITOR_MANAGER_CAPABILITY_MIRRORING = (1 << 0),
657d8e
   META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE = (1 << 1),
657d8e
-  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 2)
657d8e
+  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 2),
657d8e
+  META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT = (1 << 3),
657d8e
 } MetaMonitorManagerCapability;
657d8e
 
657d8e
 /* Equivalent to the 'method' enum in org.gnome.Mutter.DisplayConfig */
657d8e
@@ -133,6 +134,7 @@ struct _MetaMonitorManager
657d8e
   int persistent_timeout_id;
657d8e
 
657d8e
   MetaMonitorConfigManager *config_manager;
657d8e
+  MetaMonitorsConfig *initial_config;
657d8e
 
657d8e
   GnomePnpIds *pnp_ids;
657d8e
 
657d8e
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
657d8e
index bb4b44188..076dca8cb 100644
657d8e
--- a/src/backends/meta-monitor-manager.c
657d8e
+++ b/src/backends/meta-monitor-manager.c
657d8e
@@ -531,14 +531,21 @@ should_use_stored_config (MetaMonitorManager *manager)
657d8e
           !meta_monitor_manager_has_hotplug_mode_update (manager));
657d8e
 }
657d8e
 
657d8e
+static gboolean
657d8e
+can_derive_current_config (MetaMonitorManager *manager)
657d8e
+{
657d8e
+  MetaMonitorManagerCapability capabilities;
657d8e
+
657d8e
+  capabilities = meta_monitor_manager_get_capabilities (manager);
657d8e
+  return !!(capabilities & META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
657d8e
+}
657d8e
+
657d8e
 MetaMonitorsConfig *
657d8e
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
657d8e
 {
657d8e
-  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
657d8e
   MetaMonitorsConfig *config = NULL;
657d8e
   GError *error = NULL;
657d8e
   gboolean use_stored_config;
657d8e
-  MetaMonitorsConfigKey *current_state_key;
657d8e
   MetaMonitorsConfigMethod method;
657d8e
   MetaMonitorsConfigMethod fallback_method =
657d8e
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
657d8e
@@ -549,17 +556,8 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
657d8e
   else
657d8e
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
657d8e
 
657d8e
-  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
657d8e
-
657d8e
-  if (initial_config)
657d8e
-    {
657d8e
-      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
657d8e
-
657d8e
-      /* don't ever reuse initial configuration, if the monitor topology changed
657d8e
-       */
657d8e
-      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
657d8e
-        g_clear_object (&initial_config);
657d8e
-    }
657d8e
+  if (can_derive_current_config (manager))
657d8e
+    meta_monitor_config_manager_ensure_inherited_config (manager->config_manager);
657d8e
 
657d8e
   if (use_stored_config)
657d8e
     {
657d8e
@@ -628,9 +626,13 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
657d8e
       g_clear_object (&config);
657d8e
     }
657d8e
 
657d8e
-  config = g_steal_pointer (&initial_config);
657d8e
-  if (config)
657d8e
+  config =
657d8e
+    meta_monitor_config_manager_get_inherited_config (manager->config_manager);
657d8e
+  if (config &&
657d8e
+      meta_monitor_manager_is_config_complete (manager, config))
657d8e
     {
657d8e
+      config = g_object_ref (config);
657d8e
+
657d8e
       if (!meta_monitor_manager_apply_monitors_config (manager,
657d8e
                                                        config,
657d8e
                                                        method,
657d8e
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
657d8e
index d60f00325..b8d6342b6 100644
657d8e
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
657d8e
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
657d8e
@@ -999,7 +999,8 @@ static MetaMonitorManagerCapability
657d8e
 meta_monitor_manager_xrandr_get_capabilities (MetaMonitorManager *manager)
657d8e
 {
657d8e
   return (META_MONITOR_MANAGER_CAPABILITY_MIRRORING |
657d8e
-          META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED);
657d8e
+          META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED |
657d8e
+          META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
657d8e
 }
657d8e
 
657d8e
 static gboolean
657d8e
-- 
657d8e
2.21.0
657d8e