[gnome-desktop/randr-connector-type: 2/3] Add gnome_rr_output_is_laptop()



commit f9e4d4e7017b97204502dc89356d85e121ca41cd
Author: Federico Mena Quintero <federico novell com>
Date:   Fri Feb 19 14:20:53 2010 -0600

    Add gnome_rr_output_is_laptop()
    
    Detecting a laptop's built-in LCD takes some trickery, so we now
    have a function to do it.
    
    You would think that all versions of RANDR would make this easy,
    but noooooo, why cater to userspace's needs when you can just
    throw together APIs without ever thinking of how people may
    need to use them.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 libgnome-desktop/gnome-rr.c            |   30 ++++++++++++++++++++++++++++++
 libgnome-desktop/libgnomeui/gnome-rr.h |    1 +
 2 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/gnome-rr.c b/libgnome-desktop/gnome-rr.c
index 7888db8..9fe862b 100644
--- a/libgnome-desktop/gnome-rr.c
+++ b/libgnome-desktop/gnome-rr.c
@@ -1085,6 +1085,36 @@ gnome_rr_output_get_connector_type (GnomeRROutput *output)
     return output->connector_type;
 }
 
+gboolean
+gnome_rr_output_is_laptop (GnomeRROutput *output)
+{
+    const char *connector_type;
+
+    g_return_val_if_fail (output != NULL, FALSE);
+
+    if (!output->connected)
+	return FALSE;
+
+    /* The ConnectorType property is present in RANDR 1.3 and greater */
+
+    connector_type = gnome_rr_output_get_connector_type (output);
+    if (connector_type && strcmp (connector_type, GNOME_RR_CONNECTOR_TYPE_PANEL) == 0)
+	return TRUE;
+
+    /* Older versions of RANDR - this is a best guess, as @#$% RANDR doesn't have standard output names,
+     * so drivers can use whatever they like.
+     */
+
+    if (output->name
+	&& (strstr (output->name, "lvds") ||  /* Most drivers use an "LVDS" prefix... */
+	    strstr (output->name, "LVDS") ||
+	    strstr (output->name, "Lvds") ||
+	    strstr (output->name, "LCD")))    /* ... but fglrx uses "LCD" in some versions.  Shoot me now, kthxbye. */
+	return TRUE;
+
+    return FALSE;
+}
+
 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 c67a94f..0cdf19e 100644
--- a/libgnome-desktop/libgnomeui/gnome-rr.h
+++ b/libgnome-desktop/libgnomeui/gnome-rr.h
@@ -112,6 +112,7 @@ GnomeRRCrtc **  gnome_rr_output_get_possible_crtcs (GnomeRROutput         *outpu
 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);
+gboolean        gnome_rr_output_is_laptop          (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]