Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2011-02-14 Thread Paolo D'Apice
Hi Peter,
  I'm sorry I reply so late. Anyway, I did the changes you suggested me to do.
Now, how can I submit the new patch? Can I use again the "git
send-email" or attach it to the X.Org Bug 27688?

Cheers,
Paolo
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-11-07 Thread Simon Thum
On 11/02/10 08:45, Peter Hutterer wrote:
> On 2/11/10 17:41 , Peter Korsgaard wrote:
>>> "PH" == Peter Hutterer  writes:
>>
>> Hi,
>>
>> PH>  right, that's the easy part. right now the property isn't hooked
>> up for
>> PH>  relative devices, so afaict that needs to be the first step. A
>> quick hack
>> PH>  shows some rather weird results, which suggests that it's not
>> quite as
>> PH>  trivial as I hoped it'd be.
>>
>> What kind of results are you seeing?
> 
> essentially what I did was change DeviceSetTransform() to write the
> matrix in as-is for relative devices (skipping scale and transform) and
> use transformAbsolute() in GetPointerEvents for relative events. That
> calculated the right values, but acceleration was off, the movement
> wasn't consistent with the pointer sometimes feeling like stuck in goo.
> It was a quick hack to try it, but that's what I meant with "not quite
> as trivial"
> 
I guess I would have found a few minutes to do it if it was that trivial.

The bottom of my coffee mug tells me you were screwing the remainder.
You really should be doing this in tune with acceleration, i.e. use the
same way of remainder handling and the same remainder. This is buried in
http://cgit.freedesktop.org/xorg/xserver/tree/dix/ptrveloc.c#n1073

A correct implementation might simply apply the 2x2-Part of the matrix
to driver input ([dx,dy] in the linked code), thereby converting it to
the equivalent of [fdx, fdy].

