summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Matos <tiagomatos@gmail.com>2015-05-08 17:31:48 +0200
committerRui Matos <tiagomatos@gmail.com>2015-05-08 17:44:57 +0200
commit7d1b593fbd85a6fc9a60cfe991a4bfa92717f778 (patch)
treeb61994704ff70ec139d2d5f42325c1d7e4d2f440
parentd6a7559750b0c849979f279f3219c86ffb10a064 (diff)
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.
-rw-r--r--src/backends/x11/meta-input-settings-x11.c49
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 d0a34402..6ef219ff 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