summaryrefslogtreecommitdiff
blob: c9a00268cdf187ea7ece523d7fa6ac1a2ad9f3d4 (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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
Index: xorg-server/Makefile.am
===================================================================
--- xorg-server.orig/Makefile.am	2011-08-24 12:52:43.205647111 +0300
+++ xorg-server/Makefile.am	2011-08-24 12:56:49.885650627 +0300
@@ -17,6 +17,10 @@
 RECORD_DIR=record
 endif
 
+if GESTURES
+GESTURE_DIR=gesture
+endif
+
 SUBDIRS = \
 	doc \
 	include \
@@ -37,6 +41,7 @@
 	$(COMPOSITE_DIR) \
 	$(GLX_DIR) \
 	exa \
+	$(GESTURE_DIR) \
 	config \
 	hw \
 	test
Index: xorg-server/configure.ac
===================================================================
--- xorg-server.orig/configure.ac	2011-08-24 12:56:49.855650623 +0300
+++ xorg-server/configure.ac	2011-08-24 12:56:49.885650627 +0300
@@ -596,6 +596,8 @@
 AC_ARG_ENABLE(pc98,     	AC_HELP_STRING([--enable-pc98], [Enable PC98 support in Xorg (default: auto)]),
 				[SUPPORT_PC98=$enableval],
 				[SUPPORT_PC98=auto])
+AC_ARG_ENABLE(gestures,         AC_HELP_STRING([--enable-gestures], [Enable gesture support (default: disabled)]),
+				[GESTURES=$enableval])
 
 dnl GLX build options
 AC_ARG_ENABLE(aiglx,          AS_HELP_STRING([--enable-aiglx], [Build accelerated indirect GLX (default: enabled)]),
@@ -1366,6 +1368,13 @@
 MIEXT_SYNC_LIB='$(top_builddir)/miext/sync/libsync.la'
 CORE_INCS='-I$(top_srcdir)/include -I$(top_builddir)/include'
 
+AM_CONDITIONAL(GESTURES, [test "x$GESTURES" = "xyes"])
+if test "x$GESTURES" = xyes; then
+	AC_DEFINE(GESTURES, 1, [Enable gesture support])
+	GESTURE_LIB='$(top_builddir)/gesture/libgesture.la'
+	GESTURE_INC='-I$(top_srcdir)/gesture'
+fi
+
 # SHA1 hashing
 AC_ARG_WITH([sha1],
             [AS_HELP_STRING([--with-sha1=libc|libmd|libgcrypt|libcrypto|libsha1|CommonCrypto|nettle],
@@ -1513,7 +1522,7 @@
 AC_DEFINE([SVR4],1,[Define to 1 on systems derived from System V Release 4])
 AC_MSG_RESULT([yes])], AC_MSG_RESULT([no]))
 
-XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SYNC_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC"
+XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SYNC_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC $GESTURE_INC"
 
 dnl ---------------------------------------------------------------------------
 dnl DDX section.
@@ -1526,7 +1535,7 @@
 AM_CONDITIONAL(XVFB, [test "x$XVFB" = xyes])
 
 if test "x$XVFB" = xyes; then
-	XVFB_LIBS="$FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB"
+	XVFB_LIBS="$FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $GESTURE_LIB"
 	XVFB_SYS_LIBS="$XVFBMODULES_LIBS $GLX_SYS_LIBS"
 	AC_SUBST([XVFB_LIBS])
 	AC_SUBST([XVFB_SYS_LIBS])
@@ -1547,7 +1556,7 @@
 	if test "x$have_xnest" = xno; then
 		AC_MSG_ERROR([Xnest build explicitly requested, but required modules not found.])
 	fi
-	XNEST_LIBS="$FB_LIB $FIXES_LIB $MI_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DIX_LIB $MAIN_LIB $OS_LIB"
+	XNEST_LIBS="$FB_LIB $FIXES_LIB $MI_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DIX_LIB $MAIN_LIB $OS_LIB $GESTURE_LIB"
 	XNEST_SYS_LIBS="$XNESTMODULES_LIBS $GLX_SYS_LIBS"
 	AC_SUBST([XNEST_LIBS])
 	AC_SUBST([XNEST_SYS_LIBS])
@@ -1575,7 +1584,7 @@
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $GESTURE_LIB"
 
 	dnl ==================================================================
 	dnl symbol visibility
@@ -1911,7 +1920,7 @@
 			XWIN_SYS_LIBS=-lwinsock2
 			;;
 	esac
-	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
+	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB $GESTURE_LIB"
 	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS"
 	AC_SUBST(XWIN_LIBS)
 	AC_SUBST(XWIN_SERVER_NAME)
@@ -1941,7 +1950,7 @@
 	AC_DEFINE(XQUARTZ,1,[Have Quartz])
 	AC_DEFINE(ROOTLESS,1,[Build Rootless code])
 
-	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $MAIN_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB"
+	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $MAIN_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB $GESTURE_LIB"
 	AC_SUBST([DARWIN_LIBS])
 
 	AC_CHECK_LIB([Xplugin],[xp_init],[:])
@@ -2002,7 +2011,7 @@
 	fi
 	DMX_INCLUDES="$XEXT_INC $RENDER_INC $RECORD_INC"
 	XDMX_CFLAGS="$DMXMODULES_CFLAGS"
-	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
+	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB $GESTURE_LIB"
 	XDMX_SYS_LIBS="$DMXMODULES_LIBS"
 	AC_SUBST([XDMX_CFLAGS])
 	AC_SUBST([XDMX_LIBS])
@@ -2113,7 +2122,7 @@
     
     KDRIVE_CFLAGS="$XSERVER_CFLAGS -DHAVE_KDRIVE_CONFIG_H $TSLIB_CFLAGS"
 
-    KDRIVE_PURE_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $OS_LIB"
+    KDRIVE_PURE_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $OS_LIB $GESTURE_LIB"
     KDRIVE_LIB='$(top_builddir)/hw/kdrive/src/libkdrive.la'
     case $host_os in
 	*linux*)
@@ -2229,6 +2238,7 @@
 Xi/Makefile
 xfixes/Makefile
 exa/Makefile
+gesture/Makefile
 hw/Makefile
 hw/xfree86/Makefile
 hw/xfree86/common/Makefile
Index: xorg-server/dix/events.c
===================================================================
--- xorg-server.orig/dix/events.c	2011-08-24 12:56:49.875650625 +0300
+++ xorg-server/dix/events.c	2011-08-24 12:56:49.895650626 +0300
@@ -6016,6 +6016,9 @@
 	    FreeResource(oc->resource, RT_NONE);
 	while ( (passive = wPassiveGrabs(pWin)) )
 	    FreeResource(passive->resource, RT_NONE);
+#ifdef GESTURES
+        DeleteWindowFromGestureEvents(pWin);
+#endif
      }
 
     DeleteWindowFromAnyExtEvents(pWin, freeResources);
Index: xorg-server/dix/window.c
===================================================================
--- xorg-server.orig/dix/window.c	2011-08-24 12:56:49.855650623 +0300
+++ xorg-server/dix/window.c	2011-08-24 12:56:49.895650626 +0300
@@ -404,6 +404,9 @@
     pWin->optional->deviceCursors = NULL;
     pWin->optional->colormap = pScreen->defColormap;
     pWin->optional->visual = pScreen->rootVisual;
+#ifdef GESTURES
+    pWin->optional->gestureMasks = NULL;
+#endif
 
     pWin->nextSib = NullWindow;
 
@@ -3415,6 +3418,10 @@
             pNode = pNode->next;
         }
     }
