mirror of
https://github.com/brl/mutter.git
synced 2025-06-13 16:59:30 +00:00
monitor-manager: Try to restore previous config before regenerating
When opening a laptop lid, one will likely want to restore the configuration one had prior to closing it, so when ensuring monitor configuration, first try to see if the previously set configuration is both complete (all connected monitors are configured) and applicable (it is a valid configuration) and only try to generate a new from scratch if that failed. https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
@ -71,6 +71,10 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaMonitorManager, meta_monitor_manager, META
|
||||
|
||||
static void initialize_dbus_interface (MetaMonitorManager *manager);
|
||||
|
||||
static gboolean
|
||||
meta_monitor_manager_is_config_complete (MetaMonitorManager *manager,
|
||||
MetaMonitorsConfig *config);
|
||||
|
||||
static void
|
||||
meta_monitor_manager_init (MetaMonitorManager *manager)
|
||||
{
|
||||
@ -529,6 +533,31 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
|
||||
}
|
||||
}
|
||||
|
||||
config = meta_monitor_config_manager_get_previous (manager->config_manager);
|
||||
if (config)
|
||||
{
|
||||
config = g_object_ref (config);
|
||||
|
||||
if (meta_monitor_manager_is_config_complete (manager, config))
|
||||
{
|
||||
if (!meta_monitor_manager_apply_monitors_config (manager,
|
||||
config,
|
||||
method,
|
||||
&error))
|
||||
{
|
||||
g_warning ("Failed to use suggested monitor configuration: %s",
|
||||
error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
else
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
g_clear_object (&config);
|
||||
}
|
||||
|
||||
config = meta_monitor_config_manager_create_linear (manager->config_manager);
|
||||
if (config)
|
||||
{
|
||||
@ -1494,6 +1523,44 @@ meta_monitor_manager_is_config_applicable (MetaMonitorManager *manager,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_monitor_manager_is_config_complete (MetaMonitorManager *manager,
|
||||
MetaMonitorsConfig *config)
|
||||
{
|
||||
GList *l;
|
||||
unsigned int configured_monitor_count = 0;
|
||||
unsigned int expected_monitor_count = 0;
|
||||
|
||||
for (l = config->logical_monitor_configs; l; l = l->next)
|
||||
{
|
||||
MetaLogicalMonitorConfig *logical_monitor_config = l->data;
|
||||
GList *k;
|
||||
|
||||
for (k = logical_monitor_config->monitor_configs; k; k = k->next)
|
||||
configured_monitor_count++;
|
||||
}
|
||||
|
||||
for (l = manager->monitors; l; l = l->next)
|
||||
{
|
||||
MetaMonitor *monitor = l->data;
|
||||
|
||||
if (meta_monitor_is_laptop_panel (monitor))
|
||||
{
|
||||
if (!meta_monitor_manager_is_lid_closed (manager))
|
||||
expected_monitor_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
expected_monitor_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (configured_monitor_count != expected_monitor_count)
|
||||
return FALSE;
|
||||
|
||||
return meta_monitor_manager_is_config_applicable (manager, config, NULL);
|
||||
}
|
||||
|
||||
static MetaMonitor *
|
||||
find_monitor_from_connector (MetaMonitorManager *manager,
|
||||
char *connector)
|
||||
|
Reference in New Issue
Block a user