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

41c151
From 0cc90f343f4caadb5c4279623a0811c378715a09 Mon Sep 17 00:00:00 2001
41c151
From: rpm-build <rpm-build>
41c151
Date: Tue, 11 Sep 2018 10:19:44 -0400
41c151
Subject: [PATCH] monitor-manager: only reuse initial-config if monitor
41c151
 topology matches startup
41c151
41c151
Right now we try to apply the current monitor config when a new
41c151
monitor is attached.  The current config obviously doesn't include the
41c151
new monitor, so the new monitor isn't lit up.
41c151
41c151
The only reason we apply the current config at all is to handle the
41c151
startup case:  We want to reuse the config set in Xorg when first
41c151
logging in.
41c151
41c151
This commit changes the code to look at the *initial config* instead
41c151
of the current config, and only if the new monitor topology matches
41c151
the start up topology.
41c151
---
41c151
 src/backends/meta-monitor-config-manager.c | 20 +++++++++++++++-----
41c151
 src/backends/meta-monitor-config-manager.h |  2 +-
41c151
 src/backends/meta-monitor-manager.c        | 16 +++++++++++++++-
41c151
 3 files changed, 31 insertions(+), 7 deletions(-)
41c151
41c151
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
41c151
index 585ee7034..1ad342a44 100644
41c151
--- a/src/backends/meta-monitor-config-manager.c
41c151
+++ b/src/backends/meta-monitor-config-manager.c
41c151
@@ -13,60 +13,61 @@
41c151
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
41c151
  * General Public License for more details.
41c151
  *
41c151
  * You should have received a copy of the GNU General Public License
41c151
  * along with this program; if not, write to the Free Software
41c151
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41c151
  * 02111-1307, USA.
41c151
  */
41c151
 
41c151
 #include "config.h"
41c151
 
41c151
 #include "backends/meta-monitor-config-manager.h"
41c151
 
41c151
 #include "backends/meta-monitor-config-migration.h"
41c151
 #include "backends/meta-monitor-config-store.h"
41c151
 #include "backends/meta-monitor-manager-private.h"
41c151
 #include "backends/meta-output.h"
41c151
 #include "core/boxes-private.h"
41c151
 
41c151
 #define CONFIG_HISTORY_MAX_SIZE 3
41c151
 
41c151
 struct _MetaMonitorConfigManager
41c151
 {
41c151
   GObject parent;
41c151
 
41c151
   MetaMonitorManager *monitor_manager;
41c151
 
41c151
   MetaMonitorConfigStore *config_store;
41c151
 
41c151
   MetaMonitorsConfig *current_config;
41c151
+  MetaMonitorsConfig *initial_config;
41c151
   GQueue config_history;
41c151
 };
41c151
 
41c151
 G_DEFINE_TYPE (MetaMonitorConfigManager, meta_monitor_config_manager,
41c151
                G_TYPE_OBJECT)
41c151
 
41c151
 G_DEFINE_TYPE (MetaMonitorsConfig, meta_monitors_config,
41c151
                G_TYPE_OBJECT)
41c151
 
41c151
 static void
41c151
 meta_crtc_info_free (MetaCrtcInfo *info);
41c151
 
41c151
 static void
41c151
 meta_output_info_free (MetaOutputInfo *info);
41c151
 
41c151
 MetaMonitorConfigManager *
41c151
 meta_monitor_config_manager_new (MetaMonitorManager *monitor_manager)
41c151
 {
41c151
   MetaMonitorConfigManager *config_manager;
41c151
 
41c151
   config_manager = g_object_new (META_TYPE_MONITOR_CONFIG_MANAGER, NULL);
41c151
   config_manager->monitor_manager = monitor_manager;
41c151
   config_manager->config_store =
41c151
     meta_monitor_config_store_new (monitor_manager);
41c151
 
41c151
   return config_manager;
41c151
 }
41c151
 
41c151
 MetaMonitorConfigStore *
