From 35e0982e35bd98f6f318e4ef5342c21f5701c1ac Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 19 Aug 2014 11:02:33 -0400 Subject: [PATCH] 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 + .../x11/meta-monitor-manager-xrandr.c | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 61f67e26a..4b2e0e388 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 a751d6d92..d7729e1d8 100644 --- a/src/backends/x11/meta-monitor-manager-xrandr.c +++ b/src/backends/x11/meta-monitor-manager-xrandr.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include "meta-backend-x11.h" #include @@ -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); - if (!info->range || info->num_values != 2) + /* This can happen on systems without backlights. */ + if (reply == NULL) + return; + + 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