[PATCH 5/6] dix: add property support for pointer acceleration.

Peter Hutterer peter.hutterer at who-t.net
Thu Dec 4 22:42:37 PST 2008


From: Simon Thum <simon.thum at gmx.de>

Note: properties don't need to be cleaned up, the DIX does it for us anyway.
Data that is stored in properties is cleaned up by the property system.
Handlers, etc. don't need to be unregistered while cleaning up, as they get
deleted when the device is removed anyway.

Signed-off-by: Peter Hutterer <peter.hutterer at redhat.com>
---
 Xi/xiproperty.c              |    6 +-
 dix/devices.c                |   10 ++
 dix/ptrveloc.c               |  206 +++++++++++++++++++++++++++++++++++++++++-
 include/ptrveloc.h           |    4 +
 include/xserver-properties.h |   12 +++
 5 files changed, 235 insertions(+), 3 deletions(-)

diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index cdfa25f..b2c5314 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -50,7 +50,11 @@ static struct dev_properties
     char *name;
 } dev_properties[] = {
     {0, XI_PROP_ENABLED},
-    {0, XATOM_FLOAT}
+    {0, XATOM_FLOAT},
+    {0, ACCEL_PROP_PROFILE_NUMBER},
+    {0, ACCEL_PROP_CONSTANT_DECELERATION},
+    {0, ACCEL_PROP_ADAPTIVE_DECELERATION},
+    {0, ACCEL_PROP_VELOCITY_SCALING}
 };
 
 static long XIPropHandlerID = 1;
diff --git a/dix/devices.c b/dix/devices.c
index 7634668..caf2e8e 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1315,6 +1315,16 @@ InitPointerAccelerationScheme(DeviceIntPtr dev,
     val->accelScheme = pointerAccelerationScheme[i];
     val->accelScheme.accelData = data;
 
+    /* post-init scheme */
+    switch(scheme){
+        case PtrAccelPredictable:
+            InitializePredictableAccelerationProperties(dev);
+            break;
+
+        default:
+            break;
+    }
+
     return TRUE;
 }
 
diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 95a7c71..60e412e 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -29,9 +29,13 @@
 #include <math.h>
 #include <ptrveloc.h>
 #include <inputstr.h>
+#include <exevents.h>
+#include <X11/Xatom.h>
 #include <assert.h>
 #include <os.h>
 
+#include <xserver-properties.h>
+
 /*****************************************************************************
  * Predictable pointer acceleration
  *
@@ -52,8 +56,8 @@
  *      which returns an acceleration
  *      for a given velocity
  *
- *  The profile can be selected by the user (potentially at runtime).
- *  the classic profile is intended to cleanly perform old-style
+ *  The profile can be selected by the user at runtime.
+ *  The classic profile is intended to cleanly perform old-style
  *  function selection (threshold =/!= 0)
  *
  ****************************************************************************/
@@ -137,6 +141,204 @@ AccelerationDefaultCleanup(DeviceIntPtr pDev)
     }
 }
 
