[gnome-control-center/wip/benzea/display: 10/12] display: Move output utility functions into CcDisplayMonitor



commit 21f889eedbceba062ef8edf8ce4ff73bf1efcc95
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Dec 22 14:41:25 2017 +0100

    display: Move output utility functions into CcDisplayMonitor
    
    This adds the following API:
     * cc_display_config_get_ui_sorted_monitors
       Returns the monitors in UI order
     * cc_display_config_count_useful_monitors
       Counts the useful monitors (active and usable)
     * cc_display_monitor_is_useful
       Checks if a monitor is active and usable
     * cc_display_monitor_is_useable
       Check if a monitor is marked as useable
     * cc_display_monitor_set_usable
       Used to mark builtin monitors as unusable if the lid is closed
     * cc_display_monitor_get_ui_*
       Get the UI number and strings for display
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786971

 panels/display/cc-display-arrangement.c |  41 ++----
 panels/display/cc-display-config.c      | 220 +++++++++++++++++++++++++++++++-
 panels/display/cc-display-config.h      |  10 ++
 panels/display/cc-display-panel.c       | 169 ++++--------------------
 4 files changed, 256 insertions(+), 184 deletions(-)
---
diff --git a/panels/display/cc-display-arrangement.c b/panels/display/cc-display-arrangement.c
index a3f0d7995..09a2da082 100644
--- a/panels/display/cc-display-arrangement.c
+++ b/panels/display/cc-display-arrangement.c
@@ -71,31 +71,6 @@ G_DEFINE_TYPE (CcDisplayArrangement, cc_display_arrangement, GTK_TYPE_DRAWING_AR
 
 static GParamSpec *props[PROP_LAST];
 
-static gboolean
-is_output_useful (CcDisplayMonitor *output)
-{
-  return (cc_display_monitor_is_active (output) &&
-          !g_object_get_data (G_OBJECT (output), "lid-is-closed"));
-}
-
-static guint
-count_useful_outputs (CcDisplayConfig *config)
-{
-  GList *outputs, *l;
-  guint active = 0;
-
-  outputs = cc_display_config_get_monitors (config);
-  for (l = outputs; l != NULL; l = l->next)
-    {
-      CcDisplayMonitor *output = l->data;
-      if (!is_output_useful (output))
-        continue;
-      else
-        active++;
-    }
-  return active;
-}
-
 static void
 apply_rotation_to_geometry (CcDisplayMonitor *output,
                            int *w,
@@ -167,7 +142,7 @@ get_bounding_box (CcDisplayConfig *config,
       CcDisplayMonitor *output = l->data;
       int x, y, w, h;
 
-      if (!is_output_useful (output))
+      if (!cc_display_monitor_is_useful (output))
         continue;
 
       get_scaled_geometry (config, output, &x, &y, &w, &h);
@@ -323,7 +298,7 @@ find_best_snapping (CcDisplayArrangement *arr,
       if (output == snap_output)
         continue;
 
-      if (!is_output_useful (output))
+      if (!cc_display_monitor_is_useful (output))
         continue;
 
       get_scaled_geometry (config, output, &_x1, &_y1, &_w, &_h);
@@ -430,7 +405,7 @@ cc_display_arrangement_find_monitor_at (CcDisplayArrangement *arr,
       CcDisplayMonitor *output = l->data;
       gint x1, y1, x2, y2;
 
-      if (!is_output_useful (output))
+      if (!cc_display_monitor_is_useful (output))
         continue;
 
       monitor_get_drawing_rect (arr, output, &x1, &y1, &x2, &y2);
@@ -474,7 +449,7 @@ static void
 cc_display_arrangement_set_config (CcDisplayArrangement *arr,
                                   CcDisplayConfig      *config)
 {
-  const gchar *signals[] = { "rotation", "mode", "primary", "active", "scale", "position-changed" };
+  const gchar *signals[] = { "rotation", "mode", "primary", "active", "scale", "position-changed", 
"is-usable" };
   GList *outputs, *l;
   guint i;
 
@@ -535,7 +510,7 @@ cc_display_arrangement_draw (GtkWidget *widget,
       gint w, h;
       gint num;
 
-      if (!is_output_useful (output))
+      if (!cc_display_monitor_is_useful (output))
         continue;
 
       gtk_style_context_save (context);
@@ -553,7 +528,7 @@ cc_display_arrangement_draw (GtkWidget *widget,
         gtk_style_context_add_class (context, "primary");
 
       /* Set in cc-display-panel.c */
-      num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (output), "ui-number"));
+      num = cc_display_monitor_get_ui_number (output);
 
       monitor_get_drawing_rect (arr, output, &x1, &y1, &x2, &y2);
       w = x2 - x1;
@@ -662,7 +637,7 @@ cc_display_arrangement_button_press_event (GtkWidget      *widget,
 
   cc_display_arrangement_set_selected_output (arr, output);
 
-  if (count_useful_outputs (arr->config) > 1)
+  if (cc_display_config_count_useful_monitors (arr->config) > 1)
     {
       arr->drag_active = TRUE;
       arr->drag_anchor_x = event_x - mon_x;
@@ -710,7 +685,7 @@ cc_display_arrangement_motion_notify_event (GtkWidget      *widget,
 
   g_return_val_if_fail (arr->config, FALSE);
 
-  if (count_useful_outputs (arr->config) <= 1)
+  if (cc_display_config_count_useful_monitors (arr->config) <= 1)
     return FALSE;
 
   if (!arr->drag_active)
diff --git a/panels/display/cc-display-config.c b/panels/display/cc-display-config.c
index 616711e0d..b919d1632 100644
--- a/panels/display/cc-display-config.c
+++ b/panels/display/cc-display-config.c
@@ -17,8 +17,67 @@
  *
  */
 
+#include <math.h>
 #include "cc-display-config.h"
 
+static const double known_diagonals[] = {
+  12.1,
+  13.3,
+  15.6
+};
+
+static char *
+diagonal_to_str (double d)
+{
+  int i;
+
+  for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++)
+    {
+      double delta;
+
+      delta = fabs(known_diagonals[i] - d);
+      if (delta < 0.1)
+          return g_strdup_printf ("%0.1lf\"", known_diagonals[i]);
+    }
+
+  return g_strdup_printf ("%d\"", (int) (d + 0.5));
+}
+
+static char *
+make_display_size_string (int width_mm,
+                          int height_mm)
+{
+  char *inches = NULL;
+
+  if (width_mm > 0 && height_mm > 0)
+    {
+      double d = sqrt (width_mm * width_mm + height_mm * height_mm);
+
+      inches = diagonal_to_str (d / 25.4);
+    }
+
+  return inches;
+}
+
+static char *
+make_output_ui_name (CcDisplayMonitor *output)
+{
+  int width_mm, height_mm;
+  char *size, *name;
+
+  cc_display_monitor_get_physical_size (output, &width_mm, &height_mm);
+  size = make_display_size_string (width_mm, height_mm);
+  if (size)
+    name = g_strdup_printf ("%s (%s)", cc_display_monitor_get_display_name (output), size);
+  else
+    name = g_strdup_printf ("%s", cc_display_monitor_get_display_name (output));
+
+  g_free (size);
+  return name;
+}
+
+
+
 G_DEFINE_TYPE (CcDisplayMode,
                cc_display_mode,
                G_TYPE_OBJECT)
@@ -70,13 +129,28 @@ cc_display_mode_get_freq_f (CcDisplayMode *self)
 }
 
 
-G_DEFINE_TYPE (CcDisplayMonitor,
-               cc_display_monitor,
-               G_TYPE_OBJECT)
+struct _CcDisplayMonitorPrivate {
+  int ui_number;
+  gchar *ui_name;
+  gchar *ui_number_name;
+  gboolean is_usable;
+};
+typedef struct _CcDisplayMonitorPrivate CcDisplayMonitorPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (CcDisplayMonitor,
+                            cc_display_monitor,
+                            G_TYPE_OBJECT)
+#define CC_DISPLAY_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_DISPLAY_MONITOR, 
CcDisplayMonitorPrivate))
 
 static void
 cc_display_monitor_init (CcDisplayMonitor *self)
 {
+  CcDisplayMonitorPrivate *priv = CC_DISPLAY_MONITOR_GET_PRIVATE (self);
+
+  priv->ui_number = 0;
+  priv->ui_name = NULL;
+  priv->ui_number_name = NULL;
+  priv->is_usable = TRUE;
 }
 
 static void
@@ -112,6 +186,11 @@ cc_display_monitor_class_init (CcDisplayMonitorClass *klass)
                 G_SIGNAL_RUN_LAST,
                 0, NULL, NULL, NULL,
                 G_TYPE_NONE, 0);
+  g_signal_new ("is-usable",
+                CC_TYPE_DISPLAY_MONITOR,
+                G_SIGNAL_RUN_LAST,
+                0, NULL, NULL, NULL,
+                G_TYPE_NONE, 0);
 }
 
 const char *
@@ -254,24 +333,127 @@ cc_display_monitor_set_scale (CcDisplayMonitor *self, double s)
   return CC_DISPLAY_MONITOR_GET_CLASS (self)->set_scale (self, s);
 }
 
+gboolean
+cc_display_monitor_is_useful (CcDisplayMonitor *self)
+{
+  return CC_DISPLAY_MONITOR_GET_PRIVATE (self)->is_usable &&
+         cc_display_monitor_is_active (self);
+}
 
-G_DEFINE_TYPE (CcDisplayConfig,
-               cc_display_config,
-               G_TYPE_OBJECT)
+gboolean
+cc_display_monitor_is_usable (CcDisplayMonitor *self)
+{
+  return CC_DISPLAY_MONITOR_GET_PRIVATE (self)->is_usable;
+}
+
+void
+cc_display_monitor_set_usable (CcDisplayMonitor *self, gboolean is_usable)
+{
+  CC_DISPLAY_MONITOR_GET_PRIVATE (self)->is_usable = is_usable;
+
+  g_signal_emit_by_name (self, "is-usable");
+}
+
+gint
+cc_display_monitor_get_ui_number (CcDisplayMonitor *self)
+{
+  return CC_DISPLAY_MONITOR_GET_PRIVATE (self)->ui_number;
+}
+
+const char *
+cc_display_monitor_get_ui_name (CcDisplayMonitor *self)
+{
+  return CC_DISPLAY_MONITOR_GET_PRIVATE (self)->ui_name;
+}
+
+const char *
+cc_display_monitor_get_ui_number_name (CcDisplayMonitor *self)
+{
+  return CC_DISPLAY_MONITOR_GET_PRIVATE (self)->ui_number_name;
+}
+
+static void
+cc_display_monitor_set_ui_info (CcDisplayMonitor *self, gint ui_number, gchar *ui_name)
+{
+  CcDisplayMonitorPrivate *priv = CC_DISPLAY_MONITOR_GET_PRIVATE (self);
+
+  priv->ui_number = ui_number;
+  g_free (priv->ui_name);
+  priv->ui_name = ui_name;
+  priv->ui_number_name = g_strdup_printf ("%d\u2003%s", ui_number, ui_name);
+}
+
+struct _CcDisplayConfigPrivate {
+  GList *ui_sorted_monitors;
+};
+typedef struct _CcDisplayConfigPrivate CcDisplayConfigPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (CcDisplayConfig,
+                            cc_display_config,
+                            G_TYPE_OBJECT)
+#define CC_DISPLAY_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_DISPLAY_CONFIG, 
CcDisplayConfigPrivate))
 
 static void
 cc_display_config_init (CcDisplayConfig *self)
 {
+  CcDisplayConfigPrivate *priv = CC_DISPLAY_CONFIG_GET_PRIVATE (self);
+
+  priv->ui_sorted_monitors = NULL;
+}
+
+static void
+cc_display_config_constructed (GObject *object)
+{
+  CcDisplayConfig *self = CC_DISPLAY_CONFIG (object);
+  CcDisplayConfigPrivate *priv = CC_DISPLAY_CONFIG_GET_PRIVATE (self);
+  GList *monitors = cc_display_config_get_monitors (self);
+  GList *item;
+  gint ui_number = 1;
+
+  for (item = monitors; item != NULL; item = item->next)
+    {
+      CcDisplayMonitor *monitor = item->data;
+
+      if (cc_display_monitor_is_builtin (monitor))
+        priv->ui_sorted_monitors = g_list_prepend (priv->ui_sorted_monitors, monitor);
+      else
+        priv->ui_sorted_monitors = g_list_append (priv->ui_sorted_monitors, monitor);
+    }
+
+  for (item = priv->ui_sorted_monitors; item != NULL; item = item->next)
+    {
+      CcDisplayMonitor *monitor = item->data;
+      char *ui_name;
+      ui_name = make_output_ui_name (monitor);
+
+      cc_display_monitor_set_ui_info (monitor, ui_number, ui_name);
+
+      ui_number += 1;
+    }
+}
+
+static void
+cc_display_config_finalize (GObject *object)
+{
+  CcDisplayConfig *self = CC_DISPLAY_CONFIG (object);
+  CcDisplayConfigPrivate *priv = CC_DISPLAY_CONFIG_GET_PRIVATE (self);
+
+  g_list_free (priv->ui_sorted_monitors);
 }
 
 static void
 cc_display_config_class_init (CcDisplayConfigClass *klass)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
   g_signal_new ("primary",
                 CC_TYPE_DISPLAY_CONFIG,
                 G_SIGNAL_RUN_LAST,
                 0, NULL, NULL, NULL,
                 G_TYPE_NONE, 0);
