Re: [PATCH libinput v3] evdev: Add support for POINTINGSTICK_CONST_ACCEL udev property

2015-04-08 Thread Peter Hutterer
On Wed, Apr 08, 2015 at 12:11:58PM +0200, Hans de Goede wrote:
> There is quite a wide spread in the delta events generated by trackpoints,
> some generate deltas of 1-2 under normal use, while others generate deltas
> from 1-20.
> 
> It is desirable to normalize trackpoint deltas just like we are normalizing
> mouse deltas to 1000 dpi, so as to give different model laptops aprox.
> the same trackpoint cursor speed ootb.
> 
> Recent versions of udev + hwdb set a POINTINGSTICK_CONST_ACCEL udev property
> which can be used to adjust trackpoints which are too slow / too fast
> ootb, this commit implements support for that property.
> 
> Signed-off-by: Hans de Goede 
> ---
> Changes in v3:
> -Fix a couple of typos
> -Document TRACKPOINT_CONST_ACCEL udev property in
>  doc/device-configuration-via-udev.dox
> -Added a test for parse_trackpoint_accel_property
> Changes in v2:
> -Use POINTINGSTICK_CONST_ACCEL instead of TRACKPOINT_CONST_ACCEL to match
>  changes to the udev patchset
> 
> foo
> ---
>  doc/device-configuration-via-udev.dox |  4 
>  src/evdev.c   | 33 +
>  src/evdev.h   |  7 +++
>  src/libinput-util.c   | 31 +++
>  src/libinput-util.h   |  1 +
>  test/misc.c   | 27 +++
>  6 files changed, 103 insertions(+)
> 
> diff --git a/doc/device-configuration-via-udev.dox 
> b/doc/device-configuration-via-udev.dox
> index fc1c0af..6579041 100644
> --- a/doc/device-configuration-via-udev.dox
> +++ b/doc/device-configuration-via-udev.dox
> @@ -57,6 +57,10 @@ See @ref motion_normalization for details.
>  The angle in degrees for each click on a mouse wheel. See
>  libinput_pointer_get_axis_source() for details.
>  
> +POINTINGSTICK_CONST_ACCEL
> +A constant (linear) acceleration factor to apply to pointingstick deltas
> +to normalize them. See evdev_get_trackpoint_dpi() for details.

You can drop the "see ... " sentence since doxygen won't resolve it anyway.
Anyone interested enough in the code will (have to) be able to git grep.

Reviewed-by: Peter Hutterer 
otherwise, feel free to push this once all the udev changes have landed.

Cheers,
   Peter


