Multitouch followup: gesture recognition?

Peter Hutterer peter.hutterer at who-t.net
Tue Mar 23 23:36:02 PDT 2010


Only replying to one email, answers to both of your comments.

On Wed, Mar 24, 2010 at 12:06:30AM +0100, Simon Thum wrote:
> [CC'ing Pter, see below]
> 
> Am 23.03.2010 18:42, schrieb Florian Echtler:
> > Just for my understanding: when talking about a special client, you think of 
> > something like a (compositing) window manager?
> Yes, 'special' since it registers itself for rights (and duties) only
> one client shall possess.

why? can't the same library be used by multiple clients (thus unifying the
gesture types) but the clients divide up the available region. This works
well for button presses, couldn't it work with gestures as well?

> >> A library can be done 'right now', since apps are free to do so. It has
> >> the advantage of a close connection to the consuming app, but also the
> >> associated disadvantages.
> >> In particular, how to cope with global gestures, e.g. switching an app
> >> or backgrounding it? Apparently, such things should be consistent. I
> >> imagine a desktop environment might want to put up such a special
> >> client, like they have preference for their WM.
> > Quite correct; this is a problem my standalone library also has right
> > now. It's currently only supporting fullscreen clients properly.
> I'm no expert in X event routing, maybe this isn't such a big problem
> after all. As said, it's just a sketch.

X events provide coordinates in root coordinates but also in event
coordinates. My naïve view would be to start registering gestures for event
coordinates 0/0 through to client width/height but _continue_ with the
gesture rec stuff if the events coords fall outside the window after the
first attempts.

