On Mon, Aug 13, 2012 at 06:05:08PM -0700, Jason Gerecke wrote:
> Instead of setting up a static mapping which "directly" associates
> flags in the button int with X11 buttons, we determine the proper
> X11 button to use based on the kernel event recieved. Normally
> these are the same, but in the case of "mouse" buttons (which have
> are now also stored in usbdata->padkey_code) don't work properly
> since there are often "holes" in the button association.
> 
> Signed-off-by: Jason Gerecke <killert...@gmail.com>
> ---
>  src/wcmConfig.c |  7 +----
>  src/wcmISDV4.c  | 13 +++++++++
>  src/wcmUSB.c    | 91 
> ++++++++++++++++++++++++++++-----------------------------
>  3 files changed, 59 insertions(+), 52 deletions(-)
> 
> diff --git a/src/wcmConfig.c b/src/wcmConfig.c
> index 157d9d3..ffbd6ea 100644
> --- a/src/wcmConfig.c
> +++ b/src/wcmConfig.c
> @@ -38,7 +38,6 @@ static int wcmAllocate(InputInfoPtr pInfo)
>       WacomDevicePtr   priv   = NULL;
>       WacomCommonPtr   common = NULL;
>       WacomToolPtr     tool   = NULL;
> -     int i;
>  
>       priv = calloc(1, sizeof(WacomDeviceRec));
>       if (!priv)
> @@ -68,12 +67,8 @@ static int wcmAllocate(InputInfoPtr pInfo)
>       priv->nPressCtrl [2] = 100;  /* pressure curve x1 */
>       priv->nPressCtrl [3] = 100;  /* pressure curve y1 */
>  
> -     /* Default button and expresskey values, offset buttons 4 and higher
> -      * by the 4 scroll buttons. */
> -     for (i=0; i<WCM_MAX_BUTTONS; i++)
> -             priv->button_default[i] = (i < 3) ? i + 1 : i + 5;
> +     /* Don't initialize buttons -- leave this up to wcmUSB/wcmISDV4 */
>  
> -     priv->nbuttons = WCM_MAX_BUTTONS;       /* Default number of buttons */
>       priv->wheel_default[WHEEL_REL_UP] = 5;
>       priv->wheel_default[WHEEL_REL_DN] = 4;
>       /* wheel events are set to 0, but the pad overwrites this default
> diff --git a/src/wcmISDV4.c b/src/wcmISDV4.c
> index 17f5326..cc3e73a 100644
> --- a/src/wcmISDV4.c
> +++ b/src/wcmISDV4.c
> @@ -272,6 +272,19 @@ static Bool isdv4Init(InputInfoPtr pInfo, char* id, 
> float *version)
>       /*set the model */
>       common->wcmModel = &isdv4General;
>  
> +     /* set available buttons */
> +     if (IsPen(priv)) {
> +             priv->nbuttons = 3;
> +             priv->button_default[0] = 1;
> +             priv->button_default[1] = 2;
> +             priv->button_default[2] = 3;
> +     }
> +     else if (IsTouch(priv)) {
> +             priv->nbuttons = 2;
> +             priv->button_default[0] = 1;
> +             priv->button_default[1] = 3;
> +     }
> +
>       return Success;
>  }
>  
> diff --git a/src/wcmUSB.c b/src/wcmUSB.c
> index 3ee5d8f..58a54af 100644
> --- a/src/wcmUSB.c
> +++ b/src/wcmUSB.c
> @@ -370,27 +370,51 @@ static Bool usbWcmInit(InputInfoPtr pInfo, char* id, 
> float *version)
>               common->wcmResolX = common->wcmResolY = 1016;
>       }
>  
> -     /* Find out supported button codes. */
> -     usbdata->npadkeys = 0;
> -     for (i = 0; i < ARRAY_SIZE(padkey_codes); i++)
> -             if (ISBITSET (common->wcmKeys, padkey_codes [i]))
> -                     usbdata->padkey_code [usbdata->npadkeys++] = 
> padkey_codes [i];
> +     if (IsPad(priv)) {
> +             /* Find out supported button codes. */
> +             usbdata->npadkeys = 0;
> +             for (i = 0; i < ARRAY_SIZE(padkey_codes); i++) {
> +                     if (ISBITSET (common->wcmKeys, padkey_codes [i])) {
> +                             priv->button_default[usbdata->npadkeys] = (i < 
> 3) ? i + 1 : i + 5;
> +                             usbdata->padkey_code [usbdata->npadkeys] = 
> padkey_codes [i];

style nitpick, no space before [
(yes, I realise that was there before)

> +                             usbdata->npadkeys++;
> +                     }
> +             }
> +     }
>  
> -     if (usbdata->npadkeys == 0) {
> +     if (IsCursor(priv) || (IsPad(priv) && usbdata->npadkeys == 0)) {
>               /* If no pad keys were detected, entertain the possibility that 
> any
>                * mouse buttons which exist may belong to the pad (e.g. 
> Graphire4).
>                * If we're wrong, this will over-state the capabilities of the 
> pad
>                * but that shouldn't actually cause problems.
>                */
> -             for (i = ARRAY_SIZE(mouse_codes) - 1; i > 0; i--)
> +             for (i = 0; i < ARRAY_SIZE(mouse_codes); i++)
>                       if (ISBITSET(common->wcmKeys, mouse_codes[i]))
> -                             break;
> +                             usbdata->padkey_code [usbdata->npadkeys++] = 
> mouse_codes[i];
> +
> +             for (i=0; i<usbdata->npadkeys; i++) {

style nit again, spaces around <

Reviewed-by: Peter Hutterer <peter.hutte...@who-t.net>

Cheers,
   Peter

> +                     switch (usbdata->padkey_code[i]) {
> +                             case BTN_LEFT:    priv->button_default[i] = 1; 
> break;
> +                             case BTN_MIDDLE:  priv->button_default[i] = 2; 
> break;
> +                             case BTN_RIGHT:   priv->button_default[i] = 3; 
> break;
> +                             case BTN_BACK:    priv->button_default[i] = 8; 
> break;
> +                             case BTN_FORWARD: priv->button_default[i] = 9; 
> break;
> +                             case BTN_SIDE:    priv->button_default[i] = 8; 
> break;
> +                             case BTN_EXTRA:   priv->button_default[i] = 9; 
> break;
> +                     }
> +             }
> +     }
>  
> -             /* Make sure room for fixed map mouse buttons.  This
> -              * means mappings may overlap with padkey_codes[].
> -              */
> -             if (i != 0)
> -                     usbdata->npadkeys = WCM_USB_MAX_MOUSE_BUTTONS;
> +     if (IsPen(priv)) {
> +             priv->button_default[0] = 1;
> +             priv->button_default[1] = 2;
> +             priv->button_default[2] = 3;
> +     }
> +
> +     if (IsTouch(priv)) {
> +             /* We only simulate left and right click */
> +             priv->button_default[0] = 1;
> +             priv->button_default[1] = 3;
>       }
>  
>       /* nbuttons tracks maximum buttons on all tools (stylus/mouse).
> @@ -1323,42 +1347,17 @@ static int usbParseBTNEvent(WacomCommonPtr common,
>       int change = 1;
>       wcmUSBData *usbdata = common->private;
>  
> -     switch (event->code)
> +     for (nkeys = 0; nkeys < usbdata->npadkeys; nkeys++)
>       {
> -             case BTN_LEFT:
> -                     ds->buttons = mod_buttons(ds->buttons, 0, event->value);
> -                     break;
> -
> -             case BTN_MIDDLE:
> -                     ds->buttons = mod_buttons(ds->buttons, 1, event->value);
> -                     break;
> -
> -             case BTN_RIGHT:
> -                     ds->buttons = mod_buttons(ds->buttons, 2, event->value);
> -                     break;
> -
> -             case BTN_SIDE:
> -             case BTN_BACK:
> -                     ds->buttons = mod_buttons(ds->buttons, 3, event->value);
> -                     break;
> -
> -             case BTN_EXTRA:
> -             case BTN_FORWARD:
> -                     ds->buttons = mod_buttons(ds->buttons, 4, event->value);
> +             if (event->code == usbdata->padkey_code[nkeys])
> +             {
> +                     ds->buttons = mod_buttons(ds->buttons, nkeys, 
> event->value);
>                       break;
> -
> -             default:
> -                     for (nkeys = 0; nkeys < usbdata->npadkeys; nkeys++)
> -                     {
> -                             if (event->code == usbdata->padkey_code[nkeys])
> -                             {
> -                                     ds->buttons = mod_buttons(ds->buttons, 
> nkeys, event->value);
> -                                     break;
> -                             }
> -                     }
> -                     if (nkeys >= usbdata->npadkeys)
> -                             change = 0;
> +             }
>       }
> +     if (nkeys >= usbdata->npadkeys)
> +             change = 0;
> +
>       return change;
>  }
>  
> -- 
> 1.7.11.4
> 
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Linuxwacom-devel mailing list
> Linuxwacom-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel
> 

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to