But then it's not simply c-n-p since you can't use the conditional axis
processing trick I used in accel (which isn't really smart anyway), so
the int->float->int+rem needs to be stabilized by other means.

The problem is that with a 0.5 remainder on an axis but motion only on
another axis, you'll still get a +1 axis with a -0.5 remainder. The axis
'toggles' as a result. So be aware of rounding and stay within remainder
[-0.5, 0.5].

Apart from that, it's probably cheesecake.

Cheers,

Simon
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-11-02 Thread Peter Hutterer

On 2/11/10 17:41 , Peter Korsgaard wrote:

"PH" == Peter Hutterer  writes:


Hi,

PH>  right, that's the easy part. right now the property isn't hooked up for
PH>  relative devices, so afaict that needs to be the first step. A quick hack
PH>  shows some rather weird results, which suggests that it's not quite as
PH>  trivial as I hoped it'd be.

What kind of results are you seeing?


essentially what I did was change DeviceSetTransform() to write the 
matrix in as-is for relative devices (skipping scale and transform) and 
use transformAbsolute() in GetPointerEvents for relative events. That 
calculated the right values, but acceleration was off, the movement 
wasn't consistent with the pointer sometimes feeling like stuck in goo.
It was a quick hack to try it, but that's what I meant with "not quite 
as trivial"


Cheers,
  Peter



PH>  CC-ing Simon and Peter, not sure what happend to the relative device
PH>  transformation plans.
PH>  http://lists.x.org/archives/xorg-devel/2010-May/008116.html

I'm afraid I've gotten caught up with all kinds of other work, so I
haven't done any more work on it yet :/

I still plan on doing work on it and push coordinate transform matrix
support to the upper (E.G. gnome-display-properties) layers, but I don't
have any hard timeline.




___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-11-02 Thread Peter Korsgaard
> "PH" == Peter Hutterer  writes:

Hi,

PH> right, that's the easy part. right now the property isn't hooked up for
PH> relative devices, so afaict that needs to be the first step. A quick hack
PH> shows some rather weird results, which suggests that it's not quite as
PH> trivial as I hoped it'd be.

What kind of results are you seeing?

PH> CC-ing Simon and Peter, not sure what happend to the relative device
PH> transformation plans.
PH> http://lists.x.org/archives/xorg-devel/2010-May/008116.html

I'm afraid I've gotten caught up with all kinds of other work, so I
haven't done any more work on it yet :/

I still plan on doing work on it and push coordinate transform matrix
support to the upper (E.G. gnome-display-properties) layers, but I don't
have any hard timeline.

-- 
Bye, Peter Korsgaard


DISCLAIMER:
Unless indicated otherwise, the information contained in this message is 
privileged and confidential, and is intended only for the use of the 
addressee(s) named above and others who have been specifically authorized to 
receive it. If you are not the intended recipient, you are hereby notified that 
any dissemination, distribution or copying of this message and/or attachments 
is strictly prohibited. The company accepts no liability for any damage caused 
by any virus transmitted by this email. Furthermore, the company does not 
warrant a proper and complete transmission of this information, nor does it 
accept liability for any delays. If you have received this message in error, 
please contact the sender and delete the message. Thank you.
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-10-31 Thread Peter Hutterer
On Fri, Oct 29, 2010 at 10:12:33AM +0200, Benjamin Tissoires wrote:
> Hi,
> 
> Le 29/10/2010 07:37, Peter Hutterer a écrit :
> >On Sun, Oct 24, 2010 at 01:45:03PM +0200, Paolo D'Apice wrote:
> >>The evdev driver does not allow to set a custom axes rotation
> >>as the mousedrv driver does with the option "AngleOffset".
> >>This option is necessary for some trackballs, for example the
> >>Logitech Cordless Optical TrackMan which has the optical
> >>sensor off-axes (in MS Windows, the Logitech proprietary driver
> >>adjusts the offset).
> >>
> >>X.Org Bug 27688
> >>
> >>Signed-off-by: Paolo D'Apice
> >
> >this patch seems simple enough that we could add it to the server as a
> >standard property for pointer devices, isn't it?  I'd much prefer that so we
> >don't have to re-implement it for the various drivers.
> 
> But isn't it already in the server?
> Since 1.9 and commit "dix: add 3x3 transformation matrix xinput
> property for multi-head handling", we already have a property
> "Coordinate Transformation Matrix" that can handle arbitrary
> transformation matrix. And a rotation can be seen as a matrix, no???
> 
> It's clear that a matrix is not very easy to handle by human people,
> but we just need a tool that provide it ;)

right, that's the easy part. right now the property isn't hooked up for
relative devices, so afaict that needs to be the first step. A quick hack
shows some rather weird results, which suggests that it's not quite as
trivial as I hoped it'd be.

CC-ing Simon and Peter, not sure what happend to the relative device
transformation plans.
http://lists.x.org/archives/xorg-devel/2010-May/008116.html
 
Cheers,
  Peter
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-10-29 Thread Benjamin Tissoires

Hi,

Le 29/10/2010 07:37, Peter Hutterer a écrit :

On Sun, Oct 24, 2010 at 01:45:03PM +0200, Paolo D'Apice wrote:

The evdev driver does not allow to set a custom axes rotation
as the mousedrv driver does with the option "AngleOffset".
This option is necessary for some trackballs, for example the
Logitech Cordless Optical TrackMan which has the optical
sensor off-axes (in MS Windows, the Logitech proprietary driver
adjusts the offset).

X.Org Bug 27688

Signed-off-by: Paolo D'Apice


this patch seems simple enough that we could add it to the server as a
standard property for pointer devices, isn't it?  I'd much prefer that so we
don't have to re-implement it for the various drivers.


But isn't it already in the server?
Since 1.9 and commit "dix: add 3x3 transformation matrix xinput property 
for multi-head handling", we already have a property
"Coordinate Transformation Matrix" that can handle arbitrary 
transformation matrix. And a rotation can be seen as a matrix, no???