this way you can easily have two clients that share the same gesture lib.
the main issue is with full-screen handling as you said - it'd be
interesting to know if this could be solved with grabs (that's kind-of what
they're for).
 
> >> § A new 'gesture' event gets created, like:
> > [...]
> >> A prosaic example would be an app learning that there's a
> >> "DIRECTED_DRAGGING gesture going on, starting at (200, 100)@70 degrees,
> >> now being at (300, 100)@95 deg" and use this information to navigate
> >> within a 3D-view. Also note the omission of (x,y) from the general
> >> gesture event, since I'd deem it specific. Other gestures may not have a
> >> primary x,y.
> > I agree, this is quite similar to the way I have implemented it right now.
> > This applies, e.g., to a relative motion gesture which only delivers a
> > vector.
> I took this particular example from a table project I'll be working with
> soon. It actually covers a vector _and_ a movement, independently
> derived from two touch points. Nice for camera navigation.
> 
> >> § A special gesture client (composite-like)
> >> This client might receive events as discussed - but all of them - by
> >> virtue of registering with the server. It analyzes the stream, and
> >> whenever it thinks something important happened, it tells the server.
> >> The server then dispatches a corresponding gesture event, according to
> >> its state and some constraints given by the special client (e.g.
> >> Florian's event regions, gesture-specific delivery constraints, ...)
> >> which may not be part of the event as delivered.
> > What kind of events are you considering here? 
> The hypothetical gesture event, as arriving in a gesture-aware client.
> It may not contain information like delivery constraints; it's business
> is just that it got the event.
> > Could a client generate new XI events?
> I don't have the impression this would suit it, though I could be wrong.
> At any rate, a client can't create a new event _type_. It can create
> some events though, e.g. via XTst, of predefined types.
> 
> My idea was that the special client instructs the server what gesture
> events to generate and how to dispatch them, whenever it thinks it has
> spotted a gesture. The server tracks some minimal state to ensure
> consistency and dispatches on behalf of the special gesture client.
> 
> Peter, maybe you can comment how suitable current mechanisms for input
> events from clients might be?

it's reasonably easy to add new events to XI2 for testing and get them
delivered to all clients. that'd be good enough for a hack, anyway.

clients can't really do that though. my idea so far in that regard was that
the library has two interfaces - a preprocessed one for library-internal
gesture events and a "raw" interface for those clients that like pain.

One reason why I'd rather not have the gesture library hooked into the
server is that these libraries require quite some run-time tweaking - such a
library would be worth its own extension including all disadvantages that
come from that.

> >> The important point here is that gesture events are asynchronous, so
> >> there's no need to wait inside the event loop. Gestures correlate to,
> >> but don't strictly depend on other input events. Their timestamps may
> >> not be in order for this reason.
> > Could you elaborate on that a bit more? I fear I'm missing some background
> > information here.
> All X events have a timestamp, but AFAIK order isn't guaranteed. The
> event loop refers to the server's event processing loop, which mustn't
> block or allocate memory and be nice in general. Guaranteeing
> synchronous gesture events from out of that loop is next to impossible,
> not to talk about communication with some client which may reside on
> another machine.
> 
> Also, why should gestures be in absolute sync to the events they
> originate from? You're normally interested in either direct events or
> derived ones, i.e. gestures, but not both. Even if both, you have
> timestamps to sort things out.
> 
> In short, dropping in-sync means making it feasible. IMO.

the order of events is guaranteed for a device but not across multiple
devices. if one device is frozen, other devices may still send events.
also, the server does motion event compression so you may lose events if the
server is busy.
other than that, we process events in the order they come in to avoid
hilarities like button releases before presses ;)
 
> >> I never fully worked this out, so I can't offer a fancy paper, but it
> >> seems sensible to me. And since anyone's free to do a library, when it
> >> comes down to something X.org-endorsed, a special client infrastructure
> >> might be a preferable choice.
> > I'm very interested in putting a quick hack together to try this out.
> > However, my knowledge about X internals is somewhat limited. Are things
> > like custom events possible, and how would a (special) client go about
> > sending them?
> There's the Generic Event Extension:
> http://www.x.org/wiki/Development/Documentation/XGE
> 
> I'd make one 'gesture' event, which multiplexes all sorts of gestures.
> Or maybe three, one for start|cont|end gesture each. Whatever fits the
> glove.
> 
> The special client would need to invoke an appropriate gesture dispatch
> request on the server, maybe as part of a 'X Gesture Extension' (hey
> that's XGE too :), which would then assemble and dispatch gesture events
> (only). I don't really see alternatives to this because only the server
> can properly dispatch events. But XTst should provide some examples to
> steal from.

for such an extension, you'd pretty much only need one request that receives
and event and passes it on. same thing XTEST does, and as Simon said you
could copy from there.

to make it simpler on the prototype I'd just extend XI2 and add the request
+ event opcodes. The code in Xi/ isn't always pretty (hardly ever, to be
precise) but it beats writing and extension from scratch.

> Obviously, the event needs to be designed along with the request, and
> dispatch needs to be worked out. At that point, you should already have
> yet another half-arsed X protocol extension spec.
> 
> The server should do some state tracking so you don't get gestures going
> on without getting their start etc, but that's for when things need to
> really work.
> 
> In reality, of course the client should 'be special', i.e. you need
> "register/unregister gesture client" requests, but for a quick stunt
> that's optional as well; no-one else will be sending the gesture
> dispatch request, so there's no contention to prevent. I think there's
> even a Xi(2) request for getting all the input events to a client, if
> it's good enough for that case you don't need to do much special for the
> special client.
> 
> But it's definitively more work than a library! Still, it may be more
> rewarding. And these days, there's XCB which reduces the pain of writing
> extensions. But maybe Peter's OK with just extending Xinput.

XCB makes it easy to write new extensions, that's true. Unfortunately some
bits are still missing from it (XKB, XI, XI2) so for now you're probably
better off biting the bullet and using libXi instead.

> It's very rough so far. A real impl would probably need to have some
> opportunity for client interaction too, e.g. an app canceling or
> grabbing gestures, which I guess you have worked out in your paper.
> 
> I hope I could give a better picture of the idea. And of course, I'd be
> delighted to see it realize.

I really recommend checking if the concept can be realized in a fully
client-side library. There may be showstoppers that I haven't noticed yet
but so far I'm still convinced that this is the better solution.
Maybe Bradley can comment on this too since he should know from his Qt work.
 
Cheers,
  Peter



More information about the xorg-devel mailing list