[gnome-desktop/randr-connector-type: 1/3] Add gnome_rr_output_get_connector_type()



commit 6f57fded4ab4a409795c8d97f998dbefe8998db9
Author: Federico Mena Quintero <federico novell com>
Date:   Fri Feb 19 14:18:43 2010 -0600

    Add gnome_rr_output_get_connector_type()
    
    We will need this to identify a laptop's built-in LCD robustly when
    RANDR 1.3 is present.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 libgnome-desktop/gnome-rr-private.h    |    2 +
 libgnome-desktop/gnome-rr.c            |   53 +++++++++++++++++++++++++++++++-
 libgnome-desktop/libgnomeui/gnome-rr.h |    3 ++
 3 files changed, 57 insertions(+), 1 deletions(-)
---
diff --git a/libgnome-desktop/gnome-rr-private.h b/libgnome-desktop/gnome-rr-private.h
index c968291..15ba4a2 100644
--- a/libgnome-desktop/gnome-rr-private.h
+++ b/libgnome-desktop/gnome-rr-private.h
@@ -38,6 +38,8 @@ struct GnomeRRScreen
     
     GnomeRRScreenChanged	callback;
     gpointer			data;
+
+    Atom                        connector_type_atom;
 };
 
 #endif
diff --git a/libgnome-desktop/gnome-rr.c b/libgnome-desktop/gnome-rr.c
index 6f23fbb..7888db8 100644
--- a/libgnome-desktop/gnome-rr.c
+++ b/libgnome-desktop/gnome-rr.c
@@ -54,6 +54,7 @@ struct GnomeRROutput
     GnomeRRMode **	modes;
     int			n_preferred;
     guint8 *		edid_data;
+    char *              connector_type;
 };
 
 struct GnomeRROutputWrap
@@ -623,6 +624,7 @@ gnome_rr_screen_new (GdkScreen *gdk_screen,
 	screen->xroot = gdk_x11_drawable_get_xid (screen->gdk_root);
 	screen->xdisplay = dpy;
 	screen->xscreen = gdk_x11_screen_get_xscreen (screen->gdk_screen);
+	screen->connector_type_atom = XInternAtom (dpy, "ConnectorType", FALSE);
 	
 	screen->callback = callback;
 	screen->data = data;
@@ -904,6 +906,44 @@ read_edid_data (GnomeRROutput *output)
     return NULL;
 }
 
+static char *
+get_connector_type_string (GnomeRROutput *output)
+{
+    char *result;
+    unsigned char *prop;
+    int actual_format;
+    unsigned long nitems, bytes_after;
+    Atom actual_type;
+    Atom connector_type;
+    char *connector_type_str;
+
+    result = NULL;
+
+    if (XRRGetOutputProperty (DISPLAY (output), output->id, output->info->screen->connector_type_atom,
+			      0, 100, False, False,
+			      AnyPropertyType,
+			      &actual_type, &actual_format,
+			      &nitems, &bytes_after, &prop) != Success)
+	return NULL;
+
+    if (!(actual_type == XA_ATOM && actual_format == 32 && nitems == 1))
+	goto out;
+
+    connector_type = *((Atom *) prop);
+
+    connector_type_str = XGetAtomName (DISPLAY (output), connector_type);
+    if (connector_type_str) {
+	result = g_strdup (connector_type_str); /* so the caller can g_free() it */
+	XFree (connector_type_str);
+    }
+
+    XFree (prop);
+
+out:
+
+    return result;
+}
+
 static gboolean
 output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **error)
 {
@@ -931,7 +971,8 @@ output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **erro
     output->width_mm = info->mm_width;
     output->height_mm = info->mm_height;
     output->connected = (info->connection == RR_Connected);
-    
+    output->connector_type = get_connector_type_string (output);
+
     /* Possible crtcs */
     a = g_ptr_array_new ();
     
@@ -987,6 +1028,7 @@ output_free (GnomeRROutput *output)
     g_free (output->possible_crtcs);
     g_free (output->edid_data);
     g_free (output->name);
+    g_free (output->connector_type);
     g_free (output);
 }
 
@@ -1034,6 +1076,15 @@ gnome_rr_output_get_crtc (GnomeRROutput *output)
     return output->current_crtc;
 }
 
+/* Returns NULL if the ConnectorType property is not available */
+const char *
+gnome_rr_output_get_connector_type (GnomeRROutput *output)
+{
+    g_return_val_if_fail (output != NULL, NULL);
+
+    return output->connector_type;
+}
+
 GnomeRRMode *
 gnome_rr_output_get_current_mode (GnomeRROutput *output)
 {
diff --git a/libgnome-desktop/libgnomeui/gnome-rr.h b/libgnome-desktop/libgnomeui/gnome-rr.h
index c43bd8f..c67a94f 100644
--- a/libgnome-desktop/libgnomeui/gnome-rr.h
+++ b/libgnome-desktop/libgnomeui/gnome-rr.h
@@ -63,6 +63,8 @@ typedef enum {
     GNOME_RR_ERROR_NO_MATCHING_CONFIG,	/* none of the saved configurations matched the current configuration */
 } GnomeRRError;
 
+#define GNOME_RR_CONNECTOR_TYPE_PANEL "Panel"  /* This is a laptop's built-in LCD */
+
 /* GnomeRRScreen */
 GnomeRRScreen * gnome_rr_screen_new                (GdkScreen             *screen,
 						    GnomeRRScreenChanged   callback,
@@ -109,6 +111,7 @@ const guint8 *  gnome_rr_output_get_edid_data      (GnomeRROutput         *outpu
 GnomeRRCrtc **  gnome_rr_output_get_possible_crtcs (GnomeRROutput         *output);
 GnomeRRMode *   gnome_rr_output_get_current_mode   (GnomeRROutput         *output);
 GnomeRRCrtc *   gnome_rr_output_get_crtc           (GnomeRROutput         *output);
+const char *    gnome_rr_output_get_connector_type (GnomeRROutput         *output);
 void            gnome_rr_output_get_position       (GnomeRROutput         *output,
 						    int                   *x,
 						    int                   *y);



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