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
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600 | From e6535498b5d756f22e19d7964a81d6a107007ea5 Mon Sep 17 00:00:00 2001
From: Andreas Pokorny <andreas.pokorny@canonical.com>
Date: Mon, 2 Nov 2015 16:13:40 +0100
Subject: [PATCH libinput 1/3] libinput: add orientation and size of touch
point and pressure to the API
This change adds four new properties to touch events:
* major: diameter of the touch ellipse along the major axis
* minor: diameter perpendicular to major axis
* pressure: a pressure value mapped into the range [0, 1]
* orientation: the angle between major and the x axis [0, 360]
Those values are optionally supported by multi-touch drivers, so default values
are used if the information is missing. The existance of each of the properties
can be queried at the event using another set of libinput_event_touch_has_*
functions.
Explanation of those values was added to the touch screen page.
Signed-off-by: Andreas Pokorny <andreas.pokorny@canonical.com>
---
doc/Makefile.am | 2 +
doc/page-hierarchy.dox | 1 +
doc/svg/touchscreen-touch-event-properties.svg | 347 +++++++++++++++++++++++++
doc/touch-event-properties.dox | 42 +++
src/evdev.c | 169 +++++++++++-
src/evdev.h | 25 ++
src/libinput-private.h | 13 +-
src/libinput.c | 212 ++++++++++++++-
src/libinput.h | 222 ++++++++++++++++
src/libinput.sym | 13 +
test/touch.c | 242 +++++++++++++++++
11 files changed, 1278 insertions(+), 10 deletions(-)
create mode 100644 doc/svg/touchscreen-touch-event-properties.svg
create mode 100644 doc/touch-event-properties.dox
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 698a316..5a346fc 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -28,6 +28,7 @@ header_files = \
$(srcdir)/test-suite.dox \
$(srcdir)/tools.dox \
$(srcdir)/touchpad-jumping-cursors.dox \
+ $(srcdir)/touch-event-properties.dox \
$(srcdir)/touchpads.dox
diagram_files = \
@@ -62,6 +63,7 @@ diagram_files = \
$(srcdir)/svg/thumb-detection.svg \
$(srcdir)/svg/top-software-buttons.svg \
$(srcdir)/svg/touchscreen-gestures.svg \
+ $(srcdir)/svg/touchscreen-touch-event-properties.svg \
$(srcdir)/svg/twofinger-scrolling.svg
style_files = \
diff --git a/doc/page-hierarchy.dox b/doc/page-hierarchy.dox
index 6f1a4bc..3beb04f 100644
--- a/doc/page-hierarchy.dox
+++ b/doc/page-hierarchy.dox
@@ -13,6 +13,7 @@
@page touchscreens Touchscreens
- @subpage absolute_axes
+- @subpage touch_event_properties
@page pointers Mice, Trackballs, etc.
diff --git a/doc/svg/touchscreen-touch-event-properties.svg b/doc/svg/touchscreen-touch-event-properties.svg
new file mode 100644
index 0000000..b728f40
--- /dev/null
+++ b/doc/svg/touchscreen-touch-event-properties.svg
@@ -0,0 +1,347 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="81.778557mm"
+ height="107.62305mm"
+ viewBox="0 0 289.76655 381.34154"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="touchscreen-touch-event-properties.svg">
+ <defs
+ id="defs4">
+ <marker
+ inkscape:stockid="DotL"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="DotL"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4259"
+ d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
+ style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
+ transform="matrix(0.8,0,0,0.8,5.92,0.8)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ inkscape:stockid="CurveOut"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="CurveOut"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4385"
+ d="m -5.4129913,-5.0456926 c 2.76,0 4.99999999,2.24 4.99999999,5.00000002 0,2.75999998 -2.23999999,4.99999998 -4.99999999,4.99999998"
+ style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
+ transform="scale(0.6,0.6)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ inkscape:stockid="StopL"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="StopL"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4367"
+ d="M 0,5.65 0,-5.65"
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
+ transform="scale(0.8,0.8)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ style="overflow:visible"
+ id="DistanceStart"
+ refX="0"
+ refY="0"
+ orient="auto"
+ inkscape:stockid="DistanceStart"
+ inkscape:isstock="true">
+ <g
+ id="g2300"
+ style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1">
+ <path
+ style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.14999998;stroke-linecap:square;stroke-opacity:1"
+ d="M 0,0 2,0"
+ id="path2306"
+ inkscape:connector-curvature="0" />
+ <path
+ style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-opacity:1"
+ d="M 0,0 13,4 9,0 13,-4 0,0 Z"
+ id="path2302"
+ inkscape:connector-curvature="0" />
+ <path
+ style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:square;stroke-opacity:1"
+ d="M 0,-4 0,40"
+ id="path2304"
+ inkscape:connector-curvature="0" />
+ </g>
+ </marker>
+ <marker
+ inkscape:stockid="Arrow2Mend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow2Mend"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4225"
+ style="fill:#cb004e;fill-opacity:1;fill-rule:evenodd;stroke:#cb004e;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
+ d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
+ transform="scale(-0.6,-0.6)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ inkscape:stockid="Arrow2Lend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow2Lend"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4219"
+ style="fill:#cb004e;fill-opacity:1;fill-rule:evenodd;stroke:#cb004e;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
+ d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
+ transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ inkscape:stockid="TriangleInL"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="TriangleInL"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4331"
+ d="m 5.77,0 -8.65,5 0,-10 8.65,5 z"
+ style="fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#b3b3b3;stroke-width:1pt;stroke-opacity:1"
+ transform="scale(-0.8,-0.8)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <marker
+ inkscape:stockid="Arrow2Lstart"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow2Lstart"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ id="path4216"
+ style="fill:#cb004e;fill-opacity:1;fill-rule:evenodd;stroke:#cb004e;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
+ d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
+ transform="matrix(1.1,0,0,1.1,1.1,0)"
+ inkscape:connector-curvature="0" />
+ </marker>
+ <inkscape:path-effect
+ effect="powerstroke"
+ id="path-effect4140"
+ is_visible="true"
+ offset_points="0,0.5"
+ sort_points="true"
+ interpolator_type="Linear"
+ interpolator_beta="0.2"
+ start_linecap_type="zerowidth"
+ linejoin_type="round"
+ miter_limit="4"
+ end_linecap_type="zerowidth"
+ cusp_linecap_type="round" />
+ <marker
+ inkscape:stockid="TriangleInL"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="TriangleInL-1"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ inkscape:connector-curvature="0"
+ id="path4331-8"
+ d="m 5.77,0 -8.65,5 0,-10 8.65,5 z"
+ style="fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#b3b3b3;stroke-width:1pt;stroke-opacity:1"
+ transform="scale(-0.8,-0.8)" />
+ </marker>
+ <marker
+ inkscape:stockid="TriangleInL"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="TriangleInL-1-3"
+ style="overflow:visible"
+ inkscape:isstock="true">
+ <path
+ inkscape:connector-curvature="0"
+ id="path4331-8-7"
+ d="m 5.77,0 -8.65,5 0,-10 8.65,5 z"
+ style="fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#b3b3b3;stroke-width:1pt;stroke-opacity:1"
+ transform="scale(-0.8,-0.8)" />
+ </marker>
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="0.99999999"
+ inkscape:cx="123.83444"
+ inkscape:cy="279.21547"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="false"
+ showguides="false"
+ inkscape:window-width="2560"
+ inkscape:window-height="1056"
+ inkscape:window-x="0"
+ inkscape:window-y="24"
+ inkscape:window-maximized="1"
+ fit-margin-top="0"
+ fit-margin-left="0"
+ fit-margin-right="0"
+ fit-margin-bottom="0" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(-99.549825,-70.836892)">
+ <path
+ style="fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#b3b3b3;stroke-width:1.79780054px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#TriangleInL-1-3)"
+ d="m 231.28087,80.931744 -0.008,371.246666"
+ id="path4144-1-8-1"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cc" />
+ <g
+ id="g6309"
+ inkscape:transform-center-x="-9.527809"
+ inkscape:transform-center-y="-8.1612127"
+ transform="matrix(1.171972,1.3632932,-1.3632932,1.171972,275.33248,-179.00364)">
+ <path
+ sodipodi:nodetypes="cc"
+ inkscape:connector-curvature="0"
+ id="path4144-1-8"
+ d="m 172.88767,70.631028 -0.004,206.500482"
+ style="fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#b3b3b3;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#TriangleInL-1)" />
+ <ellipse
+ ry="77.321434"
+ rx="45.89286"
+ cy="180.93364"
+ cx="172.85715"
+ id="path4136"
+ style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ inkscape:connector-curvature="0"
+ id="path4142"
+ d="m 126.9449,180.93396 91.84596,0.007"
+ style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cc"
+ inkscape:connector-curvature="0"
+ id="path4144"
+ d="m 172.84766,103.6564 -0.004,154.59727"
+ style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <text
+ sodipodi:linespacing="125%"
+ id="text4146"
+ y="188.01213"
+ x="128.08986"
+ style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ xml:space="preserve"><tspan
+ y="188.01213"
+ x="128.08986"
+ id="tspan4148"
+ sodipodi:role="line">minor axis</tspan></text>
+ <text
+ transform="matrix(0,-1,1,0,0,0)"
+ sodipodi:linespacing="125%"
+ id="text4150"
+ y="169.33234"
+ x="-256.35562"
+ style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ xml:space="preserve"><tspan
+ y="169.33234"
+ x="-256.35562"
+ id="tspan4152"
+ sodipodi:role="line">major axis</tspan></text>
+ </g>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:71.91202545px;line-height:125%;font-family:Sans;letter-spacing:0px;word-spacing:0px;fill:#b3b3b3;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ x="44.285629"
+ y="369.12045"
+ id="text6877"
+ sodipodi:linespacing="125%"
+ transform="matrix(0.76306478,-0.64632201,0.64632201,0.76306478,0,0)"><tspan
+ sodipodi:role="line"
+ id="tspan6879"
+ x="44.285629"
+ y="369.12045"
+ style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13.4835043px;font-family:sans-serif;-inkscape-font-specification:sans-serif;fill:#b3b3b3;fill-opacity:1">pointing direction</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13.4835043px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#b3b3b3;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ x="237.00804"
+ y="99.788658"
+ id="text6887"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan6889"
+ x="237.00804"
+ y="99.788658">y axis</tspan></text>
+ <path
+ style="fill:none;fill-opacity:1;stroke:#cb004e;stroke-width:1.79780054;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow2Mend)"
+ id="path7011"
+ sodipodi:type="arc"
+ sodipodi:cx="231.14914"
+ sodipodi:cy="268.54077"
+ sodipodi:rx="79.092262"
+ sodipodi:ry="79.092262"
+ sodipodi:start="4.7157629"
+ sodipodi:end="5.5461565"
+ d="m 231.41599,189.44896 a 79.092262,79.092262 0 0 1 58.2985,25.93463"
+ sodipodi:open="true" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.98900318px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#cb004e;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ x="232.66777"
+ y="184.40468"
+ id="text7119"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan7121"
+ x="232.66777"
+ y="184.40468"
+ style="font-size:13.4835043px;fill:#cb004e;fill-opacity:1">orientation</tspan></text>
+ </g>
+</svg>
diff --git a/doc/touch-event-properties.dox b/doc/touch-event-properties.dox
new file mode 100644
index 0000000..bf326f7
--- /dev/null
+++ b/doc/touch-event-properties.dox
@@ -0,0 +1,42 @@
+/**
+@page touch_event_properties Properties of a touch event
+
+This page gives some overview on touchscreen events. With libinput touchscreens
+provide the event types @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref LIBINPUT_EVENT_TOUCH_UP,
+@ref LIBINPUT_EVENT_TOUCH_MOTION and @ref LIBINPUT_EVENT_TOUCH_CANCEL. The
+touchscreen events @ref LIBINPUT_EVENT_TOUCH_DOWN and
+@ref LIBINPUT_EVENT_TOUCH_MOTION provide alongside the actual state change and
+the absolute coordinates (@ref absolute_axes_handling) additional information
+about the touch contact.
+
+@image html touchscreen-touch-event-properties.svg "Properties of a touch screen contact"
+
+Assuming the interaction of fingers with a touch screen, touch contacts are
+approximated with an ellipse. The major axis of the ellipse describes the
+pointing direction of the finger. The minor axis is the perpendicular
+extent of the touching shape. The orientation angle is the clockwise rotation of
+the pointing direction against the y-axis of the touchscreen.
+
+Additionally to the values shown in the drawing above, most touchscreens also
+provide a pressure value to indicate the force applied with the contact point.
+
+The support for those contact properties varies between the different
+available touchscreens. In the case of pressure libinput will return the
+maximum pressure value, which is 1.0. If only the major axis but no minor axis
+is present, libinput will assume a circular shape and return the major axis
+value for convenience. If also no major axis value is known 0.0 is returned.
+If the orientation is not available libinput will return 0.0 degrees.
+
+For querying the touch properties see:
+- libinput_event_touch_get_major_transformed()
+- libinput_event_touch_get_minor_transformed()
+- libinput_event_touch_get_orientation()
+- libinput_event_touch_get_pressure()
+
+For testing which of the touch properties are available see:
+- libinput_event_touch_has_major()
+- libinput_event_touch_has_minor()
+- libinput_event_touch_has_orientation()
+- libinput_event_touch_has_pressure()
+
+*/
diff --git a/src/evdev.c b/src/evdev.c
index d49b391..7ae1276 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -49,6 +49,10 @@
#define DEFAULT_WHEEL_CLICK_ANGLE 15
#define DEFAULT_MIDDLE_BUTTON_SCROLL_TIMEOUT ms2us(200)
+#define DEFAULT_TOUCH_PRESSURE 1.0
+#define DEFAULT_TOUCH_ORIENTATION 0.0
+#define DEFAULT_TOUCH_MAJOR 0.0
+#define DEFAULT_TOUCH_MINOR 0.0
enum evdev_key_type {
EVDEV_KEY_TYPE_NONE,
@@ -321,6 +325,100 @@ evdev_device_transform_y(struct evdev_device *device,
return scale_axis(device->abs.absinfo_y, y, height);
}
+double
+evdev_device_transform_ellipse_diameter_to_mm(struct evdev_device *device,
+ int diameter,
+ double axis_angle)
+{
+ double x_res = device->abs.absinfo_x->resolution;
+ double y_res = device->abs.absinfo_y->resolution;
+
+ if (x_res == y_res)
+ return diameter / x_res;
+
+ /* resolution differs but no orientation available
+ * -> estimate resolution using the average */
+ if (device->abs.absinfo_orientation == NULL) {
+ return diameter * 2.0 / (x_res + y_res);
+ } else {
+ /* Why scale x using sine of angle?
+ * axis_angle = 0 indicates that the given diameter
+ * is aligned with the y-axis. */
+ double x_scaling_ratio = fabs(sin(deg2rad(axis_angle)));
+ double y_scaling_ratio = fabs(cos(deg2rad(axis_angle)));
+
+ return diameter / hypotf(y_res * y_scaling_ratio,
+ x_res * x_scaling_ratio);
+ }
+}
+
+double
+evdev_device_transform_ellipse_diameter(struct evdev_device *device,
+ int diameter,
+ double axis_angle,
+ uint32_t width,
+ uint32_t height)
+{
+ double x_res = device->abs.absinfo_x->resolution;
+ double y_res = device->abs.absinfo_y->resolution;
+ double x_scale = width / (device->abs.dimensions.x + 1.0);
+ double y_scale = height / (device->abs.dimensions.y + 1.0);
+
+ if (x_res == y_res)
+ return diameter * x_scale;
+
+ /* no orientation available -> estimate resolution using the
+ * average */
+ if (device->abs.absinfo_orientation == NULL) {
+ return diameter * (x_scale + y_scale) / 2.0;
+ } else {
+ /* Why scale x using sine of angle?
+ * axis_angle = 0 indicates that the given diameter
+ * is aligned with the y-axis. */
+ double x_scaling_ratio = fabs(sin(deg2rad(axis_angle)));
+ double y_scaling_ratio = fabs(cos(deg2rad(axis_angle)));
+
+ return diameter * (y_scale * y_scaling_ratio +
+ x_scale * x_scaling_ratio);
+ }
+}
+
+double
+evdev_device_transform_orientation(struct evdev_device *device,
+ int32_t orientation)
+{
+ const struct input_absinfo *orientation_info =
+ device->abs.absinfo_orientation;
+
+ double angle = DEFAULT_TOUCH_ORIENTATION;
+
+ /* ABS_MT_ORIENTATION is defined as a clockwise rotation - zero
+ * (instead of minimum) is mapped to the y-axis, and maximum is
+ * mapped to the x-axis. So minimum is likely to be negative but
+ * plays no role in scaling the value to degrees.*/
+ if (orientation_info)
+ angle = (90.0 * orientation) / orientation_info->maximum;
+
+ return fmod(360.0 + angle, 360.0);
+}
+
+double
+evdev_device_transform_pressure(struct evdev_device *device,
+ int32_t pressure)
+{
+ const struct input_absinfo *pressure_info =
+ device->abs.absinfo_pressure;
+
+ if (pressure_info) {
+ double max_pressure = pressure_info->maximum;
+ double min_pressure = pressure_info->minimum;
+ return (pressure - min_pressure) /
+ (max_pressure - min_pressure);
+ } else {
+ return DEFAULT_TOUCH_PRESSURE;
+ }
+}
+
static inline void
normalize_delta(struct evdev_device *device,
const struct device_coords *delta,
@@ -462,6 +560,7 @@ fallback_flush_mt_down(struct fallback_dispatch *dispatch,
struct libinput_seat *seat = base->seat;
struct device_coords point;
struct mt_slot *slot;
+
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
@@ -490,7 +589,8 @@ fallback_flush_mt_down(struct fallback_dispatch *dispatch,
evdev_transform_absolute(device, &point);
touch_notify_touch_down(base, time, slot_idx, seat_slot,
- &point);
+ &point, &slot->area, slot->pressure);
+
return true;
}
@@ -521,7 +621,7 @@ fallback_flush_mt_motion(struct fallback_dispatch *dispatch,
evdev_transform_absolute(device, &point);
touch_notify_touch_motion(base, time, slot_idx, seat_slot,
- &point);
+ &point, &slot->area, slot->pressure);
return true;
}
@@ -562,6 +662,11 @@ fallback_flush_st_down(struct fallback_dispatch *dispatch,
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
struct device_coords point;
+ struct ellipse default_area = {
+ .major = DEFAULT_TOUCH_MAJOR,
+ .minor = DEFAULT_TOUCH_MINOR,
+ .orientation = DEFAULT_TOUCH_ORIENTATION,
+ };
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
@@ -588,7 +693,8 @@ fallback_flush_st_down(struct fallback_dispatch *dispatch,
point = dispatch->abs.point;
evdev_transform_absolute(device, &point);
- touch_notify_touch_down(base, time, -1, seat_slot, &point);
+ touch_notify_touch_down(base, time, -1, seat_slot, &point,
+ &default_area, DEFAULT_TOUCH_PRESSURE);
return true;
}
@@ -600,6 +706,11 @@ fallback_flush_st_motion(struct fallback_dispatch *dispatch,
{
struct libinput_device *base = &device->base;
struct device_coords point;
+ struct ellipse default_area = {
+ .major = DEFAULT_TOUCH_MAJOR,
+ .minor = DEFAULT_TOUCH_MINOR,
+ .orientation = DEFAULT_TOUCH_ORIENTATION,
+ };
int seat_slot;
point = dispatch->abs.point;
@@ -610,7 +721,8 @@ fallback_flush_st_motion(struct fallback_dispatch *dispatch,
if (seat_slot == -1)
return false;
- touch_notify_touch_motion(base, time, -1, seat_slot, &point);
+ touch_notify_touch_motion(base, time, -1, seat_slot, &point,
+ &default_area, DEFAULT_TOUCH_PRESSURE);
return true;
}
@@ -829,6 +941,9 @@ fallback_process_touch(struct fallback_dispatch *dispatch,
struct input_event *e,
uint64_t time)
{
+ struct mt_slot *current_slot = &dispatch->mt.slots[dispatch->mt.slot];
+ int pending_event = EVDEV_NONE;
+
switch (e->code) {
case ABS_MT_SLOT:
if ((size_t)e->value >= dispatch->mt.slots_len) {
@@ -858,10 +973,28 @@ fallback_process_touch(struct fallback_dispatch *dispatch,
break;
case ABS_MT_POSITION_Y:
dispatch->mt.slots[dispatch->mt.slot].point.y = e->value;
- if (dispatch->pending_event == EVDEV_NONE)
- dispatch->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
+ pending_event = EVDEV_ABSOLUTE_MT_MOTION;
+ break;
+ case ABS_MT_TOUCH_MAJOR:
+ current_slot->area.major = e->value;
+ pending_event = EVDEV_ABSOLUTE_MT_MOTION;
+ break;
+ case ABS_MT_TOUCH_MINOR:
+ current_slot->area.minor = e->value;
+ pending_event = EVDEV_ABSOLUTE_MT_MOTION;
+ break;
+ case ABS_MT_ORIENTATION:
+ current_slot->area.orientation = e->value;
+ pending_event = EVDEV_ABSOLUTE_MT_MOTION;
+ break;
+ case ABS_MT_PRESSURE:
+ current_slot->pressure = e->value;
+ pending_event = EVDEV_ABSOLUTE_MT_MOTION;
break;
}
+
+ if (dispatch->pending_event == EVDEV_NONE && pending_event != EVDEV_NONE)
+ dispatch->pending_event = pending_event;;
}
static inline void
fallback_process_absolute_motion(struct fallback_dispatch *dispatch,
@@ -1684,6 +1817,21 @@ fallback_dispatch_init_slots(struct fallback_dispatch *dispatch,
slots[slot].point.y = libevdev_get_slot_value(evdev,
slot,
ABS_MT_POSITION_Y);
+ slots[slot].area.major =
+ libevdev_get_slot_value(evdev,
+ slot,
+ ABS_MT_TOUCH_MAJOR);
+ slots[slot].area.minor =
+ libevdev_get_slot_value(evdev,
+ slot,
+ ABS_MT_TOUCH_MINOR);
+ slots[slot].area.orientation =
+ libevdev_get_slot_value(evdev,
+ slot,
+ ABS_MT_ORIENTATION);
+ slots[slot].pressure =
+ libevdev_get_slot_value(evdev, slot, ABS_MT_PRESSURE);
+
}
dispatch->mt.slots = slots;
dispatch->mt.slots_len = num_slots;
@@ -2482,6 +2630,15 @@ evdev_configure_device(struct evdev_device *device)
return NULL;
}
+ device->abs.absinfo_orientation =
+ libevdev_get_abs_info(evdev, ABS_MT_ORIENTATION);
+ device->abs.absinfo_pressure =
+ libevdev_get_abs_info(evdev, ABS_MT_PRESSURE);
+ device->abs.absinfo_major =
+ libevdev_get_abs_info(evdev, ABS_MT_TOUCH_MAJOR);
+ device->abs.absinfo_minor =
+ libevdev_get_abs_info(evdev, ABS_MT_TOUCH_MINOR);
+
if (!evdev_is_fake_mt_device(device))
evdev_fix_android_mt(device);
diff --git a/src/evdev.h b/src/evdev.h
index 4e28e05..a4c00af 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -126,6 +126,8 @@ struct mt_slot {
int32_t seat_slot;
struct device_coords point;
struct device_coords hysteresis_center;
+ struct ellipse area;
+ int32_t pressure;
};
struct evdev_device {
@@ -152,6 +154,8 @@ struct evdev_device {
struct {
const struct input_absinfo *absinfo_x, *absinfo_y;
+ const struct input_absinfo *absinfo_major, *absinfo_minor,
+ *absinfo_pressure, *absinfo_orientation;
bool is_fake_resolution;
int apply_calibration;
@@ -431,6 +435,27 @@ double
evdev_device_transform_y(struct evdev_device *device,
double y,
uint32_t height);
+
+double
+evdev_device_transform_ellipse_diameter_to_mm(struct evdev_device *device,
+ int32_t diameter,
+ double axis_angle);
+
+double
+evdev_device_transform_ellipse_diameter(struct evdev_device *device,
+ int32_t diameter,
+ double axis_angle,
+ uint32_t width,
+ uint32_t height);
+
+double
+evdev_device_transform_orientation(struct evdev_device *device,
+ int32_t orientation);
+
+double
+evdev_device_transform_pressure(struct evdev_device *device,
+ int32_t pressure);
+
void
evdev_device_suspend(struct evdev_device *device);
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 5b46da7..29d1187 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -48,6 +48,11 @@ struct device_coords {
int x, y;
};
+/* Ellipse parameters in device coordinates */
+struct ellipse {
+ int major, minor, orientation;
+};
+
/*
* A coordinate pair in device coordinates, capable of holding non discrete
* values, this is necessary e.g. when device coordinates get averaged.
@@ -514,14 +519,18 @@ touch_notify_touch_down(struct libinput_device *device,
uint64_t time,
int32_t slot,
int32_t seat_slot,
- const struct device_coords *point);
+ const struct device_coords *point,
+ const struct ellipse *area,
+ int32_t pressure);
void
touch_notify_touch_motion(struct libinput_device *device,
uint64_t time,
int32_t slot,
int32_t seat_slot,
- const struct device_coords *point);
+ const struct device_coords *point,
+ const struct ellipse *area,
+ int32_t pressure);
void
touch_notify_touch_up(struct libinput_device *device,
diff --git a/src/libinput.c b/src/libinput.c
index 1e97ad1..f3df972 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -112,6 +112,8 @@ struct libinput_event_touch {
int32_t slot;
int32_t seat_slot;
struct device_coords point;
+ struct ellipse area;
+ int32_t pressure;
};
struct libinput_event_gesture {
@@ -793,6 +795,204 @@ libinput_event_touch_get_y(struct libinput_event_touch *event)
return evdev_convert_to_mm(device->abs.absinfo_y, event->point.y);
}
+LIBINPUT_EXPORT double
+libinput_event_touch_get_major(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+ double angle;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ angle = evdev_device_transform_orientation(device,
+ event->area.orientation);
+
+ return evdev_device_transform_ellipse_diameter_to_mm(device,
+ event->area.major,
+ angle);
+}
+
+LIBINPUT_EXPORT double
+libinput_event_touch_get_major_transformed(struct libinput_event_touch *event,
+ uint32_t width,
+ uint32_t height)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+ double angle;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ angle = evdev_device_transform_orientation(device,
+ event->area.orientation);
+
+ return evdev_device_transform_ellipse_diameter(device,
+ event->area.major,
+ angle,
+ width,
+ height);
+}
+
+LIBINPUT_EXPORT int
+libinput_event_touch_has_major(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ return device->abs.absinfo_major != 0;
+}
+
+LIBINPUT_EXPORT double
+libinput_event_touch_get_minor(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+ double angle;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ angle = evdev_device_transform_orientation(device,
+ event->area.orientation);
+
+ /* angle + 90 since the minor diameter is perpendicular to the
+ * major axis */
+ return evdev_device_transform_ellipse_diameter_to_mm(device,
+ event->area.minor,
+ angle + 90.0);
+
+}
+
+LIBINPUT_EXPORT double
+libinput_event_touch_get_minor_transformed(struct libinput_event_touch *event,
+ uint32_t width,
+ uint32_t height)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+ double angle;
+ int diameter;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ angle = evdev_device_transform_orientation(device,
+ event->area.orientation);
+
+ /* use major diameter if minor is not available, but if it is
+ * add 90 since the minor diameter is perpendicular to the
+ * major axis */
+ if (device->abs.absinfo_minor) {
+ diameter = event->area.minor,
+ angle += 90.0;
+ } else {
+ diameter = event->area.major;
+ }
+
+ return evdev_device_transform_ellipse_diameter(device,
+ diameter,
+ angle,
+ width,
+ height);
+}
+
+LIBINPUT_EXPORT int
+libinput_event_touch_has_minor(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ return device->abs.absinfo_minor != 0;
+}
+
+LIBINPUT_EXPORT double
+libinput_event_touch_get_orientation(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ return evdev_device_transform_orientation(device,
+ event->area.orientation);
+}
+
+LIBINPUT_EXPORT int
+libinput_event_touch_has_orientation(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ return device->abs.absinfo_orientation != 0;
+}
+
+LIBINPUT_EXPORT double
+libinput_event_touch_get_pressure(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ return evdev_device_transform_pressure(device,
+ event->pressure);
+}
+
+LIBINPUT_EXPORT int
+libinput_event_touch_has_pressure(struct libinput_event_touch *event)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ LIBINPUT_EVENT_TOUCH_MOTION);
+
+ return device->abs.absinfo_pressure != 0;
+}
+
LIBINPUT_EXPORT uint32_t
libinput_event_gesture_get_time(struct libinput_event_gesture *event)
{
@@ -2181,7 +2381,9 @@ touch_notify_touch_down(struct libinput_device *device,
uint64_t time,
int32_t slot,
int32_t seat_slot,
- const struct device_coords *point)
+ const struct device_coords *point,
+ const struct ellipse *area,
+ int32_t pressure)
{
struct libinput_event_touch *touch_event;
@@ -2197,6 +2399,8 @@ touch_notify_touch_down(struct libinput_device *device,
.slot = slot,
.seat_slot = seat_slot,
.point = *point,
+ .area = *area,
+ .pressure = pressure,
};
post_device_event(device, time,
@@ -2209,7 +2413,9 @@ touch_notify_touch_motion(struct libinput_device *device,
uint64_t time,
int32_t slot,
int32_t seat_slot,
- const struct device_coords *point)
+ const struct device_coords *point,
+ const struct ellipse *area,
+ int32_t pressure)
{
struct libinput_event_touch *touch_event;
@@ -2225,6 +2431,8 @@ touch_notify_touch_motion(struct libinput_device *device,
.slot = slot,
.seat_slot = seat_slot,
.point = *point,
+ .area = *area,
+ .pressure = pressure,
};
post_device_event(device, time,
diff --git a/src/libinput.h b/src/libinput.h
index 18a96bd..09fdbf6 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1475,6 +1475,228 @@ libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
/**
* @ingroup event_touch
*
+ * Return the diameter of the major axis of the touch ellipse in mm.
+ * This value might not be provided by the device, in that case the value
+ * 0.0 is returned.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return The current major axis diameter
+ */
+double
+libinput_event_touch_get_major(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return the diameter of the major axis of the touch ellipse in screen
+ * space. This value might not be provided by the device, in that case the
+ * value 0.0 is returned.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @param width The current output screen width
+ * @param height The current output screen height
+ * @return The current major axis diameter
+ */
+double
+libinput_event_touch_get_major_transformed(struct libinput_event_touch *event,
+ uint32_t width,
+ uint32_t height);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return if the event contains a major axis value of the touch ellipse.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return Non-zero when a major diameter is available
+ */
+int
+libinput_event_touch_has_major(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return the diameter of the minor axis of the touch ellipse in mm.
+ * This value might not be provided by the device, in this case the value
+ * 0.0 is returned.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return The current minor diameter
+ */
+double
+libinput_event_touch_get_minor(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return the diameter of the minor axis of the touch ellipse in screen
+ * space. This value might not be provided by the device, in this case
+ * the value 0.0 is returned.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @param width The current output screen width
+ * @param height The current output screen height
+ * @return The current minor diameter
+ */
+double
+libinput_event_touch_get_minor_transformed(struct libinput_event_touch *event,
+ uint32_t width,
+ uint32_t height);
+/**
+ * @ingroup event_touch
+ *
+ * Return if the event contains a minor axis value of the touch ellipse.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return Non-zero when a minor diameter is available
+ */
+int
+libinput_event_touch_has_minor(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return the pressure value applied to the touch contact normalized to the
+ * range [0, 1]. If this value is not available the function returns the maximum
+ * value 1.0.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return The current pressure value
+ */
+double
+libinput_event_touch_get_pressure(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return if the event contains a pressure value for the touch contact.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return Non-zero when a pressure value is available
+ */
+int
+libinput_event_touch_has_pressure(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return the major axis rotation in degrees, clockwise from the logical north
+ * of the touch screen.
+ *
+ * @note Even when the orientation is measured by the device, it might be only
+ * available in coarse steps (e.g only indicating alignment with either of the
+ * axes).
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return The current orientation value
+ */
+double
+libinput_event_touch_get_orientation(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
+ * Return if the event contains a orientation value for the touch contact.
+ *
+ * A more detailed explanation can be found in @ref touch_event_properties.
+ *
+ * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events of type
+ * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref
+ * LIBINPUT_EVENT_TOUCH_MOTION.
+ *
+ * @param event The libinput touch event
+ * @return Non-zero when an orientation value is available
+ */
+int
+libinput_event_touch_has_orientation(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
* @return The generic libinput_event of this event
*/
struct libinput_event *
diff --git a/src/libinput.sym b/src/libinput.sym
index 97bb57f..b4b3599 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -280,3 +280,16 @@ LIBINPUT_1.5 {
libinput_device_config_tap_get_default_button_map;
libinput_device_config_tap_set_button_map;
} LIBINPUT_1.4;
+
+LIBINPUT_1.6_unreleased {
+ libinput_event_touch_get_major;
+ libinput_event_touch_get_major_transformed;
+ libinput_event_touch_get_minor;
+ libinput_event_touch_get_minor_transformed;
+ libinput_event_touch_get_orientation;
+ libinput_event_touch_get_pressure;
+ libinput_event_touch_has_major;
+ libinput_event_touch_has_minor;
+ libinput_event_touch_has_orientation;
+ libinput_event_touch_has_pressure;
+} LIBINPUT_1.5;
diff --git a/test/touch.c b/test/touch.c
index ac2f29f..1676aac 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -719,6 +719,245 @@ START_TEST(touch_fuzz)
}
END_TEST
+static inline double calc_diameter_scale(double x_res,
+ double y_res,
+ double orientation)
+{
+ double orientation_rad = deg2rad(orientation);
+ if (x_res == y_res)
+ return x_res;
+
+ return hypotf(y_res * fabs(cos(orientation_rad)),
+ x_res * fabs(sin(orientation_rad)));
+}
+
+static inline bool exceeds_range(const struct input_absinfo *info,
+ int value)
+{
+ return !info || (info->minimum > value) || (info->maximum < value);
+}
+
+START_TEST(touch_point_properties)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *ev;
+ struct libinput_event_touch *tev;
+
+ const int touch_x = 50;
+ const int touch_y = 90;
+ const int input_orientation = 64;
+ const int input_pressure = 128;
+ const int input_major = 14;
+ const int input_minor= 8;
+
+ const int input_orientation_2 = 128;
+ const int input_major_2 = 30;
+
+ struct axis_replacement down_values[] = {
+ {ABS_MT_PRESSURE, input_pressure},
+ {ABS_MT_ORIENTATION, input_orientation},
+ {ABS_MT_TOUCH_MAJOR, input_major},
+ {ABS_MT_TOUCH_MINOR, input_minor},
+ {-1, -1}};
+ struct axis_replacement move_values[] = {
+ {ABS_MT_ORIENTATION, input_orientation_2},
+ {ABS_MT_TOUCH_MAJOR, input_major_2},
+ {-1, -1}};
+ const struct input_absinfo *orientation_info;
+ const struct input_absinfo *pressure_info;
+ const struct input_absinfo *major_info;
+ const struct input_absinfo *minor_info;
+ const struct input_absinfo *x_info, *y_info;
+
+ double x_res, y_res, touch_minor_scale, touch_major_scale;
+
+ double expected_major;
+ double expected_minor;
+ double expected_orientation;
+ double expected_pressure;
+
+ pressure_info = libevdev_get_abs_info(dev->evdev, ABS_MT_PRESSURE);
+ orientation_info = libevdev_get_abs_info(dev->evdev, ABS_MT_ORIENTATION);
+ major_info = libevdev_get_abs_info(dev->evdev, ABS_MT_TOUCH_MAJOR);
+ minor_info = libevdev_get_abs_info(dev->evdev, ABS_MT_TOUCH_MINOR);
+ x_info = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_X);
+ y_info = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_Y);
+
+ if (!orientation_info || !pressure_info || !major_info || !minor_info)
+ return;
+
+ if (exceeds_range(pressure_info, input_pressure) ||
+ exceeds_range(major_info, input_major) ||
+ exceeds_range(major_info, input_major_2) ||
+ exceeds_range(minor_info, input_minor) ||
+ exceeds_range(orientation_info, input_orientation) ||
+ exceeds_range(orientation_info, input_orientation_2)) {
+ fprintf(stderr,
+ "%s does not support the required value ranges\n",
+ libinput_device_get_name(dev->libinput_device));
+ return;
+ }
+
+ x_res = x_info->resolution ? x_info->resolution : 1;
+ y_res = y_info->resolution ? y_info->resolution : 1;
+
+ expected_orientation = 90.0 * input_orientation /
+ orientation_info->maximum;
+ touch_major_scale = calc_diameter_scale(x_res,
+ y_res,
+ expected_orientation);
+ touch_minor_scale = calc_diameter_scale(x_res,
+ y_res,
+ expected_orientation + 90.0);
+ expected_major = input_major / touch_major_scale;
+ expected_minor = input_minor / touch_minor_scale;
+ expected_pressure = (double)input_pressure / (pressure_info->maximum -
+ pressure_info->minimum);
+
+ litest_drain_events(li);
+
+ litest_touch_down_extended(dev, 0, touch_x, touch_y, down_values);
+
+ litest_wait_for_event(li);
+ ev = libinput_get_event(li);
+ tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
+
+ ck_assert_double_eq(libinput_event_touch_get_pressure(tev),
+ expected_pressure);
+ ck_assert_double_eq(libinput_event_touch_get_orientation(tev),
+ expected_orientation);
+ ck_assert_double_eq(libinput_event_touch_get_major(tev),
+ expected_major);
+ ck_assert_double_eq(libinput_event_touch_get_minor(tev),
+ expected_minor);
+
+ litest_touch_move_extended(dev, 0, touch_x, touch_y, move_values);
+
+ do {
+ libinput_event_destroy(ev);
+ litest_wait_for_event(li);
+ ev = libinput_get_event(li);
+ } while (libinput_event_get_type(ev) == LIBINPUT_EVENT_TOUCH_FRAME);
+
+ tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_MOTION);
+
+ expected_orientation = 90.0 * input_orientation_2 /
+ orientation_info->maximum;
+ touch_major_scale = calc_diameter_scale(x_res,
+ y_res,
+ expected_orientation);
+ expected_major = input_major_2 / touch_major_scale;
+
+ ck_assert_double_eq(libinput_event_touch_get_pressure(tev),
+ expected_pressure);
+ ck_assert_double_eq(libinput_event_touch_get_orientation(tev),
+ expected_orientation);
+ ck_assert_double_eq(libinput_event_touch_get_major(tev),
+ expected_major);
+ ck_assert_double_eq(libinput_event_touch_get_minor(tev),
+ expected_minor);
+
+ libinput_event_destroy(ev);
+}
+END_TEST
+
+START_TEST(touch_point_no_minor_or_orientation)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *ev;
+ struct libinput_event_touch *tev;
+ const int touch_x = 50;
+ const int touch_y = 90;
+ const int input_pressure = 43;
+ const int input_major = 23;
+ const int input_major_2 = 30;
+
+ struct axis_replacement down_values[] = {
+ {ABS_MT_PRESSURE, input_pressure},
+ {ABS_MT_TOUCH_MAJOR, input_major},
+ {-1, -1}};
+ struct axis_replacement move_values[] = {
+ {ABS_MT_TOUCH_MAJOR, input_major_2},
+ {-1, -1}};
+
+ const struct input_absinfo *orientation_info;
+ const struct input_absinfo *pressure_info;
+ const struct input_absinfo *x_info;
+ const struct input_absinfo *major_info;
+ double touch_major_scale;
+
+ double expected_major;
+ double expected_minor;
+ double expected_orientation = 0.0;
+ double expected_pressure;
+
+ x_info = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_X);
+ pressure_info = libevdev_get_abs_info(dev->evdev, ABS_MT_PRESSURE);
+ major_info = libevdev_get_abs_info(dev->evdev, ABS_MT_TOUCH_MAJOR);
+ orientation_info = libevdev_get_abs_info(dev->evdev,
+ ABS_MT_ORIENTATION);
+
+ if (orientation_info || !pressure_info || !x_info || !major_info ||
+ !libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOUCH_MAJOR) ||
+ libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOUCH_MINOR))
+ return;
+
+ if (exceeds_range(pressure_info, input_pressure) ||
+ exceeds_range(major_info, input_major) ||
+ exceeds_range(major_info, input_major_2)) {
+ fprintf(stderr,
+ "%s does not support the required value ranges\n",
+ libinput_device_get_name(dev->libinput_device));
+ return;
+ }
+
+ expected_pressure = (double) input_pressure /
+ (pressure_info->maximum - pressure_info->minimum);
+ touch_major_scale = x_info->resolution ? x_info->resolution : 1;
+ expected_major = input_major / touch_major_scale;
+ expected_minor = expected_major;
+
+ litest_drain_events(li);
+
+ litest_touch_down_extended(dev, 0, touch_x, touch_y, down_values);
+
+ litest_wait_for_event(li);
+ ev = libinput_get_event(li);
+ tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
+
+ ck_assert_double_eq(libinput_event_touch_get_orientation(tev),
+ expected_orientation);
+ ck_assert_double_eq(libinput_event_touch_get_pressure(tev),
+ expected_pressure);
+ ck_assert_double_eq(libinput_event_touch_get_major(tev),
+ expected_major);
+ ck_assert_double_eq(libinput_event_touch_get_minor(tev),
+ expected_minor);
+
+ expected_major = input_major_2 / touch_major_scale;
+ expected_minor = expected_major;
+
+ litest_touch_move_extended(dev, 0, touch_x, touch_y, move_values);
+
+ do {
+ libinput_event_destroy(ev);
+ litest_wait_for_event(li);
+ ev = libinput_get_event(li);
+ } while (libinput_event_get_type(ev) == LIBINPUT_EVENT_TOUCH_FRAME);
+
+ tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_MOTION);
+
+ ck_assert_double_eq(libinput_event_touch_get_major(tev),
+ expected_major);
+ ck_assert_double_eq(libinput_event_touch_get_minor(tev),
+ expected_minor);
+
+ libinput_event_destroy(ev);
+}
+END_TEST
+
void
litest_setup_tests_touch(void)
{
@@ -743,10 +982,13 @@ litest_setup_tests_touch(void)
litest_add("touch:protocol a", touch_protocol_a_init, LITEST_PROTOCOL_A, LITEST_ANY);
litest_add("touch:protocol a", touch_protocol_a_touch, LITEST_PROTOCOL_A, LITEST_ANY);
litest_add("touch:protocol a", touch_protocol_a_2fg_touch, LITEST_PROTOCOL_A, LITEST_ANY);
+ litest_add("touch:properties", touch_point_properties, LITEST_TOUCH|LITEST_ELLIPSE, LITEST_ANY);
+ litest_add("touch:properties", touch_point_no_minor_or_orientation, LITEST_TOUCH|LITEST_ELLIPSE, LITEST_ANY);
litest_add_ranged("touch:state", touch_initial_state, LITEST_TOUCH, LITEST_PROTOCOL_A, &axes);
litest_add("touch:time", touch_time_usec, LITEST_TOUCH, LITEST_TOUCHPAD);
litest_add_for_device("touch:fuzz", touch_fuzz, LITEST_MULTITOUCH_FUZZ_SCREEN);
+
}
--
2.9.3
|