[PATCH 1/5] Split out helper function TouchListenerAcceptReject()

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 12 21:49:22 PDT 2012


On Wed, Apr 11, 2012 at 11:22:10AM -0700, Chase Douglas wrote:
> This will be used for accepting and rejecting touches in the future.
> 
> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
> ---
>  dix/events.c    |   11 +-------
>  dix/touch.c     |   68 ++++++++++++++++++++++++++++++++++--------------------
>  include/input.h |    2 +
>  3 files changed, 47 insertions(+), 34 deletions(-)
> 
> diff --git a/dix/events.c b/dix/events.c
> index 4470947..6bcb5eb 100644
> --- a/dix/events.c
> +++ b/dix/events.c
> @@ -1273,18 +1273,11 @@ ComputeFreezes(void)
>                         event->root_x, event->root_y);
>          if (!CheckDeviceGrabs(replayDev, event, syncEvents.replayWin)) {
>              if (IsTouchEvent((InternalEvent *) event)) {
> -                InternalEvent *events = InitEventList(GetMaximumEventsNum());
> -                int i, nev;
>                  TouchPointInfoPtr ti =
>                      TouchFindByClientID(replayDev, event->touchid);
>                  BUG_WARN(!ti);
> -                nev =
> -                    GetTouchOwnershipEvents(events, replayDev, ti,
> -                                            XIRejectTouch,
> -                                            ti->listeners[0].listener, 0);
> -                for (i = 0; i < nev; i++)
> -                    mieqProcessDeviceEvent(replayDev, events + i, NULL);
> -                ProcessInputEvents();
> +
> +                TouchListenerAcceptReject(replayDev, ti, 0, XIRejectTouch);
>              }
>              else if (replayDev->focus &&
>                       !IsPointerEvent((InternalEvent *) event))
> diff --git a/dix/touch.c b/dix/touch.c
> index 0829b65..dedc686 100644
> --- a/dix/touch.c
> +++ b/dix/touch.c
> @@ -960,15 +960,52 @@ TouchListenerGone(XID resource)
>  }
>  
>  int
> +TouchListenerAcceptReject(DeviceIntPtr dev, TouchPointInfoPtr ti, int listener,
> +                          int mode)
> +{
> +    InternalEvent *events;
> +    int nev;
> +    int i;
> +
> +    if (listener > 0) {
> +        if (mode == XIRejectTouch)
> +            TouchRejected(dev, ti, ti->listeners[listener].listener, NULL);
> +        else
> +            ti->listeners[listener].state = LISTENER_EARLY_ACCEPT;
> +
> +        return Success;
> +    }
> +
> +    events = InitEventList(GetMaximumEventsNum());
> +    if (!events) {
> +        BUG_WARN_MSG(TRUE, "Failed to allocate touch ownership events\n");
> +        return BadAlloc;
> +    }
> +
> +    nev = GetTouchOwnershipEvents(events, dev, ti, mode,
> +                                  ti->listeners[0].listener, 0);
> +    if (nev == 0) {
> +        BUG_WARN_MSG(TRUE, "Failed to get touch ownership events\n");
> +        FreeEventList(events, GetMaximumEventsNum());
> +        return BadMatch;

you could turn this into a 
BUG_WARN_MSG(nev == 0, ...)
and then return nev ? Success : BadMatch;
if nev is 0, the loop isn't handled, PIE doesn't do much (I think, can be
conditional on nev > 0) and FreeEventList is needed anyay.
This is just so that the bug macro has a better condition than just always
TRUE.

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> otherwise


Cheers,
  Peter

> +    }
> +
> +    for (i = 0; i < nev; i++)
> +        mieqProcessDeviceEvent(dev, events + i, NULL);
> +
> +    ProcessInputEvents();
> +
> +    FreeEventList(events, GetMaximumEventsNum());
> +
> +    return Success;
> +}
> +
> +int
>  TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode,
>                    uint32_t touchid, Window grab_window, XID *error)
>  {
>      TouchPointInfoPtr ti;
> -    int nev, i;
> -    InternalEvent *events = InitEventList(GetMaximumEventsNum());
> -
> -    if (!events)
> -        return BadAlloc;
> +    int i;
>  
>      if (!dev->touch) {
>          *error = dev->id;
> @@ -989,24 +1026,5 @@ TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode,
>      if (i == ti->num_listeners)
>          return BadAccess;
>  
> -    if (i > 0) {
> -        if (mode == XIRejectTouch)
> -            TouchRejected(dev, ti, ti->listeners[i].listener, NULL);
> -        else
> -            ti->listeners[i].state = LISTENER_EARLY_ACCEPT;
> -
> -        return Success;
> -    }
> -
> -    nev = GetTouchOwnershipEvents(events, dev, ti, mode,
> -                                  ti->listeners[0].listener, 0);
> -    if (nev == 0)
> -        return BadAlloc;
> -    for (i = 0; i < nev; i++)
> -        mieqProcessDeviceEvent(dev, events + i, NULL);
> -
> -    ProcessInputEvents();
> -
> -    FreeEventList(events, GetMaximumEventsNum());
> -    return Success;
> +    return TouchListenerAcceptReject(dev, ti, i, mode);
>  }
> diff --git a/include/input.h b/include/input.h
> index d891fe5..9a6fdfe 100644
> --- a/include/input.h
> +++ b/include/input.h
> @@ -572,6 +572,8 @@ extern int TouchConvertToPointerEvent(const InternalEvent *ev,
>  extern int TouchGetPointerEventType(const InternalEvent *ev);
>  extern void TouchRemovePointerGrab(DeviceIntPtr dev);
>  extern void TouchListenerGone(XID resource);
> +extern int TouchListenerAcceptReject(DeviceIntPtr dev, TouchPointInfoPtr ti,
> +                                     int listener, int mode);
>  extern int TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode,
>                               uint32_t touchid, Window grab_window, XID *error);
>  
> -- 
> 1.7.9.1
> 


More information about the xorg-devel mailing list