monitor-config-manager: Take device orientation into account for new configs

When creating a new config because of a monitor being (un)plugged or
because of super+p being pressed, honor the orientation reported by
the accelerometer for the internal panel.

Before this commit we would always configure the internal panel with
a normal / upright transform when e.g. an external monitor gets plugged
in even if another transform was in use before plugging in the external
monitor. This is inconsistent and causes problems for several use-cases.
This commit fixes this by querying the accelerometer when creating a new
config for an internal panel.

Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/707
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/924

https://gitlab.gnome.org/GNOME/mutter/merge_requests/959
This commit is contained in:
Hans de Goede 2019-12-04 16:34:38 +01:00 committed by Carlos Garnacho
parent c37e2523ac
commit e4d5cb72ee

View File

@ -590,6 +590,34 @@ create_monitor_config (MetaMonitor *monitor,
return monitor_config;
}
static MetaMonitorTransform
get_monitor_transform (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor)
{
MetaOrientationManager *orientation_manager;
MetaBackend *backend;
if (!meta_monitor_is_laptop_panel (monitor))
return META_MONITOR_TRANSFORM_NORMAL;
backend = meta_monitor_manager_get_backend (monitor_manager);
orientation_manager = meta_backend_get_orientation_manager (backend);
switch (meta_orientation_manager_get_orientation (orientation_manager))
{
case META_ORIENTATION_BOTTOM_UP:
return META_MONITOR_TRANSFORM_180;
case META_ORIENTATION_LEFT_UP:
return META_MONITOR_TRANSFORM_90;
case META_ORIENTATION_RIGHT_UP:
return META_MONITOR_TRANSFORM_270;
case META_ORIENTATION_UNDEFINED:
case META_ORIENTATION_NORMAL:
default:
return META_MONITOR_TRANSFORM_NORMAL;
}
}
static MetaLogicalMonitorConfig *
create_preferred_logical_monitor_config (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor,
@ -601,6 +629,7 @@ create_preferred_logical_monitor_config (MetaMonitorManager *monitor_ma
MetaMonitorMode *mode;
int width, height;
float scale;
MetaMonitorTransform transform;
MetaMonitorConfig *monitor_config;
MetaLogicalMonitorConfig *logical_monitor_config;
@ -628,6 +657,14 @@ create_preferred_logical_monitor_config (MetaMonitorManager *monitor_ma
monitor_config = create_monitor_config (monitor, mode);
transform = get_monitor_transform (monitor_manager, monitor);
if (meta_monitor_transform_is_rotated (transform))
{
int temp = width;
width = height;
height = temp;
}
logical_monitor_config = g_new0 (MetaLogicalMonitorConfig, 1);
*logical_monitor_config = (MetaLogicalMonitorConfig) {
.layout = (MetaRectangle) {
@ -636,6 +673,7 @@ create_preferred_logical_monitor_config (MetaMonitorManager *monitor_ma
.width = width,
.height = height
},
.transform = transform,
.scale = scale,
.monitor_configs = g_list_append (NULL, monitor_config)
};