[gnome-settings-daemon] common: Add X property setting helper
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] common: Add X property setting helper
- Date: Tue, 31 May 2011 11:30:45 +0000 (UTC)
commit f1e81e32ecfd9108629c13a2e8d24e64a1869ed8
Author: Bastien Nocera <hadess hadess net>
Date: Tue May 31 12:03:50 2011 +0100
common: Add X property setting helper
From the wacom plugin, thanks Peter.
plugins/common/gsd-input-helper.c | 51 +++++++++++++++++++++++++++++++++++++
plugins/common/gsd-input-helper.h | 27 ++++++++++++++++---
2 files changed, 74 insertions(+), 4 deletions(-)
---
diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c
index 7215b48..07c2b92 100644
--- a/plugins/common/gsd-input-helper.c
+++ b/plugins/common/gsd-input-helper.c
@@ -35,6 +35,57 @@ typedef gboolean (* InfoIdentifyFunc) (XDeviceInfo *device_info);
typedef gboolean (* DeviceIdentifyFunc) (XDevice *xdevice);
gboolean
+device_set_property (XDevice *xdevice,
+ const char *device_name,
+ PropertyHelper *property)
+{
+ int rc;
+ Atom prop;
+ Atom realtype;
+ int realformat;
+ unsigned long nitems, bytes_after;
+ unsigned char *data;
+
+ prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ property->name, False);
+ if (!prop)
+ return FALSE;
+
+ gdk_error_trap_push ();
+
+ rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ xdevice, prop, 0, property->nitems, False,
+ XA_INTEGER, &realtype, &realformat, &nitems,
+ &bytes_after, &data);
+
+ if (rc == Success && realtype == XA_INTEGER &&
+ realformat == property->format && nitems >= property->nitems) {
+ int i;
+ for (i = 0; i < nitems; i++) {
+ switch (property->format) {
+ case 8:
+ data[i] = property->data.c[i];
+ break;
+ case 32:
+ ((long*)data)[i] = property->data.i[i];
+ break;
+ }
+ }
+
+ XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ xdevice, prop, XA_INTEGER, realformat,
+ PropModeReplace, data, nitems);
+ }
+
+ if (gdk_error_trap_pop ()) {
+ g_warning ("Error in setting \"%s\" for \"%s\"", property->name, device_name);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
supports_xinput_devices (void)
{
gint op_code, event, error;
diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h
index 6f405d0..727ed90 100644
--- a/plugins/common/gsd-input-helper.h
+++ b/plugins/common/gsd-input-helper.h
@@ -28,11 +28,26 @@ G_BEGIN_DECLS
#include <X11/extensions/XIproto.h>
typedef enum {
- COMMAND_DEVICE_ADDED,
- COMMAND_DEVICE_REMOVED,
- COMMAND_DEVICE_PRESENT
+ COMMAND_DEVICE_ADDED,
+ COMMAND_DEVICE_REMOVED,
+ COMMAND_DEVICE_PRESENT
} CustomCommand;
+/* Generic property setting code. Fill up the struct property with the property
+ * data and pass it into device_set_property together with the device to be
+ * changed. Note: doesn't cater for non-zero offsets yet, but we don't have
+ * any settings that require that.
+ */
+typedef struct {
+ const char *name; /* property name */
+ gint nitems; /* number of items in data */
+ gint format; /* CARD8 or CARD32 sized-items */
+ union {
+ const gchar *c; /* 8 bit data */
+ const gint *i; /* 32 bit data */
+ } data;
+} PropertyHelper;
+
gboolean supports_xinput_devices (void);
gboolean device_is_touchpad (XDevice *xdevice);
@@ -42,8 +57,12 @@ gboolean device_info_is_touchscreen (XDeviceInfo *device_info);
gboolean touchpad_is_present (void);
gboolean touchscreen_is_present (void);
+gboolean device_set_property (XDevice *xdevice,
+ const char *device_name,
+ PropertyHelper *property);
+
gboolean run_custom_command (GdkDevice *device,
- CustomCommand command);
+ CustomCommand command);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]