--- Xi/exevents.c.orig 2013-01-26 00:34:29.000000000 +0100 +++ Xi/exevents.c 2013-04-17 10:01:24.466342003 +0200 @@ -1231,9 +1231,16 @@ * touchpoint if it is pending finish. */ static void -ProcessTouchOwnershipEvent(DeviceIntPtr dev, TouchPointInfoPtr ti, - TouchOwnershipEvent *ev) +ProcessTouchOwnershipEvent(TouchOwnershipEvent *ev, + DeviceIntPtr dev) { + TouchPointInfoPtr ti = TouchFindByClientID(dev, ev->touchid); + + if (!ti) { + DebugF("[Xi] %s: Failed to get event %d for touchpoint %d\n", + dev->name, ev->type, ev->touchid); + return; + } if (ev->reason == XIRejectTouch) TouchRejected(dev, ti, ev->resource, ev); @@ -1546,10 +1553,7 @@ if (!t) return; - if (ev->any.type == ET_TouchOwnership) - touchid = ev->touch_ownership_event.touchid; - else - touchid = ev->device_event.touchid; + touchid = ev->device_event.touchid; if (type == ET_TouchBegin) { ti = TouchBeginTouch(dev, ev->device_event.sourceid, touchid, @@ -1622,22 +1626,21 @@ (type != ET_TouchEnd && ti->sprite.spriteTraceGood == 0)) return; - /* TouchOwnership events are handled separately from the rest, as they - * have more complex semantics. */ - if (ev->any.type == ET_TouchOwnership) - ProcessTouchOwnershipEvent(dev, ti, &ev->touch_ownership_event); - else { - TouchCopyValuatorData(&ev->device_event, ti); - /* WARNING: the event type may change to TouchUpdate in - * DeliverTouchEvents if a TouchEnd was delivered to a grabbing - * owner */ - DeliverTouchEvents(dev, ti, (InternalEvent *) ev, 0); - if (ev->any.type == ET_TouchEnd) - TouchEndTouch(dev, ti); - } - - if (emulate_pointer) + TouchCopyValuatorData(&ev->device_event, ti); + /* WARNING: the event type may change to TouchUpdate in + * DeliverTouchEvents if a TouchEnd was delivered to a grabbing + * owner */ + DeliverTouchEvents(dev, ti, (InternalEvent *) ev, 0); + if (ev->any.type == ET_TouchEnd) + TouchEndTouch(dev, ti); + + if (emulate_pointer) { + /* The event type might have been changed above. However, for pointer + * emulation purposes, we want to restore the original event type for + * correct processing of TouchEnd events. */ + ev->any.type = type; UpdateDeviceState(dev, &ev->device_event); + } } /** @@ -1785,10 +1788,14 @@ break; case ET_TouchBegin: case ET_TouchUpdate: - case ET_TouchOwnership: case ET_TouchEnd: ProcessTouchEvent(ev, device); break; + case ET_TouchOwnership: + /* TouchOwnership events are handled separately from the rest, as they + * have more complex semantics. */ + ProcessTouchOwnershipEvent(&ev->touch_ownership_event, device); + break; default: ProcessDeviceEvent(ev, device); break;