[gnome-desktop] gnome-rr: add a way to get the display name from the RROutput



commit e1ce0a63923f27282b6c9cd2211482166b0b821e
Author: William Jon McCann <jmccann redhat com>
Date:   Thu Feb 14 10:41:18 2013 -0500

    gnome-rr: add a way to get the display name from the RROutput

 libgnome-desktop/display-name.c |   16 ++++++++++++
 libgnome-desktop/edid.h         |    1 +
 libgnome-desktop/gnome-rr.c     |   49 +++++++++++++++++++++++++++++++++++++++
 libgnome-desktop/gnome-rr.h     |    1 +
 4 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/display-name.c b/libgnome-desktop/display-name.c
index 3e51bce..7c9ff28 100644
--- a/libgnome-desktop/display-name.c
+++ b/libgnome-desktop/display-name.c
@@ -73,6 +73,22 @@ diagonal_to_str (double d)
 }
 
 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;
+}
+
+char *
 make_display_name (const MonitorInfo *info)
 {
     const char *vendor;
diff --git a/libgnome-desktop/edid.h b/libgnome-desktop/edid.h
index 234d966..84a6893 100644
--- a/libgnome-desktop/edid.h
+++ b/libgnome-desktop/edid.h
@@ -190,5 +190,6 @@ struct MonitorInfo
 
 MonitorInfo *decode_edid (const uchar *data);
 char *make_display_name (const MonitorInfo *info);
+char *make_display_size_string (int width_mm, int height_mm);
 
 #endif
diff --git a/libgnome-desktop/gnome-rr.c b/libgnome-desktop/gnome-rr.c
index 3d4813c..f652325 100644
--- a/libgnome-desktop/gnome-rr.c
+++ b/libgnome-desktop/gnome-rr.c
@@ -69,6 +69,7 @@ struct GnomeRROutput
     RROutput           id;
     
     char *             name;
+    char *             display_name;
     GnomeRRCrtc *      current_crtc;
     gboolean           connected;
     gulong             width_mm;
@@ -1582,6 +1583,7 @@ output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **erro
     }
     
     output->name = g_strdup (info->name); /* FIXME: what is nameLen used for? */
+    output->display_name = NULL; /* set first time the getter is used */
     output->current_crtc = crtc_by_id (output->info, info->crtc);
     output->width_mm = info->mm_width;
     output->height_mm = info->mm_height;
@@ -1695,6 +1697,7 @@ output_free (GnomeRROutput *output)
     g_free (output->possible_crtcs);
     g_free (output->edid_data);
     g_free (output->name);
+    g_free (output->display_name);
     g_free (output->connector_type);
     g_slice_free (GnomeRROutput, output);
 }
@@ -1744,6 +1747,52 @@ gnome_rr_output_get_ids_from_edid (GnomeRROutput         *output,
 
 }
 
+static void
+ensure_display_name (GnomeRROutput *output)
+{
+    if (output->display_name != NULL)
+        return;
+
+    if (gnome_rr_output_is_laptop (output))
+        output->display_name = g_strdup (_("Laptop"));
+
+    if (output->display_name == NULL
+        && output->edid_data != NULL) {
+        MonitorInfo *info;
+
+        info = decode_edid (output->edid_data);
+        if (info != NULL)
+            output->display_name = make_display_name (info);
+
+        g_free (info);
+    }
+
+    if (output->display_name == NULL) {
+        char *inches;
+        inches = make_display_size_string (output->width_mm, output->height_mm);
+        if (inches != NULL) {
+            /* Translators: %s is the size of the monitor in inches */
+            output->display_name = g_strdup_printf (_("%s Display"), inches);
+        }
+        g_free (inches);
+    }
+
+    /* last chance on the stairway */
+    if (output->display_name == NULL) {
+      output->display_name = g_strdup (_("Unknown Display"));
+    }
+}
+
+const char *
+gnome_rr_output_get_display_name (GnomeRROutput *output)
+{
+    g_return_val_if_fail (output != NULL, NULL);
+
+    ensure_display_name (output);
+
+    return output->display_name;
+}
+
 /**
  * gnome_rr_output_get_backlight_min:
  *
diff --git a/libgnome-desktop/gnome-rr.h b/libgnome-desktop/gnome-rr.h
index c73eaa1..776869f 100644
--- a/libgnome-desktop/gnome-rr.h
+++ b/libgnome-desktop/gnome-rr.h
@@ -148,6 +148,7 @@ gboolean        gnome_rr_screen_set_dpms_mode      (GnomeRRScreen         *scree
 /* GnomeRROutput */
 guint32         gnome_rr_output_get_id             (GnomeRROutput         *output);
 const char *    gnome_rr_output_get_name           (GnomeRROutput         *output);
+const char *    gnome_rr_output_get_display_name   (GnomeRROutput         *output);
 gboolean        gnome_rr_output_is_connected       (GnomeRROutput         *output);
 int             gnome_rr_output_get_size_inches    (GnomeRROutput         *output);
 int             gnome_rr_output_get_width_mm       (GnomeRROutput         *outout);


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