It's clear that a matrix is not very easy to handle by human people, but 
we just need a tool that provide it ;)


Cheers,
Benjamin
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-10-28 Thread Oliver McFadden
On Fri, 2010-10-29 at 15:37 +1000, ext Peter Hutterer wrote:
> On Sun, Oct 24, 2010 at 01:45:03PM +0200, Paolo D'Apice wrote:
> > The evdev driver does not allow to set a custom axes rotation
> > as the mousedrv driver does with the option "AngleOffset".
> > This option is necessary for some trackballs, for example the
> > Logitech Cordless Optical TrackMan which has the optical
> > sensor off-axes (in MS Windows, the Logitech proprietary driver
> > adjusts the offset).
> > 
> > X.Org Bug 27688 
> > 
> > Signed-off-by: Paolo D'Apice 
> 
> this patch seems simple enough that we could add it to the server as a
> standard property for pointer devices, isn't it?  I'd much prefer that so we
> don't have to re-implement it for the various drivers.
> 
> > ---
> >  include/evdev-properties.h |4 
> >  man/evdev.man  |   12 
> >  src/evdev.c|   25 +
> >  src/evdev.h|1 +
> >  4 files changed, 42 insertions(+), 0 deletions(-)
> > 
> > diff --git a/include/evdev-properties.h b/include/evdev-properties.h
> > index 7df2876..a658e2b 100644
> > --- a/include/evdev-properties.h
> > +++ b/include/evdev-properties.h
> > @@ -66,4 +66,8 @@
> >  /* BOOL */
> >  #define EVDEV_PROP_SWAP_AXES "Evdev Axes Swap"
> >  
> > +/* Axes Rotation */
> > +/* CARD16 */
> > +#define EVDEV_PROP_AXES_ROTATION "Evdev Axes Rotation"
> > +
> 
> note that CARD16 is unsigned, this should probably read INT16?
> 
> >  #endif
> > diff --git a/man/evdev.man b/man/evdev.man
> > index adb3f8d..f7c5e9f 100644
> > --- a/man/evdev.man
> > +++ b/man/evdev.man
> > @@ -177,6 +177,15 @@ This option has no effect on devices without absolute 
> > axes.
> >  .BI "Option \*qSwapAxes\*q \*q" Bool \*q
> >  Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
> >  .TP 7
> > +.BI "Option \*qAxesRotation\*q \*q" integer \*q
> > +Clockwise axes rotation (in degrees) to apply to the pointer motion. 
> > +This transformation is applied before the 
> > +.BR SwapAxes , 
> > +.BR InvertX 
> > +and
> > +.B InvertY 
> > +transformations. Default: 0. Property: "Evdev Axes Rotation".
> > +.TP 7
> >  .BI "Option \*qXAxisMapping\*q \*q" "N1 N2" \*q
> >  Specifies which buttons are mapped to motion in the X direction in wheel
> >  emulation mode.  Button number
> > @@ -210,6 +219,9 @@ in-driver axis calibration.
> >  .BI "Evdev Axes Swap"
> >  1 boolean value (8 bit, 0 or 1). 1 swaps x/y axes.
> >  .TP 7
> > +.BI "Evdev Axes Rotation"
> > +1 16-bit positive and negative value. 0 disable rotation.
> 
> How about "1 16-bit signed value". hard to have a non-zero positive _and_
> negative value anyway :)
> 
> > +.TP 7
> >  .BI "Evdev Drag Lock Buttons"
> >  8-bit. Either 1 value or pairs of values. Value range 0-32, 0 disables a
> >  value.
> > diff --git a/src/evdev.c b/src/evdev.c
> > index 9e1fb10..fc8918e 100644
> > --- a/src/evdev.c
> > +++ b/src/evdev.c
> > @@ -47,6 +47,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> >  #ifdef HAVE_PROPERTIES
> >  #include 
> > @@ -114,6 +115,7 @@ static Atom prop_calibration = 0;
> >  static Atom prop_swap = 0;
> >  static Atom prop_axis_label = 0;
> >  static Atom prop_btn_label = 0;
> > +static Atom prop_axes_rotation = 0;
> >  #endif
> >  
> >  /* All devices the evdev driver has allocated and knows about.
> > @@ -383,6 +385,15 @@ EvdevProcessValuators(InputInfoPtr pInfo, int 
> > v[MAX_VALUATORS], int *num_v,
> >  int first = REL_CNT, last = 0;
> >  int i;
> >  
> > +if (pEvdev->axes_rotation) {
> > +float rotation = (pEvdev->axes_rotation % 360) * M_PI / 180.0; 
> > // degrees to radians 
> 
> see comment below about storing the radians.
> 
> > +float rot_cos = cos(rotation), rot_sin = sin(rotation);
> 
> please split this line up, I read over it the first time and then got
> confused.

Perhaps also try using sincos (wrapped in ifdef _GNU_SOURCE) as the
valuators are processed quite often, so this might save a few cycles.

Although I'm only speculating about the real-world impact.

> 
> > +   
> > +tmp = pEvdev->delta[REL_X];
> > +pEvdev->delta[REL_X] = (int)(pEvdev->delta[REL_X] * rot_cos - 
> > pEvdev->delta[REL_Y] * rot_sin);
> > +pEvdev->delta[REL_Y] = (int)(pEvdev->delta[REL_Y] * rot_cos + 
> > tmp * rot_sin);
> > +}
> > +
> >  if (pEvdev->swap_axes) {
> >  tmp = pEvdev->delta[REL_X];
> >  pEvdev->delta[REL_X] = pEvdev->delta[REL_Y];
> > @@ -2516,6 +2527,13 @@ EvdevInitProperty(DeviceIntPtr dev)
> >  
> >  XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
> >  
> > +prop_axes_rotation = MakeAtom(EVDEV_PROP_AXES_ROTATION,
> > +strlen(EVDEV_PROP_AXES_ROTATION), TRUE);
> > +rc = XIChangeDeviceProperty(dev, prop_axes_rotation, XA_INTEGER, 
> > 16,
> > +PropModeReplace, 1, &pEvdev->axes_rot

Re: [PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-10-28 Thread Peter Hutterer
On Sun, Oct 24, 2010 at 01:45:03PM +0200, Paolo D'Apice wrote:
> The evdev driver does not allow to set a custom axes rotation
> as the mousedrv driver does with the option "AngleOffset".
> This option is necessary for some trackballs, for example the
> Logitech Cordless Optical TrackMan which has the optical
> sensor off-axes (in MS Windows, the Logitech proprietary driver
> adjusts the offset).
> 
> X.Org Bug 27688 
> 
> Signed-off-by: Paolo D'Apice 

this patch seems simple enough that we could add it to the server as a
standard property for pointer devices, isn't it?  I'd much prefer that so we
don't have to re-implement it for the various drivers.

> ---
>  include/evdev-properties.h |4 
>  man/evdev.man  |   12 
>  src/evdev.c|   25 +
>  src/evdev.h|1 +
>  4 files changed, 42 insertions(+), 0 deletions(-)
> 
> diff --git a/include/evdev-properties.h b/include/evdev-properties.h
> index 7df2876..a658e2b 100644
> --- a/include/evdev-properties.h
> +++ b/include/evdev-properties.h
> @@ -66,4 +66,8 @@
>  /* BOOL */
>  #define EVDEV_PROP_SWAP_AXES "Evdev Axes Swap"
>  
> +/* Axes Rotation */
> +/* CARD16 */
> +#define EVDEV_PROP_AXES_ROTATION "Evdev Axes Rotation"
> +

