[PATCH 15/18] Add rotation support for synaptics driver

Peter Hutterer peter.hutterer at who-t.net
Tue Oct 12 21:13:00 PDT 2010


wacom calls it rotation, not sure about other drivers (evdev has an
unfortunate mix of swapaxes and invert). some consistency would be nice.
also, add man page update please with the allowed values.

IMO the orientation property should go into the server anyway, so we finally
have some consistency. there's also a demand for orientation other than in
90 deg increments, so perhaps parsing the actual degrees would be useful.

Cheers,
  Peter

On Fri, Oct 08, 2010 at 07:22:39PM +0200, Takashi Iwai wrote:
> Signed-off-by: Takashi Iwai <tiwai at suse.de>
> ---
>  include/synaptics-properties.h |    3 +++
>  src/properties.c               |    8 ++++++++
>  src/synaptics.c                |   35 +++++++++++++++++++++++++++++++++++
>  src/synapticsstr.h             |    1 +
>  tools/synclient.c              |    1 +
>  5 files changed, 48 insertions(+), 0 deletions(-)
> 
> diff --git a/include/synaptics-properties.h b/include/synaptics-properties.h
> index 5d440be..f6fbfac 100644
> --- a/include/synaptics-properties.h
> +++ b/include/synaptics-properties.h
> @@ -179,4 +179,7 @@
>  /* 32bit, read-only */
>  #define SYNAPTICS_PROP_GESTURE_MODE "Current Gesture Mode"
>  
> +/* 32 bit */
> +#define SYNAPTICS_PROP_ORIENTATION "Synaptics Orientation"
> +
>  #endif /* _SYNAPTICS_PROPERTIES_H_ */
> diff --git a/src/properties.c b/src/properties.c
> index 7788a13..7278560 100644
> --- a/src/properties.c
> +++ b/src/properties.c
> @@ -46,6 +46,7 @@ static Atom float_type;
>  
>  Atom prop_edges                 = 0;
>  Atom prop_finger                = 0;
> +Atom prop_orientation           = 0;
>  Atom prop_tap_time              = 0;
>  Atom prop_tap_move              = 0;
>  Atom prop_tap_durations         = 0;
> @@ -263,6 +264,8 @@ InitDeviceProperties(InputInfoPtr pInfo)
>  
>      prop_pressuremotion_factor = InitFloatAtom(pInfo->dev, SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 2, fvalues);
>  
> +    prop_orientation = InitAtom(local->dev, SYNAPTICS_PROP_ORIENTATION, 32, 1, &para->orientation);
> +
>      prop_grab = InitAtom(pInfo->dev, SYNAPTICS_PROP_GRAB, 8, 1, &para->grab_event_device);
>  
>      values[0] = para->tap_and_drag_gesture;
> @@ -674,6 +677,11 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
>  
>          para->press_motion_min_z = press[0];
>          para->press_motion_max_z = press[1];
> +    } else if (property == prop_orientation) {
> +        if (prop->size != 1 || prop->format != 32 || prop->type != XA_INTEGER)
> +            return BadMatch;
> +
> +	para->orientation = *(INT32*)prop->data;
>      } else if (property == prop_grab)
>      {
>          if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER)
> diff --git a/src/synaptics.c b/src/synaptics.c
> index 2f264f0..71a5134 100644
> --- a/src/synaptics.c
> +++ b/src/synaptics.c
> @@ -600,6 +600,7 @@ static void set_default_parameters(InputInfoPtr pInfo)
>      pars->coasting_friction = xf86SetRealOption(opts, "CoastingFriction", 50);
>      pars->press_motion_min_factor = xf86SetRealOption(opts, "PressureMotionMinFactor", 1.0);
>      pars->press_motion_max_factor = xf86SetRealOption(opts, "PressureMotionMaxFactor", 1.0);
> +    pars->orientation = xf86SetIntOption(opts, "Orientation", 0);
>      pars->grab_event_device = xf86SetBoolOption(opts, "GrabEventDevice", TRUE);
>      pars->tap_and_drag_gesture = xf86SetBoolOption(opts, "TapAndDragGesture", TRUE);
>      pars->resolution_horiz = xf86SetIntOption(opts, "HorizResolution", horizResolution);
> @@ -2818,6 +2819,38 @@ repeat_scrollbuttons(const InputInfoPtr pInfo,
>      return delay;
>  }
>  
> +static void do_rotation(SynapticsPrivate *priv, int orientation, int *xp, int *yp)
> +{
> +    int width = priv->maxx - priv->minx;
> +    int height = priv->maxy - priv->miny;
> +    int x = *xp;
> +    int y = *yp;
> +
> +    switch (orientation) {
> +    case 1:
> +	*xp = (priv->maxy - y) * width / height + priv->minx;
> +	*yp = (x - priv->minx) * height / width + priv->miny;
> +	break;
> +    case 2:
> +	*xp = priv->maxx + priv->minx - x;
> +	*yp = priv->maxy + priv->miny - y;
> +	break;
> +    case 3:
> +	*xp = (y - priv->miny) * width / height + priv->minx;
> +	*yp = (priv->maxx - x) * height / width + priv->miny;
> +	break;
> +    }
> +}
> +
> +static void update_orientation(SynapticsPrivate *priv,
> +			       struct SynapticsHwState *hw)
> +{
> +    SynapticsParameters *para = &priv->synpara;
> +    do_rotation(priv, para->orientation, &hw->x, &hw->y);
> +    if (hw->multi_touch > 1)
> +	do_rotation(priv, para->orientation, &hw->multi_touch_x, &hw->multi_touch_y);
> +}
> +
>  /*
>   * React on changes in the hardware state. This function is called every time
>   * the hardware state changes. The return value is used to specify how many
> @@ -2843,6 +2876,8 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw)
>  
>      prev_gesture_mode = priv->gesture_mode;
>  
> +    update_orientation(priv, hw);
> +
>      update_multi_touch(priv, hw);
>  
>      update_shm(pInfo, hw);
> diff --git a/src/synapticsstr.h b/src/synapticsstr.h
> index 285c8f3..e972a42 100644
> --- a/src/synapticsstr.h
> +++ b/src/synapticsstr.h
> @@ -101,6 +101,7 @@ typedef struct _SynapticsParameters
>  {
>      /* Parameter data */
>      int left_edge, right_edge, top_edge, bottom_edge; /* edge coordinates absolute */
> +    int orientation;
>      int finger_low, finger_high, finger_press;	      /* finger detection values in Z-values */
>      int tap_time;
>      int tap_move;			    /* max. tapping time and movement in packets and coord. */
> diff --git a/tools/synclient.c b/tools/synclient.c
> index 68faa13..c08d30c 100644
> --- a/tools/synclient.c
> +++ b/tools/synclient.c
> @@ -78,6 +78,7 @@ static struct Parameter params[] = {
>      {"RightEdge",             PT_INT,    0, 10000, SYNAPTICS_PROP_EDGES,	32,	1},
>      {"TopEdge",               PT_INT,    0, 10000, SYNAPTICS_PROP_EDGES,	32,	2},
>      {"BottomEdge",            PT_INT,    0, 10000, SYNAPTICS_PROP_EDGES,	32,	3},
> +    {"Orientation",           PT_INT,    0, 3,     SYNAPTICS_PROP_ORIENTATION,	32,     0},
>      {"FingerLow",             PT_INT,    0, 255,   SYNAPTICS_PROP_FINGER,	32,	0},
>      {"FingerHigh",            PT_INT,    0, 255,   SYNAPTICS_PROP_FINGER,	32,	1},
>      {"FingerPress",           PT_INT,    0, 256,   SYNAPTICS_PROP_FINGER,	32,	2},
> -- 
> 1.7.3.1
> 


More information about the xorg-devel mailing list