+#ifdef GESTURES
+    if (optional->gestureMasks != NULL)
+        return;
+#endif
 
     parentOptional = FindWindowWithOptional(w)->optional;
     if (optional->visual != parentOptional->visual)
@@ -3458,6 +3465,9 @@
     optional->inputShape = NULL;
     optional->inputMasks = NULL;
     optional->deviceCursors = NULL;
+#ifdef GESTURES
+    optional->gestureMasks = NULL;
+#endif
 
     parentOptional = FindWindowWithOptional(pWin)->optional;
     optional->visual = parentOptional->visual;
Index: xorg-server/gesture/Makefile.am
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ xorg-server/gesture/Makefile.am	2011-08-24 12:56:49.895650626 +0300
@@ -0,0 +1,10 @@
+noinst_LTLIBRARIES = libgesture.la
+
+AM_CFLAGS = $(DIX_CFLAGS)
+
+libgesture_la_SOURCES = 	\
+	init.c			\
+	gesture.c		\
+	gesture.h
+
+sdk_HEADERS = gesture.h
Index: xorg-server/gesture/gesture.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ xorg-server/gesture/gesture.c	2011-08-24 12:56:49.895650626 +0300
@@ -0,0 +1,430 @@
+/*
+ * 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>
+ *
+ */
+
+#include "windowstr.h"
+#include "gestureint.h"
+
+int
+SProcGestureQueryVersion(ClientPtr client)
+{
+    char n;
+
+    REQUEST(GestureQueryVersionReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(GestureQueryVersionReq);
+    swaps(&stuff->major_version, n);
+    swaps(&stuff->minor_version, n);
+    return (ProcGestureQueryVersion(client));
+}
+
+GestureExtensionVersion GestureVersion;
+/**
+ * Return the supported Gesture version.
+ *
+ * Saves the version the client claims to support as well, for future
+ * reference.
+ */
+int
+ProcGestureQueryVersion(ClientPtr client)
+{
+    GestureQueryVersionReply rep;
+    GestureClientPtr gestureClient;
+    int major, minor;
+    unsigned int sversion, cversion;
+
+    REQUEST(GestureQueryVersionReq);
+    REQUEST_SIZE_MATCH(GestureQueryVersionReq);
+
+    gestureClient = dixLookupPrivate(&client->devPrivates,
+                                     &GestureClientPrivateKeyRec);
+
+    sversion = GestureVersion.major_version * 1000 + GestureVersion.minor_version;
+    cversion = stuff->major_version * 1000 + stuff->minor_version;
+
+    if (sversion > cversion)
+    {
+        major = stuff->major_version;
+        minor = stuff->minor_version;
+    } else
+    {
+        major = GestureVersion.major_version;
+        minor = GestureVersion.minor_version;
+    }
+
+    gestureClient->major_version = major;
+    gestureClient->minor_version = minor;
+
+    memset(&rep, 0, sizeof(GestureQueryVersionReply));
+    rep.repType = X_Reply;
+    rep.RepType = X_GestureQueryVersion;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.major_version = major;
+    rep.minor_version = minor;
+
+    WriteReplyToClient(client, sizeof(GestureQueryVersionReply), &rep);
+
+    return Success;
+}
+
+void
+SRepGestureQueryVersion(ClientPtr client, int size, GestureQueryVersionReply *rep)
+{
+    char n;
+    swaps(&rep->sequenceNumber, n);
+    swapl(&rep->length, n);
+    swaps(&rep->major_version, n);
+    swaps(&rep->minor_version, n);
+    WriteToClient(client, size, (char *)rep);
+}
+
+static Bool
+MakeGestureMasks(WindowPtr pWin)
+{
+    struct _GestureMasks *masks;
+
+    masks = calloc(1, sizeof(struct _GestureMasks));
+    if (!masks)
+        return FALSE;
+    pWin->optional->gestureMasks = masks;
+    return TRUE;
+}
+
+static int
+AddGestureClient(WindowPtr pWin, ClientPtr client)
+{
+    GestureClientsPtr others;
+
+    if (!pWin->optional && !MakeWindowOptional(pWin))
+        return BadAlloc;
+    others = calloc(1, sizeof(GestureClients));
+    if (!others)
+        return BadAlloc;
+    if (!pWin->optional->gestureMasks && !MakeGestureMasks(pWin))
+        return BadAlloc;
+    others->resource = FakeClientID(client->index);
+    others->next = pWin->optional->gestureMasks->clients;
+    pWin->optional->gestureMasks->clients = others;
+    if (!AddResource(others->resource, RT_GESTURECLIENT, (pointer) pWin))
+        return BadAlloc;
+    return Success;
+}
+
+/**
+ * Check the given mask (in len bytes) for invalid mask bits.
+ * Invalid mask bits are any bits above GestureLastEvent.
+ *
+ * @return BadValue if at least one invalid bit is set or Success otherwise.
+ */
+static int
+GestureCheckInvalidMaskBits(unsigned char *mask, int len)
+{
+    if (len >= GESTUREMASKSIZE)
+    {
+        int i;
+        for (i = GESTURELASTEVENT + 1; i < len * 8; i++)
+            if (BitIsOn(mask, i))
+                return BadValue;
+    }
+
+    return Success;
+}
+
+int
+SProcGestureSelectEvents(ClientPtr client)
+{
+    char n;
+    int i;
+
+    REQUEST(GestureSelectEventsReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(GestureSelectEventsReq);
+    swapl(&stuff->window, n);
+    swaps(&stuff->mask.device_id, n);
+    swaps(&stuff->mask.mask_len, n);
+
+    for (i = 0; i < stuff->mask.mask_len; i++)
+        swapl(((uint32_t *)(stuff + 1)) + i, n);
+
+    return (ProcGestureSelectEvents(client));
+}
+
+static void
+RecalculateGestureDeliverableEvents(WindowPtr win)
+{
+    GestureClientsPtr others;
+    int i;
+
+    if (!win->optional || !wGestureMasks(win))
+        return;
+
+    memset(&wGestureMasks(win)->mask, 0, sizeof(wGestureMasks(win)->mask));
+
+    for (others = wGestureMasks(win)->clients; others; others = others->next)
+        for (i = 0; i < sizeof(others->gestureMask) * 8; i++)
+            if (BitIsOn(&others->gestureMask, i))
+                SetBit(wGestureMasks(win)->mask, i % (GESTURELASTEVENT + 1));
+}
+
+static int
+GestureSetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
+                    unsigned int len, unsigned char* mask)
+{
+    GestureMasks *masks;
+    GestureClientsPtr others = NULL;
+
+    masks = wGestureMasks(win);
+    if (masks)
+    {
+        for (others = masks->clients; others;
+             others = others->next) {
+            if (SameClient(others, client)) {
+                memset(others->gestureMask[dev->id], 0,
+                       sizeof(others->gestureMask[dev->id]));
+                break;
+            }
+        }
+    }
+
+    len = min(len, sizeof(others->gestureMask[dev->id]));
+
+    if (len && !others)
+    {
+        if (AddGestureClient(win, client) != Success)
+            return BadAlloc;
+        masks = wGestureMasks(win);
+        others = masks->clients;
+    }
+
+    if (others)
+        memset(others->gestureMask[dev->id], 0,
+               sizeof(others->gestureMask[dev->id]));
+
+    if (len)
+        memcpy(others->gestureMask[dev->id], mask, len);
+
+    RecalculateGestureDeliverableEvents(win);
+
+    return Success;
+}
+
+int
+ProcGestureSelectEvents(ClientPtr client)
+{
+    int rc;
+    WindowPtr win;
+    DeviceIntPtr dev;
+    DeviceIntRec dummy;
+
+    REQUEST(GestureSelectEventsReq);
+    REQUEST_AT_LEAST_SIZE(GestureSelectEventsReq);
+
+    if (sizeof(GestureSelectEventsReq) + stuff->mask.mask_len * 4 >
+        stuff->length * 4)
+        return BadLength;
+
+    rc = dixLookupWindow(&win, stuff->window, client, DixReceiveAccess);
+    if (rc != Success)
+        return rc;
+
+    if (GestureCheckInvalidMaskBits((unsigned char*)(stuff + 1),
+                                    stuff->mask.mask_len * 4) != Success)
+        return BadValue;
+
+    if (stuff->mask.device_id == GestureAllDevices)
+    {
+        dummy.id = stuff->mask.device_id;
+        dev = &dummy;
+    } else {
+        rc = dixLookupDevice(&dev, stuff->mask.device_id, client, DixUseAccess);
+        if (rc != Success)
+            return rc;
+    }
+
+    if (GestureSetEventMask(dev, win, client, stuff->mask.mask_len * 4,
+                            (unsigned char*)(stuff + 1)) != Success)
+        return BadAlloc;
+
+    return Success;
+}
+
+int
+SProcGestureGetSelectedEvents(ClientPtr client)
+{
+    char n;
+
+    REQUEST(GestureGetSelectedEventsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(GestureGetSelectedEventsReq);
+    swapl(&stuff->window, n);
+
+    return (ProcGestureGetSelectedEvents(client));
+}
+
+int
+ProcGestureGetSelectedEvents(ClientPtr client)
+{
+    int rc, i;
+    WindowPtr win;
+    char n;
+    char *buffer = NULL;
+    GestureGetSelectedEventsReply reply;
+    GestureMasks *masks;
+    GestureClientsPtr others = NULL;
+    GestureEventMask *evmask = NULL;
+    DeviceIntPtr dev;
+
+    REQUEST(GestureGetSelectedEventsReq);
+    REQUEST_SIZE_MATCH(GestureGetSelectedEventsReq);
+
+    rc = dixLookupWindow(&win, stuff->window, client, DixGetAttrAccess);
+    if (rc != Success)
+        return rc;
+
+    reply.repType = X_Reply;
+    reply.RepType = X_GestureGetSelectedEvents;
+    reply.length = 0;
+    reply.sequenceNumber = client->sequence;
+    reply.num_masks = 0;
+
+    masks = wGestureMasks(win);
+    if (masks)
+    {
+        for (others = masks->clients; others; others = others->next) {
+            if (SameClient(others, client)) {
+                break;
+            }
+        }
+    }
+
+    if (!others)
+    {
+        WriteReplyToClient(client, sizeof(GestureGetSelectedEventsReply), &reply);
+        return Success;
+    }
+
+    buffer = calloc(MAXDEVICES, sizeof(GestureEventMask) + pad_to_int32(GESTUREMASKSIZE));
+    if (!buffer)
+        return BadAlloc;
+
+    evmask = (GestureEventMask*)buffer;
+    for (i = 0; i < MAXDEVICES; i++)
+    {
+        int j;
+        unsigned char *devmask = others->gestureMask[i];
+
+        if (i > 2)
+        {
+            rc = dixLookupDevice(&dev, i, client, DixGetAttrAccess);
+            if (rc != Success)
+                continue;
+        }
+
+
+        for (j = GESTUREMASKSIZE - 1; j >= 0; j--)
+        {
+            if (devmask[j] != 0)
+            {
+                int mask_len = (j + 4)/4; /* j is an index, hence + 4, not + 3 */
+                evmask->device_id = i;
+                evmask->mask_len = mask_len;
+                reply.num_masks++;
+                reply.length += sizeof(GestureEventMask)/4 + evmask->mask_len;
+
+                if (client->swapped)
+                {
+                    swaps(&evmask->device_id, n);
+                    swaps(&evmask->mask_len, n);
+                }
+
+                memcpy(&evmask[1], devmask, j + 1);
+                evmask = (GestureEventMask*)((char*)evmask +
+                           sizeof(GestureEventMask) + mask_len * 4);
+                break;
+            }
+        }
+    }
+
+    WriteReplyToClient(client, sizeof(GestureGetSelectedEventsReply), &reply);
+
+    if (reply.num_masks)
+        WriteToClient(client, reply.length * 4, buffer);
+
+    free(buffer);
+    return Success;
+}
+
+void
+SRepGestureGetSelectedEvents(ClientPtr client,
+                             int len, GestureGetSelectedEventsReply *rep)
+{
+    char n;
+
+    swaps(&rep->sequenceNumber, n);
+    swapl(&rep->length, n);
+    swaps(&rep->num_masks, n);
+    WriteToClient(client, len, (char *)rep);
+}
+
+int
+GestureClientGone(WindowPtr pWin, XID id)
+{
+    GestureClientsPtr other, prev;
+
+    if (!wGestureMasks(pWin))
+        return (Success);
+    prev = 0;
+    for (other = wGestureMasks(pWin)->clients; other;
+         other = other->next) {
+        if (other->resource == id) {
+            if (prev) {
+                prev->next = other->next;
+                free(other);
+            } else if (!(other->next)) {
+                free(wGestureMasks(pWin));
+                pWin->optional->gestureMasks = (GestureMasks *) NULL;
+                CheckWindowOptionalNeed(pWin);
+                free(other);
+            } else {
+                wGestureMasks(pWin)->clients = other->next;
+                free(other);
+            }
+            RecalculateGestureDeliverableEvents(pWin);
+            return (Success);
+        }
+        prev = other;
+    }
+    FatalError("client not on device event list");
+}
+
+void
+DeleteWindowFromGestureEvents(WindowPtr pWin)
+{
+    struct _GestureMasks *gestureMasks;
+
+    while ((gestureMasks = wGestureMasks(pWin)) != 0)
+        FreeResource(gestureMasks->clients->resource, RT_NONE);
+}
Index: xorg-server/gesture/gesture.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ xorg-server/gesture/gesture.h	2011-08-24 12:56:49.895650626 +0300
@@ -0,0 +1,78 @@
+/*
+ * 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 _GESTURE_H_
+#define _GESTURE_H_
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "inputstr.h"
+
+/* This is the last Gesture event supported by the server. If you add
+ * events to the protocol, the server will not support these events until
+ * this number here is bumped.
+ */
+#define GESTURELASTEVENT     63
+#define GESTUREMASKSIZE      (GESTURELASTEVENT/8 + 1) /* no of bits for masks */
+
+extern _X_EXPORT int GestureReqCode;
+
+/**
+ * Attached to the devPrivates of each client. Specifies the version number as
+ * supported by the client.
+ */
+typedef struct _GestureClientRec {
+        int major_version;
+        int minor_version;
+} GestureClientRec, *GestureClientPtr;
+
+typedef struct _GestureClients *GestureClientsPtr;
+
+/**
+ * This struct stores the Gesture event mask for each client.
+ *
+ * Each window that has events selected has at least one of these masks. If
+ * multiple client selected for events on the same window, these masks are in
+ * a linked list.
+ */
+typedef struct _GestureClients {
+    GestureClientsPtr  next; /**< Pointer to the next mask */
+    XID                resource; /**< id for putting into resource manager */
+    /** Gesture event masks. One per device, each bit is a mask of (1 << type) */
+    unsigned char      gestureMask[EMASKSIZE][GESTUREMASKSIZE];
+} GestureClients;
+
+typedef struct _GestureMasks {
+    GestureClientsPtr   clients;
+    unsigned char       mask[GESTUREMASKSIZE];
+} GestureMasks;
+
+extern int GestureClientGone(WindowPtr pWin, XID id);
+extern void DeleteWindowFromGestureEvents(WindowPtr pWin);
+
+#endif /* _GESTURE_H_ */
Index: xorg-server/gesture/gestureint.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ xorg-server/gesture/gestureint.h	2011-08-24 12:56:49.895650626 +0300
@@ -0,0 +1,49 @@
+/*
+ * 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 _GESTUREINT_H_
+#define _GESTUREINT_H_
+
+#include "gestureproto.h"
+
+typedef struct {
+        short   major_version;
+        short   minor_version;
+} GestureExtensionVersion;
+
+extern DevPrivateKeyRec GestureClientPrivateKeyRec;
+extern int RT_GESTURECLIENT;
+
+extern int ProcGestureQueryVersion(ClientPtr client);
+extern int ProcGestureSelectEvents(ClientPtr client);
+extern int ProcGestureGetSelectedEvents(ClientPtr client);
+extern int SProcGestureQueryVersion(ClientPtr client);
+extern int SProcGestureSelectEvents(ClientPtr client);
+extern int SProcGestureGetSelectedEvents(ClientPtr client);
+extern void SRepGestureQueryVersion(ClientPtr client, int size, GestureQueryVersionReply *rep);
+extern void SRepGestureGetSelectedEvents(ClientPtr client, int len, GestureGetSelectedEventsReply *rep);
+
+#endif /* _GESTUREINT_H_ */
Index: xorg-server/gesture/gestureproto.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ xorg-server/gesture/gestureproto.h	2011-08-24 12:56:49.895650626 +0300
@@ -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_ */
Index: xorg-server/gesture/init.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ xorg-server/gesture/init.c	2011-08-24 12:56:49.895650626 +0300
@@ -0,0 +1,280 @@
+/************************************************************
+
+Copyright 2010 Canonical, Ltd.
+Copyright 1989, 1998  The Open Group
+
+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.
+
+The above copyright notice and this permission notice 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
+OPEN GROUP 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.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
+
+			All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+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 Hewlett-Packard not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+HEWLETT-PACKARD 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.
+
+********************************************************/
+
+/********************************************************************
+ *
+ *  Dispatch routines and initialization routines for the X gesture extension.
+ *
+ */
+
+#define	 NUMTYPES 15
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "gcstruct.h"	/* pointer for extnsionst.h */
+#include "extnsionst.h"	/* extension entry   */
+#include "gesture.h"
+#include "gestureint.h"
+#include <X11/extensions/geproto.h>
+#include "geext.h" /* extension interfaces for ge */
+
+#include "swaprep.h"
+#include "privates.h"
+#include "protocol-versions.h"
+#include "dixstruct.h"
+
+#define GESTURE_NAME "GestureExtension"
+#define GESTURE_EVENTS 0
+#define GESTURE_ERRORS 0
+
+void GestureExtensionInit(void);
+
+/**
+ * Dispatch vector. Functions defined in here will be called when the matching
+ * request arrives.
+ */
+static int (*ProcGestureVector[])(ClientPtr) = {
+        NULL,                                   /*  0 */
+	ProcGestureQueryVersion,                     /*  1 */
+	ProcGestureSelectEvents,                     /*  2 */
+	ProcGestureGetSelectedEvents,                /*  3 */
+};
+
+/* For swapped clients */
+static int (*SProcGestureVector[])(ClientPtr) = {
+        NULL,                                    /*  0 */
+	SProcGestureQueryVersion,                     /*  1 */
+	SProcGestureSelectEvents,                     /*  2 */
+	SProcGestureGetSelectedEvents,                /*  3 */
+};
+
+/*****************************************************************
+ *
+ * Globals referenced elsewhere in the server.
+ *
+ */
+
+int GestureReqCode = 0;
+int GestureNotify = 0;
+
+int RT_GESTURECLIENT;
+
+/*****************************************************************
+ *
+ * Externs defined elsewhere in the X server.
+ *
+ */
+
+extern GestureExtensionVersion GestureVersion;
+
+
+/*****************************************************************
+ *
+ * Versioning support
+ *
+ */
+
+DevPrivateKeyRec GestureClientPrivateKeyRec;
+
+
+/*****************************************************************
+ *
+ * Declarations of local routines.
+ *
+ */
+
+static void
+GestureClientCallback(CallbackListPtr        *list,
+                      pointer                closure,
+                      pointer                data)
+{
+    NewClientInfoRec *clientinfo = (NewClientInfoRec*)data;
+    ClientPtr client = clientinfo->client;
+    GestureClientPtr gestureClient;
+
+    gestureClient = dixLookupPrivate(&client->devPrivates,
+                                     &GestureClientPrivateKeyRec);
+    gestureClient->major_version = 0;
+    gestureClient->minor_version = 0;
+}
+
+/*************************************************************************
+ *
+ * ProcGestureDispatch - main dispatch routine for requests to this extension.
+ * This routine is used if server and client have the same byte ordering.
+ *
+ */
+
+static int
+ProcGestureDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+    if (stuff->data > GESTUREREQUESTS || !ProcGestureVector[stuff->data])
+        return BadRequest;
+
+    return (*ProcGestureVector[stuff->data])(client);
+}
+
+/*******************************************************************************
+ *
+ * SProcXDispatch
+ *
+ * Main swapped dispatch routine for requests to this extension.
+ * This routine is used if server and client do not have the same byte ordering.
+ *
+ */
+
+static int
+SProcGestureDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+    if (stuff->data > GESTUREREQUESTS || !SProcGestureVector[stuff->data])
+        return BadRequest;
+
+    return (*SProcGestureVector[stuff->data])(client);
+}
+
+/**********************************************************************
+ *
+ * SReplyGestureDispatch
+ * Swap any replies defined in this extension.
+ *
+ */
+
+static void
+SReplyGestureDispatch(ClientPtr client, int len, GestureQueryVersionReply *rep)
+{
+    if (rep->RepType == X_GestureQueryVersion)
+        SRepGestureQueryVersion(client, len, (GestureQueryVersionReply*)rep);
+    else if (rep->RepType == X_GestureGetSelectedEvents)
+	SRepGestureGetSelectedEvents(client, len, (GestureGetSelectedEventsReply *) rep);
+    else {
+	FatalError("Gesture confused sending swapped reply");
+    }
+}
+
+static void SGestureEvent(GestureEvent *from, GestureEvent *to)
+{
+    char n;
+
+    memcpy(to, from, sizeof(xEvent) + from->length * 4);
+
+    swaps(&to->sequenceNumber, n);
+    swapl(&to->length, n);
+    swaps(&to->evtype, n);
+    swaps(&to->gesture_id, n);
+    swaps(&to->gesture_type, n);
+    swaps(&to->device_id, n);
+    swapl(&to->time, n);
+    swapl(&to->root, n);
+    swapl(&to->event, n);
+    swapl(&to->child, n);
+    swapl(&to->focus_x, n);
+    swapl(&to->focus_y, n);
+    swaps(&to->status, n);
+    swaps(&to->num_props, n);
+}
+
+static void
+GestureEventSwap(xGenericEvent *from, xGenericEvent *to)
+{
+    SGestureEvent((GestureEvent *)from, (GestureEvent *)to);
+}
+
+static void
+CloseGestureExt(ExtensionEntry *unused)
+{
+    ReplySwapVector[GestureReqCode] = ReplyNotSwappd;
+    GestureReqCode = 0;
+    GestureNotify = 0;
+}
+
+/**********************************************************************
+ *
+ * GestureExtensionInit - initialize the gesture extension.
+ *
+ * Called from InitExtensions in main() or from QueryExtension() if the
+ * extension is dynamically loaded.
+ *
+ * This extension has several events and errors.
+ */
+
+void
+GestureExtensionInit(void)
+{
+    ExtensionEntry *extEntry;
+    GestureExtensionVersion thisversion = {
+        SERVER_GESTURE_MAJOR_VERSION,
+        SERVER_GESTURE_MINOR_VERSION,
+    };
+
+    if (!dixRegisterPrivateKey(&GestureClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(GestureClientRec)))
+        FatalError("Cannot request private for Gesture.\n");
+
+    if (!AddCallback(&ClientStateCallback, GestureClientCallback, 0))
+        FatalError("Failed to add callback to Gesture.\n");
+
+    extEntry = AddExtension(GESTURE_NAME, GESTURE_EVENTS, GESTURE_ERRORS,
+                            ProcGestureDispatch, SProcGestureDispatch, CloseGestureExt,
+                            StandardMinorOpcode);
+    if (extEntry) {
+	GestureReqCode = extEntry->base;
+	GestureVersion = thisversion;
+	RT_GESTURECLIENT = CreateNewResourceType((DeleteType) GestureClientGone,
+					         "GESTURECLIENT");
+	if (!RT_GESTURECLIENT)
+	    FatalError("Failed to add resource type for Gesture.\n");
+	ReplySwapVector[GestureReqCode] = (ReplySwapPtr) SReplyGestureDispatch;
+
+	GERegisterExtension(GestureReqCode, GestureEventSwap);
+    } else {
+	FatalError("GestureExtensionInit: AddExtensions failed\n");
+    }
+}
+
Index: xorg-server/hw/xfree86/common/xf86Xinput.c
===================================================================
--- xorg-server.orig/hw/xfree86/common/xf86Xinput.c	2011-08-24 12:56:49.875650625 +0300
+++ xorg-server/hw/xfree86/common/xf86Xinput.c	2011-08-24 12:56:49.895650626 +0300
@@ -99,6 +99,15 @@
 		return;								\
 	}
 
