diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c index 4540aaab3..d96baf7e8 100644 --- a/src/backends/meta-monitor-config-manager.c +++ b/src/backends/meta-monitor-config-manager.c @@ -299,6 +299,58 @@ meta_monitor_config_manager_assign (MetaMonitorManager *manager, return TRUE; } +static MetaMonitorsConfigKey * +create_key_for_current_state (MetaMonitorManager *monitor_manager) +{ + MetaMonitorsConfigKey *config_key; + GList *l; + GList *monitor_specs; + + monitor_specs = NULL; + for (l = monitor_manager->monitors; l; l = l->next) + { + MetaMonitor *monitor = l->data; + MetaMonitorSpec *monitor_spec; + + if (meta_monitor_is_laptop_panel (monitor) && + meta_monitor_manager_is_lid_closed (monitor_manager)) + continue; + + monitor_spec = meta_monitor_spec_clone (meta_monitor_get_spec (monitor)); + monitor_specs = g_list_prepend (monitor_specs, monitor_spec); + } + + if (!monitor_specs) + return NULL; + + monitor_specs = g_list_sort (monitor_specs, + (GCompareFunc) meta_monitor_spec_compare); + + config_key = g_new0 (MetaMonitorsConfigKey, 1); + *config_key = (MetaMonitorsConfigKey) { + .monitor_specs = monitor_specs + }; + + return config_key; +} + +MetaMonitorsConfig * +meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager) +{ + MetaMonitorsConfigKey *config_key; + MetaMonitorsConfig *config; + + config_key = create_key_for_current_state (config_manager->monitor_manager); + if (!config_key) + return NULL; + + config = meta_monitor_config_store_lookup (config_manager->config_store, + config_key); + meta_monitors_config_key_free (config_key); + + return config; +} + typedef enum _MonitorMatchRule { MONITOR_MATCH_ALL = 0, diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h index d10cc8fdf..c5587dfaa 100644 --- a/src/backends/meta-monitor-config-manager.h +++ b/src/backends/meta-monitor-config-manager.h @@ -70,6 +70,8 @@ gboolean meta_monitor_config_manager_assign (MetaMonitorManager *manager, GPtrArray **output_infos, GError **error); +MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager); + MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager); MetaMonitorsConfig * meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index ce0b6b5d7..5d73c208f 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -353,6 +353,12 @@ meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager) return FALSE; } +static gboolean +should_use_stored_config (MetaMonitorManager *manager) +{ + return !meta_monitor_manager_has_hotplug_mode_update (manager); +} + static void legacy_ensure_configured (MetaMonitorManager *manager) { @@ -372,6 +378,27 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager) return NULL; } + if (should_use_stored_config (manager)) + { + config = meta_monitor_config_manager_get_stored (manager->config_manager); + if (config) + { + if (!meta_monitor_manager_apply_monitors_config (manager, config, + &error)) + { + config = NULL; + g_warning ("Failed to use stored monitor configuration: %s", + error->message); + g_clear_error (&error); + } + else + { + g_object_ref (config); + goto done; + } + } + } + config = meta_monitor_config_manager_create_suggested (manager->config_manager); if (config) {