[mutter] monitor-config-manager: Handle headless setup gracefully



commit 3f994646f25449bd706c901276aba8f6489db7d9
Author: Jonas Ådahl <jadahl gmail com>
Date:   Thu Jan 12 13:47:54 2017 +0800

    monitor-config-manager: Handle headless setup gracefully
    
    Handle headless setup gracefully by having no logical monitors. This
    commit only makes the monitor management code deal with it; other areas
    may still not be able to handle it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777732

 src/backends/meta-monitor-config-manager.c     |    4 ++
 src/backends/meta-monitor-manager-private.h    |    2 +
 src/backends/meta-monitor-manager.c            |   62 ++++++++++++++++--------
 src/backends/native/meta-monitor-manager-kms.c |    7 +++
 4 files changed, 54 insertions(+), 21 deletions(-)
---
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
index 840e186..07a3636 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 e4b01d4..0424d03 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 0cc5ce7..ce0b6b5 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))
-    {
-      g_clear_object (&config);
-      g_warning ("Failed to use linear monitor configuration: %s",
-                 error->message);
-      g_clear_error (&error);
-    }
-  else
+  if (config)
     {
-      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:
+  meta_monitor_config_manager_set_current (manager->config_manager, config);
+
   if (!config)
-    meta_fatal ("Failed to find any working monitor configuration, giving up");
+    {
+      meta_monitor_manager_rebuild (manager, NULL);
+      return NULL;
+    }
 
-  meta_monitor_config_manager_set_current (manager->config_manager, config);
   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 de8889e..25c1b77 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))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]