note that CARD16 is unsigned, this should probably read INT16?

>  #endif
> diff --git a/man/evdev.man b/man/evdev.man
> index adb3f8d..f7c5e9f 100644
> --- a/man/evdev.man
> +++ b/man/evdev.man
> @@ -177,6 +177,15 @@ This option has no effect on devices without absolute 
> axes.
>  .BI "Option \*qSwapAxes\*q \*q" Bool \*q
>  Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
>  .TP 7
> +.BI "Option \*qAxesRotation\*q \*q" integer \*q
> +Clockwise axes rotation (in degrees) to apply to the pointer motion. 
> +This transformation is applied before the 
> +.BR SwapAxes , 
> +.BR InvertX 
> +and
> +.B InvertY 
> +transformations. Default: 0. Property: "Evdev Axes Rotation".
> +.TP 7
>  .BI "Option \*qXAxisMapping\*q \*q" "N1 N2" \*q
>  Specifies which buttons are mapped to motion in the X direction in wheel
>  emulation mode.  Button number
> @@ -210,6 +219,9 @@ in-driver axis calibration.
>  .BI "Evdev Axes Swap"
>  1 boolean value (8 bit, 0 or 1). 1 swaps x/y axes.
>  .TP 7
> +.BI "Evdev Axes Rotation"
> +1 16-bit positive and negative value. 0 disable rotation.