+#include "gestureproto.h"
+
+_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);
+
 EventListPtr xf86Events = NULL;
 
 static int
@@ -972,6 +981,40 @@
  */
 
 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)
+{
+    DeviceEvent *ev = (DeviceEvent *)xf86Events->event;
+
+    if (num_props > MAX_GESTURE_PROPS)
+        num_props = MAX_GESTURE_PROPS;
+
+    memset(ev, 0, sizeof(DeviceEvent));
+    ev->header = ET_Internal;
+    ev->length = sizeof(DeviceEvent);
+    ev->time = GetTimeInMillis();
+    ev->deviceid = dev->id;
+    ev->sourceid = dev->id;
+    ev->type = ET_Gesture;
+    ev->root_x = x;
+    ev->root_y = y;
+    ev->gesture.client_id = client_id;
+    ev->gesture.id = gesture_id;
+    ev->gesture.type = gesture_type;
+    ev->root = root;
+    ev->gesture.event = event;
+    ev->gesture.child = child;
+    ev->gesture.status = status;
+    ev->gesture.num_props = num_props;
+    memcpy(ev->gesture.props, props, num_props * sizeof(float));
+
+    mieqEnqueue(dev, (InternalEvent*)ev);
+}
+
+void
 xf86PostMotionEvent(DeviceIntPtr	device,
                     int			is_absolute,
                     int			first_valuator,
Index: xorg-server/include/dix-config.h.in
===================================================================
--- xorg-server.orig/include/dix-config.h.in	2011-08-24 12:56:49.505650620 +0300
+++ xorg-server/include/dix-config.h.in	2011-08-24 12:56:49.895650626 +0300
@@ -30,6 +30,9 @@
 /* Support Damage extension */
 #undef DAMAGE
 
+/* Support Gesture extension */
+#undef GESTURES
+
 /* Build for darwin with Quartz support */
 #undef DARWIN_WITH_QUARTZ
 
Index: xorg-server/include/eventstr.h
===================================================================
--- xorg-server.orig/include/eventstr.h	2011-08-24 12:56:49.865650624 +0300
+++ xorg-server/include/eventstr.h	2011-08-24 12:56:49.895650626 +0300
@@ -70,6 +70,7 @@
     ET_TouchMotion,
     ET_TouchMotionUnowned,
     ET_TouchOwnership,
+    ET_Gesture,
     ET_Internal = 0xFF /* First byte */
 };
 
