Blame SOURCES/0001-monitor-manager-only-reuse-initial-config-if-monitor.patch

1c7749
From 4ad8fd80355189ecbde6c38961335ae4be4db8b3 Mon Sep 17 00:00:00 2001
1c7749
From: rpm-build <rpm-build>
1c7749
Date: Tue, 11 Sep 2018 10:19:44 -0400
1c7749
Subject: [PATCH] monitor-manager: only reuse initial-config if monitor
1c7749
 topology matches startup
1c7749
1c7749
Right now we try to apply the current monitor config when a new
1c7749
monitor is attached.  The current config obviously doesn't include the
1c7749
new monitor, so the new monitor isn't lit up.
1c7749
1c7749
The only reason we apply the current config at all is to handle the
1c7749
startup case:  We want to reuse the config set in Xorg when first
1c7749
logging in.
1c7749
1c7749
This commit changes the code to look at the *initial config* instead
1c7749
of the current config, and only if the new monitor topology matches
1c7749
the start up topology.
1c7749
---
1c7749
 src/backends/meta-monitor-config-manager.c | 20 +++++++++++++++-----
1c7749
 src/backends/meta-monitor-config-manager.h |  2 +-
1c7749
 src/backends/meta-monitor-manager.c        | 16 +++++++++++++++-
1c7749
 3 files changed, 31 insertions(+), 7 deletions(-)
1c7749
1c7749
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
1c7749
index d64ca1f79..c09edbe00 100644
1c7749
--- a/src/backends/meta-monitor-config-manager.c
1c7749
+++ b/src/backends/meta-monitor-config-manager.c
1c7749
@@ -42,6 +42,7 @@ struct _MetaMonitorConfigManager
1c7749
   MetaMonitorConfigStore *config_store;
1c7749
 
1c7749
   MetaMonitorsConfig *current_config;
1c7749
+  MetaMonitorsConfig *initial_config;
1c7749
   GQueue config_history;
1c7749
 };
1c7749
 
1c7749
@@ -663,9 +664,10 @@ create_logical_monitor_config_from_output (MetaMonitorManager           *monitor
1c7749
 }
1c7749
 
1c7749
 MetaMonitorsConfig *
1c7749
-meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager)
1c7749
+meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
1c7749
 {
1c7749
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
1c7749
+  MetaMonitorsConfig *initial_config;
1c7749
   GList *logical_monitor_configs;
1c7749
   MetaMonitor *primary_monitor;
1c7749
   MetaLogicalMonitorLayoutMode layout_mode;
1c7749
@@ -673,6 +675,9 @@ meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_man
1c7749
   GList *monitors;
1c7749
   GList *l;
1c7749
 
1c7749
+  if (config_manager->initial_config != NULL)
1c7749
+    return g_object_ref (config_manager->initial_config);
1c7749
+
1c7749
   if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
1c7749
     return NULL;
1c7749
 
1c7749
@@ -714,10 +719,14 @@ meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_man
1c7749
                                                logical_monitor_config);
1c7749
     }
1c7749
 
1c7749
-  return meta_monitors_config_new (monitor_manager,
1c7749
-                                   logical_monitor_configs,
1c7749
-                                   layout_mode,
1c7749
-                                   META_MONITORS_CONFIG_FLAG_NONE);
1c7749
+  initial_config = meta_monitors_config_new (monitor_manager,
1c7749
+                                             logical_monitor_configs,
1c7749
+                                             layout_mode,
1c7749
+                                             META_MONITORS_CONFIG_FLAG_NONE);
1c7749
+
1c7749
+  config_manager->initial_config = g_object_ref (initial_config);
1c7749
+
1c7749
+  return initial_config;
1c7749
 }
1c7749
 
1c7749
 MetaMonitorsConfig *
1c7749
@@ -1256,6 +1265,7 @@ meta_monitor_config_manager_dispose (GObject *object)
1c7749
     META_MONITOR_CONFIG_MANAGER (object);
1c7749
 
1c7749
   g_clear_object (&config_manager->current_config);
1c7749
+  g_clear_object (&config_manager->initial_config);
1c7749
   meta_monitor_config_manager_clear_history (config_manager);
1c7749
 
1c7749
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
1c7749
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
1c7749
index 364a2b36b..409611bb0 100644
1c7749
--- a/src/backends/meta-monitor-config-manager.h
1c7749
+++ b/src/backends/meta-monitor-config-manager.h
1c7749
@@ -95,7 +95,7 @@ META_EXPORT_TEST
1c7749
 MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
1c7749
 
1c7749
 META_EXPORT_TEST
1c7749
-MetaMonitorsConfig * meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager);
1c7749
+MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
1c7749
 META_EXPORT_TEST
1c7749
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
1c7749
 
1c7749
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
1c7749
index 05b27c6be..bb4b44188 100644
1c7749
--- a/src/backends/meta-monitor-manager.c
1c7749
+++ b/src/backends/meta-monitor-manager.c
1c7749
@@ -534,9 +534,11 @@ should_use_stored_config (MetaMonitorManager *manager)
1c7749
 MetaMonitorsConfig *
1c7749
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1c7749
 {
1c7749
+  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
1c7749
   MetaMonitorsConfig *config = NULL;
1c7749
   GError *error = NULL;
1c7749
   gboolean use_stored_config;
1c7749
+  MetaMonitorsConfigKey *current_state_key;
1c7749
   MetaMonitorsConfigMethod method;
1c7749
   MetaMonitorsConfigMethod fallback_method =
1c7749
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
1c7749
@@ -547,6 +549,18 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1c7749
   else
1c7749
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
1c7749
 
1c7749
+  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
1c7749
+
1c7749
+  if (initial_config)
1c7749
+    {
1c7749
+      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
1c7749
+
1c7749
+      /* don't ever reuse initial configuration, if the monitor topology changed
1c7749
+       */
1c7749
+      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
1c7749
+        g_clear_object (&initial_config);
1c7749
+    }
1c7749
+
1c7749
   if (use_stored_config)
1c7749
     {
1c7749
       config = meta_monitor_config_manager_get_stored (manager->config_manager);
1c7749
@@ -614,7 +628,7 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1c7749
       g_clear_object (&config);
1c7749
     }
1c7749
 
1c7749
-  config = meta_monitor_config_manager_create_current (manager->config_manager);
1c7749
+  config = g_steal_pointer (&initial_config);
1c7749
   if (config)
1c7749
     {
1c7749
       if (!meta_monitor_manager_apply_monitors_config (manager,
1c7749
-- 
1c7749
2.21.0
1c7749