summaryrefslogtreecommitdiff
blob: fd55d1ade52bf924d1f2ddbad3d060176ef505f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
--- a/configure.ac
+++ b/configure.ac
@@ -68,6 +68,22 @@ sdkdir=`$PKG_CONFIG --variable=sdkdir xo
 AC_ARG_WITH([sdkdir], [], [sdkdir="$withval"])
 AC_SUBST([sdkdir])
 
+AC_ARG_ENABLE(utouch-grail, AS_HELP_STRING([--enable-utouch-grail], [Build with utouch-grail gesture support (default: auto)]), [GRAIL=$enableval], [GRAIL=auto])
+PKG_CHECK_MODULES(GRAIL, utouch-grail, [have_grail=yes], [have_grail=no])
+if test "x$GRAIL" = xauto; then
+        GRAIL="$have_grail"
+fi
+if test "x$GRAIL" = xyes; then
+        if test "x$have_grail" = xno; then
+                AC_MSG_ERROR([Grail build explicitly requested, but required modules not found.])
+        fi
+        AC_DEFINE(USE_GRAIL, 1, Whether to use grail or not)
+        AC_DEFINE(GESTURES, 1, Needed to interpret xorg headers properly)
+else
+        AC_DEFINE(USE_GRAIL, 0, Whether to use grail or not)
+fi
+AM_CONDITIONAL(USE_GRAIL, [test "x$GRAIL" = xyes])
+
 DRIVER_NAME=evdev
 AC_SUBST([DRIVER_NAME])
 
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,12 +29,17 @@ AM_CFLAGS = $(XORG_CFLAGS) $(CWARNFLAGS)
 AM_CPPFLAGS =-I$(top_srcdir)/include
 
 @DRIVER_NAME@_drv_la_LTLIBRARIES = @DRIVER_NAME@_drv.la
-@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version
+@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version @GRAIL_LIBS@
 @DRIVER_NAME@_drv_la_LIBADD = $(MTDEV_LIBS)
 @DRIVER_NAME@_drv_ladir = @inputdir@
 
+if USE_GRAIL
+GRAIL_SRC=evdev-grail.c evdev-grail.h
+endif
+
 @DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c \
                                @DRIVER_NAME@.h \
+                               $(GRAIL_SRC) \
                                emuMB.c \
                                emuWheel.c \
                                draglock.c
--- /dev/null
+++ b/src/evdev-grail.c
@@ -0,0 +1,375 @@
+/*
+ * Copyright © 2010 Canonical, Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of Red Hat
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.  Red
+ * Hat makes no representations about the suitability of this software
+ * for any purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors:
+ *	Chase Douglas (chase.douglas@canonical.com)
+ */
+
+/* So we can get at the right data in xorg/windowstr.h */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xorg-server.h>
+#include <X11/Xatom.h>
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+#include <windowstr.h>
+#include <xorg/os.h>
+
+#include <evdev-properties.h>
+#include "evdev.h"
+#include "evdev-grail.h"
+#include "gestureproto.h"
+
+/* Copied from evdev.c, will be in evdev.h when xserver 1.9 is merged */
+#define EVDEV_RELATIVE_EVENTS   (1 << 2)
+#define EVDEV_TOUCHPAD          (1 << 4)
+
+/*
+ * Provided by the Maverick X server, we don't want to pollute the official
+ * X.org API.
+ */
+extern _X_EXPORT void xf86PostGestureEvent(DeviceIntPtr dev, unsigned short x,
+                         unsigned short y, unsigned short client_id,
+                         unsigned short gesture_id, unsigned short gesture_type,
+                         Window root, Window event, Window child,
+                         unsigned short status, unsigned short num_props,
+                         float *props);
+
+static WindowPtr CommonAncestor(WindowPtr a, WindowPtr b)
+{
+    WindowPtr c;
+
+    if (a == b)
+        return a;
+
+    for (b = b; b; b = b->parent)
+        for (c = a; c; c = c->parent)
+            if (c == b)
+                return b;
+
+    return NullWindow;
+}
+
+static WindowPtr GetWindowForGestures(struct grail *grail,
+                                      const struct grail_coord *contacts,
+                                      int num_contacts)
+{
+    WindowPtr window = NULL;
+    int i;
+
+    for (i = 0; i < num_contacts; i++)
+    {
+        float screen_x = contacts[i].x;
+        float screen_y = contacts[i].y;
+        WindowPtr this_window;
+
+        this_window = xf86CoordinatesToWindow(screen_x, screen_y, 0);
+        if (!this_window)
+            return NullWindow;
+
+        if (!window)
+            window = this_window;
+        else
+            window = CommonAncestor(window, this_window);
+    }
+
+    return window;
+}
+
+static int GetClients(struct grail *grail,
+		      struct grail_client_info *clients, int max_clients,
+		      const struct grail_coord *contacts, int num_contacts,
+		      const grail_mask_t *types, int type_bytes)
+{
+    WindowPtr child_window;
+    WindowPtr window;
+    WindowPtr root_window;
+    InputInfoPtr pInfo = grail->priv;
+    EvdevPtr pEvdev = pInfo->private;
+    int j;
+    int found_match = 0;
+    int num_clients = 0;
+    int type;
+
+    if (max_clients <= 0)
+        return 0;
+
+    if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_TOUCHPAD))
+    {
+        DeviceIntPtr master = pInfo->dev->u.master;
+        struct grail_coord cursor_coord;
+
+        /* If this mouse isn't hooked up to a cursor, don't do anything */
+        if (!master)
+            return 0;
+
+        cursor_coord.x = master->last.valuators[0];
+        cursor_coord.y = master->last.valuators[1];
+
+        child_window = GetWindowForGestures(grail, &cursor_coord, 1);
+    } else
+        child_window = GetWindowForGestures(grail, contacts, num_contacts);
+
+    if (!child_window)
+        return 0;
+
+    memset(clients, 0, sizeof(struct grail_client_info) * max_clients);
+
+    /* Find the root window. */
+    for (root_window = child_window; root_window->parent;
+         root_window = root_window->parent);
+
+    /*
+     * Check for a root client with SYSFLAG1 set. SYSFLAG1 is effectively an
+     * active grab for system gestures. We assume only one client has SYSFLAG1
+     * set.
+     */
+    window = child_window;
+    while (window)
+    {
+        /* Check if any gestures have been selected on this window. */
+        if (wGestureMasks(window))
+        {
+            GestureClientsPtr client;
+
+            /* For each client */
+            for (client = wGestureMasks(window)->clients; client;
+                 client = client->next)
+            {
+                int first = 1;
+
+                /* If the client has set the SYSFLAG1 bit */
+                if (BitIsOn(client->gestureMask[0], GRAIL_TYPE_SYSFLAG1))
+                {
+                    /* For each recognized gesture */
+                    grail_mask_foreach(type, types, type_bytes)
+                    {
+                        if (type == GRAIL_TYPE_SYSFLAG1)
+                            continue;
+
+                        /*
+                         * Check if this client selected for this gesture.
+                         * Request may be for this device or all devices.
+                         */
+                        if (BitIsOn(client->gestureMask[pInfo->dev->id], type) ||
+                            BitIsOn(client->gestureMask[0], type))
+                        {
+                            if (first) {
+                                /* Set up new client in array */
+                                clients[0].id.client = CLIENT_ID(client->resource);
+                                clients[0].id.root = root_window->drawable.id;
+                                clients[0].id.child = child_window->drawable.id;
+                                clients[0].id.event = window->drawable.id;
+                                grail_mask_clear(clients[0].mask,
+                                                 DIM_GRAIL_TYPE_BYTES);
+                                first = 0;
+                            }
+
+                            /* Set this gesture bit in the client's gesture mask */
+                            SetBit(clients[0].mask, type);
+                            num_clients = 1;
+                        }
+                    }
+
+                    /*
+                     * Either we found a gesture, or we stop looking for SYSFLAG1
+                     * clients.
+                     */
+                    if (num_clients) {
+                        SetBit(clients[0].mask, GRAIL_TYPE_SYSFLAG1);
+                        goto next_window;
+                    }
+                }
+            }
+        }
+
+next_window:
+        window = window->parent;
+    }
+
+    /*
+     * Traverse the window hierarchy looking for a window with a client
+     * selecting for one of the recognized gestures.
+     *
+     * All clients of the top most window with a match will receive events if
+     * they have selected for gestures that have been recognized, even if they
+     * have selected for different gestures between them.
+     *
+     * Once any gesture is matched on a window, propagation through the window
+     * hierarchy ends.
+     */
+    for (window = child_window; window && !found_match; window = window->parent)
+    {
+        /* No client selected for gestures on this window */
+        if (!wGestureMasks(window))
+            continue;
+
+        /* For each recognized gesture */
+        grail_mask_foreach(type, types, type_bytes)
+        {
+            if (type == GRAIL_TYPE_SYSFLAG1)
+                continue;
+
+            /* Check if any client selected for this gesture on the window */
+            if (BitIsOn(wGestureMasks(window)->mask, type))
+            {
+                GestureClientsPtr client;
+
+                /* For each client that selected for gestures on this window */
+                for (client = wGestureMasks(window)->clients; client;
+                     client = client->next)
+                {
+                     /*
+                      * Check if this client selected for this gesture. Request
+                      * may be for this device or all devices.
+                      */
+                     if (BitIsOn(client->gestureMask[pInfo->dev->id], type) ||
+                         BitIsOn(client->gestureMask[0], type))
+                     {
+                         /*
+                          * Find this client in the clients array passed back to
+                          * the caller.
+                          */
+                         for (j = 0; j < num_clients; j++)
+                             if (clients[j].id.client ==
+                                 CLIENT_ID(client->resource))
+                                 break;
+
+                         /* Check if the client exists in the array yet */
+                         if (j >= num_clients)
+                         {
+                             /* We ran out of room in the array, return error */
+                             if (num_clients >= max_clients)
+                                 return -1;
+                             /* Set up new client in array */
+                             clients[j].id.client = CLIENT_ID(client->resource);
+                             clients[j].id.root = root_window->drawable.id;
+                             clients[j].id.child = child_window->drawable.id;
+                             clients[j].id.event = window->drawable.id;
+                             num_clients++;
+                         }
+
+                         /* Set this gesture bit in the client's gesture mask */
+                         SetBit(clients[j].mask, type);
+                     }
+                }
+
+                /* A match has been found, stop propagating */
+                found_match = 1;
+            }
+        }
+    }
+
+    return num_clients;
+}
+
+static void GrailEvent(struct grail *grail, const struct input_event *ev)
+{
+    InputInfoPtr pInfo = (InputInfoPtr)grail->priv;
+    EvdevProcessEvent(pInfo, (struct input_event *)ev);
+}
+
+static void GrailGesture(struct grail *grail, const struct grail_event *ev)
+{
+    InputInfoPtr pInfo = grail->priv;
+    EvdevPtr pEvdev = pInfo->private;
+    int x;
+    int y;
+
+    /* Override event focus point if this is a relative device */
+    if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_TOUCHPAD))
+    {
+        DeviceIntPtr master = pInfo->dev->u.master;
+
+        /* If this mouse isn't hooked up to a cursor, don't do anything */
+        if (!master)
+            return;
+
+        /* Note: Master device valuators are in screen coordinates */
+        x = master->last.valuators[0];
+        y = master->last.valuators[1];
+    } else {
+        x = ev->pos.x;
+        y = ev->pos.y;
+    }
+
+    xf86PostGestureEvent(pInfo->dev, x, y, ev->client_id.client, ev->id,
+                         ev->type, ev->client_id.root, ev->client_id.event,
+                         ev->client_id.child, ev->status,
+                         ev->nprop, (float *)ev->prop);
+}
+
+int
+GrailOpen(InputInfoPtr pInfo)
+{
+    EvdevPtr pEvdev = pInfo->private;
+
+    pEvdev->grail = malloc(sizeof(struct grail));
+    if (!pEvdev->grail) {
+        xf86Msg(X_ERROR, "evdev-grail: failed to allocate grail structure\n");
+        return -1;
+    }
+
+    memset(pEvdev->grail, 0, sizeof(struct grail));
+    pEvdev->grail->get_clients = GetClients;
+    pEvdev->grail->event = GrailEvent;
+    pEvdev->grail->gesture = GrailGesture;
+    pEvdev->grail->priv = pInfo;
+
+    if (grail_open(pEvdev->grail, pInfo->fd)) {
+        xf86Msg(X_INFO,
+                "evdev-grail: failed to open grail, no gesture support\n");
+        free(pEvdev->grail);
+        pEvdev->grail = NULL;
+        return -1;
+    }
+
+    {
+        struct grail_coord min;
+        struct grail_coord max;
+
+        min.x = screenInfo.screens[0]->x;
+        min.y = screenInfo.screens[0]->y;
+        max.x = min.x + screenInfo.screens[0]->width;
+        max.y = min.y + screenInfo.screens[0]->height;
+
+        grail_set_bbox(pEvdev->grail, &min, &max);
+    }
+
+    return 0;
+}
+
+void
+GrailClose(InputInfoPtr pInfo)
+{
+    EvdevPtr pEvdev = pInfo->private;
+
+    if (pEvdev->grail) {
+        grail_close(pEvdev->grail, pInfo->fd);
+        free(pEvdev->grail);
+        pEvdev->grail = NULL;
+    }
+}
--- /dev/null
+++ b/src/evdev-grail.h
@@ -0,0 +1,9 @@
+#ifndef EVDEV_GRAIL_H_
+#define EVDEV_GRAIL_H_
+
+#include <grail.h>
+
+extern int GrailOpen(InputInfoPtr pInfo);
+extern void GrailClose(InputInfoPtr pInfo);
+
+#endif /* _EVDEV_GRAIL_H_ */
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -60,6 +60,13 @@
 #define MAXDEVICES MAX_DEVICES
 #endif
 
+#if USE_GRAIL
+#include "evdev-grail.h"
+#else
+#define GrailOpen(pInfo)
+#define GrailClose(pInfo)
+#endif
+
 #define ArrayLength(a) (sizeof(a) / (sizeof((a)[0])))
 
 #define MIN_KEYCODE 8
@@ -900,7 +907,7 @@ EvdevProcessSyncEvent(InputInfoPtr pInfo
  * Process the events from the device; nothing is actually posted to the server
  * until an EV_SYN event is received.
  */
-static void
+void
 EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
 {
     switch (ev->type) {
@@ -934,17 +941,14 @@ EvdevReadInput(InputInfoPtr pInfo)
 
     while (len == sizeof(ev))
     {
-#ifdef MULTITOUCH
+#if USE_GRAIL
         EvdevPtr pEvdev = pInfo->private;
 
-        if (pEvdev->mtdev)
-            len = mtdev_get(pEvdev->mtdev, pInfo->fd, ev, NUM_EVENTS) *
-                sizeof(struct input_event);
+        if (pEvdev->grail)
+            len = grail_pull(pEvdev->grail, pInfo->fd);
         else
-            len = read(pInfo->fd, &ev, sizeof(ev));
-#else
-            len = read(pInfo->fd, &ev, sizeof(ev));
 #endif
+            len = read(pInfo->fd, &ev, sizeof(ev));
         if (len <= 0)
         {
             if (errno == ENODEV) /* May happen after resume */
@@ -962,6 +966,11 @@ EvdevReadInput(InputInfoPtr pInfo)
             break;
         }
 
+#if USE_GRAIL
+        if (pEvdev->grail)
+		return;
+#endif
+
         /* The kernel promises that we always only read a complete
          * event, so len != sizeof ev is an error. */
         if (len % sizeof(ev[0])) {
@@ -1620,6 +1629,7 @@ EvdevProc(DeviceIntPtr device, int what)
         if (pEvdev->mtdev)
             mtdev_close(pEvdev->mtdev);
 #endif
+        GrailClose(pInfo);
         EvdevRemoveDevice(pInfo);
         pEvdev->min_maj = 0;
 	break;
@@ -1857,6 +1867,8 @@ EvdevProbe(InputInfoPtr pInfo)
         xf86Msg(X_PROBED, "%s: Found absolute axes\n", pInfo->name);
         pEvdev->flags |= EVDEV_ABSOLUTE_EVENTS;
 
+        GrailOpen(pInfo);
+
         if ((TestBit(ABS_X, pEvdev->abs_bitmask) &&
              TestBit(ABS_Y, pEvdev->abs_bitmask))) {
             xf86Msg(X_PROBED, "%s: Found x and y absolute axes\n", pInfo->name);
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -207,8 +207,14 @@ typedef struct {
     /* Event queue used to defer keyboard/button events until EV_SYN time. */
     int                     num_queue;
     EventQueueRec           queue[EVDEV_MAXQUEUE];
+
+#if USE_GRAIL
+    struct grail *grail;
+#endif
 } EvdevRec, *EvdevPtr;
 
+void EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev);
+
 /* Event posting functions */
 void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
 void EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
--- /dev/null
+++ b/src/gestureproto.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2010 Canonical, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Chase Douglas <chase.douglas@canonical.com>
+ *
+ */
+
+#ifndef _GESTUREPROTO_H_
+#define _GESTUREPROTO_H_
+
+#include <stdint.h>
+#include <X11/X.h>
+
+#define Window  uint32_t
+#define Time    uint32_t
+
+#define X_GestureQueryVersion                1
+#define X_GestureSelectEvents                2
+#define X_GestureGetSelectedEvents           3
+
+#define GESTUREREQUESTS (X_GestureGetSelectedEvents - X_GestureQueryVersion + 1)
+
+#define GestureAllDevices 0
+
+/**
+ * Used to select for events on a given window.
+ * Struct is followed by (mask_len * CARD8), with each bit set representing
+ * the event mask for the given type. A mask bit represents an event type if
+ * (mask == (1 << type)).
+ */
+typedef struct {
+    uint16_t    device_id;       /**< Device id to select for        */
+    uint16_t    mask_len;        /**< Length of mask in 4 byte units */
+} GestureEventMask;
+
+typedef struct {
+    uint8_t     reqType;                /**< Gesture extension major code */
+    uint8_t     ReqType;                /**< Always ::X_GestureQueryVersion */
+    uint16_t    length;                 /**< Length in 4 byte units */
+    uint16_t    major_version;
+    uint16_t    minor_version;
+} GestureQueryVersionReq;
+
+typedef struct {
+    uint8_t     repType;                /**< ::X_Reply */
+    uint8_t     RepType;                /**< Always ::X_GestureQueryVersion */
+    uint16_t    sequenceNumber;
+    uint32_t    length;
+    uint16_t    major_version;
+    uint16_t    minor_version;
+    uint32_t    pad1;
+    uint32_t    pad2;
+    uint32_t    pad3;
+    uint32_t    pad4;
+    uint32_t    pad5;
+} GestureQueryVersionReply;
+
+typedef struct {
+    uint8_t     reqType;                /**< Gesture extension major code */
+    uint8_t     ReqType;                /**< Always ::X_GestureSelectEvents */
+    uint16_t    length;                 /**< Length in 4 byte units */
+    Window      window;
+    GestureEventMask mask;
+} GestureSelectEventsReq;
+
+typedef struct {
+    uint8_t     reqType;                /**< Gesture extension major code */
+    uint8_t     ReqType;                /**< Always ::X_GestureGetSelectedEvents */
+    uint16_t    length;                 /**< Length in 4 byte units */
+    Window      window;
+} GestureGetSelectedEventsReq;
+
+typedef struct {
+    uint8_t     repType;                /**< Gesture extension major opcode */
+    uint8_t     RepType;                /**< Always ::X_GestureGetSelectedEvents */
+    uint16_t    sequenceNumber;
+    uint32_t    length;
+    uint16_t    num_masks;              /**< Number of GestureEventMask structs
+                                             trailing the reply */
+    uint16_t    pad0;
+    uint32_t    pad1;
+    uint32_t    pad2;
+    uint32_t    pad3;
+    uint32_t    pad4;
+    uint32_t    pad5;
+} GestureGetSelectedEventsReply;
+
+typedef struct
+{
+    uint8_t     type;                   /**< Always GenericEvent */
+    uint8_t     extension;              /**< Gesture extension offset */
+    uint16_t    sequenceNumber;         /**< Xevent sequence number */
+    uint32_t    length;                 /**< Length in 4 byte uints */
+    uint16_t    evtype;                 /**< X generic event type */
+    uint16_t    gesture_id;             /**< Unique ID for gesture */
+    uint16_t    gesture_type;           /**< Gesture type (zoom, rotate, etc.) */
+    uint16_t    device_id;              /**< Device that generated this gesture */
+    Time        time;                   /**< Time of gesture event */
+    Window      root;                   /**< Root window event occurred on */
+    Window      event;                  /**< Window selecting this event for a client */
+    Window      child;                  /**< Top-most window of gesture event */
+/* └──────── 32 byte boundary ────────┘ */
+    float       focus_x;                /**< Always window coords, 16.16 fixed point */
+    float       focus_y;                /**< Relative to event window */
+    uint16_t    status;                 /**< Gesture event status */
+    uint16_t    num_props;               /**< Number of properties for gesture event */
+/* └──── Gesture properties below ────┘ */
+} GestureEvent;
+
+#undef Window
+#undef Time
+
+#endif /* _GESTUREPROTO_H_ */