diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c index 840e18614..07a36362b 100644 --- a/src/backends/meta-monitor-config-manager.c +++ b/src/backends/meta-monitor-config-manager.c @@ -439,6 +439,8 @@ meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_mana GList *l; primary_monitor = find_primary_monitor (monitor_manager); + if (!primary_monitor) + return NULL; primary_logical_monitor_config = create_preferred_logical_monitor_config (primary_monitor, 0, 0); @@ -480,6 +482,8 @@ meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_ma MetaLogicalMonitorConfig *primary_logical_monitor_config; primary_monitor = find_primary_monitor (monitor_manager); + if (!primary_monitor) + return NULL; primary_logical_monitor_config = create_preferred_logical_monitor_config (primary_monitor, 0, 0); diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index e4b01d4e3..0424d0310 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -437,6 +437,8 @@ gboolean meta_monitor_manager_is_lid_closed (MetaMonitorManager *manag void meta_monitor_manager_lid_is_closed_changed (MetaMonitorManager *manager); +gboolean meta_monitor_manager_is_headless (MetaMonitorManager *manager); + void meta_monitor_manager_clear_output (MetaOutput *output); void meta_monitor_manager_clear_mode (MetaCrtcMode *mode); void meta_monitor_manager_clear_crtc (MetaCrtc *crtc); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 0cc5ce7ce..ce0b6b5d7 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -153,12 +153,14 @@ static void meta_monitor_manager_rebuild_logical_monitors (MetaMonitorManager *manager, MetaMonitorsConfig *config) { + GList *logical_monitor_configs; GList *logical_monitors = NULL; GList *l; int monitor_number = 0; MetaLogicalMonitor *primary_logical_monitor = NULL; - for (l = config->logical_monitor_configs; l; l = l->next) + logical_monitor_configs = config ? config->logical_monitor_configs : NULL; + for (l = logical_monitor_configs; l; l = l->next) { MetaLogicalMonitorConfig *logical_monitor_config = l->data; MetaLogicalMonitor *logical_monitor; @@ -312,6 +314,12 @@ meta_monitor_manager_is_lid_closed (MetaMonitorManager *manager) return META_MONITOR_MANAGER_GET_CLASS (manager)->is_lid_closed (manager); } +gboolean +meta_monitor_manager_is_headless (MetaMonitorManager *manager) +{ + return !manager->monitors; +} + static void meta_monitor_manager_ensure_initial_config (MetaMonitorManager *manager) { @@ -381,36 +389,46 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager) } config = meta_monitor_config_manager_create_linear (manager->config_manager); - if (!meta_monitor_manager_apply_monitors_config (manager, config, &error)) + if (config) { - g_clear_object (&config); - g_warning ("Failed to use linear monitor configuration: %s", - error->message); - g_clear_error (&error); - } - else - { - goto done; + if (!meta_monitor_manager_apply_monitors_config (manager, config, &error)) + { + g_clear_object (&config); + g_warning ("Failed to use linear monitor configuration: %s", + error->message); + g_clear_error (&error); + } + else + { + goto done; + } } config = meta_monitor_config_manager_create_fallback (manager->config_manager); - if (!meta_monitor_manager_apply_monitors_config (manager, config, &error)) + if (config) { - g_clear_object (&config); - g_warning ("Failed to use fallback monitor configuration: %s", + if (!meta_monitor_manager_apply_monitors_config (manager, config, &error)) + { + g_clear_object (&config); + g_warning ("Failed to use fallback monitor configuration: %s", error->message); - g_clear_error (&error); - } - else - { - goto done; + g_clear_error (&error); + } + else + { + goto done; + } } done: - if (!config) - meta_fatal ("Failed to find any working monitor configuration, giving up"); - meta_monitor_config_manager_set_current (manager->config_manager, config); + + if (!config) + { + meta_monitor_manager_rebuild (manager, NULL); + return NULL; + } + g_object_unref (config); return config; @@ -1791,9 +1809,11 @@ static void meta_monitor_manager_update_monitor_modes (MetaMonitorManager *manager, MetaMonitorsConfig *config) { + GList *logical_monitor_configs; GList *l; - for (l = config->logical_monitor_configs; l; l = l->next) + logical_monitor_configs = config ? config->logical_monitor_configs : NULL; + for (l = logical_monitor_configs; l; l = l->next) { MetaLogicalMonitorConfig *logical_monitor_config = l->data; diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c index de8889eaa..25c1b77ea 100644 --- a/src/backends/native/meta-monitor-manager-kms.c +++ b/src/backends/native/meta-monitor-manager-kms.c @@ -1499,6 +1499,13 @@ meta_monitor_manager_kms_apply_monitors_config (MetaMonitorManager *manager, GPtrArray *crtc_infos; GPtrArray *output_infos; + if (!config) + { + manager->screen_width = 0; + manager->screen_height = 0; + return TRUE; + } + if (!meta_monitor_config_manager_assign (manager, config, &crtc_infos, &output_infos, error))