summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Hlusiak <saschahlusiak@arcor.de>2008-08-23 23:31:33 +0200
committerSascha Hlusiak <saschahlusiak@arcor.de>2008-08-23 23:31:33 +0200
commit0410505147a416844fae6dcf6f9ea782f1b74863 (patch)
tree30c4ec17e9c4698020f4f743f950c2d2432aeb53
parente64b4ebcd121a9080d1da39e5037182df7edfdbb (diff)
Expose device properties for mouse_enabled, keys_enabled and axes deadzones.
Deadzones takes up to MAXAXES 32 bit numbers. If only one value is supplied, it is applied to all axes the same. If multiple values are supplied, they are applied to the axis they stand for, all other values are untouched.
-rw-r--r--src/jstk_properties.c98
1 files changed, 92 insertions, 6 deletions
diff --git a/src/jstk_properties.c b/src/jstk_properties.c
index 5cc223b..1ff3613 100644
--- a/src/jstk_properties.c
+++ b/src/jstk_properties.c
@@ -42,7 +42,17 @@
#define JSTK_PROP_DEBUGLEVEL "Debug Level"
-static Atom prop_debuglevel = 0;
+static Atom prop_debuglevel = 0; /* 8 bit, 0..20 */
+
+#define JSTK_PROP_MOUSE_ENABLED "Generate Mouse Events"
+static Atom prop_mouse_enabled = 0; /* 8 bit, 0 or 1 */
+
+#define JSTK_PROP_KEYS_ENABLED "Generate Key Events"
+static Atom prop_keys_enabled = 0; /* 8 bit, 0 or 1 */
+
+#define JSTK_PROP_DEADZONES "Axes Deadzones"
+static Atom prop_deadzones = 0; /* 32 bit, 0..30000 for each axis*/
+
@@ -51,11 +61,51 @@ jstkSetProperty(DeviceIntPtr pJstk, Atom atom, XIPropertyValuePtr val)
{
InputInfoPtr pInfo = pJstk->public.devicePrivate;
JoystickDevPtr priv = pInfo->private;
+ int i;
if (atom == prop_debuglevel)
{
+#if DEBUG
+ if (val->size != 1 || val->format != 8 || val->type != XA_INTEGER)
+ return FALSE;
debug_level = *((INT8*)val->data);
-
+ ErrorF("JOYSTICK: DebugLevel set to %d\n", debug_level);
+#endif
+ }else if (atom == prop_mouse_enabled)
+ {
+ if (val->size != 1 || val->format != 8 || val->type != XA_INTEGER)
+ return FALSE;
+ priv->mouse_enabled = (*((INT8*)val->data)) != 0;
+ DBG(1, ErrorF("mouse_enabled set to %d\n", priv->mouse_enabled));
+ }else if (atom == prop_keys_enabled)
+ {
+ if (val->size != 1 || val->format != 8 || val->type != XA_INTEGER)
+ return FALSE;
+ priv->keys_enabled = (*((INT8*)val->data)) != 0;
+ DBG(1, ErrorF("keys_enabled set to %d\n", priv->keys_enabled));
+ }else if (atom == prop_deadzones)
+ {
+ if (val->size > MAXAXES || val->format != 32 || val->type != XA_INTEGER)
+ return FALSE;
+ if (val->size == 1) { /* Single value to be applied to all axes */
+ INT32 value;
+ value = *((INT32*)val->data);
+ if (value < 0) value = (-value);
+ if (value > 30000) return FALSE;
+ for (i =0; i<MAXAXES; i++)
+ priv->axis[i].deadzone = value;
+ DBG(1, ErrorF("Deadzone of all axes set to %d\n",value));
+ } else { /* Apply supplied values to axes beginning with the first */
+ INT32 *values;
+ values = (INT32*)val->data;
+ for (i =0; i<val->size; i++) /* Fail, if one value is out of range */
+ if (values[i] > 30000 || values[i] < -30000)
+ return FALSE;
+ for (i =0; i<val->size; i++) {
+ priv->axis[i].deadzone = (values[i]<0)?(-values[i]):(values[i]);
+ DBG(1, ErrorF("Deadzone of axis %d set to %d\n",i, priv->axis[i].deadzone));
+ }
+ }
}
@@ -73,18 +123,54 @@ jstkGetProperty(DeviceIntPtr pJstk, Atom property)
Bool
jstkInitProperties(DeviceIntPtr pJstk, JoystickDevPtr priv)
{
- int rc = TRUE;
+ int axes_values[MAXAXES];
+ INT32 values[32]; /* We won't tell about properties with
+ more than 32 possible values */
+ int i;
XIRegisterPropertyHandler(pJstk, jstkSetProperty, jstkGetProperty);
+#ifdef DEBUG
/* Debug Level */
prop_debuglevel = MakeAtom(JSTK_PROP_DEBUGLEVEL, strlen(JSTK_PROP_DEBUGLEVEL), TRUE);
- rc = XIChangeDeviceProperty(pJstk, prop_debuglevel, XA_INTEGER, 8,
+ XIChangeDeviceProperty(pJstk, prop_debuglevel, XA_INTEGER, 8,
PropModeReplace, 1,
&debug_level,
FALSE, FALSE, FALSE);
- if (rc != Success)
- return;
+#endif
+
+
+ /* priv->mouse_enabled */
+ prop_mouse_enabled = MakeAtom(JSTK_PROP_MOUSE_ENABLED, strlen(JSTK_PROP_MOUSE_ENABLED), TRUE);
+ XIChangeDeviceProperty(pJstk, prop_mouse_enabled, XA_INTEGER, 8,
+ PropModeReplace, 1,
+ &priv->mouse_enabled,
+ FALSE, FALSE, FALSE);
+ values[0] = 0;
+ values[1] = 1;
+ XIConfigureDeviceProperty(pJstk, prop_mouse_enabled, FALSE, FALSE, FALSE, 2, values);
+
+
+ /* priv->keys_enabled */
+ prop_keys_enabled = MakeAtom(JSTK_PROP_KEYS_ENABLED, strlen(JSTK_PROP_KEYS_ENABLED), TRUE);
+ XIChangeDeviceProperty(pJstk, prop_keys_enabled, XA_INTEGER, 8,
+ PropModeReplace, 1,
+ &priv->keys_enabled,
+ FALSE, FALSE, FALSE);
+ values[0] = 0;
+ values[1] = 1;
+ XIConfigureDeviceProperty(pJstk, prop_mouse_enabled, FALSE, FALSE, FALSE, 2, values);
+
+
+ /* priv->axis[].deadzone */
+ for (i=0;i<MAXAXES;i++)
+ axes_values[i] = priv->axis[i].deadzone;
+ prop_deadzones = MakeAtom(JSTK_PROP_DEADZONES, strlen(JSTK_PROP_DEADZONES), TRUE);
+ XIChangeDeviceProperty(pJstk, prop_deadzones, XA_INTEGER, 32,
+ PropModeReplace, MAXAXES,
+ axes_values,
+ FALSE, FALSE, FALSE);
+
return TRUE;