[PATCH] Don't include touch state for emulated button press events

Chase Douglas chase.douglas at canonical.com
Fri Jul 6 14:50:18 PDT 2012


On 07/03/2012 05:30 PM, Chase Douglas wrote:
> When a touch begin is pointer emulated, do not include touch state when
> calculating the button state for the initial motion and button press
> events. This ensures the logical state of the buttons prior to the
> events is set properly.

This doesn't fully take care of the issue. A subsequent motion event 
after the emulated button release will still have the button 1 mask set. 
I am working on a solution for this.

> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
> ---
>   Xi/exevents.c        |   17 +++++++++++++----
>   dix/events.c         |    2 +-
>   dix/inpututils.c     |   10 ++++++----
>   include/inpututils.h |    5 +++--
>   4 files changed, 23 insertions(+), 11 deletions(-)
>
> diff --git a/Xi/exevents.c b/Xi/exevents.c
> index e99bf6c..dfc89df 100644
> --- a/Xi/exevents.c
> +++ b/Xi/exevents.c
> @@ -1417,8 +1417,15 @@ DeliverTouchEmulatedEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
>           ptrev = &button;
>
>       kbd = GetMaster(dev, KEYBOARD_OR_FLOAT);
> -    event_set_state(dev, kbd, &ptrev->device_event);
> -    ptrev->device_event.corestate = event_get_corestate(dev, kbd);
> +
> +    /* Don't include touch state for touch begin events that are emulated as
> +     * button press events. The touch state already includes the button press
> +     * for the touch, but the button press event state is supposed to represent
> +     * the state of the buttons *before* the event occurred */
> +    event_set_state(dev, kbd, &ptrev->device_event,
> +                    ev->any.type != ET_TouchBegin);
> +    ptrev->device_event.corestate =
> +        event_get_corestate(dev, kbd, ev->any.type != ET_TouchBegin);
>
>       if (grab) {
>           /* this side-steps the usual activation mechansims, but... */
> @@ -1673,8 +1680,10 @@ ProcessDeviceEvent(InternalEvent *ev, DeviceIntPtr device)
>               mouse = NULL;
>       }
>
> -    corestate = event_get_corestate(mouse, kbd);
> -    event_set_state(mouse, kbd, event);
> +    corestate = event_get_corestate(mouse, kbd,
> +                                    ev->device_event.flags != XIPointerEmulated);
> +    event_set_state(mouse, kbd, event,
> +                    ev->device_event.flags != XIPointerEmulated);
>
>       ret = UpdateDeviceState(device, event);
>       if (ret == DONT_PROCESS)
> diff --git a/dix/events.c b/dix/events.c
> index 89877a1..e328b40 100644
> --- a/dix/events.c
> +++ b/dix/events.c
> @@ -5142,7 +5142,7 @@ ProcQueryPointer(ClientPtr client)
>       memset(&rep, 0, sizeof(xQueryPointerReply));
>       rep.type = X_Reply;
>       rep.sequenceNumber = client->sequence;
> -    rep.mask = event_get_corestate(mouse, keyboard);
> +    rep.mask = event_get_corestate(mouse, keyboard, TRUE);
>       rep.length = 0;
>       rep.root = (GetCurrentRootWindow(mouse))->drawable.id;
>       rep.rootX = pSprite->hot.x;
> diff --git a/dix/inpututils.c b/dix/inpututils.c
> index 223d547..b483e71 100644
> --- a/dix/inpututils.c
> +++ b/dix/inpututils.c
> @@ -662,7 +662,7 @@ init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
>   }
>
>   int
> -event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd)
> +event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd, Bool include_touch)
>   {
>       int corestate;
>
> @@ -671,13 +671,15 @@ event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd)
>                    kbd->key) ? XkbStateFieldFromRec(&kbd->key->xkbInfo->
>                                                     state) : 0;
>       corestate |= (mouse && mouse->button) ? (mouse->button->state) : 0;
> -    corestate |= (mouse && mouse->touch) ? (mouse->touch->state) : 0;
> +    corestate |= (include_touch && mouse && mouse->touch) ?
> +                 (mouse->touch->state) : 0;
>
>       return corestate;
>   }
>
>   void
> -event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event)
> +event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event,
> +                Bool include_touch)
>   {
>       int i;
>
> @@ -685,7 +687,7 @@ event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd, DeviceEvent *event)
>           if (BitIsOn(mouse->button->down, i))
>               SetBit(event->buttons, mouse->button->map[i]);
>
> -    if (mouse && mouse->touch && mouse->touch->buttonsDown > 0)
> +    if (include_touch && mouse && mouse->touch && mouse->touch->buttonsDown > 0)
>           SetBit(event->buttons, mouse->button->map[1]);
>
>       if (kbd && kbd->key) {
> diff --git a/include/inpututils.h b/include/inpututils.h
> index cd9a4de..1eac13d 100644
> --- a/include/inpututils.h
> +++ b/include/inpututils.h
> @@ -42,9 +42,10 @@ struct _ValuatorMask {
>
>   extern void verify_internal_event(const InternalEvent *ev);
>   extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
> -extern int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd);
> +extern int event_get_corestate(DeviceIntPtr mouse, DeviceIntPtr kbd,
> +                               Bool include_touch);
>   extern void event_set_state(DeviceIntPtr mouse, DeviceIntPtr kbd,
> -                            DeviceEvent *event);
> +                            DeviceEvent *event, Bool include_touch);
>   extern Mask event_get_filter_from_type(DeviceIntPtr dev, int evtype);
>   extern Mask event_get_filter_from_xi2type(int evtype);
>
>



More information about the xorg-devel mailing list