From 0b3a1c9c314a88c57668437245d54b200537e619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 25 Apr 2018 10:43:11 +0200 Subject: [PATCH] monitor-manager: Find active monitor when deriving global scale When deriving the global scale directly from the current hardware state (as done when using the X11 backend) we are inspecting the logical state they had prior to the most recent hot plug. That means that a primary monitor might have been disabled, and a new primary monitor may not have been assigned yet. Stop assuming a primary monitor has an active mode before having reconstructed the logical state by finding some active monitor if the old primary monitor was disabled. This avoids a crash when trying to derive the global scale from a disabled monitor. Closes: https://gitlab.gnome.org/GNOME/mutter/issues/130 --- src/backends/meta-monitor-manager.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 829c189ea..0b5e54c48 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -89,6 +89,9 @@ static gboolean meta_monitor_manager_is_config_complete (MetaMonitorManager *manager, MetaMonitorsConfig *config); +static MetaMonitor * +meta_monitor_manager_get_active_monitor (MetaMonitorManager *manager); + MetaBackend * meta_monitor_manager_get_backend (MetaMonitorManager *manager) { @@ -198,13 +201,17 @@ calculate_monitor_scale (MetaMonitorManager *manager, static float derive_calculated_global_scale (MetaMonitorManager *manager) { - MetaMonitor *primary_monitor; + MetaMonitor *monitor = NULL; - primary_monitor = meta_monitor_manager_get_primary_monitor (manager); - if (!primary_monitor) + monitor = meta_monitor_manager_get_primary_monitor (manager); + + if (!monitor || !meta_monitor_is_active (monitor)) + monitor = meta_monitor_manager_get_active_monitor (manager); + + if (!monitor) return 1.0; - return calculate_monitor_scale (manager, primary_monitor); + return calculate_monitor_scale (manager, monitor); } static float @@ -2378,6 +2385,12 @@ meta_monitor_manager_get_laptop_panel (MetaMonitorManager *manager) return find_monitor (manager, meta_monitor_is_laptop_panel); } +static MetaMonitor * +meta_monitor_manager_get_active_monitor (MetaMonitorManager *manager) +{ + return find_monitor (manager, meta_monitor_is_active); +} + MetaMonitor * meta_monitor_manager_get_monitor_from_connector (MetaMonitorManager *manager, const char *connector)