New approach to multitouch using DIDs and bitmasked events

Peter Hutterer peter.hutterer at who-t.net
Sun Jul 11 19:00:04 PDT 2010


On Wed, Jul 07, 2010 at 03:21:32PM -0400, Chase Douglas wrote:
> On Tue, 2010-07-06 at 11:33 +1000, Peter Hutterer wrote:
> > On Fri, Jul 02, 2010 at 09:09:48PM -0400, Chase Douglas wrote:
> > > > This is a good start. Eventually, we should have DIDs exposed as a new 
> > > > device class on the protocol though. Likewise, I don't think ET_DM 
> > > > should not be converted to normal XIDeviceEvents but rather to their own 
> > > > type that can be expanded in the future to accommodate for additional 
> > > > features (e.g. the touch area).
> > > 
> > > I hacked some more today, and I'm not sure we need a separate XI2 event
> > > type. I'm going to send out another RFC "pull request" with the work
> > > soon, but as an overview I wanted to work on the "magicmouse" scenario.
> > > The result is the following:
> > > 
> > > MT Touchscreen:
> > >   - Device is marked as a DID
> > >   - Starts out floating, can't be attached
> > >   - MT touch coordinates are the first two valuators, XIDeviceEvents are
> > >     in screen coordinates. However, an app can grab XIRawEvents for
> > >     device coordinates. *
> > >   - Since it's a DID, button events are also blocked for core, XI1
> > > 
> > > Magic Mouse:
> > >   - Device is *not* marked as a DID
> > >   - Starts out attached to virtual core master pointer
> > >   - First two axes are REL_X, REL_Y
> > >   - Device is marked as relative (for core and XI1 events)
> > >   - Abs MT axes are marked as absolute
> > >     * Can only be sent through XI2 since XI can't handle mixed mode
> > >   - Since Abs MT touches are not the first two axes, they are not
> > >     translated to screen coordinates
> > >   - Abs MT axes sent through XI2 are also sent through attached master
> > >   - Button events are not blocked for core, XI1
> > > 
> > > I am not aware of any use case that is not covered by the above scheme
> > > and requires a new XI2 event type. If you know of any, please let me
> > > know.
> > 
> > How will a client know if a device is a DID? XIQueryDevice must return this
> > information.
> > 
> > One of the things I do also expect from DIDs is that the _first_ touchpoint
> > is converted into core events. Thus, even on a multitouch device you can
> > still interact in a traditional way with apps that won't support touch
> > events  Hoping for Tk and others to be updated to support a new device type
> > is a bit too optimistic. Worse, it introduces a hard transition between what
> > we have now and what we can, i.e. you force everyone to update or otherwise
> > they lose what they have. That's not good IMO, we need a transitional
> > solution.
> > 
> > Anyway. My idea of DIDs was the following:
> > the driver creates one master pointer device for a physical touchscreen.
> > This master pointer device is controlled by the first touchpoint on the
> > screen. At the same time, the driver creates DIDs on-demand as it is being
> > used. Each DID stands for one touchpoint and sends DirectEvents or whatever
> > they're called. Obviously, that gives you a duplication but the device
> > hierarchy should reference which device is a DID device, thus MT aware apps
> > can just ignore pointer events from that master (or not, in the case of the
> > magic mouse, possibly need some flag here).
> > 
> > DIDs are short-lived and don't show up in the hierarchy, only the parent
> > device does, indicating that DIDs may be present. Button or key events are
> > all routed through the master pointer.
> > 
> > This is the approach that I think could work. though we won't know until we
> > write down the spec. Something I recommend for your approach as well, sit
> > down with XI2proto.txt and write the additions and how clients can use them.
> > More often than not, you'll likely notice some issues and have to go back to
> > the code.
> 
> I started to think about this, which led to the following:
> 
> 1. Instead of allocating devices one at a time each time a touch begins
> and then deallocating when the touch ends, lets just have a pool of
> devices.
> 2. If we have a pool of devices and we have MTDev, why not index the
> devices in the pool by ABS_MT_SLOT. If we encounter a higher slot than
> we have allocated for, just allocate a new one on the spot.
> 3. If we have a pool of slotted devices, then what's the point of DIDs?

Don't think too much in terms of implementation, think about what clients
will see in the protocol. There's a number of ways how to get DIDs into the
server and I think I said before that DIDs may not necessarily be
DeviceIntRec in the implementation.

I've been thinking of a DID mostly as a sequence of events following the
init-move-destroy cycle. How that's implemented doesn't matter just yet.

> I was keying all my work off of the concepts Peter pointed out here:
> 
>    http://lists.x.org/archives/xorg-devel/2010-June/009757.html
> 
>    The arguments boiled down mostly to: input devices can't be transient
> due to grab issues. But our touch devices aren't transient anymore.
> 
> I took a look at Carlos' evdev driver (mentioned in the above email),
> and it matches rather closely to my thinking. The difference is that he
> preallocates a defined amount of touch devices instead of using MTDev.
> 
> I also wonder why we can't just create a master pointer for each touch
> point device? I can see where there could be some funkiness if the user
> sees cursors for touch pointers (slots change between touches, so if you
> dragged one cursor to a window, ended the touch, then touched again you
> may see a different cursor be controlled). However, disabling the cursor
> sprite for touch pointers would solve that issue. Otherwise, everything
> should just work as well as MPX does today. (This could also be an evdev
> option if people didn't want touches as MPX master pointers).

expensive and it would push us to some limits quite quickly. we have a
current limit of 40 devices. that could be pushed up to 127 easily at the
cost of some memory but once you get past 127 it'll get tricky and will
likely require some extra coding that I'd prefer to avoid.

adding new master devices is costly, you get hierarchy events, XTEST
devices, forced pairing with keyboards, etc.
I also don't quite know what you would do if you have 1 physical keyboards
but 15 master pointers (from the touchpoints). I can't think of a
half-decent UI to even deal with that.

> The main difference I see between the DIDs approach and Carlos' approach
> is that the DIDs would explicitly disappear after the touch ends and a
> new one would be created when a touch begins. Is there a necessity for
> this behavior?

Implementation detail. Doesn't matter what the server does, the important
thing is what happens on the wire.
 
Cheers,
  Peter


More information about the xorg-devel mailing list