+
+  gobject_class->constructed = cc_display_config_constructed;
+  gobject_class->finalize = cc_display_config_finalize;
 }
 
 GList *
@@ -280,6 +462,32 @@ cc_display_config_get_monitors (CcDisplayConfig *self)
   return CC_DISPLAY_CONFIG_GET_CLASS (self)->get_monitors (self);
 }
 
+GList *
+cc_display_config_get_ui_sorted_monitors (CcDisplayConfig *self)
+{
+  return CC_DISPLAY_CONFIG_GET_PRIVATE (self)->ui_sorted_monitors;
+}
+
+int
+cc_display_config_count_useful_monitors (CcDisplayConfig *self)
+{
+  CcDisplayConfigPrivate *priv = CC_DISPLAY_CONFIG_GET_PRIVATE (self);
+  GList *outputs, *l;
+  guint count = 0;
+
+  outputs = priv->ui_sorted_monitors;
+  for (l = outputs; l != NULL; l = l->next)
+    {
+      CcDisplayMonitor *output = l->data;
+      if (!cc_display_monitor_is_useful (output))
+        continue;
+      else
+        count++;
+    }
+  return count;
+
+}
+
 gboolean
 cc_display_config_is_applicable (CcDisplayConfig *self)
 {
diff --git a/panels/display/cc-display-config.h b/panels/display/cc-display-config.h
index d76c13a64..15bfbf35b 100644
--- a/panels/display/cc-display-config.h
+++ b/panels/display/cc-display-config.h
@@ -159,6 +159,8 @@ struct _CcDisplayConfigClass
 
 
 GList*            cc_display_config_get_monitors            (CcDisplayConfig    *config);
+GList*            cc_display_config_get_ui_sorted_monitors  (CcDisplayConfig    *config);
+int               cc_display_config_count_useful_monitors   (CcDisplayConfig    *config);
 gboolean          cc_display_config_is_applicable           (CcDisplayConfig    *config);
 gboolean          cc_display_config_equal                   (CcDisplayConfig    *config,
                                                              CcDisplayConfig    *other);
@@ -212,6 +214,14 @@ void              cc_display_monitor_set_position           (CcDisplayMonitor  *
                                                              int                x,
                                                              int                y);
 
+gboolean          cc_display_monitor_is_useful              (CcDisplayMonitor  *monitor);
+gboolean          cc_display_monitor_is_usable              (CcDisplayMonitor  *monitor);
+void              cc_display_monitor_set_usable             (CcDisplayMonitor  *monitor,
+                                                             gboolean           is_usable);
+int               cc_display_monitor_get_ui_number          (CcDisplayMonitor  *monitor);
+const char*       cc_display_monitor_get_ui_name            (CcDisplayMonitor  *monitor);
+const char*       cc_display_monitor_get_ui_number_name     (CcDisplayMonitor  *monitor);
+
 void              cc_display_mode_get_resolution            (CcDisplayMode     *mode,
                                                              int               *width,
                                                              int               *height);
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index 8603675d0..0e8fa3b90 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -115,67 +115,9 @@ static void
 update_apply_button (CcDisplayPanel *panel);
 static void
 apply_current_configuration (CcDisplayPanel *self);
-static char *
-make_display_size_string (int width_mm,
-                          int height_mm);
 static void
 reset_current_config (CcDisplayPanel *panel);
 
-static char *
-make_output_ui_name (CcDisplayMonitor *output)
-{
-  int width_mm, height_mm;
-  char *size, *name;
-
-  cc_display_monitor_get_physical_size (output, &width_mm, &height_mm);
-  size = make_display_size_string (width_mm, height_mm);
-  if (size)
-    name = g_strdup_printf ("%s (%s)", cc_display_monitor_get_display_name (output), size);
-  else
-    name = g_strdup_printf ("%s", cc_display_monitor_get_display_name (output));
-
-  g_free (size);
-  return name;
-}
-
-static void
-ensure_output_numbers (CcDisplayPanel *self)
-{
-  GList *outputs, *l;
-  GList *sorted = NULL;
-  gint n = 0;
-
-  outputs = cc_display_config_get_monitors (self->priv->current_config);
-
-  for (l = outputs; l != NULL; l = l->next)
-    {
-      CcDisplayMonitor *output = l->data;
-      if (cc_display_monitor_is_builtin (output))
-        sorted = g_list_prepend (sorted, output);
-      else
-        sorted = g_list_append (sorted, output);
-    }
-
-  for (l = sorted; l != NULL; l = l->next)
-    {
-      CcDisplayMonitor *output = l->data;
-      gchar *ui_name = make_output_ui_name (output);
-      gboolean lid_is_closed = (cc_display_monitor_is_builtin (output) &&
-                                self->priv->lid_is_closed);
-
-      g_object_set_data (G_OBJECT (output), "ui-number", GINT_TO_POINTER (++n));
-      g_object_set_data_full (G_OBJECT (output), "ui-number-name",
-                              g_strdup_printf ("%d\u2003%s", n, ui_name),
-                              g_free);
-      g_object_set_data_full (G_OBJECT (output), "ui-name", ui_name, g_free);
-
-      g_object_set_data (G_OBJECT (output), "lid-is-closed", GINT_TO_POINTER (lid_is_closed));
-    }
-
-  g_object_set_data_full (G_OBJECT (self->priv->current_config), "ui-sorted-outputs",
-                          sorted, (GDestroyNotify) g_list_free);
-}
-
 static void
 monitor_labeler_hide (CcDisplayPanel *self)
 {
@@ -201,7 +143,7 @@ monitor_labeler_show (CcDisplayPanel *self)
   if (!priv->shell_proxy || !priv->current_config)
     return;
 
-  outputs = g_object_get_data (G_OBJECT (priv->current_config), "ui-sorted-outputs");
+  outputs = cc_display_config_get_ui_sorted_monitors (priv->current_config);
   if (!outputs)
     return;
 
@@ -215,7 +157,7 @@ monitor_labeler_show (CcDisplayPanel *self)
     {
       CcDisplayMonitor *output = l->data;
 
-      number = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (output), "ui-number"));
+      number = cc_display_monitor_get_ui_number (output);
       if (number == 0)
         continue;
 
@@ -1113,7 +1055,7 @@ make_single_output_ui (CcDisplayPanel *panel)
 
   vbox = make_main_vbox (priv->main_size_group);
 
-  frame = make_frame (g_object_get_data (G_OBJECT (priv->current_output), "ui-name"), NULL);
+  frame = make_frame (cc_display_monitor_get_ui_name (priv->current_output), NULL);
   gtk_container_add (GTK_CONTAINER (vbox), frame);
 
   gtk_container_add (GTK_CONTAINER (frame), make_output_ui (panel));
@@ -1170,32 +1112,6 @@ make_arrangement_row (CcDisplayPanel *panel)
   return row;
 }
 
