monitor-manager: Apply built-in monitor orientation to previous configurations

When we reuse a monitor configuration (from the storage or previously
used), we need to make sure that the built-in monitor rotation matches
with the current sensors status.

So, instead of trying to apply a previously used or stored configuration
with a wrong orientation and fix it later, if orientation is managed by
sensor, try to create another configuration based on the previous one that
uses the current built-in monitor orientation and use it.

Related to: https://gitlab.gnome.org/GNOME/mutter/-/issues/646

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/592
Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/646
Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/954
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1233>
This commit is contained in:
Marco Trevisan (Treviño) 2020-05-01 15:24:34 +02:00 committed by Jonas Ådahl
parent dbf5e38f03
commit d773aaf7a9
3 changed files with 95 additions and 7 deletions

View File

@ -1031,6 +1031,7 @@ find_logical_config_for_builtin_display_rotation (MetaMonitorConfigManager *conf
static MetaMonitorsConfig * static MetaMonitorsConfig *
create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager, create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
MetaMonitorsConfig *base_config,
gboolean rotate, gboolean rotate,
MetaMonitorTransform transform) MetaMonitorTransform transform)
{ {
@ -1040,10 +1041,9 @@ create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
GList *logical_monitor_configs, *current_configs; GList *logical_monitor_configs, *current_configs;
MetaLogicalMonitorLayoutMode layout_mode; MetaLogicalMonitorLayoutMode layout_mode;
if (!config_manager->current_config) g_return_val_if_fail (base_config, NULL);
return NULL;
current_configs = config_manager->current_config->logical_monitor_configs; current_configs = base_config->logical_monitor_configs;
current_logical_monitor_config = current_logical_monitor_config =
find_logical_config_for_builtin_display_rotation (config_manager, find_logical_config_for_builtin_display_rotation (config_manager,
current_configs); current_configs);
@ -1071,7 +1071,7 @@ create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
return NULL; return NULL;
logical_monitor_configs = logical_monitor_configs =
clone_logical_monitor_config_list (config_manager->current_config->logical_monitor_configs); clone_logical_monitor_config_list (base_config->logical_monitor_configs);
logical_monitor_config = logical_monitor_config =
find_logical_config_for_builtin_display_rotation (config_manager, logical_monitor_configs); find_logical_config_for_builtin_display_rotation (config_manager, logical_monitor_configs);
logical_monitor_config->transform = transform; logical_monitor_config->transform = transform;
@ -1084,7 +1084,7 @@ create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
logical_monitor_config->layout.height = temp; logical_monitor_config->layout.height = temp;
} }
layout_mode = config_manager->current_config->layout_mode; layout_mode = base_config->layout_mode;
return meta_monitors_config_new (monitor_manager, return meta_monitors_config_new (monitor_manager,
logical_monitor_configs, logical_monitor_configs,
layout_mode, layout_mode,
@ -1093,15 +1093,38 @@ create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
MetaMonitorsConfig * MetaMonitorsConfig *
meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager, meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager,
MetaMonitorsConfig *base_config,
MetaMonitorTransform transform) MetaMonitorTransform transform)
{ {
return create_for_builtin_display_rotation (config_manager, FALSE, transform); return create_for_builtin_display_rotation (config_manager, base_config,
FALSE, transform);
}
MetaMonitorsConfig *
meta_monitor_config_manager_create_for_builtin_orientation (MetaMonitorConfigManager *config_manager,
MetaMonitorsConfig *base_config)
{
MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
MetaMonitorTransform current_transform;
MetaMonitor *laptop_panel;
g_return_val_if_fail (
meta_monitor_manager_get_panel_orientation_managed (monitor_manager), NULL);
laptop_panel = meta_monitor_manager_get_laptop_panel (monitor_manager);
current_transform = get_monitor_transform (monitor_manager, laptop_panel);
return create_for_builtin_display_rotation (config_manager, base_config,
FALSE, current_transform);
} }
MetaMonitorsConfig * MetaMonitorsConfig *
meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager) meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager)
{ {
return create_for_builtin_display_rotation (config_manager, TRUE, META_MONITOR_TRANSFORM_NORMAL); return create_for_builtin_display_rotation (config_manager,
config_manager->current_config,
TRUE,
META_MONITOR_TRANSFORM_NORMAL);
} }
static MetaMonitorsConfig * static MetaMonitorsConfig *