> +
>  
>  
>  Below is an example udev rule to assign "seat1" to a device from vendor
> diff --git a/src/evdev.c b/src/evdev.c
> index 4205c2d..1730dae 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -1319,6 +1319,31 @@ evdev_read_wheel_click_prop(struct evdev_device 
> *device)
>  
>   return angle;
>  }
> +
> +static inline int
> +evdev_get_trackpoint_dpi(struct evdev_device *device)
> +{
> + struct libinput *libinput = device->base.seat->libinput;
> + const char *trackpoint_accel;
> + double accel = DEFAULT_TRACKPOINT_ACCEL;
> +
> + trackpoint_accel = udev_device_get_property_value(
> + device->udev_device, 
> "POINTINGSTICK_CONST_ACCEL");
> + if (trackpoint_accel) {
> + accel = parse_trackpoint_accel_property(trackpoint_accel);
> + if (accel == 0.0) {
> + log_error(libinput, "Trackpoint accel property for "
> + "'%s' is present but invalid, "
> + "using %.2f instead\n",
> + device->devname,
> + DEFAULT_TRACKPOINT_ACCEL);
> + accel = DEFAULT_TRACKPOINT_ACCEL;
> + }
> + }
> +
> + return DEFAULT_MOUSE_DPI / accel;
> +}
> +
>  static inline int
>  evdev_read_dpi_prop(struct evdev_device *device)
>  {
> @@ -1326,6 +1351,14 @@ evdev_read_dpi_prop(struct evdev_device *device)
>   const char *mouse_dpi;
>   int dpi = DEFAULT_MOUSE_DPI;
>  
> + /*
> +  * Trackpoints do not have dpi, instead hwdb may contain a
> +  * POINTINGSTICK_CONST_ACCEL value to compensate for sensitivity
> +  * differences between models, we translate this to a fake dpi.
> +  */
> + if (libevdev_has_property(device->evdev, INPUT_PROP_POINTING_STICK))
> + return evdev_get_trackpoint_dpi(device);
> +
>   mouse_dpi = udev_device_get_property_value(device->udev_device,
>  "MOUSE_DPI");
>   if (mouse_dpi) {
> diff --git a/src/evdev.h b/src/evdev.h
> index c7a9e75..b63ae86 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -36,6 +36,13 @@
>  
>  /* The HW DPI rate we normalize to before calculating pointer acceleration */
>  #define DEFAULT_MOUSE_DPI 1000
> +
> +/*
> + * The constant (linear) acceleration factor we use to normalize trackpoint
> + * deltas before calculating pointer acceleration.
> + */
> +#define DEFAULT_TRACKPOINT_ACCEL 1.0
> +
>  /* The fake resolution value for abs devices without resolution */
>  #define EVDEV_FAKE_RESOLUTION 1
>  
> diff --git a/src/libinput-util.c b/src/libinput-util.c
> index 49e

[PATCH libinput v3] evdev: Add support for POINTINGSTICK_CONST_ACCEL udev property

2015-04-08 Thread Hans de Goede
There is quite a wide spread in the delta events generated by trackpoints,
some generate deltas of 1-2 under normal use, while others generate deltas
from 1-20.

It is desirable to normalize trackpoint deltas just like we are normalizing
mouse deltas to 1000 dpi, so as to give different model laptops aprox.
the same trackpoint cursor speed ootb.

Recent versions of udev + hwdb set a POINTINGSTICK_CONST_ACCEL udev property
which can be used to adjust trackpoints which are too slow / too fast
ootb, this commit implements support for that property.

Signed-off-by: Hans de Goede 
---
Changes in v3:
-Fix a couple of typos
-Document TRACKPOINT_CONST_ACCEL udev property in
 doc/device-configuration-via-udev.dox
-Added a test for parse_trackpoint_accel_property
Changes in v2:
-Use POINTINGSTICK_CONST_ACCEL instead of TRACKPOINT_CONST_ACCEL to match
 changes to the udev patchset

foo
---
 doc/device-configuration-via-udev.dox |  4 
 src/evdev.c   | 33 +
 src/evdev.h   |  7 +++
 src/libinput-util.c   | 31 +++
 src/libinput-util.h   |  1 +
 test/misc.c   | 27 +++
 6 files changed, 103 insertions(+)

diff --git a/doc/device-configuration-via-udev.dox 
b/doc/device-configuration-via-udev.dox
index fc1c0af..6579041 100644
--- a/doc/device-configuration-via-udev.dox
+++ b/doc/device-configuration-via-udev.dox
@@ -57,6 +57,10 @@ See @ref motion_normalization for details.
 The angle in degrees for each click on a mouse wheel. See
 libinput_pointer_get_axis_source() for details.
 
+POINTINGSTICK_CONST_ACCEL
+A constant (linear) acceleration factor to apply to pointingstick deltas
+to normalize them. See evdev_get_trackpoint_dpi() for details.
+
 
 
 Below is an example udev rule to assign "seat1" to a device from vendor
diff --git a/src/evdev.c b/src/evdev.c
index 4205c2d..1730dae 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1319,6 +1319,31 @@ evdev_read_wheel_click_prop(struct evdev_device *device)
 
return angle;
 }
+
+static inline int
+evdev_get_trackpoint_dpi(struct evdev_device *device)
+{
+   struct libinput *libinput = device->base.seat->libinput;
+   const char *trackpoint_accel;
+   double accel = DEFAULT_TRACKPOINT_ACCEL;
+
+   trackpoint_accel = udev_device_get_property_value(
+   device->udev_device, 
"POINTINGSTICK_CONST_ACCEL");
+   if (trackpoint_accel) {
+   accel = parse_trackpoint_accel_property(trackpoint_accel);
+   if (accel == 0.0) {
+   log_error(libinput, "Trackpoint accel property for "
+   "'%s' is present but invalid, "
+   "using %.2f instead\n",
+   device->devname,
+   DEFAULT_TRACKPOINT_ACCEL);
+   accel = DEFAULT_TRACKPOINT_ACCEL;
+   }
+   }
+
+   return DEFAULT_MOUSE_DPI / accel;
+}
+
 static inline int
 evdev_read_dpi_prop(struct evdev_device *device)
 {
@@ -1326,6 +1351,14 @@ evdev_read_dpi_prop(struct evdev_device *device)
const char *mouse_dpi;
int dpi = DEFAULT_MOUSE_DPI;
 
+   /*
+* Trackpoints do not have dpi, instead hwdb may contain a
+* POINTINGSTICK_CONST_ACCEL value to compensate for sensitivity
+* differences between models, we translate this to a fake dpi.
+*/
+   if (libevdev_has_property(device->evdev, INPUT_PROP_POINTING_STICK))
+   return evdev_get_trackpoint_dpi(device);
+
mouse_dpi = udev_device_get_property_value(device->udev_device,
   "MOUSE_DPI");
if (mouse_dpi) {
diff --git a/src/evdev.h b/src/evdev.h
index c7a9e75..b63ae86 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -36,6 +36,13 @@
 
 /* The HW DPI rate we normalize to before calculating pointer acceleration */
 #define DEFAULT_MOUSE_DPI 1000
+
+/*
+ * The constant (linear) acceleration factor we use to normalize trackpoint
+ * deltas before calculating pointer acceleration.
+ */
+#define DEFAULT_TRACKPOINT_ACCEL 1.0
+
 /* The fake resolution value for abs devices without resolution */
 #define EVDEV_FAKE_RESOLUTION 1
 
diff --git a/src/libinput-util.c b/src/libinput-util.c
index 49e297a..4857435 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -29,6 +29,7 @@
 #include "config.h"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -201,3 +202,33 @@ parse_mouse_wheel_click_angle_property(const char *prop)
 
 return angle;
 }
+
+/**
+ * Helper function to parse the TRACKPOINT_CONST_ACCEL property from udev.
+ * Property is of the form:
+ * TRACKPOINT_CONST_ACCEL=
+ *
+ * @param prop The value of the udev property (without the 
TRACKPOINT_CONST_ACCEL=)
+ * @return The