@@ -77,6 +78,9 @@
                           FatalError("Wrong event type %d.\n", \
                                      ((InternalEvent*)(ev))->any.header);
 
+/* Should match DIM_GRAIL_PROP in grail.h */
+#define MAX_GESTURE_PROPS 32
+
 /**
  * Used for ALL input device events internal in the server until
  * copied into the matching protocol event.
@@ -120,6 +124,16 @@
         uint8_t locked;  /**< XKB locked group */
         uint8_t effective;/**< XKB effective group */
     } group;
+    struct {
+        uint16_t client_id;
+        uint16_t id;
+        uint16_t type;
+        Window event;
+        Window child;
+        uint16_t status;
+        uint16_t num_props;
+        float props[MAX_GESTURE_PROPS];
+    } gesture;
     Window      root; /**< Root window of the event */
     int corestate;    /**< Core key/button state BEFORE the event */
     int key_repeat;   /**< Internally-generated key repeat event */
Index: xorg-server/include/protocol-versions.h
===================================================================
--- xorg-server.orig/include/protocol-versions.h	2011-08-24 12:56:49.865650624 +0300
+++ xorg-server/include/protocol-versions.h	2011-08-24 12:56:49.895650626 +0300
@@ -145,4 +145,8 @@
 #define SERVER_XVMC_MAJOR_VERSION		1
 #define SERVER_XVMC_MINOR_VERSION		1
 