+
+/*************************
+ * Input property support
+ ************************/
+
+/* ACCEL_PROP_PROFILE_NUMBER,
+ *            CONSTANT_DECELERATION,
+ *            ADAPTIVE_DECELERATION,
+ *            VELOCITY_SCALING */
+static int prop_handler_ids[4];
+
+/**
+ * choose profile
+ */
+static int
+AccelSetProfileProperty(DeviceIntPtr dev, Atom atom,
+                        XIPropertyValuePtr val, BOOL checkOnly)
+{
+    DeviceVelocityPtr pVel;
+    int profile, *ptr = &profile;
+    int rc;
+
+    if (atom != XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER))
+        return Success;
+
+    pVel = GetDevicePredictableAccelData(dev);
+    rc = XIPropToInt(val, &ptr);
+
+    if(checkOnly)
+    {
+        if (rc)
+            return rc;
+
+        if (GetAccelerationProfile(pVel, profile) == NULL)
+            return BadValue;
+    } else
+	SetAccelerationProfile(pVel, profile);
+
+    return Success;
+}
+
+static int
+AccelInitProfileProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel)
+{
+    int profile = pVel->statistics.profile_number;
+    Atom prop_profile_number = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
+
+    XIChangeDeviceProperty(dev, prop_profile_number, XA_INTEGER, 32,
+                           PropModeReplace, 1, &profile, FALSE);
+    XISetDevicePropertyDeletable(dev, prop_profile_number, FALSE);
+    return XIRegisterPropertyHandler(dev, AccelSetProfileProperty, NULL, NULL);
+}
+
+/**
+ * constant deceleration
+ */
+static int
+AccelSetDecelProperty(DeviceIntPtr dev, Atom atom,
+                      XIPropertyValuePtr val, BOOL checkOnly)
+{
+    DeviceVelocityPtr pVel;
+    float v, *ptr = &v;
+    int rc;
+
+    if (atom != XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION))
+        return Success;
+
+    pVel = GetDevicePredictableAccelData(dev);
+    rc = XIPropToFloat(val, &ptr);
+
+    if(checkOnly)
+    {
+        if (rc)
+            return rc;
+	return (v >= 1.0f) ? Success : BadValue;
+    }
+
+    if(v >= 1.0f)
+	pVel->const_acceleration = 1/v;
+
+    return Success;
+}
+
+static int
+AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel)
+{
+    float fval = 1.0/pVel->const_acceleration;
+    Atom prop_const_decel = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
+    XIChangeDeviceProperty(dev, prop_const_decel,
+                           XIGetKnownProperty(XATOM_FLOAT), 32,
+                           PropModeReplace, 1, &fval, FALSE);
+    XISetDevicePropertyDeletable(dev, prop_const_decel, FALSE);
+    return XIRegisterPropertyHandler(dev, AccelSetDecelProperty, NULL, NULL);
+}
+
+
+/**
+ * adaptive deceleration
+ */
+static int
+AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom,
+                           XIPropertyValuePtr val, BOOL checkOnly)
+{
+    DeviceVelocityPtr pVel;
+    float v, *ptr = &v;
+    int rc;
+
+    if (atom != XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION))
+        return Success;
+
+    pVel = GetDevicePredictableAccelData(dev);
+    rc = XIPropToFloat(val, &ptr);
+
+    if(checkOnly)
+    {
+        if (rc)
+            return rc;
+	return (v >= 1.0f) ? Success : BadValue;
+    }
+
+    if(v >= 1.0f)
+	pVel->min_acceleration = 1/v;
+
+    return Success;
+}
+
+static int
+AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel)
+{
+    float fval = 1.0/pVel->min_acceleration;
+    Atom prop_adapt_decel = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION);
+
+    XIChangeDeviceProperty(dev, prop_adapt_decel, XIGetKnownProperty(XATOM_FLOAT), 32,
+                           PropModeReplace, 1, &fval, FALSE);
+    XISetDevicePropertyDeletable(dev, prop_adapt_decel, FALSE);
+    return XIRegisterPropertyHandler(dev, AccelSetAdaptDecelProperty, NULL, NULL);
+}
+
+
+/**
+ * velocity scaling
+ */
+static int
+AccelSetScaleProperty(DeviceIntPtr dev, Atom atom,
+                      XIPropertyValuePtr val, BOOL checkOnly)
+{
+    DeviceVelocityPtr pVel;
+    float v, *ptr = &v;
+    int rc;
+
+    if (atom != XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING))
+        return Success;
+
+    pVel = GetDevicePredictableAccelData(dev);
+    rc = XIPropToFloat(val, &ptr);
+
+    if (checkOnly)
+    {
+        if (rc)
+            return rc;
+
+        return (v > 0) ? Success : BadValue;
+    }
+
+    if(v > 0)
+	pVel->corr_mul = v;
+
+    return Success;
+}
+
+static int
+AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel)
+{
+    float fval = pVel->corr_mul;
+    Atom prop_velo_scale = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
+
+    XIChangeDeviceProperty(dev, prop_velo_scale, XIGetKnownProperty(XATOM_FLOAT), 32,
+                           PropModeReplace, 1, &fval, FALSE);
+    XISetDevicePropertyDeletable(dev, prop_velo_scale, FALSE);
+    return XIRegisterPropertyHandler(dev, AccelSetScaleProperty, NULL, NULL);
+}
+
+BOOL
+InitializePredictableAccelerationProperties(DeviceIntPtr device)
+{
+    int               *prophandler = prop_handler_ids;
+    DeviceVelocityPtr  pVel        = GetDevicePredictableAccelData(device);
+
+    if(!pVel)
+	return FALSE;
+
+    *prophandler++ = AccelInitProfileProperty(device, pVel);
+    *prophandler++ = AccelInitDecelProperty(device, pVel);
+    *prophandler++ = AccelInitAdaptDecelProperty(device, pVel);
+    *prophandler   = AccelInitScaleProperty(device, pVel);
+    return TRUE;
+}
+
 /*********************
  * Filtering logic
  ********************/
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index e491051..096dea8 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -43,6 +43,7 @@
 #define AccelProfilePower 5
 #define AccelProfileLinear 6
 #define AccelProfileReserved 7
+#define AccelProfileLAST AccelProfileReserved
 
 /* fwd */
 struct _DeviceVelocityRec;
@@ -103,6 +104,9 @@ typedef struct _DeviceVelocityRec {
 extern _X_EXPORT void
 InitVelocityData(DeviceVelocityPtr s);
 
+extern _X_EXPORT BOOL
+InitializePredictableAccelerationProperties(DeviceIntPtr pDev);
+
 extern _X_EXPORT void
 InitFilterChain(DeviceVelocityPtr s, float rdecay, float degression,
                 int lutsize, int stages);
diff --git a/include/xserver-properties.h b/include/xserver-properties.h
index 0a0e849..3356186 100644
--- a/include/xserver-properties.h
+++ b/include/xserver-properties.h
@@ -32,4 +32,16 @@
 /* BOOL. 0 - device disabled, 1 - device enabled */
 #define XI_PROP_ENABLED      "Device Enabled"
 
+/* Type for a 4 byte float number */
+#define FLOAT "FLOAT"
+/* Pointer acceleration properties */
+/* INTEGER of any format */
+#define ACCEL_PROP_PROFILE_NUMBER "Acceleration Profile"
+/* FLOAT, format 32 */
+#define ACCEL_PROP_CONSTANT_DECELERATION "Constant Deceleration"
+/* FLOAT, format 32 */
+#define ACCEL_PROP_ADAPTIVE_DECELERATION "Adaptive Deceleration"
+/* FLOAT, format 32 */
+#define ACCEL_PROP_VELOCITY_SCALING "Device Velocity Scaling"
+
 #endif
-- 
1.6.0.4




More information about the xorg mailing list