-static gboolean
-is_output_useful (CcDisplayMonitor *output)
-{
-  return (cc_display_monitor_is_active (output) &&
-          !g_object_get_data (G_OBJECT (output), "lid-is-closed"));
-}
-
-static guint
-count_useful_outputs (CcDisplayPanel *panel)
-{
-  CcDisplayPanelPrivate *priv = panel->priv;
-  GList *outputs, *l;
-  guint active = 0;
-
-  outputs = cc_display_config_get_monitors (priv->current_config);
-  for (l = outputs; l != NULL; l = l->next)
-    {
-      CcDisplayMonitor *output = l->data;
-      if (!is_output_useful (output))
-        continue;
-      else
-        active++;
-    }
-  return active;
-}
-
 static void
 primary_chooser_sync (GtkPopover      *popover,
                       CcDisplayConfig *config)
@@ -1210,7 +1126,7 @@ primary_chooser_sync (GtkPopover      *popover,
       CcDisplayMonitor *output = l->data;
       if (cc_display_monitor_is_primary (output))
         {
-          gchar *text = g_object_get_data (G_OBJECT (output), "ui-number-name");
+          const gchar *text = cc_display_monitor_get_ui_number_name (output);
           gtk_label_set_text (GTK_LABEL (label), text);
           return;
         }
@@ -1234,7 +1150,7 @@ make_primary_chooser_popover (CcDisplayPanel *panel)
   GtkWidget *listbox;
   GList *outputs, *l;
 
-  outputs = g_object_get_data (G_OBJECT (priv->current_config), "ui-sorted-outputs");
+  outputs = cc_display_config_get_ui_sorted_monitors (priv->current_config);
 
   listbox = make_list_box ();
   g_object_set (listbox, "margin", 12, NULL);
@@ -1243,12 +1159,12 @@ make_primary_chooser_popover (CcDisplayPanel *panel)
     {
       CcDisplayMonitor *output = l->data;
       GtkWidget *row;
-      gchar *text;
+      const gchar *text;
 
-      if (!is_output_useful (output))
+      if (!cc_display_monitor_is_useful (output))
         continue;
 
-      text = g_object_get_data (G_OBJECT (output), "ui-number-name");
+      text = cc_display_monitor_get_ui_number_name (output);
       row = g_object_new (CC_TYPE_LIST_BOX_ROW,
                           "child", make_popover_label (text),
                           NULL);
@@ -1350,7 +1266,7 @@ make_two_output_chooser (CcDisplayPanel *panel)
   GtkRadioButton *group;
   GList *outputs, *l;
 
-  outputs = g_object_get_data (G_OBJECT (priv->current_config), "ui-sorted-outputs");
+  outputs = cc_display_config_get_ui_sorted_monitors (priv->current_config);
 
   box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_button_box_set_layout (GTK_BUTTON_BOX (box), GTK_BUTTONBOX_EXPAND);
@@ -1362,7 +1278,7 @@ make_two_output_chooser (CcDisplayPanel *panel)
       CcDisplayMonitor *output = l->data;
       GtkWidget *button = gtk_radio_button_new_from_widget (group);
 
-      gtk_button_set_label (GTK_BUTTON (button), g_object_get_data (G_OBJECT (output), "ui-name"));
+      gtk_button_set_label (GTK_BUTTON (button), cc_display_monitor_get_ui_name (output));
       gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
 
       g_object_set_data (G_OBJECT (button), "output", output);
@@ -1759,7 +1675,7 @@ make_two_output_ui (CcDisplayPanel *panel)
 
   if (cc_display_config_is_cloning (priv->current_config) && show_mirror)
     gtk_stack_set_visible_child_name (GTK_STACK (stack), "mirror");
-  else if (count_useful_outputs (panel) > 1)
+  else if (cc_display_config_count_useful_monitors (priv->current_config) > 1)
     gtk_stack_set_visible_child_name (GTK_STACK (stack), "join");
   else
     gtk_stack_set_visible_child_name (GTK_STACK (stack), "single");
@@ -1796,8 +1712,8 @@ make_output_switch (CcDisplayPanel *panel)
                            button, G_CONNECT_SWAPPED);
   output_switch_sync (button, priv->current_output);
 
-  if ((count_useful_outputs (panel) < 2 && cc_display_monitor_is_active (priv->current_output)) ||
-      (cc_display_monitor_is_builtin (priv->current_output) && priv->lid_is_closed))
+  if ((cc_display_config_count_useful_monitors (priv->current_config) < 2 && cc_display_monitor_is_active 
(priv->current_output)) ||
+      !cc_display_monitor_is_usable (priv->current_output))
     gtk_widget_set_sensitive (button, FALSE);
 
   return button;
@@ -1824,7 +1740,7 @@ static void
 output_chooser_sync (GtkWidget      *button,
                      CcDisplayPanel *panel)
 {
-  gchar *text = g_object_get_data (G_OBJECT (panel->priv->current_output), "ui-number-name");
+  const gchar *text = cc_display_monitor_get_ui_number_name (panel->priv->current_output);
   GtkWidget *label = gtk_bin_get_child (GTK_BIN (button));
 
   gtk_label_set_text (GTK_LABEL (label), text);
@@ -1837,7 +1753,7 @@ make_output_chooser_button (CcDisplayPanel *panel)
   GtkWidget *listbox, *button, *popover;
   GList *outputs, *l;
 
-  outputs = g_object_get_data (G_OBJECT (priv->current_config), "ui-sorted-outputs");
+  outputs = cc_display_config_get_ui_sorted_monitors (priv->current_config);
 
   listbox = make_list_box ();
 
@@ -1845,9 +1761,9 @@ make_output_chooser_button (CcDisplayPanel *panel)
     {
       CcDisplayMonitor *output = l->data;
       GtkWidget *row;
-      gchar *text;
+      const gchar *text;
 
-      text = g_object_get_data (G_OBJECT (output), "ui-number-name");
+      text = cc_display_monitor_get_ui_number_name (output);
       row = g_object_new (CC_TYPE_LIST_BOX_ROW,
                           "child", make_popover_label (text),
                           NULL);
@@ -1923,14 +1839,16 @@ reset_current_config (CcDisplayPanel *panel)
 
   priv->current_config = current;
 
-  ensure_output_numbers (panel);
-
-  outputs = g_object_get_data (G_OBJECT (current), "ui-sorted-outputs");
+  outputs = cc_display_config_get_ui_sorted_monitors (priv->current_config);
   for (l = outputs; l; l = l->next)
     {
       CcDisplayMonitor *output = l->data;
 
-      if (!is_output_useful (output))
+      /* Mark any builtin monitor as unusable if the lid is closed. */
+      if (cc_display_monitor_is_builtin (output) && priv->lid_is_closed)
+        cc_display_monitor_set_usable (output, FALSE);
+
+      if (!cc_display_monitor_is_useful (output))
         continue;
 
       priv->current_output = output;
@@ -1965,7 +1883,7 @@ on_screen_changed (CcDisplayPanel *panel)
   if (!priv->current_output)
     goto show_error;
 
-  outputs = g_object_get_data (G_OBJECT (priv->current_config), "ui-sorted-outputs");
+  outputs = cc_display_config_get_ui_sorted_monitors (priv->current_config);
   n_outputs = g_list_length (outputs);
   if (priv->lid_is_closed)
     {
@@ -2197,45 +2115,6 @@ get_frequency_string (CcDisplayMode *mode)
   return frequency;
 }
 
-static const double known_diagonals[] = {
-    12.1,
-    13.3,
-    15.6
-};
-
-static char *
-diagonal_to_str (double d)
-{
-    int i;
-
-    for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++)
-    {
-        double delta;
-
-        delta = fabs(known_diagonals[i] - d);
-        if (delta < 0.1)
-            return g_strdup_printf ("%0.1lf\"", known_diagonals[i]);
-    }
-
-    return g_strdup_printf ("%d\"", (int) (d + 0.5));
-}
-
-static char *
-make_display_size_string (int width_mm,
-                          int height_mm)
-{
-  char *inches = NULL;
-
-  if (width_mm > 0 && height_mm > 0)
-    {
-      double d = sqrt (width_mm * width_mm + height_mm * height_mm);
-
-      inches = diagonal_to_str (d / 25.4);
-    }
-
-  return inches;
-}
-
 static gboolean
 should_show_rotation (CcDisplayPanel *panel,
                       CcDisplayMonitor  *output)


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