+/* Gesture */
+#define SERVER_GESTURE_MAJOR_VERSION		0
+#define SERVER_GESTURE_MINOR_VERSION		5
+
 #endif
Index: xorg-server/include/windowstr.h
===================================================================
--- xorg-server.orig/include/windowstr.h	2011-08-24 12:52:43.235647111 +0300
+++ xorg-server/include/windowstr.h	2011-08-24 12:56:49.895650626 +0300
@@ -48,6 +48,10 @@
 #ifndef WINDOWSTRUCT_H
 #define WINDOWSTRUCT_H
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
 #include "window.h"
 #include "pixmapstr.h"
 #include "regionstr.h"
@@ -60,6 +64,10 @@
 #include <X11/Xprotostr.h>
 #include "opaque.h"
 
+#ifdef GESTURES
+#include "gesture.h"
+#endif
+
 #define GuaranteeNothing	0
 #define GuaranteeVisBack	1
 
@@ -94,6 +102,9 @@
     RegionPtr		inputShape;	   /* default: NULL */
     struct _OtherInputMasks *inputMasks;   /* default: NULL */
     DevCursorList       deviceCursors;     /* default: NULL */
+#ifdef GESTURES
+    struct _GestureMasks *gestureMasks;    /* default: NULL */
+#endif
 } WindowOptRec, *WindowOptPtr;
 
 #define BackgroundPixel	    2L