41c151
 meta_monitor_config_manager_get_store (MetaMonitorConfigManager *config_manager)
41c151
@@ -552,115 +553,123 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
41c151
       .width = width,
41c151
       .height = height
41c151
     },
41c151
     .scale = scale,
41c151
     .monitor_configs = g_list_append (NULL, monitor_config)
41c151
   };
41c151
 
41c151
   return logical_monitor_config;
41c151
 }
41c151
 
41c151
 static MetaLogicalMonitorConfig *
41c151
 create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
41c151
                                            MetaMonitor                  *monitor,
41c151
                                            MetaLogicalMonitorConfig     *primary_logical_monitor_config,
41c151
                                            MetaLogicalMonitorLayoutMode  layout_mode)
41c151
 {
41c151
     MetaOutput *output;
41c151
     MetaCrtc *crtc;
41c151
 
41c151
     output = meta_monitor_get_main_output (monitor);
41c151
     crtc = meta_output_get_assigned_crtc (output);
41c151
     return create_preferred_logical_monitor_config (monitor_manager,
41c151
                                                     monitor,
41c151
                                                     crtc->rect.x,
41c151
                                                     crtc->rect.y,
41c151
                                                     primary_logical_monitor_config,
41c151
                                                     layout_mode);
41c151
 }
41c151
 
41c151
 MetaMonitorsConfig *
41c151
-meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager)
41c151
+meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
41c151
 {
41c151
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
41c151
+  MetaMonitorsConfig *initial_config;
41c151
   GList *logical_monitor_configs;
41c151
   MetaMonitor *primary_monitor;
41c151
   MetaLogicalMonitorLayoutMode layout_mode;
41c151
   MetaLogicalMonitorConfig *primary_logical_monitor_config;
41c151
   GList *monitors;
41c151
   GList *l;
41c151
 
41c151
+  if (config_manager->initial_config != NULL)
41c151
+    return g_object_ref (config_manager->initial_config);
41c151
+
41c151
   if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
41c151
     return NULL;
41c151
 
41c151
   primary_monitor = find_primary_monitor (monitor_manager);
41c151
   if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
41c151
     return NULL;
41c151
 
41c151
   layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
41c151
 
41c151
   primary_logical_monitor_config =
41c151
     create_logical_monitor_config_from_output (monitor_manager,
41c151
                                                primary_monitor,
41c151
                                                NULL,
41c151
                                                layout_mode);
41c151
 
41c151
   primary_logical_monitor_config->is_primary = TRUE;
41c151
   logical_monitor_configs = g_list_append (NULL,
41c151
                                            primary_logical_monitor_config);
41c151
 
41c151
   monitors = meta_monitor_manager_get_monitors (monitor_manager);
41c151
   for (l = monitors; l; l = l->next)
41c151
     {
41c151
       MetaMonitor *monitor = l->data;
41c151
       MetaLogicalMonitorConfig *logical_monitor_config;
41c151
 
41c151
       if (monitor == primary_monitor)
41c151
         continue;
41c151
 
41c151
       if (!meta_monitor_is_active (monitor))
41c151
         continue;
41c151
 
41c151
       logical_monitor_config =
41c151
         create_logical_monitor_config_from_output (monitor_manager,
41c151
                                                    monitor,
41c151
                                                    primary_logical_monitor_config,
41c151
                                                    layout_mode);
41c151
 
41c151
       logical_monitor_configs = g_list_append (logical_monitor_configs,
41c151
                                                logical_monitor_config);
41c151
     }
41c151
 
41c151
-  return meta_monitors_config_new (monitor_manager,
41c151
-                                   logical_monitor_configs,
41c151
-                                   layout_mode,
41c151
-                                   META_MONITORS_CONFIG_FLAG_NONE);
41c151
+  initial_config = meta_monitors_config_new (monitor_manager,
41c151
+                                             logical_monitor_configs,
41c151
+                                             layout_mode,
41c151
+                                             META_MONITORS_CONFIG_FLAG_NONE);
41c151
+
41c151
+  config_manager->initial_config = g_object_ref (initial_config);
41c151
+
41c151
+  return initial_config;
41c151
 }