View File

@ -105,8 +105,13 @@ MetaMonitorsConfig * meta_monitor_config_manager_create_suggested (MetaMonitorCo
META_EXPORT_TEST META_EXPORT_TEST
MetaMonitorsConfig * meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager, MetaMonitorsConfig * meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager,
MetaMonitorsConfig *base_config,
MetaMonitorTransform transform); MetaMonitorTransform transform);
META_EXPORT_TEST
MetaMonitorsConfig * meta_monitor_config_manager_create_for_builtin_orientation (MetaMonitorConfigManager *config_manager,
MetaMonitorsConfig *base_config);
META_EXPORT_TEST META_EXPORT_TEST
MetaMonitorsConfig * meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager); MetaMonitorsConfig * meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager);

View File

@ -689,6 +689,17 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
config = meta_monitor_config_manager_get_stored (manager->config_manager); config = meta_monitor_config_manager_get_stored (manager->config_manager);
if (config) if (config)
{ {
g_autoptr (MetaMonitorsConfig) oriented_config = NULL;
if (manager->panel_orientation_managed)
{
oriented_config = meta_monitor_config_manager_create_for_builtin_orientation (
manager->config_manager, config);
if (oriented_config)
config = oriented_config;
}
if (!meta_monitor_manager_apply_monitors_config (manager, if (!meta_monitor_manager_apply_monitors_config (manager,
config, config,
method, method,
@ -707,6 +718,39 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
} }
} }
if (manager->panel_orientation_managed)
{
MetaMonitorsConfig *current_config =
meta_monitor_config_manager_get_current (manager->config_manager);
if (current_config)
{
config = meta_monitor_config_manager_create_for_builtin_orientation (
manager->config_manager, current_config);
}
}
if (config)
{
if (meta_monitor_manager_is_config_complete (manager, config))
{
if (!meta_monitor_manager_apply_monitors_config (manager,
config,
method,
&error))
{
g_clear_object (&config);
g_warning ("Failed to use current monitor configuration: %s",
error->message);
g_clear_error (&error);
}
else
{
goto done;
}
}
}
config = meta_monitor_config_manager_create_suggested (manager->config_manager); config = meta_monitor_config_manager_create_suggested (manager->config_manager);
if (config) if (config)
{ {
@ -813,6 +857,7 @@ handle_orientation_change (MetaOrientationManager *orientation_manager,
MetaMonitorsConfig *config; MetaMonitorsConfig *config;
MetaMonitor *laptop_panel; MetaMonitor *laptop_panel;
MetaLogicalMonitor *laptop_logical_monitor; MetaLogicalMonitor *laptop_logical_monitor;
MetaMonitorsConfig *current_config;
laptop_panel = meta_monitor_manager_get_laptop_panel (manager); laptop_panel = meta_monitor_manager_get_laptop_panel (manager);
g_return_if_fail (laptop_panel); g_return_if_fail (laptop_panel);
@ -844,8 +889,11 @@ handle_orientation_change (MetaOrientationManager *orientation_manager,
if (meta_logical_monitor_get_transform (laptop_logical_monitor) == transform) if (meta_logical_monitor_get_transform (laptop_logical_monitor) == transform)
return; return;
current_config =
meta_monitor_config_manager_get_current (manager->config_manager);
config = config =
meta_monitor_config_manager_create_for_orientation (manager->config_manager, meta_monitor_config_manager_create_for_orientation (manager->config_manager,
current_config,
transform); transform);
if (!config) if (!config)
return; return;
@ -1502,6 +1550,18 @@ restore_previous_config (MetaMonitorManager *manager)
{ {
MetaMonitorsConfigMethod method; MetaMonitorsConfigMethod method;
if (manager->panel_orientation_managed)
{
g_autoptr (MetaMonitorsConfig) oriented_config = NULL;
oriented_config =
meta_monitor_config_manager_create_for_builtin_orientation (
manager->config_manager, previous_config);
if (oriented_config)
g_set_object (&previous_config, oriented_config);
}
method = META_MONITORS_CONFIG_METHOD_TEMPORARY; method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
if (meta_monitor_manager_apply_monitors_config (manager, if (meta_monitor_manager_apply_monitors_config (manager,
previous_config, previous_config,