@@ -202,6 +213,9 @@
 #define wInputShape(w)          wUseDefault(w, inputShape, NULL)
 #define wClient(w)		(clients[CLIENT_ID((w)->drawable.id)])
 #define wBorderWidth(w)		((int) (w)->borderWidth)
+#ifdef GESTURES
+#define wGestureMasks(w)        wUseDefault(w, gestureMasks, NULL)
+#endif
 
 /* true when w needs a border drawn. */
 
Index: xorg-server/mi/mieq.c
===================================================================
--- xorg-server.orig/mi/mieq.c	2011-08-24 12:56:49.865650624 +0300
+++ xorg-server/mi/mieq.c	2011-08-24 12:56:49.895650626 +0300
@@ -58,6 +58,8 @@
 # include <X11/extensions/dpmsconst.h>
 #endif
 
+#include "gestureproto.h"
+
 #define QUEUE_SIZE  512
 
 #define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen
@@ -383,6 +385,39 @@
 
     CHECKEVENT(event);
 
+    if (event->any.header == ET_Internal && event->any.type == ET_Gesture){
+        GestureEvent gev;
+        DeviceEvent *ev = (DeviceEvent *)event;
+        ClientPtr client = clients[ev->gesture.client_id];
+
+        /* Check if client still exists */
+        if (!client)
+            return;
+
+        gev.type = GenericEvent;
+        gev.extension =  GestureReqCode;
+        gev.sequenceNumber = client->sequence;
+        gev.evtype = 0;
+        gev.time = ev->time;
+        gev.length = (sizeof(GestureEvent) +
+                      ev->gesture.num_props * sizeof(float) -
+                       sizeof(xEvent)) / 4;
+        gev.gesture_id = ev->gesture.id;
+        gev.gesture_type = ev->gesture.type;
+        gev.device_id = ev->deviceid;
+        gev.root = ev->root;
+        gev.event = ev->gesture.event;
+        gev.child = ev->gesture.child;
+        gev.focus_x = ev->root_x;
+        gev.focus_y = ev->root_y;
+        gev.status = ev->gesture.status;
+        gev.num_props = ev->gesture.num_props;
+
+        WriteToClient(client, sizeof(GestureEvent), &gev);
+        WriteToClient(client, sizeof(float) * gev.num_props, ev->gesture.props);
+        return;
+    }
+
     /* Custom event handler */
     handler = miEventQueue.handlers[event->any.type];
 
