[mutter] xrandr: Port some checks to XCB so we don't have to deal with BadName



commit 35e0982e35bd98f6f318e4ef5342c21f5701c1ac
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Aug 19 11:02:33 2014 -0400

    xrandr: Port some checks to XCB so we don't have to deal with BadName
    
    RandR's QueryOutputProperty request makes the incredible decision of
    throwing a BadName if you pass a property that doesn't exist, which
    means that trying to check if a property exists is a royal pain when
    using Xlib.
    
    XCB's interface is much more friendly about errors and not having global
    state and things like that, so use that instead to query our backlight
    property.

 configure.ac                                   |    1 +
 src/backends/x11/meta-monitor-manager-xrandr.c |   32 ++++++++++++++---------
 2 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 61f67e2..4b2e0e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,7 @@ MUTTER_PC_MODULES="
    xkbfile
    xkeyboard-config
    xkbcommon-x11
+   xcb-randr
 "
 
 GLIB_GSETTINGS
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
index a751d6d..d7729e1 100644
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
@@ -35,6 +35,8 @@
 #include <X11/Xatom.h>
 #include <X11/extensions/Xrandr.h>
 #include <X11/extensions/dpms.h>
+#include <X11/Xlib-xcb.h>
+#include <xcb/randr.h>
 
 #include "meta-backend-x11.h"
 #include <meta/main.h>
@@ -214,30 +216,34 @@ output_get_backlight_limits_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
                                     MetaOutput               *output)
 {
   Atom atom;
-  XRRPropertyInfo *info;
+  xcb_connection_t *xcb_conn;
+  xcb_randr_query_output_property_reply_t *reply;
 
   atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
-  info = XRRQueryOutputProperty (manager_xrandr->xdisplay,
-                                 (XID)output->winsys_id,
-                                 atom);
 
-  if (info == NULL)
-    {
-      meta_verbose ("could not get output property for %s\n", output->name);
-      return;
-    }
+  xcb_conn = XGetXCBConnection (manager_xrandr->xdisplay);
+  reply = xcb_randr_query_output_property_reply (xcb_conn,
+                                                 xcb_randr_query_output_property (xcb_conn,
+                                                                                  (xcb_randr_output_t) 
output->winsys_id,
+                                                                                  (xcb_atom_t) atom),
+                                                 NULL);
+
+  /* This can happen on systems without backlights. */
+  if (reply == NULL)
+    return;
 
-  if (!info->range || info->num_values != 2)
+  if (!reply->range || reply->length != 2)
     {
       meta_verbose ("backlight %s was not range\n", output->name);
       goto out;
     }
 
-  output->backlight_min = info->values[0];
-  output->backlight_max = info->values[1];
+  int32_t *values = xcb_randr_query_output_property_valid_values (reply);
+  output->backlight_min = values[0];
+  output->backlight_max = values[1];
 
 out:
-  XFree (info);
+  free (reply);
 }
 
 static int


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