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
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
|
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gdkintl.h"
#include "gdkeventsprivate.h"
#include "gdkinternals.h"
#include "gdkdisplayprivate.h"
#include "gdkdragprivate.h"
#include "gdkdropprivate.h"
#include "gdkkeysprivate.h"
#include "gdk-private.h"
#include <gobject/gvaluecollector.h>
#include <string.h>
#include <math.h>
/**
* SECTION:events
* @Short_description: Functions for handling events from the window system
* @Title: Events
*
* This section describes functions dealing with events from the window
* system.
*
* In GTK applications the events are handled automatically by toplevel
* widgets and passed on to the event controllers of appropriate widgets,
* so these functions are rarely needed.
*/
/**
* GdkEvent: (ref-func gdk_event_ref) (unref-func gdk_event_unref)
*
* The GdkEvent struct contains only private fields and
* should not be accessed directly.
*/
/**
* GdkEventSequence:
*
* GdkEventSequence is an opaque type representing a sequence
* of related touch events.
*/
static void
value_event_init (GValue *value)
{
value->data[0].v_pointer = NULL;
}
static void
value_event_free_value (GValue *value)
{
if (value->data[0].v_pointer != NULL)
gdk_event_unref (value->data[0].v_pointer);
}
static void
value_event_copy_value (const GValue *src,
GValue *dst)
{
if (src->data[0].v_pointer != NULL)
dst->data[0].v_pointer = gdk_event_ref (src->data[0].v_pointer);
else
dst->data[0].v_pointer = NULL;
}
static gpointer
value_event_peek_pointer (const GValue *value)
{
return value->data[0].v_pointer;
}
static char *
value_event_collect_value (GValue *value,
guint n_collect_values,
GTypeCValue *collect_values,
guint collect_flags)
{
GdkEvent *event = collect_values[0].v_pointer;
if (event == NULL)
{
value->data[0].v_pointer = NULL;
return NULL;
}
if (event->parent_instance.g_class == NULL)
return g_strconcat ("invalid unclassed GdkEvent pointer for "
"value type '",
G_VALUE_TYPE_NAME (value),
"'",
NULL);
value->data[0].v_pointer = gdk_event_ref (event);
return NULL;
}
static char *
value_event_lcopy_value (const GValue *value,
guint n_collect_values,
GTypeCValue *collect_values,
guint collect_flags)
{
GdkEvent **event_p = collect_values[0].v_pointer;
if (event_p == NULL)
return g_strconcat ("value location for '",
G_VALUE_TYPE_NAME (value),
"' passed as NULL",
NULL);
if (value->data[0].v_pointer == NULL)
*event_p = NULL;
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
*event_p = value->data[0].v_pointer;
else
*event_p = gdk_event_ref (value->data[0].v_pointer);
return NULL;
}
static void
gdk_event_finalize (GdkEvent *self)
{
GdkDisplay *display = gdk_event_get_display (self);
if (display != NULL)
_gdk_display_event_data_free (display, self);
g_clear_object (&self->surface);
g_clear_object (&self->device);
g_clear_object (&self->source_device);
g_type_free_instance ((GTypeInstance *) self);
}
static GdkModifierType
gdk_event_real_get_state (GdkEvent *self)
{
return 0;
}
static gboolean
gdk_event_real_get_position (GdkEvent *self,
double *x,
double *y)
{
*x = NAN;
*y = NAN;
return FALSE;
}
static GdkEventSequence *
gdk_event_real_get_sequence (GdkEvent *self)
{
return NULL;
}
static GdkDeviceTool *
gdk_event_real_get_tool (GdkEvent *self)
{
return NULL;
}
static gboolean
gdk_event_real_get_axes (GdkEvent *self,
double **axes,
guint *n_axes)
{
return FALSE;
}
static void
gdk_event_class_init (GdkEventClass *klass)
{
klass->finalize = gdk_event_finalize;
klass->get_state = gdk_event_real_get_state;
klass->get_position = gdk_event_real_get_position;
klass->get_sequence = gdk_event_real_get_sequence;
klass->get_tool = gdk_event_real_get_tool;
klass->get_axes = gdk_event_real_get_axes;
}
static void
gdk_event_init (GdkEvent *self)
{
g_ref_count_init (&self->ref_count);
}
GType
gdk_event_get_type (void)
{
static volatile gsize event_type__volatile;
if (g_once_init_enter (&event_type__volatile))
{
static const GTypeFundamentalInfo finfo = {
(G_TYPE_FLAG_CLASSED |
G_TYPE_FLAG_INSTANTIATABLE |
G_TYPE_FLAG_DERIVABLE |
G_TYPE_FLAG_DEEP_DERIVABLE),
};
static const GTypeValueTable value_table = {
value_event_init,
value_event_free_value,
value_event_copy_value,
value_event_peek_pointer,
"p",
value_event_collect_value,
"p",
value_event_lcopy_value,
};
const GTypeInfo event_info = {
/* Class */
sizeof (GdkEventClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gdk_event_class_init,
(GClassFinalizeFunc) NULL,
NULL,
/* Instance */
sizeof (GdkEvent),
0,
(GInstanceInitFunc) gdk_event_init,
/* GValue */
&value_table,
};
GType event_type =
g_type_register_fundamental (g_type_fundamental_next (),
g_intern_static_string ("GdkEvent"),
&event_info, &finfo,
G_TYPE_FLAG_ABSTRACT);
g_once_init_leave (&event_type__volatile, event_type);
}
return event_type__volatile;
}
/*< private >
* GdkEventTypeInfo:
* @instance_size: the size of the instance of a GdkEvent subclass
* @instance_init: (nullable): the function to initialize the instance data
* @finalize: (nullable): the function to free the instance data
* @get_state: (nullable): the function to retrieve the #GdkModifierType
* associated to the event
* @get_position: (nullable): the function to retrieve the event coordinates
* @get_sequence: (nullable): the function to retrieve the event sequence
* @get_tool: (nullable): the function to retrieve the event's device tool
* @get_axes: (nullable): the function to retrieve the event's axes
*
* A structure used when registering a new GdkEvent type.
*/
typedef struct {
gsize instance_size;
void (* instance_init) (GdkEvent *event);
void (* finalize) (GdkEvent *event);
GdkModifierType (* get_state) (GdkEvent *event);
gboolean (* get_position) (GdkEvent *event,
double *x,
double *y);
GdkEventSequence *(* get_sequence) (GdkEvent *event);
GdkDeviceTool *(* get_tool) (GdkEvent *event);
gboolean (* get_axes) (GdkEvent *event,
double **axes,
guint *n_axes);
} GdkEventTypeInfo;
static void
gdk_event_generic_class_init (gpointer g_class,
gpointer class_data)
{
GdkEventTypeInfo *info = class_data;
GdkEventClass *event_class = g_class;
/* Optional */
if (info->finalize != NULL)
event_class->finalize = info->finalize;
if (info->get_state != NULL)
event_class->get_state = info->get_state;
if (info->get_position != NULL)
event_class->get_position = info->get_position;
if (info->get_sequence != NULL)
event_class->get_sequence = info->get_sequence;
if (info->get_tool != NULL)
event_class->get_tool = info->get_tool;
if (info->get_axes != NULL)
event_class->get_axes = info->get_axes;
g_free (info);
}
static GType
gdk_event_type_register_static (const char *type_name,
const GdkEventTypeInfo *type_info)
{
GTypeInfo info;
info.class_size = sizeof (GdkEventClass);
info.base_init = NULL;
info.base_finalize = NULL;
info.class_init = gdk_event_generic_class_init;
info.class_finalize = NULL;
info.class_data = g_memdup (type_info, sizeof (GdkEventTypeInfo));
info.instance_size = type_info->instance_size;
info.n_preallocs = 0;
info.instance_init = (GInstanceInitFunc) type_info->instance_init;
info.value_table = NULL;
return g_type_register_static (GDK_TYPE_EVENT, type_name, &info, 0);
}
/* Map GdkEventType to the appropriate GType */
static GType gdk_event_types[GDK_EVENT_LAST];
/*< private >
* GDK_EVENT_TYPE_SLOT:
* @ETYPE: a #GdkEventType
*
* Associates a #GdkEvent type with the given #GdkEventType enumeration.
*
* This macro can only be used with %GDK_DEFINE_EVENT_TYPE.
*/
#define GDK_EVENT_TYPE_SLOT(ETYPE) { gdk_event_types[ETYPE] = gdk_define_event_type_id; }
/*< private >
* GDK_DEFINE_EVENT_TYPE:
* @TypeName: the type name, in camel case
* @type_name: the type name, in snake case
* @type_info: the address of the #GdkEventTypeInfo for the event type
* @_C_: custom code to call after registering the event type
*
* Registers a new #GdkEvent subclass with the given @TypeName and @type_info.
*
* Similarly to %G_DEFINE_TYPE_WITH_CODE, this macro will generate a `get_type()`
* function that registers the event type.
*
* You can specify code to be run after the type registration; the #GType of
* the event is available in the `gdk_define_event_type_id` variable.
*/
#define GDK_DEFINE_EVENT_TYPE(TypeName, type_name, type_info, _C_) \
GType \
type_name ## _get_type (void) \
{ \
static volatile gsize gdk_define_event_type_id__volatile; \
if (g_once_init_enter (&gdk_define_event_type_id__volatile)) \
{ \
GType gdk_define_event_type_id = \
gdk_event_type_register_static (g_intern_static_string (#TypeName), type_info); \
{ _C_ } \
g_once_init_leave (&gdk_define_event_type_id__volatile, gdk_define_event_type_id); \
} \
return gdk_define_event_type_id__volatile; \
}
#define GDK_EVENT_SUPER(event) \
((GdkEventClass *) g_type_class_peek (g_type_parent (G_TYPE_FROM_INSTANCE (event))))
/*< private >
* gdk_event_alloc:
* @event_type: the #GdkEventType to allocate
* @surface: (nullable): the #GdkSurface of the event
* @device: (nullable): the #GdkDevice of the event
* @source_device: (nullable): the source #GdkDevice of the event
* @time_: the event serial
*
* Allocates a #GdkEvent for the given @event_type, and sets its
* common fields with the given parameters.
*
* Returns: (transfer full): the newly allocated #GdkEvent instance
*/
static gpointer
gdk_event_alloc (GdkEventType event_type,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time_)
{
g_assert (event_type >= GDK_DELETE && event_type < GDK_EVENT_LAST);
g_assert (gdk_event_types[event_type] != G_TYPE_INVALID);
GdkEvent *event = (GdkEvent *) g_type_create_instance (gdk_event_types[event_type]);
GDK_NOTE (EVENTS, {
char *str = g_enum_to_string (GDK_TYPE_EVENT_TYPE, event_type);
g_message ("Allocating a new %s for event type %s",
g_type_name (gdk_event_types[event_type]), str);
g_free (str);
});
event->event_type = event_type;
event->surface = surface != NULL ? g_object_ref (surface) : NULL;
event->device = device != NULL ? g_object_ref (device) : NULL;
event->source_device = source_device != NULL ? g_object_ref (source_device) : NULL;
event->time = time_;
return event;
}
static void
gdk_event_init_types_once (void)
{
g_type_ensure (GDK_TYPE_BUTTON_EVENT);
g_type_ensure (GDK_TYPE_CONFIGURE_EVENT);
g_type_ensure (GDK_TYPE_CROSSING_EVENT);
g_type_ensure (GDK_TYPE_DELETE_EVENT);
g_type_ensure (GDK_TYPE_DND_EVENT);
g_type_ensure (GDK_TYPE_FOCUS_EVENT);
g_type_ensure (GDK_TYPE_GRAB_BROKEN_EVENT);
g_type_ensure (GDK_TYPE_KEY_EVENT);
g_type_ensure (GDK_TYPE_MOTION_EVENT);
g_type_ensure (GDK_TYPE_PAD_EVENT);
g_type_ensure (GDK_TYPE_PROXIMITY_EVENT);
g_type_ensure (GDK_TYPE_SCROLL_EVENT);
g_type_ensure (GDK_TYPE_TOUCH_EVENT);
g_type_ensure (GDK_TYPE_TOUCHPAD_EVENT);
}
/*< private >
* gdk_event_init_types:
*
* Initializes all GdkEvent types.
*/
void
gdk_event_init_types (void)
{
static volatile gsize event_types__volatile;
if (g_once_init_enter (&event_types__volatile))
{
gboolean initialized = FALSE;
gdk_event_init_types_once ();
initialized = TRUE;
g_once_init_leave (&event_types__volatile, initialized);
}
}
#ifdef G_ENABLE_DEBUG
static gboolean
check_event_sanity (GdkEvent *event)
{
if (event->device != NULL &&
gdk_surface_get_display (event->surface) != gdk_device_get_display (event->device))
{
char *type = g_enum_to_string (GDK_TYPE_EVENT_TYPE, event->event_type);
g_warning ("Event of type %s with mismatched device display", type);
g_free (type);
return FALSE;
}
if (event->source_device != NULL &&
gdk_surface_get_display (event->surface) != gdk_device_get_display (event->source_device))
{
char *type = g_enum_to_string (GDK_TYPE_EVENT_TYPE, event->event_type);
g_warning ("Event of type %s with mismatched source device display", type);
g_free (type);
return FALSE;
}
return TRUE;
}
#endif
void
_gdk_event_emit (GdkEvent *event)
{
#ifdef G_ENABLE_DEBUG
if (!check_event_sanity (event))
return;
#endif
if (gdk_drag_handle_source_event (event))
return;
gdk_surface_handle_event (event);
}
/*********************************************
* Functions for maintaining the event queue *
*********************************************/
/**
* _gdk_event_queue_find_first:
* @display: a #GdkDisplay
*
* Find the first event on the queue that is not still
* being filled in.
*
* Returns: (nullable): Pointer to the list node for that event, or
* %NULL.
**/
GList*
_gdk_event_queue_find_first (GdkDisplay *display)
{
GList *tmp_list;
GList *pending_motion = NULL;
gboolean paused = display->event_pause_count > 0;
tmp_list = g_queue_peek_head_link (&display->queued_events);
while (tmp_list)
{
GdkEvent *event = tmp_list->data;
if ((event->flags & GDK_EVENT_PENDING) == 0 &&
(!paused || (event->flags & GDK_EVENT_FLUSHED) != 0))
{
if (pending_motion)
return pending_motion;
if (event->event_type == GDK_MOTION_NOTIFY && (event->flags & GDK_EVENT_FLUSHED) == 0)
pending_motion = tmp_list;
else
return tmp_list;
}
tmp_list = tmp_list->next;
}
return NULL;
}
/**
* _gdk_event_queue_append:
* @display: a #GdkDisplay
* @event: Event to append.
*
* Appends an event onto the tail of the event queue.
*
* Returns: the newly appended list node.
**/
GList *
_gdk_event_queue_append (GdkDisplay *display,
GdkEvent *event)
{
g_queue_push_tail (&display->queued_events, event);
return g_queue_peek_tail_link (&display->queued_events);
}
/**
* _gdk_event_queue_remove_link:
* @display: a #GdkDisplay
* @node: node to remove
*
* Removes a specified list node from the event queue.
**/
void
_gdk_event_queue_remove_link (GdkDisplay *display,
GList *node)
{
g_queue_unlink (&display->queued_events, node);
}
/**
* _gdk_event_unqueue:
* @display: a #GdkDisplay
*
* Removes and returns the first event from the event
* queue that is not still being filled in.
*
* Returns: (nullable): the event, or %NULL. Ownership is transferred
* to the caller.
**/
GdkEvent*
_gdk_event_unqueue (GdkDisplay *display)
{
GdkEvent *event = NULL;
GList *tmp_list;
tmp_list = _gdk_event_queue_find_first (display);
if (tmp_list)
{
event = tmp_list->data;
_gdk_event_queue_remove_link (display, tmp_list);
g_list_free_1 (tmp_list);
}
return event;
}
/*
* If the last N events in the event queue are smooth scroll events
* for the same surface and device, combine them into one.
*/
void
gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
{
GList *l;
GdkSurface *surface = NULL;
GdkDevice *device = NULL;
GdkEvent *last_event = NULL;
GList *scrolls = NULL;
double delta_x, delta_y;
GArray *history = NULL;
GdkTimeCoord hist;
l = g_queue_peek_tail_link (&display->queued_events);
while (l)
{
GdkEvent *event = l->data;
if (event->flags & GDK_EVENT_PENDING)
break;
if (event->event_type != GDK_SCROLL ||
gdk_scroll_event_get_direction (event) != GDK_SCROLL_SMOOTH)
break;
if (surface != NULL &&
surface != event->surface)
break;
if (device != NULL &&
device != event->device)
break;
if (!last_event)
last_event = event;
surface = event->surface;
device = event->device;
scrolls = l;
l = l->prev;
}
delta_x = delta_y = 0;
while (scrolls && scrolls->next != NULL)
{
GdkEvent *event = scrolls->data;
GList *next = scrolls->next;
double dx, dy;
if (!history)
history = g_array_new (FALSE, TRUE, sizeof (GdkTimeCoord));
gdk_scroll_event_get_deltas (event, &dx, &dy);
delta_x += dx;
delta_y += dy;
memset (&hist, 0, sizeof (GdkTimeCoord));
hist.time = gdk_event_get_time (event);
hist.flags = GDK_AXIS_FLAG_DELTA_X | GDK_AXIS_FLAG_DELTA_Y;
hist.axes[GDK_AXIS_DELTA_X] = dx;
hist.axes[GDK_AXIS_DELTA_Y] = dy;
g_array_append_val (history, hist);
gdk_event_unref (event);
g_queue_delete_link (&display->queued_events, scrolls);
scrolls = next;
}
if (scrolls)
{
GdkEvent *old_event, *event;
double dx, dy;
old_event = scrolls->data;
gdk_scroll_event_get_deltas (old_event, &dx, &dy);
event = gdk_scroll_event_new (surface,
device,
gdk_event_get_source_device (old_event),
gdk_event_get_device_tool (old_event),
gdk_event_get_time (old_event),
gdk_event_get_modifier_state (old_event),
delta_x + dx,
delta_y + dy,
gdk_scroll_event_is_stop (old_event));
((GdkScrollEvent *)event)->history = history;
g_queue_delete_link (&display->queued_events, scrolls);
g_queue_push_tail (&display->queued_events, event);
}
if (g_queue_get_length (&display->queued_events) == 1 &&
g_queue_peek_head_link (&display->queued_events) == scrolls)
{
GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
if (clock) /* might be NULL if surface was destroyed */
gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
}
}
static void
gdk_motion_event_push_history (GdkEvent *event,
GdkEvent *history_event)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
GdkTimeCoord hist;
GdkDevice *device;
int i, n_axes;
g_assert (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY));
g_assert (GDK_IS_EVENT_TYPE (history_event, GDK_MOTION_NOTIFY));
device = gdk_event_get_device (history_event);
n_axes = gdk_device_get_n_axes (device);
memset (&hist, 0, sizeof (GdkTimeCoord));
hist.time = gdk_event_get_time (history_event);
hist.flags = gdk_device_get_axes (device);
for (i = 0; i < n_axes; i++)
{
GdkAxisUse use = gdk_device_get_axis_use (device, i);
gdk_event_get_axis (history_event, use, &hist.axes[use]);
}
if (G_UNLIKELY (!self->history))
self->history = g_array_new (FALSE, TRUE, sizeof (GdkTimeCoord));
g_array_append_val (self->history, hist);
}
void
_gdk_event_queue_handle_motion_compression (GdkDisplay *display)
{
GList *tmp_list;
GList *pending_motions = NULL;
GdkSurface *pending_motion_surface = NULL;
GdkDevice *pending_motion_device = NULL;
GdkEvent *last_motion = NULL;
/* If the last N events in the event queue are motion notify
* events for the same surface, drop all but the last */
tmp_list = g_queue_peek_tail_link (&display->queued_events);
while (tmp_list)
{
GdkEvent *event = tmp_list->data;
if (event->flags & GDK_EVENT_PENDING)
break;
if (event->event_type != GDK_MOTION_NOTIFY)
break;
if (pending_motion_surface != NULL &&
pending_motion_surface != event->surface)
break;
if (pending_motion_device != NULL &&
pending_motion_device != event->device)
break;
if (!last_motion)
last_motion = event;
pending_motion_surface = event->surface;
pending_motion_device = event->device;
pending_motions = tmp_list;
tmp_list = tmp_list->prev;
}
while (pending_motions && pending_motions->next != NULL)
{
GList *next = pending_motions->next;
if (last_motion != NULL)
{
GdkModifierType state = gdk_event_get_modifier_state (last_motion);
if (state &
(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK |
GDK_BUTTON4_MASK | GDK_BUTTON5_MASK))
gdk_motion_event_push_history (last_motion, pending_motions->data);
}
gdk_event_unref (pending_motions->data);
g_queue_delete_link (&display->queued_events, pending_motions);
pending_motions = next;
}
if (g_queue_get_length (&display->queued_events) == 1 &&
g_queue_peek_head_link (&display->queued_events) == pending_motions)
{
GdkFrameClock *clock = gdk_surface_get_frame_clock (pending_motion_surface);
if (clock) /* might be NULL if surface was destroyed */
gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
}
}
void
_gdk_event_queue_flush (GdkDisplay *display)
{
GList *tmp_list;
for (tmp_list = display->queued_events.head; tmp_list; tmp_list = tmp_list->next)
{
GdkEvent *event = tmp_list->data;
event->flags |= GDK_EVENT_FLUSHED;
}
}
/**
* gdk_event_ref:
* @event: a #GdkEvent
*
* Increase the ref count of @event.
*
* Returns: (transfer full): @event
*/
GdkEvent *
gdk_event_ref (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_ref_count_inc (&event->ref_count);
return event;
}
/**
* gdk_event_unref:
* @event: (transfer full): a #GdkEvent
*
* Decrease the ref count of @event, and free it
* if the last reference is dropped.
*/
void
gdk_event_unref (GdkEvent *event)
{
g_return_if_fail (GDK_IS_EVENT (event));
if (g_ref_count_dec (&event->ref_count))
GDK_EVENT_GET_CLASS (event)->finalize (event);
}
/**
* gdk_event_get_pointer_emulated:
* @event: a #GdkEvent
*
* Returns whether this event is an 'emulated' pointer event (typically
* from a touch event), as opposed to a real one.
*
* Returns: %TRUE if this event is emulated
*/
gboolean
gdk_event_get_pointer_emulated (GdkEvent *event)
{
switch ((int) event->event_type)
{
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_END:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_CANCEL:
{
GdkTouchEvent *tevent = (GdkTouchEvent *) event;
return tevent->pointer_emulated;
}
case GDK_SCROLL:
case GDK_SCROLL_SMOOTH:
{
GdkScrollEvent *sevent = (GdkScrollEvent *) event;
return sevent->pointer_emulated;
}
default:
break;
}
return FALSE;
}
/**
* gdk_event_get_axis:
* @event: a #GdkEvent
* @axis_use: the axis use to look for
* @value: (out): location to store the value found
*
* Extract the axis value for a particular axis use from
* an event structure.
*
* Returns: %TRUE if the specified axis was found, otherwise %FALSE
**/
gboolean
gdk_event_get_axis (GdkEvent *event,
GdkAxisUse axis_use,
double *value)
{
double *axes;
guint n_axes;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
if (axis_use == GDK_AXIS_X || axis_use == GDK_AXIS_Y)
{
double x, y;
if (!gdk_event_get_position (event, &x, &y))
return FALSE;
if (axis_use == GDK_AXIS_X && value != NULL)
*value = x;
if (axis_use == GDK_AXIS_Y && value != NULL)
*value = y;
return TRUE;
}
if (!gdk_event_get_axes (event, &axes, &n_axes))
return FALSE;
if (axis_use >= gdk_device_get_n_axes (event->device))
return FALSE;
return gdk_device_get_axis (event->device, axes, axis_use, value);
}
/**
* gdk_event_triggers_context_menu:
* @event: a #GdkEvent, currently only button events are meaningful values
*
* This function returns whether a #GdkEventButton should trigger a
* context menu, according to platform conventions. The right mouse
* button always triggers context menus.
*
* This function should always be used instead of simply checking for
* event->button == %GDK_BUTTON_SECONDARY.
*
* Returns: %TRUE if the event should trigger a context menu.
**/
gboolean
gdk_event_triggers_context_menu (GdkEvent *event)
{
g_return_val_if_fail (event != NULL, FALSE);
if (event->event_type == GDK_BUTTON_PRESS)
{
GdkButtonEvent *bevent = (GdkButtonEvent *) event;
g_return_val_if_fail (GDK_IS_SURFACE (event->surface), FALSE);
if (bevent->button == GDK_BUTTON_SECONDARY &&
! (bevent->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK)))
return TRUE;
}
return FALSE;
}
static gboolean
gdk_events_get_axis_distances (GdkEvent *event1,
GdkEvent *event2,
gdouble *x_distance,
gdouble *y_distance,
gdouble *distance)
{
gdouble x1, x2, y1, y2;
gdouble xd, yd;
if (!gdk_event_get_position (event1, &x1, &y1) ||
!gdk_event_get_position (event2, &x2, &y2))
return FALSE;
xd = x2 - x1;
yd = y2 - y1;
if (x_distance)
*x_distance = xd;
if (y_distance)
*y_distance = yd;
if (distance)
*distance = sqrt ((xd * xd) + (yd * yd));
return TRUE;
}
/**
* gdk_events_get_distance:
* @event1: first #GdkEvent
* @event2: second #GdkEvent
* @distance: (out): return location for the distance
*
* If both events have X/Y information, the distance between both coordinates
* (as in a straight line going from @event1 to @event2) will be returned.
*
* Returns: %TRUE if the distance could be calculated.
**/
gboolean
gdk_events_get_distance (GdkEvent *event1,
GdkEvent *event2,
gdouble *distance)
{
return gdk_events_get_axis_distances (event1, event2,
NULL, NULL,
distance);
}
/**
* gdk_events_get_angle:
* @event1: first #GdkEvent
* @event2: second #GdkEvent
* @angle: (out): return location for the relative angle between both events
*
* If both events contain X/Y information, this function will return %TRUE
* and return in @angle the relative angle from @event1 to @event2. The rotation
* direction for positive angles is from the positive X axis towards the positive
* Y axis.
*
* Returns: %TRUE if the angle could be calculated.
**/
gboolean
gdk_events_get_angle (GdkEvent *event1,
GdkEvent *event2,
gdouble *angle)
{
gdouble x_distance, y_distance, distance;
if (!gdk_events_get_axis_distances (event1, event2,
&x_distance, &y_distance,
&distance))
return FALSE;
if (angle)
{
*angle = atan2 (x_distance, y_distance);
/* Invert angle */
*angle = (2 * G_PI) - *angle;
/* Shift it 90° */
*angle += G_PI / 2;
/* And constraint it to 0°-360° */
*angle = fmod (*angle, 2 * G_PI);
}
return TRUE;
}
/**
* gdk_events_get_center:
* @event1: first #GdkEvent
* @event2: second #GdkEvent
* @x: (out): return location for the X coordinate of the center
* @y: (out): return location for the Y coordinate of the center
*
* If both events contain X/Y information, the center of both coordinates
* will be returned in @x and @y.
*
* Returns: %TRUE if the center could be calculated.
**/
gboolean
gdk_events_get_center (GdkEvent *event1,
GdkEvent *event2,
gdouble *x,
gdouble *y)
{
gdouble x1, x2, y1, y2;
if (!gdk_event_get_position (event1, &x1, &y1) ||
!gdk_event_get_position (event2, &x2, &y2))
return FALSE;
if (x)
*x = (x2 + x1) / 2;
if (y)
*y = (y2 + y1) / 2;
return TRUE;
}
static GdkEventSequence *
gdk_event_sequence_copy (GdkEventSequence *sequence)
{
return sequence;
}
static void
gdk_event_sequence_free (GdkEventSequence *sequence)
{
/* Nothing to free here */
}
G_DEFINE_BOXED_TYPE (GdkEventSequence, gdk_event_sequence,
gdk_event_sequence_copy,
gdk_event_sequence_free)
/**
* gdk_event_get_axes:
* @event: a #GdkEvent
* @axes: (transfer none) (out) (array length=n_axes): the array of values for all axes
* @n_axes: (out): the length of array
*
* Extracts all axis values from an event.
*
* Returns: %TRUE on success, otherwise %FALSE
**/
gboolean
gdk_event_get_axes (GdkEvent *event,
double **axes,
guint *n_axes)
{
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
return GDK_EVENT_GET_CLASS (event)->get_axes (event, axes, n_axes);
}
/**
* gdk_event_get_event_type:
* @event: a #GdkEvent
*
* Retrieves the type of the event.
*
* Returns: a #GdkEventType
*/
GdkEventType
gdk_event_get_event_type (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
return event->event_type;
}
/**
* gdk_event_get_surface:
* @event: a #GdkEvent
*
* Extracts the #GdkSurface associated with an event.
*
* Returns: (transfer none): The #GdkSurface associated with the event
*/
GdkSurface *
gdk_event_get_surface (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
return event->surface;
}
/**
* gdk_event_get_seat:
* @event: a #GdkEvent
*
* Returns the seat that originated the event.
*
* Returns: (nullable) (transfer none): a #GdkSeat.
*/
GdkSeat *
gdk_event_get_seat (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
return event->device ? gdk_device_get_seat (event->device) : NULL;
}
/**
* gdk_event_get_device:
* @event: a #GdkEvent.
*
* Returns the device of an event.
*
* Returns: (nullable) (transfer none): a #GdkDevice.
*/
GdkDevice *
gdk_event_get_device (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
return event->device;
}
/**
* gdk_event_get_source_device:
* @event: a #GdkEvent
*
* This function returns the physical #GdkDevice that has triggered
* the event, falling back to the logical device, as returned by
* gdk_event_get_device(), if the event wasn’t caused by
* interaction with a hardware device. This may happen for example
* in synthesized crossing events after a #GdkSurface updates its
* geometry or a grab is acquired/released.
*
* If the event does not contain a device field, this function will
* return %NULL.
*
* Returns: (nullable) (transfer none): a #GdkDevice, or %NULL.
**/
GdkDevice *
gdk_event_get_source_device (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
if (event->source_device)
return event->source_device;
return event->device;
}
/**
* gdk_event_get_device_tool:
* @event: a #GdkEvent
*
* If the event was generated by a device that supports
* different tools (eg. a tablet), this function will
* return a #GdkDeviceTool representing the tool that
* caused the event. Otherwise, %NULL will be returned.
*
* Note: the #GdkDeviceTools will be constant during
* the application lifetime, if settings must be stored
* persistently across runs, see gdk_device_tool_get_serial()
*
* Returns: (transfer none) (nullable): The current device tool, or %NULL
**/
GdkDeviceTool *
gdk_event_get_device_tool (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
return GDK_EVENT_GET_CLASS (event)->get_tool (event);
}
/**
* gdk_event_get_time:
* @event: a #GdkEvent
*
* Returns the time stamp from @event, if there is one; otherwise
* returns #GDK_CURRENT_TIME.
*
* Returns: time stamp field from @event
**/
guint32
gdk_event_get_time (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), GDK_CURRENT_TIME);
return event->time;
}
/**
* gdk_event_get_display:
* @event: a #GdkEvent
*
* Retrieves the #GdkDisplay associated to the @event.
*
* Returns: (transfer none) (nullable): a #GdkDisplay
*/
GdkDisplay *
gdk_event_get_display (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
if (event->surface)
return gdk_surface_get_display (event->surface);
return NULL;
}
/**
* gdk_event_get_event_sequence:
* @event: a #GdkEvent
*
* If @event is a touch event, returns the #GdkEventSequence
* to which the event belongs. Otherwise, return %NULL.
*
* Returns: (transfer none): the event sequence that the event belongs to
*/
GdkEventSequence *
gdk_event_get_event_sequence (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
return GDK_EVENT_GET_CLASS (event)->get_sequence (event);
}
/**
* gdk_event_get_modifier_state:
* @event: a #GdkEvent
*
* Returns the modifier state field of an event.
*
* Returns: the modifier state of @event
**/
GdkModifierType
gdk_event_get_modifier_state (GdkEvent *event)
{
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
return GDK_EVENT_GET_CLASS (event)->get_state (event);
}
/**
* gdk_event_get_position:
* @event: a #GdkEvent
* @x: (out): location to put event surface x coordinate
* @y: (out): location to put event surface y coordinate
*
* Extract the event surface relative x/y coordinates from an event.
**/
gboolean
gdk_event_get_position (GdkEvent *event,
double *x,
double *y)
{
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
return GDK_EVENT_GET_CLASS (event)->get_position (event, x, y);
}
/* {{{ GdkButtonEvent */
static void
gdk_button_event_finalize (GdkEvent *event)
{
GdkButtonEvent *self = (GdkButtonEvent *) event;
g_clear_object (&self->tool);
g_clear_pointer (&self->axes, g_free);
GDK_EVENT_SUPER (event)->finalize (event);
}
static GdkModifierType
gdk_button_event_get_state (GdkEvent *event)
{
GdkButtonEvent *self = (GdkButtonEvent *) event;
return self->state;
}
static gboolean
gdk_button_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkButtonEvent *self = (GdkButtonEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static GdkDeviceTool *
gdk_button_event_get_tool (GdkEvent *event)
{
GdkButtonEvent *self = (GdkButtonEvent *) event;
return self->tool;
}
static gboolean
gdk_button_event_get_axes (GdkEvent *event,
double **axes,
guint *n_axes)
{
GdkButtonEvent *self = (GdkButtonEvent *) event;
GdkDevice *source_device = gdk_event_get_source_device (event);
if (source_device == NULL)
return FALSE;
*axes = self->axes;
*n_axes = gdk_device_get_n_axes (source_device);
return TRUE;
}
static const GdkEventTypeInfo gdk_button_event_info = {
sizeof (GdkButtonEvent),
NULL,
gdk_button_event_finalize,
gdk_button_event_get_state,
gdk_button_event_get_position,
NULL,
gdk_button_event_get_tool,
gdk_button_event_get_axes,
};
GDK_DEFINE_EVENT_TYPE (GdkButtonEvent, gdk_button_event,
&gdk_button_event_info,
GDK_EVENT_TYPE_SLOT (GDK_BUTTON_PRESS)
GDK_EVENT_TYPE_SLOT (GDK_BUTTON_RELEASE))
GdkEvent *
gdk_button_event_new (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
guint button,
double x,
double y,
double *axes)
{
g_return_val_if_fail (type == GDK_BUTTON_PRESS ||
type == GDK_BUTTON_RELEASE, NULL);
GdkButtonEvent *self = gdk_event_alloc (type, surface, device, source_device, time);
self->tool = tool != NULL ? g_object_ref (tool) : NULL;
self->axes = axes;
self->state = state;
self->button = button;
self->x = x;
self->y = y;
return (GdkEvent *) self;
}
/**
* gdk_button_event_get_button:
* @event: (type GdkButtonEvent): a button event
*
* Extract the button number from a button event.
*
* Returns: the button of @event
**/
guint
gdk_button_event_get_button (GdkEvent *event)
{
GdkButtonEvent *self = (GdkButtonEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_BUTTON_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_BUTTON_RELEASE), 0);
return self->button;
}
/* }}} */
/* {{{ GdkKeyEvent */
static GdkModifierType
gdk_key_event_get_state (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
return self->state;
}
static const GdkEventTypeInfo gdk_key_event_info = {
sizeof (GdkKeyEvent),
NULL,
NULL,
gdk_key_event_get_state,
NULL,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkKeyEvent, gdk_key_event,
&gdk_key_event_info,
GDK_EVENT_TYPE_SLOT (GDK_KEY_PRESS)
GDK_EVENT_TYPE_SLOT (GDK_KEY_RELEASE))
/*< private >
* gdk_key_event_new:
* @type: the event type, either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
* @surface: the #GdkSurface of the event
* @device: the #GdkDevice related to the event
* @source_device: the source #GdkDevice related to the event
* @time: the event's timestamp
* @keycode: the keycode of the event
* @state: the modifiers state
* @is_modifier: whether the event is a modifiers only event
* @translated: the translated key data for the given @state
* @no_lock: the translated key data without the given @state
*
* Creates a new #GdkKeyEvent.
*
* Returns: (transfer full) (type GdkKeyEvent): the newly created #GdkEvent
*/
GdkEvent *
gdk_key_event_new (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
guint keycode,
GdkModifierType state,
gboolean is_modifier,
GdkTranslatedKey *translated,
GdkTranslatedKey *no_lock)
{
g_return_val_if_fail (type == GDK_KEY_PRESS ||
type == GDK_KEY_RELEASE, NULL);
GdkKeyEvent *self = gdk_event_alloc (type, surface, device, source_device, time);
GdkEvent *event = (GdkEvent *) self;
self->keycode = keycode;
self->state = state;
self->key_is_modifier = is_modifier;
self->translated[0] = *translated;
self->translated[1] = *no_lock;
return event;
}
/*< private >
* gdk_key_event_get_translated_key:
* @event: (type GdkKeyEvent): a key event
* @no_lock: whether the translated key should take the event
* state into account
*
* Extracts the translated key from a key event.
*
* Returns: (transfer none): the translated key
*/
GdkTranslatedKey *
gdk_key_event_get_translated_key (GdkEvent *event,
gboolean no_lock)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), NULL);
if (no_lock)
return &(self->translated[1]);
return &(self->translated[0]);
}
/**
* gdk_key_event_get_keyval:
* @event: (type GdkKeyEvent): a key event
*
* Extracts the keyval from a key event.
*
* Returns: the keyval of @event
*/
guint
gdk_key_event_get_keyval (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), 0);
return self->translated[0].keyval;
}
/**
* gdk_key_event_get_keycode:
* @event: (type GdkKeyEvent): a key event
*
* Extracts the keycode from a key event.
*
* Returns: the keycode of @event
*/
guint
gdk_key_event_get_keycode (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), 0);
return self->keycode;
}
/**
* gdk_key_event_get_level:
* @event: (type GdkKeyEvent): a key event
*
* Extracts the shift level from a key event.
*
* Returns: the shift level of @event
*/
guint
gdk_key_event_get_level (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), 0);
return self->translated[0].level;
}
/**
* gdk_key_event_get_layout:
* @event: (type GdkKeyEvent): a key event
*
* Extracts the layout from a key event.
*
* Returns: the layout of @event
*/
guint
gdk_key_event_get_layout (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), 0);
return self->translated[0].layout;
}
/**
* gdk_key_event_get_consumed_modifiers:
* @event: (type GdkKeyEvent): a key event
*
* Extracts the consumed modifiers from a key event.
*
* Returns: the consumed modifiers or @event
*/
GdkModifierType
gdk_key_event_get_consumed_modifiers (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), 0);
return self->translated[0].consumed;
}
/**
* gdk_key_event_is_modifier:
* @event: (type GdkKeyEvent): a key event
*
* Extracts whether the key event is for a modifier key.
*
* Returns: %TRUE if the @event is for a modifier key
*/
gboolean
gdk_key_event_is_modifier (GdkEvent *event)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), FALSE);
return self->key_is_modifier;
}
/**
* gdk_key_event_matches:
* @event: (type GdkKeyEvent): a key #GdkEvent
* @keyval: the keyval to match
* @modifiers: the modifiers to match
*
* Matches a key event against a keyboard shortcut that is specified
* as a keyval and modifiers. Partial matches are possible where the
* combination matches if the currently active group is ignored.
*
* Note that we ignore Caps Lock for matching.
*
* Returns: a GdkKeyMatch value describing whether @event matches
*/
GdkKeyMatch
gdk_key_event_matches (GdkEvent *event,
guint keyval,
GdkModifierType modifiers)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
GdkKeymap *keymap;
guint keycode;
GdkModifierType state;
guint ev_keyval;
int layout;
int level;
GdkModifierType consumed_modifiers;
GdkModifierType shift_group_mask;
gboolean group_mod_is_accel_mod = FALSE;
const GdkModifierType mask = GDK_CONTROL_MASK |
GDK_SHIFT_MASK |
GDK_ALT_MASK |
GDK_SUPER_MASK |
GDK_HYPER_MASK |
GDK_META_MASK;
g_return_val_if_fail (GDK_IS_EVENT (event), GDK_KEY_MATCH_NONE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), GDK_KEY_MATCH_NONE);
keycode = self->keycode;
state = self->state & ~GDK_LOCK_MASK;
ev_keyval = self->translated[1].keyval;
layout = self->translated[1].layout;
level = self->translated[1].level;
consumed_modifiers = self->translated[1].consumed;
/* if the group-toggling modifier is part of the default accel mod
* mask, and it is active, disable it for matching
*
* FIXME: get shift group mask from backends
*/
shift_group_mask = 0;
if (mask & shift_group_mask)
group_mod_is_accel_mod = TRUE;
if ((modifiers & ~consumed_modifiers & mask) == (state & ~consumed_modifiers & mask))
{
/* modifier match */
GdkKeymapKey *keys;
guint n_keys;
int i;
guint key;
/* Shift gets consumed and applied for the event,
* so apply it to our keyval to match
*/
key = keyval;
if (modifiers & GDK_SHIFT_MASK)
{
if (key == GDK_KEY_Tab)
key = GDK_KEY_ISO_Left_Tab;
else
key = gdk_keyval_to_upper (key);
}
if (ev_keyval == key && /* exact match */
(!group_mod_is_accel_mod ||
(state & shift_group_mask) == (modifiers & shift_group_mask)))
{
return GDK_KEY_MATCH_EXACT;
}
keymap = gdk_display_get_keymap (gdk_event_get_display (event));
gdk_keymap_get_cached_entries_for_keyval (keymap, keyval, &keys, &n_keys);
for (i = 0; i < n_keys; i++)
{
if (keys[i].keycode == keycode &&
keys[i].level == level &&
/* Only match for group if it's an accel mod */
(!group_mod_is_accel_mod || keys[i].group == layout))
{
return GDK_KEY_MATCH_PARTIAL;
}
}
}
return GDK_KEY_MATCH_NONE;
}
/**
* gdk_key_event_get_match:
* @event: (type GdkKeyEvent): a key #GdkEvent
* @keyval: (out): return location for a keyval
* @modifiers: (out): return location for modifiers
*
* Gets a keyval and modifier combination that will cause
* gdk_key_event_matches() to successfully match the given event.
*
* Returns: %TRUE on success
*/
gboolean
gdk_key_event_get_match (GdkEvent *event,
guint *keyval,
GdkModifierType *modifiers)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
guint key;
guint accel_key;
GdkModifierType accel_mods;
GdkModifierType consumed_modifiers;
const GdkModifierType mask = GDK_CONTROL_MASK |
GDK_SHIFT_MASK |
GDK_ALT_MASK |
GDK_SUPER_MASK |
GDK_HYPER_MASK |
GDK_META_MASK;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), FALSE);
accel_key = self->translated[1].keyval;
accel_mods = self->state;
consumed_modifiers = self->translated[1].consumed;
if (accel_key == GDK_KEY_Sys_Req &&
(accel_mods & GDK_ALT_MASK) != 0)
{
/* HACK: we don't want to use SysRq as a keybinding (but we do
* want Alt+Print), so we avoid translation from Alt+Print to SysRq
*/
*keyval = GDK_KEY_Print;
*modifiers = accel_mods & mask;
return TRUE;
}
key = gdk_keyval_to_lower (accel_key);
if (key == GDK_KEY_ISO_Left_Tab)
key = GDK_KEY_Tab;
accel_mods &= mask & ~consumed_modifiers;
if (accel_key != key)
accel_mods |= GDK_SHIFT_MASK;
*keyval = key;
*modifiers = accel_mods;
return TRUE;
}
/* }}} */
/* {{{ GdkConfigureEvent */
static gboolean
gdk_configure_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkConfigureEvent *self = (GdkConfigureEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static const GdkEventTypeInfo gdk_configure_event_info = {
sizeof (GdkConfigureEvent),
NULL,
NULL,
NULL,
gdk_configure_event_get_position,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkConfigureEvent, gdk_configure_event,
&gdk_configure_event_info,
GDK_EVENT_TYPE_SLOT (GDK_CONFIGURE))
GdkEvent *
gdk_configure_event_new (GdkSurface *surface,
int width,
int height)
{
GdkConfigureEvent *self;
g_return_val_if_fail (width >= 0 && height >= 0, NULL);
self = gdk_event_alloc (GDK_CONFIGURE, surface, NULL, NULL, GDK_CURRENT_TIME);
self->width = width;
self->height = height;
return (GdkEvent *) self;
}
/**
* gdk_configure_event_get_size:
* @event: (type GdkConfigureEvent): a configure event
* @width: (out): return location for surface width
* @height: (out): return location for surface height
*
* Extracts the surface size from a configure event.
*/
void
gdk_configure_event_get_size (GdkEvent *event,
int *width,
int *height)
{
GdkConfigureEvent *self = (GdkConfigureEvent *) event;
g_return_if_fail (GDK_IS_EVENT (event));
g_return_if_fail (GDK_IS_EVENT_TYPE (event, GDK_CONFIGURE));
*width = self->width;
*height = self->height;
}
/* }}} */
/* {{{ GdkTouchEvent */
static void
gdk_touch_event_finalize (GdkEvent *event)
{
GdkTouchEvent *self = (GdkTouchEvent *) event;
g_clear_pointer (&self->axes, g_free);
GDK_EVENT_SUPER (event)->finalize (event);
}
static GdkModifierType
gdk_touch_event_get_state (GdkEvent *event)
{
GdkTouchEvent *self = (GdkTouchEvent *) event;
return self->state;
}
static gboolean
gdk_touch_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkTouchEvent *self = (GdkTouchEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static GdkEventSequence *
gdk_touch_event_get_sequence (GdkEvent *event)
{
GdkTouchEvent *self = (GdkTouchEvent *) event;
return self->sequence;
}
static gboolean
gdk_touch_event_get_axes (GdkEvent *event,
double **axes,
guint *n_axes)
{
GdkTouchEvent *self = (GdkTouchEvent *) event;
GdkDevice *source_device = gdk_event_get_source_device (event);
if (source_device == NULL)
return FALSE;
*axes = self->axes;
*n_axes = gdk_device_get_n_axes (source_device);
return TRUE;
}
static const GdkEventTypeInfo gdk_touch_event_info = {
sizeof (GdkTouchEvent),
NULL,
gdk_touch_event_finalize,
gdk_touch_event_get_state,
gdk_touch_event_get_position,
gdk_touch_event_get_sequence,
NULL,
gdk_touch_event_get_axes,
};
GDK_DEFINE_EVENT_TYPE (GdkTouchEvent, gdk_touch_event,
&gdk_touch_event_info,
GDK_EVENT_TYPE_SLOT (GDK_TOUCH_BEGIN)
GDK_EVENT_TYPE_SLOT (GDK_TOUCH_END)
GDK_EVENT_TYPE_SLOT (GDK_TOUCH_UPDATE)
GDK_EVENT_TYPE_SLOT (GDK_TOUCH_CANCEL))
GdkEvent *
gdk_touch_event_new (GdkEventType type,
GdkEventSequence *sequence,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
GdkModifierType state,
double x,
double y,
double *axes,
gboolean emulating)
{
GdkTouchEvent *self;
g_return_val_if_fail (type == GDK_TOUCH_BEGIN ||
type == GDK_TOUCH_END ||
type == GDK_TOUCH_UPDATE ||
type == GDK_TOUCH_CANCEL, NULL);
self = gdk_event_alloc (type, surface, device, source_device, time);
self->sequence = sequence;
self->state = state;
self->x = x;
self->y = y;
self->axes = axes;
self->touch_emulating = emulating;
self->pointer_emulated = emulating;
return (GdkEvent *) self;
}
/**
* gdk_touch_event_get_emulating_pointer:
* @event: (type GdkTouchEvent): a touch event
*
* Extracts whether a touch event is emulating a pointer event.
*
* Returns: %TRUE if @event is emulating
**/
gboolean
gdk_touch_event_get_emulating_pointer (GdkEvent *event)
{
GdkTouchEvent *self = (GdkTouchEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCH_BEGIN) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCH_UPDATE) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCH_END) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCH_CANCEL), FALSE);
return self->touch_emulating;
}
/* }}} */
/* {{{ GdkCrossingEvent */
static void
gdk_crossing_event_finalize (GdkEvent *event)
{
GdkCrossingEvent *self = (GdkCrossingEvent *) event;
g_clear_object (&self->child_surface);
GDK_EVENT_SUPER (self)->finalize (event);
}
static GdkModifierType
gdk_crossing_event_get_state (GdkEvent *event)
{
GdkCrossingEvent *self = (GdkCrossingEvent *) event;
return self->state;
}
static gboolean
gdk_crossing_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkCrossingEvent *self = (GdkCrossingEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static const GdkEventTypeInfo gdk_crossing_event_info = {
sizeof (GdkCrossingEvent),
NULL,
gdk_crossing_event_finalize,
gdk_crossing_event_get_state,
gdk_crossing_event_get_position,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkCrossingEvent, gdk_crossing_event,
&gdk_crossing_event_info,
GDK_EVENT_TYPE_SLOT (GDK_ENTER_NOTIFY)
GDK_EVENT_TYPE_SLOT (GDK_LEAVE_NOTIFY))
GdkEvent *
gdk_crossing_event_new (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
GdkModifierType state,
double x,
double y,
GdkCrossingMode mode,
GdkNotifyType detail)
{
GdkCrossingEvent *self;
g_return_val_if_fail (type == GDK_ENTER_NOTIFY ||
type == GDK_LEAVE_NOTIFY, NULL);
self = gdk_event_alloc (type, surface, device, source_device, time);
self->state = state;
self->x = x;
self->y = y;
self->mode = mode;
self->detail = detail;
return (GdkEvent *) self;
}
/**
* gdk_crossing_event_get_mode:
* @event: (type GdkCrossingEvent): a crossing event
*
* Extracts the crossing mode from a crossing event.
*
* Returns: the mode of @event
*/
GdkCrossingMode
gdk_crossing_event_get_mode (GdkEvent *event)
{
GdkCrossingEvent *self = (GdkCrossingEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_ENTER_NOTIFY) ||
GDK_IS_EVENT_TYPE (event, GDK_LEAVE_NOTIFY), 0);
return self->mode;
}
/**
* gdk_crossing_event_get_focus:
* @event: (type GdkCrossingEvent): a crossing event
*
* Checks if the @event surface is the focus surface.
*
* Returns: %TRUE if the surface is the focus surface
*/
gboolean
gdk_crossing_event_get_focus (GdkEvent *event)
{
GdkCrossingEvent *self = (GdkCrossingEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_ENTER_NOTIFY) ||
GDK_IS_EVENT_TYPE (event, GDK_LEAVE_NOTIFY), FALSE);
return self->focus;
}
/**
* gdk_crossing_event_get_detail:
* @event: (type GdkCrossingEvent): a crossing event
*
* Extracts the notify detail from a crossing event.
*
* Returns: the notify detail of @event
*/
GdkNotifyType
gdk_crossing_event_get_detail (GdkEvent *event)
{
GdkCrossingEvent *self = (GdkCrossingEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_ENTER_NOTIFY) ||
GDK_IS_EVENT_TYPE (event, GDK_LEAVE_NOTIFY), 0);
return self->detail;
}
/* }}} */
/* {{{ GdkDeleteEvent */
static const GdkEventTypeInfo gdk_delete_event_info = {
sizeof (GdkDeleteEvent),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkDeleteEvent, gdk_delete_event,
&gdk_delete_event_info,
GDK_EVENT_TYPE_SLOT (GDK_DELETE))
GdkEvent *
gdk_delete_event_new (GdkSurface *surface)
{
return gdk_event_alloc (GDK_DELETE, surface, NULL, NULL, GDK_CURRENT_TIME);
}
/* }}} */
/* {{{ GdkFocusEvent */
static const GdkEventTypeInfo gdk_focus_event_info = {
sizeof (GdkFocusEvent),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkFocusEvent, gdk_focus_event,
&gdk_focus_event_info,
GDK_EVENT_TYPE_SLOT (GDK_FOCUS_CHANGE))
GdkEvent *
gdk_focus_event_new (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
gboolean focus_in)
{
GdkFocusEvent *self = gdk_event_alloc (GDK_FOCUS_CHANGE, surface, device, source_device, GDK_CURRENT_TIME);
self->focus_in = focus_in;
return (GdkEvent *) self;
}
/**
* gdk_focus_event_get_in:
* @event: (type GdkFocusEvent): a focus change event
*
* Extracts whether this event is about focus entering or
* leaving the surface.
*
* Returns: %TRUE of the focus is entering
*/
gboolean
gdk_focus_event_get_in (GdkEvent *event)
{
GdkFocusEvent *self = (GdkFocusEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_FOCUS_CHANGE), FALSE);
return self->focus_in;
}
/* }}} */
/* {{{ GdkScrollEvent */
static void
gdk_scroll_event_finalize (GdkEvent *event)
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
g_clear_object (&self->tool);
if (self->history)
g_array_free (self->history, TRUE);
GDK_EVENT_SUPER (self)->finalize (event);
}
static GdkModifierType
gdk_scroll_event_get_state (GdkEvent *event)
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
return self->state;
}
static GdkDeviceTool *
gdk_scroll_event_get_tool (GdkEvent *event)
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
return self->tool;
}
static const GdkEventTypeInfo gdk_scroll_event_info = {
sizeof (GdkScrollEvent),
NULL,
gdk_scroll_event_finalize,
gdk_scroll_event_get_state,
NULL,
NULL,
gdk_scroll_event_get_tool,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkScrollEvent, gdk_scroll_event,
&gdk_scroll_event_info,
GDK_EVENT_TYPE_SLOT (GDK_SCROLL))
GdkEvent *
gdk_scroll_event_new (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
double delta_x,
double delta_y,
gboolean is_stop)
{
GdkScrollEvent *self = gdk_event_alloc (GDK_SCROLL, surface, device, source_device, time);
self->tool = tool != NULL ? g_object_ref (tool) : NULL;
self->state = state;
self->direction = GDK_SCROLL_SMOOTH;
self->delta_x = delta_x;
self->delta_y = delta_y;
self->is_stop = is_stop;
return (GdkEvent *) self;
}
GdkEvent *
gdk_scroll_event_new_discrete (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
GdkScrollDirection direction,
gboolean emulated)
{
GdkScrollEvent *self = gdk_event_alloc (GDK_SCROLL, surface, device, source_device, time);
self->tool = tool != NULL ? g_object_ref (tool) : NULL;
self->state = state;
self->direction = direction;
self->pointer_emulated = emulated;
return (GdkEvent *) self;
}
/**
* gdk_scroll_event_get_direction:
* @event: (type GdkScrollEvent): a scroll event
*
* Extracts the direction of a scroll event.
*
* Returns: the scroll direction of @event
*/
GdkScrollDirection
gdk_scroll_event_get_direction (GdkEvent *event)
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_SCROLL), 0);
return self->direction;
}
/**
* gdk_scroll_event_get_deltas:
* @event: (type GdkScrollEvent): a scroll event
* @delta_x: (out): return location for x scroll delta
* @delta_y: (out): return location for y scroll delta
*
* Extracts the scroll deltas of a scroll event.
*
* The deltas will be zero unless the scroll direction
* is %GDK_SCROLL_SMOOTH.
*/
void
gdk_scroll_event_get_deltas (GdkEvent *event,
double *delta_x,
double *delta_y)
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
g_return_if_fail (GDK_IS_EVENT (event));
g_return_if_fail (GDK_IS_EVENT_TYPE (event, GDK_SCROLL));
*delta_x = self->delta_x;
*delta_y = self->delta_y;
}
/**
* gdk_scroll_event_is_stop:
* @event: (type GdkScrollEvent): a scroll event
*
* Check whether a scroll event is a stop scroll event. Scroll sequences
* with smooth scroll information may provide a stop scroll event once the
* interaction with the device finishes, e.g. by lifting a finger. This
* stop scroll event is the signal that a widget may trigger kinetic
* scrolling based on the current velocity.
*
* Stop scroll events always have a delta of 0/0.
*
* Returns: %TRUE if the event is a scroll stop event
*/
gboolean
gdk_scroll_event_is_stop (GdkEvent *event)
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_SCROLL), FALSE);
return self->is_stop;
}
/* }}} */
/* {{{ GdkTouchpadEvent */
static GdkModifierType
gdk_touchpad_event_get_state (GdkEvent *event)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
return self->state;
}
static gboolean
gdk_touchpad_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static const GdkEventTypeInfo gdk_touchpad_event_info = {
sizeof (GdkTouchpadEvent),
NULL,
NULL,
gdk_touchpad_event_get_state,
gdk_touchpad_event_get_position,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkTouchpadEvent, gdk_touchpad_event,
&gdk_touchpad_event_info,
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_SWIPE)
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_PINCH))
GdkEvent *
gdk_touchpad_event_new_swipe (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy)
{
GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_SWIPE, surface, device, source_device, time);
self->state = state;
self->phase = phase;
self->x = x;
self->y = y;
self->dx = dx;
self->dy = dy;
self->n_fingers = n_fingers;
return (GdkEvent *) self;
}
GdkEvent *
gdk_touchpad_event_new_pinch (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy,
double scale,
double angle_delta)
{
GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_PINCH, surface, device, source_device, time);
self->state = state;
self->phase = phase;
self->x = x;
self->y = y;
self->dx = dx;
self->dy = dy;
self->n_fingers = n_fingers;
self->scale = scale;
self->angle_delta = angle_delta;
return (GdkEvent *) self;
}
/**
* gdk_touchpad_event_get_gesture_phase:
* @event: (type GdkTouchpadEvent): a touchpad #GdkEvent
*
* Extracts the touchpad gesture phase from a touchpad event.
*
* Returns: the gesture phase of @event
**/
GdkTouchpadGesturePhase
gdk_touchpad_event_get_gesture_phase (GdkEvent *event)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE), 0);
return self->phase;
}
/**
* gdk_touchpad_event_get_n_fingers:
* @event: (type GdkTouchpadEvent): a touchpad event
*
* Extracts the number of fingers from a touchpad event.
*
* Returns: the number of fingers for @event
**/
guint
gdk_touchpad_event_get_n_fingers (GdkEvent *event)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE), 0);
return self->n_fingers;
}
/**
* gdk_touchpad_event_get_deltas:
* @event: (type GdkTouchpadEvent): a touchpad event
* @dx: (out): return location for x
* @dy: (out): return location for y
*
* Extracts delta information from a touchpad event.
**/
void
gdk_touchpad_event_get_deltas (GdkEvent *event,
double *dx,
double *dy)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
g_return_if_fail (GDK_IS_EVENT (event));
g_return_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE));
*dx = self->dx;
*dy = self->dy;
}
/**
* gdk_touchpad_event_get_pinch_angle_delta:
* @event: (type GdkTouchpadEvent): a touchpad pinch event
*
* Extracts the angle delta from a touchpad pinch event.
*
* Returns: the angle delta of @event
*/
double
gdk_touchpad_event_get_pinch_angle_delta (GdkEvent *event)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0.0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH), 0.0);
return self->angle_delta;
}
/**
* gdk_touchpad_event_get_pinch_scale:
* @event: (type GdkTouchpadEvent): a touchpad pinch event
*
* Extracts the scale from a touchpad pinch event.
*
* Returns: the scale of @event
**/
double
gdk_touchpad_event_get_pinch_scale (GdkEvent *event)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0.0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH), 0.0);
return self->scale;
}
/* }}} */
/* {{{ GdkPadEvent */
static const GdkEventTypeInfo gdk_pad_event_info = {
sizeof (GdkPadEvent),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkPadEvent, gdk_pad_event,
&gdk_pad_event_info,
GDK_EVENT_TYPE_SLOT (GDK_PAD_BUTTON_PRESS)
GDK_EVENT_TYPE_SLOT (GDK_PAD_BUTTON_RELEASE)
GDK_EVENT_TYPE_SLOT (GDK_PAD_RING)
GDK_EVENT_TYPE_SLOT (GDK_PAD_STRIP)
GDK_EVENT_TYPE_SLOT (GDK_PAD_GROUP_MODE))
GdkEvent *
gdk_pad_event_new_ring (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
guint group,
guint index,
guint mode,
double value)
{
GdkPadEvent *self = gdk_event_alloc (GDK_PAD_RING, surface, device, source_device, time);
self->group = group;
self->index = index;
self->mode = mode;
self->value = value;
return (GdkEvent *) self;
}
GdkEvent *
gdk_pad_event_new_strip (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
guint group,
guint index,
guint mode,
double value)
{
GdkPadEvent *self = gdk_event_alloc (GDK_PAD_STRIP, surface, device, source_device, time);
self->group = group;
self->index = index;
self->mode = mode;
self->value = value;
return (GdkEvent *) self;
}
GdkEvent *
gdk_pad_event_new_button (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
guint group,
guint button,
guint mode)
{
GdkPadEvent *self;
g_return_val_if_fail (type == GDK_PAD_BUTTON_PRESS ||
type == GDK_PAD_BUTTON_RELEASE, NULL);
self = gdk_event_alloc (type, surface, device, source_device, time);
self->group = group;
self->button = button;
self->mode = mode;
return (GdkEvent *) self;
}
GdkEvent *
gdk_pad_event_new_group_mode (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
guint32 time,
guint group,
guint mode)
{
GdkPadEvent *self = gdk_event_alloc (GDK_PAD_GROUP_MODE, surface, device, source_device, time);
self->group = group;
self->mode = mode;
return (GdkEvent *) self;
}
/**
* gdk_pad_event_get_button:
* @event: (type GdkPadEvent): a pad button event
*
* Extracts information about the pressed button from
* a pad event.
*
* Returns: the button of @event
**/
guint
gdk_pad_event_get_button (GdkEvent *event)
{
GdkPadEvent *self = (GdkPadEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_PAD_BUTTON_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_PAD_BUTTON_RELEASE), 0);
return self->button;
}
/**
* gdk_pad_event_get_axis_value:
* @event: (type GdkPadEvent): a pad strip or ring event
* @index: (out): Return location for the axis index
* @value: (out): Return location for the axis value
*
* Extracts the information from a pad strip or ring event.
**/
void
gdk_pad_event_get_axis_value (GdkEvent *event,
guint *index,
double *value)
{
GdkPadEvent *self = (GdkPadEvent *) event;
g_return_if_fail (GDK_IS_EVENT (event));
g_return_if_fail (GDK_IS_EVENT_TYPE (event, GDK_PAD_RING) ||
GDK_IS_EVENT_TYPE (event, GDK_PAD_STRIP));
*index = self->index;
*value = self->value;
}
/**
* gdk_pad_event_get_group_mode:
* @event: (type GdkPadEvent): a pad event
* @group: (out): return location for the group
* @mode: (out): return location for the mode
*
* Extracts group and mode information from a pad event.
**/
void
gdk_pad_event_get_group_mode (GdkEvent *event,
guint *group,
guint *mode)
{
GdkPadEvent *self = (GdkPadEvent *) event;
g_return_if_fail (GDK_IS_EVENT (event));
g_return_if_fail (GDK_IS_EVENT_TYPE (event, GDK_PAD_GROUP_MODE) ||
GDK_IS_EVENT_TYPE (event, GDK_PAD_BUTTON_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_PAD_BUTTON_RELEASE) ||
GDK_IS_EVENT_TYPE (event, GDK_PAD_RING) ||
GDK_IS_EVENT_TYPE (event, GDK_PAD_STRIP));
*group = self->group;
*mode = self->mode;
}
/* }}} */
/* {{{ GdkMotionEvent */
static void
gdk_motion_event_finalize (GdkEvent *event)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
g_clear_object (&self->tool);
g_clear_pointer (&self->axes, g_free);
if (self->history)
g_array_free (self->history, TRUE);
GDK_EVENT_SUPER (event)->finalize (event);
}
static GdkModifierType
gdk_motion_event_get_state (GdkEvent *event)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
return self->state;
}
static gboolean
gdk_motion_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static GdkDeviceTool *
gdk_motion_event_get_tool (GdkEvent *event)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
return self->tool;
}
static gboolean
gdk_motion_event_get_axes (GdkEvent *event,
double **axes,
guint *n_axes)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
GdkDevice *source_device = gdk_event_get_source_device (event);
if (source_device == NULL)
return FALSE;
*axes = self->axes;
*n_axes = gdk_device_get_n_axes (source_device);
return TRUE;
}
static const GdkEventTypeInfo gdk_motion_event_info = {
sizeof (GdkMotionEvent),
NULL,
gdk_motion_event_finalize,
gdk_motion_event_get_state,
gdk_motion_event_get_position,
NULL,
gdk_motion_event_get_tool,
gdk_motion_event_get_axes,
};
GDK_DEFINE_EVENT_TYPE (GdkMotionEvent, gdk_motion_event,
&gdk_motion_event_info,
GDK_EVENT_TYPE_SLOT (GDK_MOTION_NOTIFY))
GdkEvent *
gdk_motion_event_new (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
GdkDeviceTool *tool,
guint32 time,
GdkModifierType state,
double x,
double y,
double *axes)
{
GdkMotionEvent *self = gdk_event_alloc (GDK_MOTION_NOTIFY, surface, device, source_device, time);
self->tool = tool ? g_object_ref (tool) : NULL;
self->state = state;
self->x = x;
self->y = y;
self->axes = axes;
self->state = state;
return (GdkEvent *) self;
}
/**
* gdk_event_get_history:
* @event: a motion or scroll #GdkEvent
* @out_n_coords: (out): Return location for the length of the returned array
*
* Retrieves the history of the @event, as a list of time and coordinates.
*
* The history includes events that are not delivered to the application
* because they occurred in the same frame as @event.
*
* Note that only motion and scroll events record history, and motion
* events only if one of the mouse buttons is down.
*
* Returns: (transfer container) (array length=out_n_coords) (nullable): an
* array of time and coordinates
*/
GdkTimeCoord *
gdk_event_get_history (GdkEvent *event,
guint *out_n_coords)
{
GArray *history;
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY) ||
GDK_IS_EVENT_TYPE (event, GDK_SCROLL), NULL);
g_return_val_if_fail (out_n_coords != NULL, NULL);
if (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY))
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
history = self->history;
}
else
{
GdkScrollEvent *self = (GdkScrollEvent *) event;
history = self->history;
}
if (history && history->len > 0)
{
GdkTimeCoord *result;
*out_n_coords = history->len;
result = g_malloc (sizeof (GdkTimeCoord) * history->len);
memcpy (result, history->data, sizeof (GdkTimeCoord) * history->len);
return result;
}
*out_n_coords = 0;
return NULL;
}
/* }}} */
/* {{{ GdkProximityEvent */
static void
gdk_proximity_event_finalize (GdkEvent *event)
{
GdkProximityEvent *self = (GdkProximityEvent *) event;
g_clear_object (&self->tool);
GDK_EVENT_SUPER (event)->finalize (event);
}
static GdkDeviceTool *
gdk_proximity_event_get_tool (GdkEvent *event)
{
GdkProximityEvent *self = (GdkProximityEvent *) event;
return self->tool;
}
static const GdkEventTypeInfo gdk_proximity_event_info = {
sizeof (GdkProximityEvent),
NULL,
gdk_proximity_event_finalize,
NULL,
NULL,
NULL,
gdk_proximity_event_get_tool,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkProximityEvent, gdk_proximity_event,
&gdk_proximity_event_info,
GDK_EVENT_TYPE_SLOT (GDK_PROXIMITY_IN)
GDK_EVENT_TYPE_SLOT (GDK_PROXIMITY_OUT))
GdkEvent *
gdk_proximity_event_new (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
GdkDeviceTool *tool,
guint32 time)
{
GdkProximityEvent *self;
g_return_val_if_fail (type == GDK_PROXIMITY_IN ||
type == GDK_PROXIMITY_OUT, NULL);
self = gdk_event_alloc (type, surface, device, source_device, time);
self->tool = tool ? g_object_ref (tool) : NULL;
return (GdkEvent *) self;
}
/* }}} */
/* {{{ GdkDNDEvent */
static void
gdk_dnd_event_finalize (GdkEvent *event)
{
GdkDNDEvent *self = (GdkDNDEvent *) event;
g_clear_object (&self->drop);
GDK_EVENT_SUPER (event)->finalize (event);
}
static gboolean
gdk_dnd_event_get_position (GdkEvent *event,
double *x,
double *y)
{
GdkDNDEvent *self = (GdkDNDEvent *) event;
*x = self->x;
*y = self->y;
return TRUE;
}
static GdkEventSequence *
gdk_dnd_event_get_sequence (GdkEvent *event)
{
GdkDNDEvent *self = (GdkDNDEvent *) event;
return (GdkEventSequence *) self->drop;
}
static const GdkEventTypeInfo gdk_dnd_event_info = {
sizeof (GdkDNDEvent),
NULL,
gdk_dnd_event_finalize,
NULL,
gdk_dnd_event_get_position,
gdk_dnd_event_get_sequence,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkDNDEvent, gdk_dnd_event,
&gdk_dnd_event_info,
GDK_EVENT_TYPE_SLOT (GDK_DRAG_ENTER)
GDK_EVENT_TYPE_SLOT (GDK_DRAG_MOTION)
GDK_EVENT_TYPE_SLOT (GDK_DRAG_LEAVE)
GDK_EVENT_TYPE_SLOT (GDK_DROP_START))
GdkEvent *
gdk_dnd_event_new (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
GdkDrop *drop,
guint32 time,
double x,
double y)
{
GdkDNDEvent *self;
g_return_val_if_fail (type == GDK_DRAG_ENTER ||
type == GDK_DRAG_MOTION ||
type == GDK_DRAG_LEAVE ||
type == GDK_DROP_START, NULL);
self = gdk_event_alloc (type, surface, device, NULL, time);
self->drop = drop != NULL ? g_object_ref (drop) : NULL;
self->x = x;
self->y = y;
return (GdkEvent *) self;
}
/**
* gdk_dnd_event_get_drop:
* @event: (type GdkDNDEvent): a DND event
*
* Gets the #GdkDrop from a DND event.
*
* Returns: (transfer none) (nullable): the drop
**/
GdkDrop *
gdk_dnd_event_get_drop (GdkEvent *event)
{
GdkDNDEvent *self = (GdkDNDEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_DRAG_ENTER) ||
GDK_IS_EVENT_TYPE (event, GDK_DRAG_MOTION) ||
GDK_IS_EVENT_TYPE (event, GDK_DRAG_LEAVE) ||
GDK_IS_EVENT_TYPE (event, GDK_DROP_START), NULL);
return self->drop;
}
/* }}} */
/* {{{ GdkGrabBrokenEvent */
static const GdkEventTypeInfo gdk_grab_broken_event_info = {
sizeof (GdkGrabBrokenEvent),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
GDK_DEFINE_EVENT_TYPE (GdkGrabBrokenEvent, gdk_grab_broken_event,
&gdk_grab_broken_event_info,
GDK_EVENT_TYPE_SLOT (GDK_GRAB_BROKEN))
GdkEvent *
gdk_grab_broken_event_new (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
GdkSurface *grab_surface,
gboolean implicit)
{
GdkGrabBrokenEvent *self = gdk_event_alloc (GDK_GRAB_BROKEN, surface, device, source_device, GDK_CURRENT_TIME);
self->grab_surface = grab_surface;
self->implicit = implicit;
self->keyboard = gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD;
return (GdkEvent *) self;
}
/**
* gdk_grab_broken_event_get_grab_surface:
* @event: (type GdkGrabBrokenEvent): a grab broken event
*
* Extracts the grab surface from a grab broken event.
*
* Returns: (transfer none): the grab surface of @event
**/
GdkSurface *
gdk_grab_broken_event_get_grab_surface (GdkEvent *event)
{
GdkGrabBrokenEvent *self = (GdkGrabBrokenEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_GRAB_BROKEN), NULL);
return self->grab_surface;
}
/**
* gdk_grab_broken_event_get_implicit:
* @event: (type GdkGrabBrokenEvent): a grab broken event
*
* Checks whether the grab broken event is for an implicit grab.
*
* Returns: %TRUE if the an implicit grab was broken
*/
gboolean
gdk_grab_broken_event_get_implicit (GdkEvent *event)
{
GdkGrabBrokenEvent *self = (GdkGrabBrokenEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_GRAB_BROKEN), FALSE);
return self->implicit;
}
/* }}} */
|