[mutter] config: Refactor the check for the lid special-case out



commit f2546dfeea73fb5fd0fd7e8e2dd5619e10c21dd2
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Oct 22 15:03:39 2014 -0700

    config: Refactor the check for the lid special-case out
    
    This also fixes the case where current_is_for_laptop_lid wasn't properly
    set in the default case.

 src/backends/meta-monitor-config.c |   55 +++++++++++++++--------------------
 1 files changed, 24 insertions(+), 31 deletions(-)
---
diff --git a/src/backends/meta-monitor-config.c b/src/backends/meta-monitor-config.c
index 1aa85b7..e5e61d0 100644
--- a/src/backends/meta-monitor-config.c
+++ b/src/backends/meta-monitor-config.c
@@ -887,8 +887,7 @@ apply_configuration (MetaMonitorConfig  *self,
   self->current = config;
   self->current_is_stored = stored;
   /* If true, we'll be overridden at the end of this call
-     inside turn_off_laptop_display()
-  */
+   * inside turn_off_laptop_display / apply_configuration_with_lid */
   self->current_is_for_laptop_lid = FALSE;
 
   if (self->current == self->previous)
@@ -990,6 +989,27 @@ make_laptop_lid_config (MetaConfiguration  *reference)
   return new;
 }
 
+static gboolean
+apply_configuration_with_lid (MetaMonitorConfig  *self,
+                              MetaConfiguration  *config,
+                              MetaMonitorManager *manager)
+{
+  if (self->lid_is_closed &&
+      config->n_outputs > 1 &&
+      laptop_display_is_on (config))
+    {
+      if (apply_configuration (self, make_laptop_lid_config (config), manager, FALSE))
+        {
+          self->current_is_for_laptop_lid = TRUE;
+          return TRUE;
+        }
+      else
+        return FALSE;
+    }
+  else
+    return apply_configuration (self, config, manager, TRUE);
+}
+
 gboolean
 meta_monitor_config_apply_stored (MetaMonitorConfig  *self,
                                  MetaMonitorManager *manager)
@@ -1002,23 +1022,7 @@ meta_monitor_config_apply_stored (MetaMonitorConfig  *self,
   stored = meta_monitor_config_get_stored (self, outputs, n_outputs);
 
   if (stored)
-    {
-      if (self->lid_is_closed &&
-          stored->n_outputs > 1 &&
-          laptop_display_is_on (stored))
-        {
-          if (apply_configuration (self, make_laptop_lid_config (stored),
-                                   manager, FALSE))
-            {
-              self->current_is_for_laptop_lid = TRUE;
-              return TRUE;
-            }
-          else
-            return FALSE;
-        }
-      else
-        return apply_configuration (self, stored, manager, TRUE);
-    }
+    return apply_configuration_with_lid (self, stored, manager);
   else
     return FALSE;
 }
@@ -1264,18 +1268,7 @@ meta_monitor_config_make_default (MetaMonitorConfig  *self,
   default_config = make_default_config (self, outputs, n_outputs, max_width, max_height);
 
   if (default_config != NULL)
-    {
-      if (self->lid_is_closed &&
-          default_config->n_outputs > 1 &&
-          laptop_display_is_on (default_config))
-        {
-          ok = apply_configuration (self, make_laptop_lid_config (default_config),
-                                    manager, FALSE);
-          config_free (default_config);
-        }
-      else
-        ok = apply_configuration (self, default_config, manager, FALSE);
-    }
+    ok = apply_configuration_with_lid (self, default_config, manager);
   else
     ok = FALSE;
 


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