How about "1 16-bit signed value". hard to have a non-zero positive _and_
negative value anyway :)

> +.TP 7
>  .BI "Evdev Drag Lock Buttons"
>  8-bit. Either 1 value or pairs of values. Value range 0-32, 0 disables a
>  value.
> diff --git a/src/evdev.c b/src/evdev.c
> index 9e1fb10..fc8918e 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -47,6 +47,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #ifdef HAVE_PROPERTIES
>  #include 
> @@ -114,6 +115,7 @@ static Atom prop_calibration = 0;
>  static Atom prop_swap = 0;
>  static Atom prop_axis_label = 0;
>  static Atom prop_btn_label = 0;
> +static Atom prop_axes_rotation = 0;
>  #endif
>  
>  /* All devices the evdev driver has allocated and knows about.
> @@ -383,6 +385,15 @@ EvdevProcessValuators(InputInfoPtr pInfo, int 
> v[MAX_VALUATORS], int *num_v,
>  int first = REL_CNT, last = 0;
>  int i;
>  
> +if (pEvdev->axes_rotation) {
> +float rotation = (pEvdev->axes_rotation % 360) * M_PI / 180.0; 
> // degrees to radians 

see comment below about storing the radians.

> +float rot_cos = cos(rotation), rot_sin = sin(rotation);

please split this line up, I read over it the first time and then got
confused.

> +   
> +tmp = pEvdev->delta[REL_X];
> +pEvdev->delta[REL_X] = (int)(pEvdev->delta[REL_X] * rot_cos - 
> pEvdev->delta[REL_Y] * rot_sin);
> +pEvdev->delta[REL_Y] = (int)(pEvdev->delta[REL_Y] * rot_cos + 
> tmp * rot_sin);
> +}
> +
>  if (pEvdev->swap_axes) {
>  tmp = pEvdev->delta[REL_X];
>  pEvdev->delta[REL_X] = pEvdev->delta[REL_Y];
> @@ -2516,6 +2527,13 @@ EvdevInitProperty(DeviceIntPtr dev)
>  
>  XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
>  
> +prop_axes_rotation = MakeAtom(EVDEV_PROP_AXES_ROTATION,
> +strlen(EVDEV_PROP_AXES_ROTATION), TRUE);
> +rc = XIChangeDeviceProperty(dev, prop_axes_rotation, XA_INTEGER, 16,
> +PropModeReplace, 1, &pEvdev->axes_rotation, FALSE);
> +if (rc != Success) 
> +return;
> +
>  #ifdef HAVE_LABELS
>  /* Axis labelling */
>  if ((pEvdev->num_vals > 0) && (prop_axis_label = 
> XIGetKnownProperty(AXIS_LABEL_PROP)))
> @@ -2575,6 +2593,13 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, 
> XIPropertyValuePtr val,
>  
>  if (!checkonly)
>  pEvdev->swap_axes = *((BOOL*)val->data);
> +} else if (atom == prop_axes_rotation)
> +{
> +if (val->format != 16 || val->type != XA_INTE

[PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-10-25 Thread Paolo D'Apice
The evdev driver does not allow to set a custom axes rotation
as the mousedrv driver does with the option "AngleOffset".
This option is necessary for some trackballs, for example the
Logitech Cordless Optical TrackMan which has the optical
sensor off-axes (in MS Windows, the Logitech proprietary driver
adjusts the offset).

X.Org Bug 27688 

Signed-off-by: Paolo D'Apice 
---
 include/evdev-properties.h |4 
 man/evdev.man  |   12 
 src/evdev.c|   25 +
 src/evdev.h|1 +
 4 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/include/evdev-properties.h b/include/evdev-properties.h
index 7df2876..a658e2b 100644
--- a/include/evdev-properties.h
+++ b/include/evdev-properties.h
@@ -66,4 +66,8 @@
 /* BOOL */
 #define EVDEV_PROP_SWAP_AXES "Evdev Axes Swap"
 
+/* Axes Rotation */
+/* CARD16 */
+#define EVDEV_PROP_AXES_ROTATION "Evdev Axes Rotation"
+
 #endif
diff --git a/man/evdev.man b/man/evdev.man
index adb3f8d..f7c5e9f 100644
--- a/man/evdev.man
+++ b/man/evdev.man
@@ -177,6 +177,15 @@ This option has no effect on devices without absolute axes.
 .BI "Option \*qSwapAxes\*q \*q" Bool \*q
 Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
 .TP 7
+.BI "Option \*qAxesRotation\*q \*q" integer \*q
+Clockwise axes rotation (in degrees) to apply to the pointer motion. 
+This transformation is applied before the 
+.BR SwapAxes , 
+.BR InvertX 
+and
+.B InvertY 
+transformations. Default: 0. Property: "Evdev Axes Rotation".
+.TP 7
 .BI "Option \*qXAxisMapping\*q \*q" "N1 N2" \*q
 Specifies which buttons are mapped to motion in the X direction in wheel
 emulation mode.  Button number
@@ -210,6 +219,9 @@ in-driver axis calibration.
 .BI "Evdev Axes Swap"
 1 boolean value (8 bit, 0 or 1). 1 swaps x/y axes.
 .TP 7
+.BI "Evdev Axes Rotation"
+1 16-bit positive and negative value. 0 disable rotation.
+.TP 7
 .BI "Evdev Drag Lock Buttons"
 8-bit. Either 1 value or pairs of values. Value range 0-32, 0 disables a
 value.
diff --git a/src/evdev.c b/src/evdev.c
index 9e1fb10..fc8918e 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -47,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef HAVE_PROPERTIES
 #include 
@@ -114,6 +115,7 @@ static Atom prop_calibration = 0;
 static Atom prop_swap = 0;
 static Atom prop_axis_label = 0;
 static Atom prop_btn_label = 0;
+static Atom prop_axes_rotation = 0;
 #endif
 
 /* All devices the evdev driver has allocated and knows about.
@@ -383,6 +385,15 @@ EvdevProcessValuators(InputInfoPtr pInfo, int 
v[MAX_VALUATORS], int *num_v,
 int first = REL_CNT, last = 0;
 int i;
 
+if (pEvdev->axes_rotation) {
+float rotation = (pEvdev->axes_rotation % 360) * M_PI / 180.0; // 
degrees to radians 
+float rot_cos = cos(rotation), rot_sin = sin(rotation);
+   
+tmp = pEvdev->delta[REL_X];
+pEvdev->delta[REL_X] = (int)(pEvdev->delta[REL_X] * rot_cos - 
pEvdev->delta[REL_Y] * rot_sin);
+pEvdev->delta[REL_Y] = (int)(pEvdev->delta[REL_Y] * rot_cos + tmp 
* rot_sin);
+}
+
 if (pEvdev->swap_axes) {
 tmp = pEvdev->delta[REL_X];
 pEvdev->delta[REL_X] = pEvdev->delta[REL_Y];
@@ -2516,6 +2527,13 @@ EvdevInitProperty(DeviceIntPtr dev)
 
 XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
 
+prop_axes_rotation = MakeAtom(EVDEV_PROP_AXES_ROTATION,
+strlen(EVDEV_PROP_AXES_ROTATION), TRUE);
+rc = XIChangeDeviceProperty(dev, prop_axes_rotation, XA_INTEGER, 16,
+PropModeReplace, 1, &pEvdev->axes_rotation, FALSE);
+if (rc != Success) 
+return;
+
 #ifdef HAVE_LABELS
 /* Axis labelling */
 if ((pEvdev->num_vals > 0) && (prop_axis_label = 
XIGetKnownProperty(AXIS_LABEL_PROP)))
@@ -2575,6 +2593,13 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, 
XIPropertyValuePtr val,
 
 if (!checkonly)
 pEvdev->swap_axes = *((BOOL*)val->data);
+} else if (atom == prop_axes_rotation)
+{
+if (val->format != 16 || val->type != XA_INTEGER || val->size != 1)
+return BadMatch;
+
+   if (!checkonly)
+  pEvdev->axes_rotation = *((CARD16*)val->data);
 } else if (atom == prop_axis_label || atom == prop_btn_label)
 return BadAccess; /* Axis/Button labels can't be changed */
 
diff --git a/src/evdev.h b/src/evdev.h
index b382670..17d607a 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -129,6 +129,7 @@ typedef struct {
 BOOL swap_axes;
 BOOL invert_x;
 BOOL invert_y;
+int axes_rotation;
 
 int delta[REL_CNT];
 unsigned int abs, rel;
-- 
1.7.1

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


[PATCH evdev] evdev: added property Evdev Axes Rotation. #27688

2010-10-19 Thread Paolo D'Apice
The evdev driver does not allow to set a custom axes rotation
as the mousedrv driver does with the option "AngleOffset".
This option is necessary for some trackballs, for example the
Logitech Cordless Optical TrackMan which has the optical
sensor off-axes (in MS Windows, the Logitech proprietary driver
adjusts the offset).

X.Org Bug 27688 

Signed-off-by: Paolo D'Apice 
---
 include/evdev-properties.h |4 
 man/evdev.man  |   12 
 src/evdev.c|   25 +
 src/evdev.h|1 +
 4 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/include/evdev-properties.h b/include/evdev-properties.h
index 7df2876..a658e2b 100644
--- a/include/evdev-properties.h
+++ b/include/evdev-properties.h
@@ -66,4 +66,8 @@
 /* BOOL */
 #define EVDEV_PROP_SWAP_AXES "Evdev Axes Swap"
 
+/* Axes Rotation */
+/* CARD16 */
+#define EVDEV_PROP_AXES_ROTATION "Evdev Axes Rotation"
+
 #endif
diff --git a/man/evdev.man b/man/evdev.man
index adb3f8d..f7c5e9f 100644
--- a/man/evdev.man
+++ b/man/evdev.man
@@ -177,6 +177,15 @@ This option has no effect on devices without absolute axes.
 .BI "Option \*qSwapAxes\*q \*q" Bool \*q
 Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
 .TP 7
+.BI "Option \*qAxesRotation\*q \*q" integer \*q
+Clockwise axes rotation (in degrees) to apply to the pointer motion. 
+This transformation is applied before the 
+.BR SwapAxes , 
+.BR InvertX 
+and
+.B InvertY 
+transformations. Default: 0. Property: "Evdev Axes Rotation".
+.TP 7
 .BI "Option \*qXAxisMapping\*q \*q" "N1 N2" \*q
 Specifies which buttons are mapped to motion in the X direction in wheel
 emulation mode.  Button number
@@ -210,6 +219,9 @@ in-driver axis calibration.
 .BI "Evdev Axes Swap"
 1 boolean value (8 bit, 0 or 1). 1 swaps x/y axes.
 .TP 7
+.BI "Evdev Axes Rotation"
+1 16-bit positive and negative value. 0 disable rotation.
+.TP 7
 .BI "Evdev Drag Lock Buttons"
 8-bit. Either 1 value or pairs of values. Value range 0-32, 0 disables a
 value.
diff --git a/src/evdev.c b/src/evdev.c
index 9e1fb10..fc8918e 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -47,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef HAVE_PROPERTIES
 #include 
@@ -114,6 +115,7 @@ static Atom prop_calibration = 0;
 static Atom prop_swap = 0;
 static Atom prop_axis_label = 0;
 static Atom prop_btn_label = 0;
+static Atom prop_axes_rotation = 0;
 #endif
 
 /* All devices the evdev driver has allocated and knows about.
@@ -383,6 +385,15 @@ EvdevProcessValuators(InputInfoPtr pInfo, int 
v[MAX_VALUATORS], int *num_v,
 int first = REL_CNT, last = 0;
 int i;
 
+if (pEvdev->axes_rotation) {
+float rotation = (pEvdev->axes_rotation % 360) * M_PI / 180.0; // 
degrees to radians 
+float rot_cos = cos(rotation), rot_sin = sin(rotation);
+   
+tmp = pEvdev->delta[REL_X];
+pEvdev->delta[REL_X] = (int)(pEvdev->delta[REL_X] * rot_cos - 
pEvdev->delta[REL_Y] * rot_sin);
+pEvdev->delta[REL_Y] = (int)(pEvdev->delta[REL_Y] * rot_cos + tmp 
* rot_sin);
+}
+
 if (pEvdev->swap_axes) {
 tmp = pEvdev->delta[REL_X];
 pEvdev->delta[REL_X] = pEvdev->delta[REL_Y];
@@ -2516,6 +2527,13 @@ EvdevInitProperty(DeviceIntPtr dev)
 
 XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
 
+prop_axes_rotation = MakeAtom(EVDEV_PROP_AXES_ROTATION,
+strlen(EVDEV_PROP_AXES_ROTATION), TRUE);
+rc = XIChangeDeviceProperty(dev, prop_axes_rotation, XA_INTEGER, 16,
+PropModeReplace, 1, &pEvdev->axes_rotation, FALSE);
+if (rc != Success) 
+return;
+
 #ifdef HAVE_LABELS
 /* Axis labelling */
 if ((pEvdev->num_vals > 0) && (prop_axis_label = 
XIGetKnownProperty(AXIS_LABEL_PROP)))
@@ -2575,6 +2593,13 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, 
XIPropertyValuePtr val,
 
 if (!checkonly)
 pEvdev->swap_axes = *((BOOL*)val->data);
+} else if (atom == prop_axes_rotation)
+{
+if (val->format != 16 || val->type != XA_INTEGER || val->size != 1)
+return BadMatch;
+
+   if (!checkonly)
+  pEvdev->axes_rotation = *((CARD16*)val->data);
 } else if (atom == prop_axis_label || atom == prop_btn_label)
 return BadAccess; /* Axis/Button labels can't be changed */
 
diff --git a/src/evdev.h b/src/evdev.h
index b382670..17d607a 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -129,6 +129,7 @@ typedef struct {
 BOOL swap_axes;
 BOOL invert_x;
 BOOL invert_y;
+int axes_rotation;
 
 int delta[REL_CNT];
 unsigned int abs, rel;
-- 
1.7.1

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel