[PATCH] evdev: allow mouse wheel emulation to work even with absolute-position devices (like touchscreens)

Peter Hutterer peter.hutterer at who-t.net
Tue Dec 1 16:15:16 PST 2009


Hi Dima,

On Sun, Nov 29, 2009 at 07:16:37PM -0800, Dima Kogan wrote:
> Hi. I modified the evdev driver to allow mousewheel emulation to work
> on touchscreen devices. Previously this wasn't possible since
> touchscreens report absolute, instead of relative positions, and the
> wheel emulation code hooked into the relative position reporting code.
> 
> The bulk is in the first patch; the second patch is not strictly
> necessary. I have tested the code on the one touchscreen device I have
> (openmoko freerunner) and it seems to work. If I get the thumbs up, I
> will modify the non-evdev versions of this code (the "mouse" driver is
> the only one, right?) Thanks.

Thanks for the patch. I'm happy to add support for mousewheel emu for
absolute devices. Please see the comments below though.

> From 4db8b697d2cf4c06b8b1d0384eab9bdc9b638335 Mon Sep 17 00:00:00 2001
> From: Dima Kogan <dkogan at secretsauce.net>
> Date: Sun, 29 Nov 2009 18:00:08 -0800
> Subject: [PATCH 1/2] allow wheel emulation to work even with absolute-position devices
> 
> Signed-off-by: Dima Kogan <dkogan at cds.caltech.edu>
> ---
>  src/emuWheel.c |   22 +++++-----------------
>  src/evdev.c    |   23 ++++++++++++++++++++---
>  src/evdev.h    |    2 +-
>  3 files changed, 26 insertions(+), 21 deletions(-)
> 
> diff --git a/src/emuWheel.c b/src/emuWheel.c
> index e7b2f98..734b11a 100644
> --- a/src/emuWheel.c
> +++ b/src/emuWheel.c
> @@ -95,11 +95,10 @@ EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
>  
>  /* Filter mouse wheel events */
>  BOOL
> -EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
> +EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, BOOL isX, int delta)
>  {
>      EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
>      WheelAxisPtr pAxis = NULL, pOtherAxis = NULL;
> -    int value = pEv->value;
>  
>      /* Has wheel emulation been configured to be enabled? */
>      if (!pEvdev->emulateWheel.enabled)
> @@ -117,20 +116,12 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
>                  return TRUE;
>          }
>  
> -	/* We don't want to intercept real mouse wheel events */
> -	switch(pEv->code) {
> -	case REL_X:
> +	if (isX) {
>  	    pAxis = &(pEvdev->emulateWheel.X);
>  	    pOtherAxis = &(pEvdev->emulateWheel.Y);
> -	    break;
> -
> -	case REL_Y:
> +	} else {
>  	    pAxis = &(pEvdev->emulateWheel.Y);
>  	    pOtherAxis = &(pEvdev->emulateWheel.X);
> -	    break;

instead of modifying the function signature and introducing a lot of churn,
you could just change the switch statement to:

switch(pEv->code)
{
        case REL_X:
        case ABS_X:
                blahblah
        ...
}

this should give you the same result but make the code a lot cleaner.
of course, the other hunks need to be adjusted for that then but the diff
should be a lot smaller.

Cheers,
  Peter


More information about the xorg-devel mailing list