[mutter] input-settings-x11: Factor out a get_property() helper
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] input-settings-x11: Factor out a get_property() helper
- Date: Fri, 8 May 2015 15:51:23 +0000 (UTC)
commit 7d1b593fbd85a6fc9a60cfe991a4bfa92717f778
Author: Rui Matos <tiagomatos gmail com>
Date: Fri May 8 17:31:48 2015 +0200
input-settings-x11: Factor out a get_property() helper
We'll need to get the value of some properties. Fail if the number of
items returned is less than we expect and warn if it exceeds it so
that we can easily find out if items are added to a property later and
fix it.
src/backends/x11/meta-input-settings-x11.c | 49 ++++++++++++++++++++++------
1 files changed, 39 insertions(+), 10 deletions(-)
---
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
index d0a3440..6ef219f 100644
--- a/src/backends/x11/meta-input-settings-x11.c
+++ b/src/backends/x11/meta-input-settings-x11.c
@@ -35,6 +35,38 @@
G_DEFINE_TYPE (MetaInputSettingsX11, meta_input_settings_x11, META_TYPE_INPUT_SETTINGS)
+static void *
+get_property (ClutterInputDevice *device,
+ const gchar *property,
+ Atom type,
+ int format,
+ gulong nitems)
+{
+ MetaBackend *backend = meta_get_backend ();
+ Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
+ gulong nitems_ret, bytes_after_ret;
+ int rc, device_id, format_ret;
+ Atom property_atom, type_ret;
+ guchar *data_ret = NULL;
+
+ property_atom = XInternAtom (xdisplay, property, False);
+ device_id = clutter_input_device_get_device_id (device);
+
+ rc = XIGetProperty (xdisplay, device_id, property_atom,
+ 0, 10, False, type, &type_ret, &format_ret,
+ &nitems_ret, &bytes_after_ret, &data_ret);
+ if (rc == Success && type_ret == type && format_ret == format && nitems_ret >= nitems)
+ {
+ if (nitems_ret > nitems)
+ g_warning ("Property '%s' for device '%s' returned %lu items, expected %lu",
+ property, clutter_input_device_get_device_name (device), nitems_ret, nitems);
+ return data_ret;
+ }
+
+ meta_XFree (data_ret);
+ return NULL;
+}
+
static void
change_property (ClutterInputDevice *device,
const gchar *property,
@@ -45,23 +77,20 @@ change_property (ClutterInputDevice *device,
{
MetaBackend *backend = meta_get_backend ();
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- gulong nitems_ret, bytes_after_ret;
- int rc, device_id, format_ret;
- Atom property_atom, type_ret;
+ int device_id;
+ Atom property_atom;
guchar *data_ret;
property_atom = XInternAtom (xdisplay, property, False);
device_id = clutter_input_device_get_device_id (device);
- rc = XIGetProperty (xdisplay, device_id, property_atom,
- 0, 0, False, type, &type_ret, &format_ret,
- &nitems_ret, &bytes_after_ret, &data_ret);
+ data_ret = get_property (device, property, type, format, nitems);
+ if (!data_ret)
+ return;
+ XIChangeProperty (xdisplay, device_id, property_atom, type,
+ format, XIPropModeReplace, data, nitems);
meta_XFree (data_ret);
-
- if (rc == Success && type_ret == type && format_ret == format)
- XIChangeProperty (xdisplay, device_id, property_atom, type,
- format, XIPropModeReplace, data, nitems);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]