[mutter/gnome-3-28] monitor-manager: use MonitorsConfig to track switch_config



commit b7bc8e56b7f6d5919f8ac5ae31c288d98ad91573
Author: Daniel Drake <drake endlessm com>
Date:   Thu Aug 30 00:34:53 2018 +0000

    monitor-manager: use MonitorsConfig to track switch_config
    
    When constructing MetaMonitorsConfig objects, store which type
    of switch_config they are for (or UNKNOWN if it is not such
    type of config).
    
    Stop unconditionally setting current_switch_config to UNKNOWN when
    handling monitors changed events. Instead, set it to the switch_config
    type stored in the MonitorsConfig in the codepath that updates logical
    state. In addition to being called in the hotplug case along the same
    code flow that generates monitors changed events, this is also called
    in the coldplug case where a secondary monitor was connected before
    mutter was started.
    
    When creating the default linear display config, create it as a
    switch_config so that internal state gets updated to represent
    linear mode when this config is used.
    
    The previous behaviour of unconditionally resetting current_switch_config
    to UNKNOWN was breaking the internal state machine for display config
    switching, causing misbehaviour in gnome-shell's switchMonitor UI when
    using display switch hotkeys. The lack of internal tracking when the
    displays are already in the default "Join Displays" linear mode was
    then causing the first display switch hotkey press to do nothing
    (it would attempt to select "Join Displays" mode, but that was already
    active).
    
    Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/281
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/213
    
    
    (cherry picked from commit 6267732bec97773883ad76f99af76057a7957283)

 src/backends/meta-monitor-config-manager.c | 36 +++++++++++++++++++++++++-----
 src/backends/meta-monitor-config-manager.h |  7 ++++++
 src/backends/meta-monitor-manager.c        | 25 ++++++++++++++++-----
 3 files changed, 56 insertions(+), 12 deletions(-)
---
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
index 197892bf2..28818ed6b 100644
--- a/src/backends/meta-monitor-config-manager.c
+++ b/src/backends/meta-monitor-config-manager.c
@@ -1007,6 +1007,7 @@ meta_monitor_config_manager_create_for_switch_config (MetaMonitorConfigManager
                                                       MetaMonitorSwitchConfigType  config_type)
 {
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
+  MetaMonitorsConfig *config;
 
   if (!meta_monitor_manager_can_switch_config (monitor_manager))
     return NULL;
@@ -1014,18 +1015,27 @@ meta_monitor_config_manager_create_for_switch_config (MetaMonitorConfigManager
   switch (config_type)
     {
     case META_MONITOR_SWITCH_CONFIG_ALL_MIRROR:
-      return create_for_switch_config_all_mirror (config_manager);
+      config = create_for_switch_config_all_mirror (config_manager);
+      break;
     case META_MONITOR_SWITCH_CONFIG_ALL_LINEAR:
-      return meta_monitor_config_manager_create_linear (config_manager);
+      config = meta_monitor_config_manager_create_linear (config_manager);
+      break;
     case META_MONITOR_SWITCH_CONFIG_EXTERNAL:
-      return create_for_switch_config_external (config_manager);
+      config = create_for_switch_config_external (config_manager);
+      break;
     case META_MONITOR_SWITCH_CONFIG_BUILTIN:
-      return create_for_switch_config_builtin (config_manager);
+      config = create_for_switch_config_builtin (config_manager);
+      break;
     case META_MONITOR_SWITCH_CONFIG_UNKNOWN:
+    default:
       g_warn_if_reached ();
-      break;
+      return NULL;
     }
-  return NULL;
+
+  if (config)
+    meta_monitors_config_set_switch_config (config, config_type);
+
+  return config;
 }
 
 void
@@ -1217,6 +1227,19 @@ meta_monitors_config_key_equal (gconstpointer data_a,
   return TRUE;
 }
 
+MetaMonitorSwitchConfigType
+meta_monitors_config_get_switch_config (MetaMonitorsConfig *config)
+{
+  return config->switch_config;
+}
+
+void
+meta_monitors_config_set_switch_config (MetaMonitorsConfig          *config,
+                                        MetaMonitorSwitchConfigType  switch_config)
+{
+  config->switch_config = switch_config;
+}
+
 MetaMonitorsConfig *
 meta_monitors_config_new_full (GList                        *logical_monitor_configs,
                                GList                        *disabled_monitor_specs,
@@ -1232,6 +1255,7 @@ meta_monitors_config_new_full (GList                        *logical_monitor_con
                                               disabled_monitor_specs);
   config->layout_mode = layout_mode;
   config->flags = flags;
+  config->switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
 
   return config;
 }
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
index 269d8e1b7..900707446 100644
--- a/src/backends/meta-monitor-config-manager.h
+++ b/src/backends/meta-monitor-config-manager.h
@@ -69,6 +69,8 @@ struct _MetaMonitorsConfig
   MetaMonitorsConfigFlag flags;
 
   MetaLogicalMonitorLayoutMode layout_mode;
+
+  MetaMonitorSwitchConfigType switch_config;
 };
 
 #define META_TYPE_MONITORS_CONFIG (meta_monitors_config_get_type ())