41c151
 
41c151
 MetaMonitorsConfig *
41c151
 meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager)
41c151
 {
41c151
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
41c151
   GList *logical_monitor_configs;
41c151
   MetaMonitor *primary_monitor;
41c151
   MetaLogicalMonitorLayoutMode layout_mode;
41c151
   MetaLogicalMonitorConfig *primary_logical_monitor_config;
41c151
   int x;
41c151
   GList *monitors;
41c151
   GList *l;
41c151
 
41c151
   primary_monitor = find_primary_monitor (monitor_manager);
41c151
   if (!primary_monitor)
41c151
     return NULL;
41c151
 
41c151
   layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
41c151
 
41c151
   primary_logical_monitor_config =
41c151
     create_preferred_logical_monitor_config (monitor_manager,
41c151
                                              primary_monitor,
41c151
                                              0, 0,
41c151
                                              NULL,
41c151
                                              layout_mode);
41c151
   primary_logical_monitor_config->is_primary = TRUE;
41c151
   logical_monitor_configs = g_list_append (NULL,
41c151
                                            primary_logical_monitor_config);
41c151
 
41c151
@@ -1135,60 +1144,61 @@ meta_monitor_config_manager_get_current (MetaMonitorConfigManager *config_manage
41c151
 {
41c151
   return config_manager->current_config;
41c151
 }
41c151
 
41c151
 MetaMonitorsConfig *
41c151
 meta_monitor_config_manager_pop_previous (MetaMonitorConfigManager *config_manager)
41c151
 {
41c151
   return g_queue_pop_head (&config_manager->config_history);
41c151
 }
41c151
 
41c151
 MetaMonitorsConfig *
41c151
 meta_monitor_config_manager_get_previous (MetaMonitorConfigManager *config_manager)
41c151
 {
41c151
   return g_queue_peek_head (&config_manager->config_history);
41c151
 }
41c151
 
41c151
 void
41c151
 meta_monitor_config_manager_clear_history (MetaMonitorConfigManager *config_manager)
41c151
 {
41c151
   g_queue_foreach (&config_manager->config_history, (GFunc) g_object_unref, NULL);
41c151
   g_queue_clear (&config_manager->config_history);
41c151
 }
41c151
 
41c151
 static void
41c151
 meta_monitor_config_manager_dispose (GObject *object)
41c151
 {
41c151
   MetaMonitorConfigManager *config_manager =
41c151
     META_MONITOR_CONFIG_MANAGER (object);
41c151
 
41c151
   g_clear_object (&config_manager->current_config);
41c151
+  g_clear_object (&config_manager->initial_config);
41c151
   meta_monitor_config_manager_clear_history (config_manager);
41c151
 
41c151
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
41c151
 }
41c151
 
41c151
 static void
41c151
 meta_monitor_config_manager_init (MetaMonitorConfigManager *config_manager)
41c151
 {
41c151
   g_queue_init (&config_manager->config_history);
41c151
 }
41c151
 
41c151
 static void
41c151
 meta_monitor_config_manager_class_init (MetaMonitorConfigManagerClass *klass)
41c151
 {
41c151
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
41c151
 
41c151
   object_class->dispose = meta_monitor_config_manager_dispose;
41c151
 }
41c151
 
41c151
 void
41c151
 meta_monitor_config_free (MetaMonitorConfig *monitor_config)
41c151
 {
41c151
   meta_monitor_spec_free (monitor_config->monitor_spec);
41c151
   g_free (monitor_config->mode_spec);
41c151
   g_free (monitor_config);
41c151
 }
41c151
 
41c151
 void
41c151
 meta_logical_monitor_config_free (MetaLogicalMonitorConfig *logical_monitor_config)
41c151
 {
41c151
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
41c151
index c36df38e6..29ef8f8ce 100644
41c151
--- a/src/backends/meta-monitor-config-manager.h
41c151
+++ b/src/backends/meta-monitor-config-manager.h
41c151
@@ -60,61 +60,61 @@ typedef enum _MetaMonitorsConfigFlag
41c151
 struct _MetaMonitorsConfig
41c151
 {
41c151
   GObject parent;
41c151
 
41c151
   MetaMonitorsConfigKey *key;
41c151
   GList *logical_monitor_configs;
41c151
 
41c151
   GList *disabled_monitor_specs;
41c151
 
41c151
   MetaMonitorsConfigFlag flags;
41c151
 
41c151
   MetaLogicalMonitorLayoutMode layout_mode;
41c151
 };
41c151
 
41c151
 #define META_TYPE_MONITORS_CONFIG (meta_monitors_config_get_type ())
41c151
 G_DECLARE_FINAL_TYPE (MetaMonitorsConfig, meta_monitors_config,
41c151
                       META, MONITORS_CONFIG, GObject)
41c151
 
41c151
 MetaMonitorConfigManager * meta_monitor_config_manager_new (MetaMonitorManager *monitor_manager);
41c151
 
41c151
 MetaMonitorConfigStore * meta_monitor_config_manager_get_store (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 gboolean meta_monitor_config_manager_assign (MetaMonitorManager *manager,
41c151
                                              MetaMonitorsConfig *config,
41c151
                                              GPtrArray         **crtc_infos,
41c151
                                              GPtrArray         **output_infos,
41c151
                                              GError            **error);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
-MetaMonitorsConfig * meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager);
41c151
+MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_create_suggested (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager,
41c151
                                                                          MetaMonitorTransform      transform);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_create_for_switch_config (MetaMonitorConfigManager    *config_manager,
41c151
                                                                            MetaMonitorSwitchConfigType  config_type);
41c151
 
41c151
 void meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_manager,
41c151
                                               MetaMonitorsConfig       *config);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_get_current (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_pop_previous (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitor_config_manager_get_previous (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 void meta_monitor_config_manager_clear_history (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 void meta_monitor_config_manager_save_current (MetaMonitorConfigManager *config_manager);
41c151
 
41c151
 MetaMonitorsConfig * meta_monitors_config_new_full (GList                        *logical_monitor_configs,
41c151
                                                     GList                        *disabled_monitors,
41c151
                                                     MetaLogicalMonitorLayoutMode  layout_mode,
41c151
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
41c151
index 4503eb841..f7ada0136 100644
41c151
--- a/src/backends/meta-monitor-manager.c
41c151
+++ b/src/backends/meta-monitor-manager.c
41c151
@@ -469,73 +469,87 @@ meta_monitor_manager_apply_monitors_config (MetaMonitorManager      *manager,
41c151
 
41c151
   return TRUE;
41c151
 }
41c151
 
41c151
 gboolean
41c151
 meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager)
41c151
 {
41c151
   GList *l;
41c151
 
41c151
   for (l = manager->gpus; l; l = l->next)
41c151
     {
41c151
       MetaGpu *gpu = l->data;
41c151
 
41c151
       if (meta_gpu_has_hotplug_mode_update (gpu))
41c151
         return TRUE;
41c151
     }
41c151
 
41c151
   return FALSE;
41c151
 }
41c151
 
41c151
 static gboolean
41c151
 should_use_stored_config (MetaMonitorManager *manager)
41c151
 {
41c151
   return (manager->in_init ||
41c151
           !meta_monitor_manager_has_hotplug_mode_update (manager));
41c151
 }
41c151
 
41c151
 MetaMonitorsConfig *
41c151
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
41c151
 {
41c151
+  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
41c151
   MetaMonitorsConfig *config = NULL;
41c151
   GError *error = NULL;
41c151
   gboolean use_stored_config;
41c151
+  MetaMonitorsConfigKey *current_state_key;
41c151
   MetaMonitorsConfigMethod method;
41c151
   MetaMonitorsConfigMethod fallback_method =
41c151
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
41c151
 
41c151
   use_stored_config = should_use_stored_config (manager);
41c151
   if (use_stored_config)
41c151
     method = META_MONITORS_CONFIG_METHOD_PERSISTENT;
41c151
   else
41c151
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
41c151
 
41c151
+  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
41c151
+
41c151
+  if (initial_config)
41c151
+    {
41c151
+      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
41c151
+
41c151
+      /* don't ever reuse initial configuration, if the monitor topology changed
41c151
+       */
41c151
+      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
41c151
+        g_clear_object (&initial_config);
41c151
+    }
41c151
+
41c151
   if (use_stored_config)
41c151
     {
41c151
       config = meta_monitor_config_manager_get_stored (manager->config_manager);
41c151
       if (config)
41c151
         {
41c151
           if (!meta_monitor_manager_apply_monitors_config (manager,
41c151
                                                            config,
41c151
                                                            method,
41c151
                                                            &error))
41c151
             {
41c151
               config = NULL;
41c151
               g_warning ("Failed to use stored monitor configuration: %s",
41c151
                          error->message);
41c151
               g_clear_error (&error);
41c151
             }
41c151
           else
41c151
             {
41c151
               g_object_ref (config);
41c151
               goto done;
41c151
             }
41c151
         }
41c151
     }
41c151
 
41c151
   config = meta_monitor_config_manager_create_suggested (manager->config_manager);
41c151
   if (config)
41c151
     {
41c151
       if (!meta_monitor_manager_apply_monitors_config (manager,
41c151
                                                        config,
41c151
                                                        method,
41c151
                                                        &error))
41c151
@@ -549,61 +563,61 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
41c151
         {
41c151
           goto done;
41c151
         }
41c151
     }
41c151
 
41c151
   config = meta_monitor_config_manager_get_previous (manager->config_manager);
41c151
   if (config)
41c151
     {
41c151
       config = g_object_ref (config);
41c151
 
41c151
       if (meta_monitor_manager_is_config_complete (manager, config))
41c151
         {
41c151
           if (!meta_monitor_manager_apply_monitors_config (manager,
41c151
                                                            config,
41c151
                                                            method,
41c151
                                                            &error))
41c151
             {
41c151
               g_warning ("Failed to use suggested monitor configuration: %s",
41c151
                          error->message);
41c151
               g_clear_error (&error);
41c151
             }
41c151
           else
41c151
             {
41c151
               goto done;
41c151
             }
41c151
         }
41c151
 
41c151
       g_clear_object (&config);
41c151
     }
41c151
 
41c151
-  config = meta_monitor_config_manager_create_current (manager->config_manager);
41c151
+  config = g_steal_pointer (&initial_config);
41c151
   if (config)
41c151
     {
41c151
       if (!meta_monitor_manager_apply_monitors_config (manager,
41c151
                                                        config,
41c151
                                                        method,
41c151
                                                        &error))
41c151
         {
41c151
           g_clear_object (&config);
41c151
           g_warning ("Failed to use current monitor configuration: %s",
41c151
                      error->message);
41c151
           g_clear_error (&error);
41c151
         }
41c151
       else
41c151
         {
41c151
           goto done;
41c151
         }
41c151
     }
41c151
 
41c151
   config = meta_monitor_config_manager_create_linear (manager->config_manager);
41c151
   if (config)
41c151
     {
41c151
       if (!meta_monitor_manager_apply_monitors_config (manager,
41c151
                                                        config,
41c151
                                                        method,
41c151
                                                        &error))
41c151
         {
41c151
           g_clear_object (&config);
41c151
           g_warning ("Failed to use linear monitor configuration: %s",
41c151
                      error->message);
41c151
           g_clear_error (&error);
41c151
-- 
41c151
2.17.1
41c151