[PATCH 1/5] Split out helper function TouchListenerAcceptReject()
Bryce Harrington
bryce at canonical.com
Thu Apr 19 09:38:02 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);
There isn't a null pointer check on ti prior to this dereference. Is it
guaranteed in all callers that ti will never be NULL?
Should listener < len(ti->listeners) be asserted to catch out of bounds
errors?
> + 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;
> + }
> +
> + 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
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
More information about the xorg-devel
mailing list