@@ -124,6 +126,11 @@ MetaMonitorsConfig * meta_monitors_config_new (MetaMonitorManager           *mon
                                                MetaLogicalMonitorLayoutMode  layout_mode,
                                                MetaMonitorsConfigFlag        flags);
 
+MetaMonitorSwitchConfigType meta_monitors_config_get_switch_config (MetaMonitorsConfig *config);
+
+void meta_monitors_config_set_switch_config (MetaMonitorsConfig          *config,
+                                             MetaMonitorSwitchConfigType  switch_config);
+
 unsigned int meta_monitors_config_key_hash (gconstpointer config_key);
 
 gboolean meta_monitors_config_key_equal (gconstpointer config_key_a,
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index ec186009b..96d794a25 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -582,7 +582,9 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
       g_clear_object (&config);
     }
 
-  config = meta_monitor_config_manager_create_linear (manager->config_manager);
+  config =
+    meta_monitor_config_manager_create_for_switch_config (manager->config_manager,
+                                                          META_MONITOR_SWITCH_CONFIG_ALL_LINEAR);
   if (config)
     {
       if (!meta_monitor_manager_apply_monitors_config (manager,
@@ -2652,8 +2654,6 @@ meta_monitor_manager_read_current_state (MetaMonitorManager *manager)
 static void
 meta_monitor_manager_notify_monitors_changed (MetaMonitorManager *manager)
 {
-  manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
-
   meta_backend_monitors_changed (manager->backend);
 
   g_signal_emit (manager, signals[MONITORS_CHANGED_INTERNAL], 0);
@@ -2710,10 +2710,17 @@ meta_monitor_manager_update_logical_state (MetaMonitorManager *manager,
                                            MetaMonitorsConfig *config)
 {
   if (config)
-    manager->layout_mode = config->layout_mode;
+    {
+      manager->layout_mode = config->layout_mode;
+      manager->current_switch_config =
+        meta_monitors_config_get_switch_config (config);
+    }
   else
-    manager->layout_mode =
-      meta_monitor_manager_get_default_layout_mode (manager);
+    {
+      manager->layout_mode =
+        meta_monitor_manager_get_default_layout_mode (manager);
+      manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
+    }
 
   meta_monitor_manager_rebuild_logical_monitors (manager, config);
 }
@@ -2755,6 +2762,12 @@ void
 meta_monitor_manager_update_logical_state_derived (MetaMonitorManager *manager,
                                                    MetaMonitorsConfig *config)
 {
+  if (config)
+    manager->current_switch_config =
+      meta_monitors_config_get_switch_config (config);
+  else
+    manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
+
   manager->layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
 
   meta_monitor_manager_rebuild_logical_monitors_derived (manager, config);


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