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.
This commit is contained in:
Jasper St. Pierre 2014-08-19 11:02:33 -04:00
parent 767455e8d8
commit 35e0982e35
2 changed files with 20 additions and 13 deletions

View File

@ -87,6 +87,7 @@ MUTTER_PC_MODULES="
xkbfile xkbfile
xkeyboard-config xkeyboard-config
xkbcommon-x11 xkbcommon-x11
xcb-randr
" "
GLIB_GSETTINGS GLIB_GSETTINGS

View File

@ -35,6 +35,8 @@
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include <X11/extensions/dpms.h> #include <X11/extensions/dpms.h>
#include <X11/Xlib-xcb.h>
#include <xcb/randr.h>
#include "meta-backend-x11.h" #include "meta-backend-x11.h"
#include <meta/main.h> #include <meta/main.h>
@ -214,30 +216,34 @@ output_get_backlight_limits_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
MetaOutput *output) MetaOutput *output)
{ {
Atom atom; Atom atom;
XRRPropertyInfo *info; xcb_connection_t *xcb_conn;
xcb_randr_query_output_property_reply_t *reply;
atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False); atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
info = XRRQueryOutputProperty (manager_xrandr->xdisplay,
(XID)output->winsys_id,
atom);
if (info == NULL) xcb_conn = XGetXCBConnection (manager_xrandr->xdisplay);
{ reply = xcb_randr_query_output_property_reply (xcb_conn,
meta_verbose ("could not get output property for %s\n", output->name); xcb_randr_query_output_property (xcb_conn,
return; (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); meta_verbose ("backlight %s was not range\n", output->name);
goto out; goto out;
} }
output->backlight_min = info->values[0]; int32_t *values = xcb_randr_query_output_property_valid_values (reply);
output->backlight_max = info->values[1]; output->backlight_min = values[0];
output->backlight_max = values[1];
out: out:
XFree (info); free (reply);
} }
static int static int