Index: xorg-server/mi/miinitext.c
===================================================================
--- xorg-server.orig/mi/miinitext.c	2011-08-24 12:52:43.285647113 +0300
+++ xorg-server/mi/miinitext.c	2011-08-24 12:56:49.895650626 +0300
@@ -152,6 +152,9 @@
 #ifdef XV
 extern Bool noXvExtension;
 #endif
+#ifdef GESTURES
+extern Bool noGestureExtension;
+#endif
 extern Bool noGEExtension;
 
 #ifndef XFree86LOADER
@@ -263,6 +266,9 @@
 extern void CompositeExtensionInit(INITARGS);
 #endif
 extern void GEExtensionInit(INITARGS);
+#ifdef GESTURES
+extern void GestureExtensionInit(INITARGS);
+#endif
 
 /* The following is only a small first step towards run-time
  * configurable extensions.
@@ -334,6 +340,9 @@
 #ifdef XV
     { "XVideo", &noXvExtension },
 #endif
+#ifdef GESTURES
+    { "Gesture", &noGestureExtension },
+#endif
     { NULL, NULL }
 };
 
@@ -470,6 +479,9 @@
 	GlxPushProvider(&__glXDRISWRastProvider);
     if (!noGlxExtension) GlxExtensionInit();
 #endif
+#ifdef GESTURES
+    if (!noGestureExtension) GestureExtensionInit();
+#endif
 }
 
 #else /* XFree86LOADER */
@@ -511,6 +523,9 @@
 #ifdef DAMAGE
     { DamageExtensionInit, "DAMAGE", &noDamageExtension, NULL },
 #endif
+#ifdef GESTURES
+    { GestureExtensionInit, "GESTURE", &noGestureExtension, NULL },
+#endif
     { NULL, NULL, NULL, NULL, NULL }
 };
     
Index: xorg-server/os/utils.c
===================================================================
--- xorg-server.orig/os/utils.c	2011-08-24 12:56:49.765650622 +0300
+++ xorg-server/os/utils.c	2011-08-24 12:56:49.895650626 +0300
@@ -185,6 +185,9 @@
 #ifdef DRI2
 Bool noDRI2Extension = FALSE;
 #endif
+#ifdef GESTURES
+Bool noGestureExtension = FALSE;
+#endif
 
 Bool noGEExtension = FALSE;