[gnome-flashback] monitor-manager: compare keys when checking whether a config is complete



commit b7afc0ac366d356072eafb5067d5717622f840ca
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Nov 3 16:03:23 2017 +0800

    monitor-manager: compare keys when checking whether a config is complete
    
    We only counted configured monitors and whether the config was
    applicable (could be assigned), howeverwe didn't include disabled
    monitors when comparing. This could caused incorrect configurations to
    be applied when trying to use the previous configuration.
    
    One scenario where this happened was one a system with one laptop
    screen and one external monitor that was hot plugged some point after
    start up. When the laptop lid was closed, the 'previous configuration'
    being the configuration where only the laptop panel was enabled, passed
    'is-complete' check as the number of configured monitors were correct,
    and the configuration was applicable.
    
    Avoid this issue by simply comparing the configuration key of the
    previous configuration and the configuration key of the current state.
    This correctly identifies a laptop panel with the lid closed as
    inaccessible, thus doesn't incorrectly revert to the previous
    configuration.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788915

 backends/gf-monitor-config-manager-private.h |    3 ++
 backends/gf-monitor-config-manager.c         |    6 ++--
 backends/gf-monitor-manager.c                |   34 ++++++-------------------
 3 files changed, 14 insertions(+), 29 deletions(-)
---
diff --git a/backends/gf-monitor-config-manager-private.h b/backends/gf-monitor-config-manager-private.h
index 48e434a..a57cf87 100644
--- a/backends/gf-monitor-config-manager-private.h
+++ b/backends/gf-monitor-config-manager-private.h
@@ -25,6 +25,7 @@
 #include "gf-logical-monitor-config-private.h"
 #include "gf-monitor-config-private.h"
 #include "gf-monitor-manager-private.h"
+#include "gf-monitors-config-private.h"
 
 G_BEGIN_DECLS
 
@@ -71,6 +72,8 @@ void                    gf_monitor_config_manager_clear_history             (GfM
 
 void                    gf_monitor_config_manager_save_current              (GfMonitorConfigManager      
*config_manager);
 
+GfMonitorsConfigKey    *gf_create_monitors_config_key_for_current_state     (GfMonitorManager            
*monitor_manager);
+
 G_END_DECLS
 
 #endif
diff --git a/backends/gf-monitor-config-manager.c b/backends/gf-monitor-config-manager.c
index 7b0ff4e..11aa638 100644
--- a/backends/gf-monitor-config-manager.c
+++ b/backends/gf-monitor-config-manager.c
@@ -644,8 +644,8 @@ assign_logical_monitor_crtcs (GfMonitorManager        *manager,
   return TRUE;
 }
 
-static GfMonitorsConfigKey *
-create_key_for_current_state (GfMonitorManager *monitor_manager)
+GfMonitorsConfigKey *
+gf_create_monitors_config_key_for_current_state (GfMonitorManager *monitor_manager)
 {
   GfMonitorsConfigKey *config_key;
   GList *l;
@@ -778,7 +778,7 @@ gf_monitor_config_manager_get_stored (GfMonitorConfigManager *config_manager)
   GfMonitorsConfig *config;
   GError *error = NULL;
 
-  config_key = create_key_for_current_state (monitor_manager);
+  config_key = gf_create_monitors_config_key_for_current_state (monitor_manager);
   if (!config_key)
     return NULL;
 
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index cdc7e05..1b3549f 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -271,35 +271,17 @@ static gboolean
 gf_monitor_manager_is_config_complete (GfMonitorManager *manager,
                                        GfMonitorsConfig *config)
 {
-  GList *l;
-  guint configured_monitor_count = 0;
-  guint expected_monitor_count = 0;
-
-  for (l = config->logical_monitor_configs; l; l = l->next)
-    {
-      GfLogicalMonitorConfig *logical_monitor_config = l->data;
-      GList *k;
+  GfMonitorsConfigKey *current_state_key;
+  gboolean is_config_complete;
 
-      for (k = logical_monitor_config->monitor_configs; k; k = k->next)
-        configured_monitor_count++;
-    }
-
-  for (l = manager->monitors; l; l = l->next)
-    {
-      GfMonitor *monitor = l->data;
+  current_state_key = gf_create_monitors_config_key_for_current_state (manager);
+  if (!current_state_key)
+    return FALSE;
 
-      if (gf_monitor_is_laptop_panel (monitor))
-        {
-          if (!gf_monitor_manager_is_lid_closed (manager))
-            expected_monitor_count++;
-        }
-      else
-        {
-          expected_monitor_count++;
-        }
-    }
+  is_config_complete = gf_monitors_config_key_equal (current_state_key, config->key);
+  gf_monitors_config_key_free (current_state_key);
 
-  if (configured_monitor_count != expected_monitor_count)
+  if (!is_config_complete)
     return FALSE;
 
   return gf_monitor_manager_is_config_applicable (manager, config, NULL);


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