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

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