Pointer emulation
Pointer emulation is the most complicated part of the code since it needs to transparently work around pointer grabs in all three protocols (core, xi2, xi).
Pointer emulation is decided on in the event generation code: if a new TouchBegin is submitted and no other emulating touchpoint is currently active, the new touchpoint becomes the emulating touchpoint. This code has a few corner cases that will be buggy. E.g. two touch device submitting their first event through the master, both will assume pointer emulation. Furthermore, the events the server deals with internally are always touch events. If a pointer-emulating touch should send pointer events, this conversion happens quite late and only for the wire protocol. The reason is simple - if an event is replayed, we need to know that the original event was a touch event to make sure we deliver the right type to the next client.