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
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
|
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
* Josh MacDonald, Ryan Lortie
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* 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 "gdkwindow-x11.h"
#include "gdkx.h"
#include "gdkwindow.h"
#include "gdkwindowimpl.h"
#include "gdkasync.h"
#include "gdkdisplay-x11.h"
#include "gdkprivate-x11.h"
#include "gdkvisualprivate.h"
#include "gdkinternals.h"
#include "gdkdeviceprivate.h"
#include "gdkeventsource.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <unistd.h>
#include <cairo-xlib.h>
#include "MwmUtil.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/shape.h>
#ifdef HAVE_XKB
#include <X11/XKBlib.h>
#endif
#ifdef HAVE_XCOMPOSITE
#include <X11/extensions/Xcomposite.h>
#endif
#ifdef HAVE_XFIXES
#include <X11/extensions/Xfixes.h>
#endif
#ifdef HAVE_XDAMAGE
#include <X11/extensions/Xdamage.h>
#endif
const int _gdk_x11_event_mask_table[21] =
{
ExposureMask,
PointerMotionMask,
PointerMotionHintMask,
ButtonMotionMask,
Button1MotionMask,
Button2MotionMask,
Button3MotionMask,
ButtonPressMask,
ButtonReleaseMask,
KeyPressMask,
KeyReleaseMask,
EnterWindowMask,
LeaveWindowMask,
FocusChangeMask,
StructureNotifyMask,
PropertyChangeMask,
VisibilityChangeMask,
0, /* PROXIMITY_IN */
0, /* PROXIMTY_OUT */
SubstructureNotifyMask,
ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
};
const gint _gdk_x11_event_mask_table_size = G_N_ELEMENTS (_gdk_x11_event_mask_table);
/* Forward declarations */
static void gdk_window_set_static_win_gravity (GdkWindow *window,
gboolean on);
static gboolean gdk_window_icon_name_set (GdkWindow *window);
static void set_wm_name (GdkDisplay *display,
Window xwindow,
const gchar *name);
static void move_to_current_desktop (GdkWindow *window);
static void gdk_window_x11_set_background (GdkWindow *window,
cairo_pattern_t *pattern);
static void gdk_window_impl_x11_finalize (GObject *object);
#define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
#define WINDOW_IS_TOPLEVEL(window) \
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
/* Return whether time1 is considered later than time2 as far as xserver
* time is concerned. Accounts for wraparound.
*/
#define XSERVER_TIME_IS_LATER(time1, time2) \
( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
(( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
)
G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_WINDOW_IMPL)
static void
gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
{
impl->toplevel_window_type = -1;
impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
(GDestroyNotify) gdk_cursor_unref);
}
GdkToplevelX11 *
_gdk_x11_window_get_toplevel (GdkWindow *window)
{
GdkWindowImplX11 *impl;
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
if (!WINDOW_IS_TOPLEVEL (window))
return NULL;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (!impl->toplevel)
impl->toplevel = g_new0 (GdkToplevelX11, 1);
return impl->toplevel;
}
static const cairo_user_data_key_t gdk_x11_cairo_key;
/**
* _gdk_x11_window_update_size:
* @impl: a #GdkWindowImplX11.
*
* Updates the state of the window (in particular the drawable's
* cairo surface) when its size has changed.
**/
void
_gdk_x11_window_update_size (GdkWindowImplX11 *impl)
{
if (impl->cairo_surface)
{
cairo_xlib_surface_set_size (impl->cairo_surface,
gdk_window_get_width (impl->wrapper),
gdk_window_get_height (impl->wrapper));
}
}
/*****************************************************
* X11 specific implementations of generic functions *
*****************************************************/
static void
gdk_x11_cairo_surface_destroy (void *data)
{
GdkWindowImplX11 *impl = data;
impl->cairo_surface = NULL;
}
static cairo_surface_t *
gdk_x11_create_cairo_surface (GdkWindowImplX11 *impl,
int width,
int height)
{
GdkVisual *visual;
visual = gdk_window_get_visual (impl->wrapper);
return cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (impl->wrapper),
GDK_WINDOW_IMPL_X11 (impl)->xid,
GDK_VISUAL_XVISUAL (visual),
width, height);
}
static cairo_surface_t *
gdk_x11_ref_cairo_surface (GdkWindow *window)
{
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (GDK_WINDOW_DESTROYED (window))
return NULL;
if (!impl->cairo_surface)
{
impl->cairo_surface = gdk_x11_create_cairo_surface (impl,
gdk_window_get_width (window),
gdk_window_get_height (window));
if (impl->cairo_surface)
cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
impl, gdk_x11_cairo_surface_destroy);
}
else
cairo_surface_reference (impl->cairo_surface);
return impl->cairo_surface;
}
static void
gdk_window_impl_x11_finalize (GObject *object)
{
GdkWindow *wrapper;
GdkWindowImplX11 *impl;
g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
impl = GDK_WINDOW_IMPL_X11 (object);
wrapper = impl->wrapper;
_gdk_x11_window_grab_check_destroy (wrapper);
if (!GDK_WINDOW_DESTROYED (wrapper))
{
GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
_gdk_xid_table_remove (display, impl->xid);
if (impl->toplevel && impl->toplevel->focus_window)
_gdk_xid_table_remove (display, impl->toplevel->focus_window);
}
g_free (impl->toplevel);
if (impl->cursor)
gdk_cursor_unref (impl->cursor);
g_hash_table_destroy (impl->device_cursor);
G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
}
typedef struct {
GdkDisplay *display;
Pixmap pixmap;
} FreePixmapData;
static void
free_pixmap (gpointer datap)
{
FreePixmapData *data = datap;
if (!gdk_display_is_closed (data->display))
{
XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
data->pixmap);
}
g_object_unref (data->display);
g_slice_free (FreePixmapData, data);
}
static void
attach_free_pixmap_handler (cairo_surface_t *surface,
GdkDisplay *display,
Pixmap pixmap)
{
static const cairo_user_data_key_t key;
FreePixmapData *data;
data = g_slice_new (FreePixmapData);
data->display = g_object_ref (display);
data->pixmap = pixmap;
cairo_surface_set_user_data (surface, &key, data, free_pixmap);
}
/* Cairo does not guarantee we get an xlib surface if we call
* cairo_surface_create_similar(). In some cases however, we must use a
* pixmap or bitmap in the X11 API.
* These functions ensure an Xlib surface.
*/
cairo_surface_t *
_gdk_x11_window_create_bitmap_surface (GdkWindow *window,
int width,
int height)
{
cairo_surface_t *surface;
Pixmap pixmap;
pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
width, height, 1);
surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
pixmap,
GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window)),
width, height);
attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
return surface;
}
/* Create a surface backed with a pixmap without alpha on the same screen as window */
static cairo_surface_t *
gdk_x11_window_create_pixmap_surface (GdkWindow *window,
int width,
int height)
{
GdkScreen *screen = gdk_window_get_screen (window);
GdkVisual *visual = gdk_screen_get_system_visual (screen);
cairo_surface_t *surface;
Pixmap pixmap;
pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
width, height,
gdk_visual_get_depth (visual));
surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
pixmap,
GDK_VISUAL_XVISUAL (visual),
width, height);
attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
return surface;
}
static void
tmp_unset_bg (GdkWindow *window)
{
GdkWindowImplX11 *impl;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
impl->no_bg = TRUE;
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window), None);
}
static void
tmp_reset_bg (GdkWindow *window)
{
GdkWindowImplX11 *impl;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
impl->no_bg = FALSE;
gdk_window_x11_set_background (window, window->background);
}
/* Unsetting and resetting window backgrounds.
*
* In many cases it is possible to avoid flicker by unsetting the
* background of windows. For example if the background of the
* parent window is unset when a window is unmapped, a brief flicker
* of background painting is avoided.
*/
void
_gdk_x11_window_tmp_unset_bg (GdkWindow *window,
gboolean recurse)
{
g_return_if_fail (GDK_IS_WINDOW (window));
if (window->input_only || window->destroyed ||
(window->window_type != GDK_WINDOW_ROOT &&
!GDK_WINDOW_IS_MAPPED (window)))
return;
if (_gdk_window_has_impl (window) &&
GDK_WINDOW_IS_X11 (window) &&
window->window_type != GDK_WINDOW_ROOT &&
window->window_type != GDK_WINDOW_FOREIGN)
tmp_unset_bg (window);
if (recurse)
{
GList *l;
for (l = window->children; l != NULL; l = l->next)
_gdk_x11_window_tmp_unset_bg (l->data, TRUE);
}
}
void
_gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
{
if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
return;
window = _gdk_window_get_impl_window (window->parent);
_gdk_x11_window_tmp_unset_bg (window, FALSE);
}
void
_gdk_x11_window_tmp_reset_bg (GdkWindow *window,
gboolean recurse)
{
g_return_if_fail (GDK_IS_WINDOW (window));
if (window->input_only || window->destroyed ||
(window->window_type != GDK_WINDOW_ROOT &&
!GDK_WINDOW_IS_MAPPED (window)))
return;
if (_gdk_window_has_impl (window) &&
GDK_WINDOW_IS_X11 (window) &&
window->window_type != GDK_WINDOW_ROOT &&
window->window_type != GDK_WINDOW_FOREIGN)
tmp_reset_bg (window);
if (recurse)
{
GList *l;
for (l = window->children; l != NULL; l = l->next)
_gdk_x11_window_tmp_reset_bg (l->data, TRUE);
}
}
void
_gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
{
if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
return;
window = _gdk_window_get_impl_window (window->parent);
_gdk_x11_window_tmp_reset_bg (window, FALSE);
}
void
_gdk_x11_screen_init_root_window (GdkScreen *screen)
{
GdkWindow *window;
GdkWindowImplX11 *impl;
GdkScreenX11 *screen_x11;
screen_x11 = GDK_SCREEN_X11 (screen);
g_assert (screen_x11->root_window == NULL);
window = screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
window->impl_window = window;
window->visual = gdk_screen_get_system_visual (screen);
impl = GDK_WINDOW_IMPL_X11 (window->impl);
impl->xid = screen_x11->xroot_window;
impl->wrapper = window;
window->window_type = GDK_WINDOW_ROOT;
window->depth = DefaultDepthOfScreen (screen_x11->xscreen);
window->x = 0;
window->y = 0;
window->abs_x = 0;
window->abs_y = 0;
window->width = WidthOfScreen (screen_x11->xscreen);
window->height = HeightOfScreen (screen_x11->xscreen);
window->viewable = TRUE;
/* see init_randr_support() in gdkscreen-x11.c */
window->event_mask = GDK_STRUCTURE_MASK;
_gdk_window_update_size (screen_x11->root_window);
_gdk_xid_table_insert (screen_x11->display,
&screen_x11->xroot_window,
screen_x11->root_window);
}
static void
set_wm_protocols (GdkWindow *window)
{
GdkDisplay *display = gdk_window_get_display (window);
Atom protocols[4];
int n = 0;
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
#ifdef HAVE_XSYNC
if (GDK_DISPLAY_X11 (display)->use_sync)
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
#endif
XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
}
static const gchar *
get_default_title (void)
{
const char *title;
title = g_get_application_name ();
if (!title)
title = g_get_prgname ();
if (!title)
title = "";
return title;
}
static void
check_leader_window_title (GdkDisplay *display)
{
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
if (display_x11->leader_window && !display_x11->leader_window_title_set)
{
set_wm_name (display,
display_x11->leader_window,
get_default_title ());
display_x11->leader_window_title_set = TRUE;
}
}
static Window
create_focus_window (GdkDisplay *display,
XID parent)
{
GdkDisplayX11 *display_x11;
GdkEventMask event_mask;
Display *xdisplay;
Window focus_window;
xdisplay = GDK_DISPLAY_XDISPLAY (display);
display_x11 = GDK_DISPLAY_X11 (display);
focus_window = XCreateSimpleWindow (xdisplay, parent,
-1, -1, 1, 1, 0,
0, 0);
/* FIXME: probably better to actually track the requested event mask for the toplevel
*/
event_mask = (GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_FOCUS_CHANGE_MASK);
gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
focus_window,
event_mask, 0);
XMapWindow (xdisplay, focus_window);
return focus_window;
}
static void
ensure_sync_counter (GdkWindow *window)
{
#ifdef HAVE_XSYNC
if (!GDK_WINDOW_DESTROYED (window))
{
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (toplevel && impl->use_synchronized_configure &&
toplevel->update_counter == None &&
GDK_DISPLAY_X11 (display)->use_sync)
{
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
XSyncValue value;
Atom atom;
XSyncIntToValue (&value, 0);
toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
atom = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_SYNC_REQUEST_COUNTER");
XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
atom, XA_CARDINAL,
32, PropModeReplace,
(guchar *)&toplevel->update_counter, 1);
XSyncIntToValue (&toplevel->current_counter_value, 0);
}
}
#endif
}
static void
setup_toplevel_window (GdkWindow *window,
GdkWindow *parent)
{
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
GdkDisplay *display = gdk_window_get_display (window);
Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
XID xid = GDK_WINDOW_XID (window);
GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
XSizeHints size_hints;
long pid;
Window leader_window;
set_wm_protocols (window);
if (!window->input_only)
{
/* The focus window is off the visible area, and serves to receive key
* press events so they don't get sent to child windows.
*/
toplevel->focus_window = create_focus_window (display, xid);
_gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
}
check_leader_window_title (screen_x11->display);
/* FIXME: Is there any point in doing this? Do any WM's pay
* attention to PSize, and even if they do, is this the
* correct value???
*/
size_hints.flags = PSize;
size_hints.width = window->width;
size_hints.height = window->height;
XSetWMNormalHints (xdisplay, xid, &size_hints);
/* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
pid = getpid ();
XChangeProperty (xdisplay, xid,
gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
XA_CARDINAL, 32,
PropModeReplace,
(guchar *)&pid, 1);
leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
if (!leader_window)
leader_window = xid;
XChangeProperty (xdisplay, xid,
gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
XA_WINDOW, 32, PropModeReplace,
(guchar *) &leader_window, 1);
if (toplevel->focus_window != None)
XChangeProperty (xdisplay, xid,
gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
XA_WINDOW, 32, PropModeReplace,
(guchar *) &toplevel->focus_window, 1);
if (!window->focus_on_map)
gdk_x11_window_set_user_time (window, 0);
else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
ensure_sync_counter (window);
}
void
_gdk_x11_display_create_window_impl (GdkDisplay *display,
GdkWindow *window,
GdkWindow *real_parent,
GdkScreen *screen,
GdkEventMask event_mask,
GdkWindowAttr *attributes,
gint attributes_mask)
{
GdkWindowImplX11 *impl;
GdkScreenX11 *screen_x11;
GdkDisplayX11 *display_x11;
Window xparent;
Visual *xvisual;
Display *xdisplay;
XSetWindowAttributes xattributes;
long xattributes_mask;
XClassHint *class_hint;
unsigned int class;
const char *title;
display_x11 = GDK_DISPLAY_X11 (display);
xparent = GDK_WINDOW_XID (real_parent);
screen_x11 = GDK_SCREEN_X11 (screen);
impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
window->impl = GDK_WINDOW_IMPL (impl);
impl->wrapper = GDK_WINDOW (window);
xdisplay = screen_x11->xdisplay;
xattributes_mask = 0;
xvisual = gdk_x11_visual_get_xvisual (window->visual);
if (attributes_mask & GDK_WA_NOREDIR)
{
xattributes.override_redirect =
(attributes->override_redirect == FALSE)?False:True;
xattributes_mask |= CWOverrideRedirect;
}
else
xattributes.override_redirect = False;
impl->override_redirect = xattributes.override_redirect;
if (window->parent && window->parent->guffaw_gravity)
{
xattributes.win_gravity = StaticGravity;
xattributes_mask |= CWWinGravity;
}
/* Sanity checks */
switch (window->window_type)
{
case GDK_WINDOW_TOPLEVEL:
case GDK_WINDOW_TEMP:
if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
{
/* The common code warns for this case */
xparent = GDK_SCREEN_XROOTWIN (screen);
}
}
if (!window->input_only)
{
class = InputOutput;
xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
xattributes_mask |= CWBorderPixel | CWBackPixel;
if (window->guffaw_gravity)
xattributes.bit_gravity = StaticGravity;
else
xattributes.bit_gravity = NorthWestGravity;
xattributes_mask |= CWBitGravity;
xattributes.colormap = _gdk_visual_get_x11_colormap (window->visual);
xattributes_mask |= CWColormap;
if (window->window_type == GDK_WINDOW_TEMP)
{
xattributes.save_under = True;
xattributes.override_redirect = True;
xattributes.cursor = None;
xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
impl->override_redirect = TRUE;
}
}
else
{
class = InputOnly;
}
if (window->width > 65535 ||
window->height > 65535)
{
g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
if (window->width > 65535)
window->width = 65535;
if (window->height > 65535)
window->height = 65535;
}
impl->xid = XCreateWindow (xdisplay, xparent,
window->x + window->parent->abs_x,
window->y + window->parent->abs_y,
window->width, window->height,
0, window->depth, class, xvisual,
xattributes_mask, &xattributes);
g_object_ref (window);
_gdk_xid_table_insert (screen_x11->display, &impl->xid, window);
switch (GDK_WINDOW_TYPE (window))
{
case GDK_WINDOW_TOPLEVEL:
case GDK_WINDOW_TEMP:
if (attributes_mask & GDK_WA_TITLE)
title = attributes->title;
else
title = get_default_title ();
gdk_window_set_title (window, title);
if (attributes_mask & GDK_WA_WMCLASS)
{
class_hint = XAllocClassHint ();
class_hint->res_name = attributes->wmclass_name;
class_hint->res_class = attributes->wmclass_class;
XSetClassHint (xdisplay, impl->xid, class_hint);
XFree (class_hint);
}
setup_toplevel_window (window, window->parent);
break;
case GDK_WINDOW_CHILD:
default:
break;
}
if (attributes_mask & GDK_WA_TYPE_HINT)
gdk_window_set_type_hint (window, attributes->type_hint);
gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
GDK_WINDOW_XID (window), event_mask,
StructureNotifyMask | PropertyChangeMask);
}
static GdkEventMask
x_event_mask_to_gdk_event_mask (long mask)
{
GdkEventMask event_mask = 0;
int i;
for (i = 0; i < _gdk_x11_event_mask_table_size; i++)
{
if (mask & _gdk_x11_event_mask_table[i])
event_mask |= 1 << (i + 1);
}
return event_mask;
}
/**
* gdk_x11_window_foreign_new_for_display:
* @display: the #GdkDisplay where the window handle comes from.
* @window: an XLib <type>Window</type>
*
* Wraps a native window in a #GdkWindow.
*
* This may fail if the window has been destroyed. If the window
* was already known to GDK, a new reference to the existing
* #GdkWindow is returned.
*
* Return value: (transfer full): a #GdkWindow wrapper for the native
* window, or %NULL if the window has been destroyed. The wrapper
* will be newly created, if one doesn't exist already.
*
* Since: 3.0
*/
GdkWindow *
gdk_x11_window_foreign_new_for_display (GdkDisplay *display,
Window window)
{
GdkScreen *screen;
GdkWindow *win;
GdkWindowImplX11 *impl;
GdkDisplayX11 *display_x11;
XWindowAttributes attrs;
Window root, parent;
Window *children = NULL;
guint nchildren;
gboolean result;
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
display_x11 = GDK_DISPLAY_X11 (display);
if ((win = _gdk_xid_table_lookup (display, window)) != NULL)
return g_object_ref (win);
gdk_x11_display_error_trap_push (display);
result = XGetWindowAttributes (display_x11->xdisplay, window, &attrs);
if (gdk_x11_display_error_trap_pop (display) || !result)
return NULL;
/* FIXME: This is pretty expensive.
* Maybe the caller should supply the parent
*/
gdk_x11_display_error_trap_push (display);
result = XQueryTree (display_x11->xdisplay, window, &root, &parent, &children, &nchildren);
if (gdk_x11_display_error_trap_pop (display) || !result)
return NULL;
if (children)
XFree (children);
screen = _gdk_x11_display_screen_for_xrootwin (display, root);
win = g_object_new (GDK_TYPE_WINDOW, NULL);
win->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
win->impl_window = win;
win->visual = gdk_x11_screen_lookup_visual (screen,
XVisualIDFromVisual (attrs.visual));
impl = GDK_WINDOW_IMPL_X11 (win->impl);
impl->wrapper = win;
win->parent = _gdk_xid_table_lookup (display, parent);
if (!win->parent || GDK_WINDOW_TYPE (win->parent) == GDK_WINDOW_FOREIGN)
win->parent = gdk_screen_get_root_window (screen);
win->parent->children = g_list_prepend (win->parent->children, win);
impl->xid = window;
win->x = attrs.x;
win->y = attrs.y;
win->width = attrs.width;
win->height = attrs.height;
win->window_type = GDK_WINDOW_FOREIGN;
win->destroyed = FALSE;
win->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
if (attrs.map_state == IsUnmapped)
win->state = GDK_WINDOW_STATE_WITHDRAWN;
else
win->state = 0;
win->viewable = TRUE;
win->depth = attrs.depth;
g_object_ref (win);
_gdk_xid_table_insert (display, &GDK_WINDOW_XID (win), win);
/* Update the clip region, etc */
_gdk_window_update_size (win);
return win;
}
/**
* gdk_x11_window_lookup_for_display:
* @display: the #GdkDisplay corresponding to the window handle
* @window: an XLib <type>Window</type>
*
* Looks up the #GdkWindow that wraps the given native window handle.
*
* Return value: (transfer none): the #GdkWindow wrapper for the native
* window, or %NULL if there is none.
*
* Since: 3.0
*/
GdkWindow *
gdk_x11_window_lookup_for_display (GdkDisplay *display,
Window window)
{
return (GdkWindow*) _gdk_xid_table_lookup (display, window);
}
static void
gdk_toplevel_x11_free_contents (GdkDisplay *display,
GdkToplevelX11 *toplevel)
{
if (toplevel->icon_pixmap)
{
cairo_surface_destroy (toplevel->icon_pixmap);
toplevel->icon_pixmap = NULL;
}
if (toplevel->icon_mask)
{
cairo_surface_destroy (toplevel->icon_mask);
toplevel->icon_mask = NULL;
}
if (toplevel->group_leader)
{
g_object_unref (toplevel->group_leader);
toplevel->group_leader = NULL;
}
#ifdef HAVE_XSYNC
if (toplevel->update_counter != None)
{
XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
toplevel->update_counter);
toplevel->update_counter = None;
XSyncIntToValue (&toplevel->current_counter_value, 0);
}
#endif
}
static void
gdk_x11_window_destroy (GdkWindow *window,
gboolean recursing,
gboolean foreign_destroy)
{
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
GdkToplevelX11 *toplevel;
g_return_if_fail (GDK_IS_WINDOW (window));
_gdk_selection_window_destroyed (window);
toplevel = _gdk_x11_window_get_toplevel (window);
if (toplevel)
gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
if (impl->cairo_surface)
{
cairo_surface_finish (impl->cairo_surface);
cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
NULL, NULL);
}
if (!recursing && !foreign_destroy)
XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
}
static cairo_surface_t *
gdk_window_x11_resize_cairo_surface (GdkWindow *window,
cairo_surface_t *surface,
gint width,
gint height)
{
cairo_xlib_surface_set_size (surface, width, height);
return surface;
}
static void
gdk_x11_window_destroy_foreign (GdkWindow *window)
{
/* It's somebody else's window, but in our hierarchy,
* so reparent it to the root window, and then send
* it a delete event, as if we were a WM
*/
XClientMessageEvent xclient;
GdkDisplay *display;
display = GDK_WINDOW_DISPLAY (window);
gdk_x11_display_error_trap_push (display);
gdk_window_hide (window);
gdk_window_reparent (window, NULL, 0, 0);
memset (&xclient, 0, sizeof (xclient));
xclient.type = ClientMessage;
xclient.window = GDK_WINDOW_XID (window);
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS");
xclient.format = 32;
xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
xclient.data.l[1] = CurrentTime;
xclient.data.l[2] = 0;
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
XSendEvent (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
False, 0, (XEvent *)&xclient);
gdk_x11_display_error_trap_pop_ignored (display);
}
static GdkWindow *
get_root (GdkWindow *window)
{
GdkScreen *screen = gdk_window_get_screen (window);
return gdk_screen_get_root_window (screen);
}
/* This function is called when the XWindow is really gone.
*/
static void
gdk_x11_window_destroy_notify (GdkWindow *window)
{
GdkWindowImplX11 *window_impl;
window_impl = GDK_WINDOW_IMPL_X11 ((window)->impl);
if (!GDK_WINDOW_DESTROYED (window))
{
if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
_gdk_window_destroy (window, TRUE);
}
_gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
if (window_impl->toplevel && window_impl->toplevel->focus_window)
_gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
_gdk_x11_window_grab_check_destroy (window);
g_object_unref (window);
}
static void
update_wm_hints (GdkWindow *window,
gboolean force)
{
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
XWMHints wm_hints;
if (!force &&
!toplevel->is_leader &&
window->state & GDK_WINDOW_STATE_WITHDRAWN)
return;
wm_hints.flags = StateHint | InputHint;
wm_hints.input = window->accept_focus ? True : False;
wm_hints.initial_state = NormalState;
if (window->state & GDK_WINDOW_STATE_ICONIFIED)
{
wm_hints.flags |= StateHint;
wm_hints.initial_state = IconicState;
}
if (toplevel->icon_pixmap)
{
wm_hints.flags |= IconPixmapHint;
wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
}
if (toplevel->icon_mask)
{
wm_hints.flags |= IconMaskHint;
wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
}
wm_hints.flags |= WindowGroupHint;
if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
{
wm_hints.flags |= WindowGroupHint;
wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
}
else
wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
if (toplevel->urgency_hint)
wm_hints.flags |= XUrgencyHint;
XSetWMHints (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
&wm_hints);
}
static void
set_initial_hints (GdkWindow *window)
{
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
Window xwindow = GDK_WINDOW_XID (window);
GdkToplevelX11 *toplevel;
Atom atoms[9];
gint i;
toplevel = _gdk_x11_window_get_toplevel (window);
if (!toplevel)
return;
update_wm_hints (window, TRUE);
/* We set the spec hints regardless of whether the spec is supported,
* since it can't hurt and it's kind of expensive to check whether
* it's supported.
*/
i = 0;
if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_MAXIMIZED_VERT");
++i;
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_MAXIMIZED_HORZ");
++i;
toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
}
if (window->state & GDK_WINDOW_STATE_ABOVE)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_ABOVE");
++i;
}
if (window->state & GDK_WINDOW_STATE_BELOW)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_BELOW");
++i;
}
if (window->state & GDK_WINDOW_STATE_STICKY)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_STICKY");
++i;
toplevel->have_sticky = TRUE;
}
if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_FULLSCREEN");
++i;
toplevel->have_fullscreen = TRUE;
}
if (window->modal_hint)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_MODAL");
++i;
}
if (toplevel->skip_taskbar_hint)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_SKIP_TASKBAR");
++i;
}
if (toplevel->skip_pager_hint)
{
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_STATE_SKIP_PAGER");
++i;
}
if (i > 0)
{
XChangeProperty (xdisplay,
xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
XA_ATOM, 32, PropModeReplace,
(guchar*) atoms, i);
}
else
{
XDeleteProperty (xdisplay,
xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
}
if (window->state & GDK_WINDOW_STATE_STICKY)
{
atoms[0] = 0xFFFFFFFF;
XChangeProperty (xdisplay,
xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
XA_CARDINAL, 32, PropModeReplace,
(guchar*) atoms, 1);
toplevel->on_all_desktops = TRUE;
}
else
{
XDeleteProperty (xdisplay,
xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
}
toplevel->map_serial = NextRequest (xdisplay);
}
static void
gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
{
GdkDisplay *display;
GdkDisplayX11 *display_x11;
GdkToplevelX11 *toplevel;
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
Window xwindow = GDK_WINDOW_XID (window);
gboolean unset_bg;
if (!already_mapped)
set_initial_hints (window);
if (WINDOW_IS_TOPLEVEL (window))
{
display = gdk_window_get_display (window);
display_x11 = GDK_DISPLAY_X11 (display);
toplevel = _gdk_x11_window_get_toplevel (window);
if (toplevel->user_time != 0 &&
display_x11->user_time != 0 &&
XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
gdk_x11_window_set_user_time (window, display_x11->user_time);
}
unset_bg = !window->input_only &&
(window->window_type == GDK_WINDOW_CHILD ||
impl->override_redirect) &&
gdk_window_is_viewable (window);
if (unset_bg)
_gdk_x11_window_tmp_unset_bg (window, TRUE);
XMapWindow (xdisplay, xwindow);
if (unset_bg)
_gdk_x11_window_tmp_reset_bg (window, TRUE);
}
static void
pre_unmap (GdkWindow *window)
{
GdkWindow *start_window = NULL;
if (window->input_only)
return;
if (window->window_type == GDK_WINDOW_CHILD)
start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
else if (window->window_type == GDK_WINDOW_TEMP)
start_window = get_root (window);
if (start_window)
_gdk_x11_window_tmp_unset_bg (start_window, TRUE);
}
static void
post_unmap (GdkWindow *window)
{
GdkWindow *start_window = NULL;
if (window->input_only)
return;
if (window->window_type == GDK_WINDOW_CHILD)
start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
else if (window->window_type == GDK_WINDOW_TEMP)
start_window = get_root (window);
if (start_window)
{
_gdk_x11_window_tmp_reset_bg (start_window, TRUE);
if (window->window_type == GDK_WINDOW_CHILD && window->parent)
{
GdkRectangle invalid_rect;
gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
invalid_rect.width = gdk_window_get_width (window);
invalid_rect.height = gdk_window_get_height (window);
gdk_window_invalidate_rect ((GdkWindow *)window->parent,
&invalid_rect, TRUE);
}
}
}
static void
gdk_window_x11_hide (GdkWindow *window)
{
/* We'll get the unmap notify eventually, and handle it then,
* but checking here makes things more consistent if we are
* just doing stuff ourself.
*/
_gdk_x11_window_grab_check_unmap (window,
NextRequest (GDK_WINDOW_XDISPLAY (window)));
/* You can't simply unmap toplevel windows. */
switch (window->window_type)
{
case GDK_WINDOW_TOPLEVEL:
case GDK_WINDOW_TEMP: /* ? */
gdk_window_withdraw (window);
return;
case GDK_WINDOW_FOREIGN:
case GDK_WINDOW_ROOT:
case GDK_WINDOW_CHILD:
break;
}
_gdk_window_clear_update_area (window);
pre_unmap (window);
XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window));
post_unmap (window);
}
static void
gdk_window_x11_withdraw (GdkWindow *window)
{
if (!window->destroyed)
{
if (GDK_WINDOW_IS_MAPPED (window))
gdk_synthesize_window_state (window,
0,
GDK_WINDOW_STATE_WITHDRAWN);
g_assert (!GDK_WINDOW_IS_MAPPED (window));
pre_unmap (window);
XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window), 0);
post_unmap (window);
}
}
static inline void
window_x11_move (GdkWindow *window,
gint x,
gint y)
{
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
{
_gdk_window_move_resize_child (window,
x, y,
window->width, window->height);
}
else
{
XMoveWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
x, y);
if (impl->override_redirect)
{
window->x = x;
window->y = y;
}
}
}
static inline void
window_x11_resize (GdkWindow *window,
gint width,
gint height)
{
if (width < 1)
width = 1;
if (height < 1)
height = 1;
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
{
_gdk_window_move_resize_child (window,
window->x, window->y,
width, height);
}
else
{
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
XResizeWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
width, height);
if (impl->override_redirect)
{
window->width = width;
window->height = height;
_gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
}
else
{
if (width != window->width || height != window->height)
window->resize_count += 1;
}
}
_gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
}
static inline void
window_x11_move_resize (GdkWindow *window,
gint x,
gint y,
gint width,
gint height)
{
if (width < 1)
width = 1;
if (height < 1)
height = 1;
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
{
_gdk_window_move_resize_child (window, x, y, width, height);
_gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
}
else
{
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
x, y, width, height);
if (impl->override_redirect)
{
window->x = x;
window->y = y;
window->width = width;
window->height = height;
_gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
}
else
{
if (width != window->width || height != window->height)
window->resize_count += 1;
}
}
}
static void
gdk_window_x11_move_resize (GdkWindow *window,
gboolean with_move,
gint x,
gint y,
gint width,
gint height)
{
if (with_move && (width < 0 && height < 0))
window_x11_move (window, x, y);
else
{
if (with_move)
window_x11_move_resize (window, x, y, width, height);
else
window_x11_resize (window, width, height);
}
}
static gboolean
gdk_window_x11_reparent (GdkWindow *window,
GdkWindow *new_parent,
gint x,
gint y)
{
GdkWindowImplX11 *impl;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
_gdk_x11_window_tmp_unset_bg (window, TRUE);
_gdk_x11_window_tmp_unset_parent_bg (window);
XReparentWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
GDK_WINDOW_XID (new_parent),
new_parent->abs_x + x, new_parent->abs_y + y);
_gdk_x11_window_tmp_reset_parent_bg (window);
_gdk_x11_window_tmp_reset_bg (window, TRUE);
if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
window->parent = new_parent;
/* Switch the window type as appropriate */
switch (GDK_WINDOW_TYPE (new_parent))
{
case GDK_WINDOW_ROOT:
case GDK_WINDOW_FOREIGN:
/* Reparenting to toplevel */
if (!WINDOW_IS_TOPLEVEL (window) &&
GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
{
/* This is also done in common code at a later stage, but we
need it in setup_toplevel, so do it here too */
if (window->toplevel_window_type != -1)
GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
/* Wasn't a toplevel, set up */
setup_toplevel_window (window, new_parent);
}
break;
case GDK_WINDOW_TOPLEVEL:
case GDK_WINDOW_CHILD:
case GDK_WINDOW_TEMP:
if (WINDOW_IS_TOPLEVEL (window) &&
impl->toplevel)
{
if (impl->toplevel->focus_window)
{
XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
_gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
}
gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
impl->toplevel);
g_free (impl->toplevel);
impl->toplevel = NULL;
}
}
return FALSE;
}
static void
gdk_window_x11_raise (GdkWindow *window)
{
XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
}
static void
gdk_window_x11_restack_under (GdkWindow *window,
GList *native_siblings /* in requested order, first is bottom-most */)
{
Window *windows;
int n_windows, i;
GList *l;
n_windows = g_list_length (native_siblings) + 1;
windows = g_new (Window, n_windows);
windows[0] = GDK_WINDOW_XID (window);
/* Reverse order, as input order is bottom-most first */
i = n_windows - 1;
for (l = native_siblings; l != NULL; l = l->next)
windows[i--] = GDK_WINDOW_XID (l->data);
XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
g_free (windows);
}
static void
gdk_window_x11_restack_toplevel (GdkWindow *window,
GdkWindow *sibling,
gboolean above)
{
XWindowChanges changes;
changes.sibling = GDK_WINDOW_XID (sibling);
changes.stack_mode = above ? Above : Below;
XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
CWStackMode | CWSibling, &changes);
}
static void
gdk_window_x11_lower (GdkWindow *window)
{
XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
}
/**
* gdk_x11_window_move_to_current_desktop:
* @window: a #GdkWindow
*
* Moves the window to the correct workspace when running under a
* window manager that supports multiple workspaces, as described
* in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
* Window Manager Hints</ulink>. Will not do anything if the
* window is already on all workspaces.
*
* Since: 2.8
*/
void
gdk_x11_window_move_to_current_desktop (GdkWindow *window)
{
GdkToplevelX11 *toplevel;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
toplevel = _gdk_x11_window_get_toplevel (window);
if (toplevel->on_all_desktops)
return;
move_to_current_desktop (window);
}
static void
move_to_current_desktop (GdkWindow *window)
{
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
{
Atom type;
gint format;
gulong nitems;
gulong bytes_after;
guchar *data;
gulong *current_desktop;
GdkDisplay *display;
display = gdk_window_get_display (window);
/* Get current desktop, then set it; this is a race, but not
* one that matters much in practice.
*/
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XROOTWIN (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
0, G_MAXLONG,
False, XA_CARDINAL, &type, &format, &nitems,
&bytes_after, &data);
if (type == XA_CARDINAL)
{
XClientMessageEvent xclient;
current_desktop = (gulong *)data;
memset (&xclient, 0, sizeof (xclient));
xclient.type = ClientMessage;
xclient.serial = 0;
xclient.send_event = True;
xclient.window = GDK_WINDOW_XID (window);
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
xclient.format = 32;
xclient.data.l[0] = *current_desktop;
xclient.data.l[1] = 0;
xclient.data.l[2] = 0;
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
XSendEvent (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XROOTWIN (window),
False,
SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient);
XFree (current_desktop);
}
}
}
static void
gdk_x11_window_focus (GdkWindow *window,
guint32 timestamp)
{
GdkDisplay *display;
g_return_if_fail (GDK_IS_WINDOW (window));
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
display = GDK_WINDOW_DISPLAY (window);
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
{
XClientMessageEvent xclient;
memset (&xclient, 0, sizeof (xclient));
xclient.type = ClientMessage;
xclient.window = GDK_WINDOW_XID (window);
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
"_NET_ACTIVE_WINDOW");
xclient.format = 32;
xclient.data.l[0] = 1; /* requestor type; we're an app */
xclient.data.l[1] = timestamp;
xclient.data.l[2] = None; /* currently active window */
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient);
}
else
{
XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
/* There is no way of knowing reliably whether we are viewable;
* _gdk_x11_set_input_focus_safe() traps errors asynchronously.
*/
_gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
RevertToParent,
timestamp);
}
}
static void
gdk_x11_window_set_type_hint (GdkWindow *window,
GdkWindowTypeHint hint)
{
GdkDisplay *display;
Atom atom;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
display = gdk_window_get_display (window);
switch (hint)
{
case GDK_WINDOW_TYPE_HINT_DIALOG:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
break;
case GDK_WINDOW_TYPE_HINT_MENU:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
break;
case GDK_WINDOW_TYPE_HINT_TOOLBAR:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
break;
case GDK_WINDOW_TYPE_HINT_UTILITY:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
break;
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
break;
case GDK_WINDOW_TYPE_HINT_DOCK:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
break;
case GDK_WINDOW_TYPE_HINT_DESKTOP:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
break;
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
break;
case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
break;
case GDK_WINDOW_TYPE_HINT_TOOLTIP:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
break;
case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
break;
case GDK_WINDOW_TYPE_HINT_COMBO:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
break;
case GDK_WINDOW_TYPE_HINT_DND:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
break;
default:
g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
/* Fall thru */
case GDK_WINDOW_TYPE_HINT_NORMAL:
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
break;
}
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
XA_ATOM, 32, PropModeReplace,
(guchar *)&atom, 1);
}
static GdkWindowTypeHint
gdk_x11_window_get_type_hint (GdkWindow *window)
{
GdkDisplay *display;
GdkWindowTypeHint type;
Atom type_return;
gint format_return;
gulong nitems_return;
gulong bytes_after_return;
guchar *data = NULL;
g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return GDK_WINDOW_TYPE_HINT_NORMAL;
type = GDK_WINDOW_TYPE_HINT_NORMAL;
display = gdk_window_get_display (window);
if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
0, G_MAXLONG, False, XA_ATOM, &type_return,
&format_return, &nitems_return, &bytes_after_return,
&data) == Success)
{
if ((type_return == XA_ATOM) && (format_return == 32) &&
(data) && (nitems_return == 1))
{
Atom atom = *(Atom*)data;
if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
type = GDK_WINDOW_TYPE_HINT_DIALOG;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
type = GDK_WINDOW_TYPE_HINT_MENU;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
type = GDK_WINDOW_TYPE_HINT_UTILITY;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
type = GDK_WINDOW_TYPE_HINT_DOCK;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
type = GDK_WINDOW_TYPE_HINT_DESKTOP;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
type = GDK_WINDOW_TYPE_HINT_COMBO;
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
type = GDK_WINDOW_TYPE_HINT_DND;
}
if (type_return != None && data != NULL)
XFree (data);
}
return type;
}
static void
gdk_wmspec_change_state (gboolean add,
GdkWindow *window,
GdkAtom state1,
GdkAtom state2)
{
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
XClientMessageEvent xclient;
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
#define _NET_WM_STATE_ADD 1 /* add/set property */
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
memset (&xclient, 0, sizeof (xclient));
xclient.type = ClientMessage;
xclient.window = GDK_WINDOW_XID (window);
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
xclient.format = 32;
xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient);
}
static void
gdk_x11_window_set_modal_hint (GdkWindow *window,
gboolean modal)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
window->modal_hint = modal;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (modal, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
GDK_NONE);
}
static void
gdk_x11_window_set_skip_taskbar_hint (GdkWindow *window,
gboolean skips_taskbar)
{
GdkToplevelX11 *toplevel;
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
toplevel = _gdk_x11_window_get_toplevel (window);
toplevel->skip_taskbar_hint = skips_taskbar;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (skips_taskbar, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
GDK_NONE);
}
static void
gdk_x11_window_set_skip_pager_hint (GdkWindow *window,
gboolean skips_pager)
{
GdkToplevelX11 *toplevel;
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
toplevel = _gdk_x11_window_get_toplevel (window);
toplevel->skip_pager_hint = skips_pager;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (skips_pager, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
GDK_NONE);
}
static void
gdk_x11_window_set_urgency_hint (GdkWindow *window,
gboolean urgent)
{
GdkToplevelX11 *toplevel;
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
toplevel = _gdk_x11_window_get_toplevel (window);
toplevel->urgency_hint = urgent;
update_wm_hints (window, FALSE);
}
static void
gdk_x11_window_set_geometry_hints (GdkWindow *window,
const GdkGeometry *geometry,
GdkWindowHints geom_mask)
{
XSizeHints size_hints;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
size_hints.flags = 0;
if (geom_mask & GDK_HINT_POS)
{
size_hints.flags |= PPosition;
/* We need to initialize the following obsolete fields because KWM
* apparently uses these fields if they are non-zero.
* #@#!#!$!.
*/
size_hints.x = 0;
size_hints.y = 0;
}
if (geom_mask & GDK_HINT_USER_POS)
{
size_hints.flags |= USPosition;
}
if (geom_mask & GDK_HINT_USER_SIZE)
{
size_hints.flags |= USSize;
}
if (geom_mask & GDK_HINT_MIN_SIZE)
{
size_hints.flags |= PMinSize;
size_hints.min_width = geometry->min_width;
size_hints.min_height = geometry->min_height;
}
if (geom_mask & GDK_HINT_MAX_SIZE)
{
size_hints.flags |= PMaxSize;
size_hints.max_width = MAX (geometry->max_width, 1);
size_hints.max_height = MAX (geometry->max_height, 1);
}
if (geom_mask & GDK_HINT_BASE_SIZE)
{
size_hints.flags |= PBaseSize;
size_hints.base_width = geometry->base_width;
size_hints.base_height = geometry->base_height;
}
if (geom_mask & GDK_HINT_RESIZE_INC)
{
size_hints.flags |= PResizeInc;
size_hints.width_inc = geometry->width_inc;
size_hints.height_inc = geometry->height_inc;
}
if (geom_mask & GDK_HINT_ASPECT)
{
size_hints.flags |= PAspect;
if (geometry->min_aspect <= 1)
{
size_hints.min_aspect.x = 65536 * geometry->min_aspect;
size_hints.min_aspect.y = 65536;
}
else
{
size_hints.min_aspect.x = 65536;
size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
}
if (geometry->max_aspect <= 1)
{
size_hints.max_aspect.x = 65536 * geometry->max_aspect;
size_hints.max_aspect.y = 65536;
}
else
{
size_hints.max_aspect.x = 65536;
size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
}
}
if (geom_mask & GDK_HINT_WIN_GRAVITY)
{
size_hints.flags |= PWinGravity;
size_hints.win_gravity = geometry->win_gravity;
}
/* FIXME: Would it be better to delete this property if
* geom_mask == 0? It would save space on the server
*/
XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
&size_hints);
}
static void
gdk_window_get_geometry_hints (GdkWindow *window,
GdkGeometry *geometry,
GdkWindowHints *geom_mask)
{
XSizeHints *size_hints;
glong junk_supplied_mask = 0;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (geometry != NULL);
g_return_if_fail (geom_mask != NULL);
*geom_mask = 0;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
size_hints = XAllocSizeHints ();
if (!size_hints)
return;
if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
size_hints,
&junk_supplied_mask))
size_hints->flags = 0;
if (size_hints->flags & PMinSize)
{
*geom_mask |= GDK_HINT_MIN_SIZE;
geometry->min_width = size_hints->min_width;
geometry->min_height = size_hints->min_height;
}
if (size_hints->flags & PMaxSize)
{
*geom_mask |= GDK_HINT_MAX_SIZE;
geometry->max_width = MAX (size_hints->max_width, 1);
geometry->max_height = MAX (size_hints->max_height, 1);
}
if (size_hints->flags & PResizeInc)
{
*geom_mask |= GDK_HINT_RESIZE_INC;
geometry->width_inc = size_hints->width_inc;
geometry->height_inc = size_hints->height_inc;
}
if (size_hints->flags & PAspect)
{
*geom_mask |= GDK_HINT_ASPECT;
geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
}
if (size_hints->flags & PWinGravity)
{
*geom_mask |= GDK_HINT_WIN_GRAVITY;
geometry->win_gravity = size_hints->win_gravity;
}
XFree (size_hints);
}
static gboolean
utf8_is_latin1 (const gchar *str)
{
const char *p = str;
while (*p)
{
gunichar ch = g_utf8_get_char (p);
if (ch > 0xff)
return FALSE;
p = g_utf8_next_char (p);
}
return TRUE;
}
/* Set the property to @utf8_str as STRING if the @utf8_str is fully
* convertable to STRING, otherwise, set it as compound text
*/
static void
set_text_property (GdkDisplay *display,
Window xwindow,
Atom property,
const gchar *utf8_str)
{
gchar *prop_text = NULL;
Atom prop_type;
gint prop_length;
gint prop_format;
gboolean is_compound_text;
if (utf8_is_latin1 (utf8_str))
{
prop_type = XA_STRING;
prop_text = gdk_utf8_to_string_target (utf8_str);
prop_length = prop_text ? strlen (prop_text) : 0;
prop_format = 8;
is_compound_text = FALSE;
}
else
{
GdkAtom gdk_type;
gdk_utf8_to_compound_text_for_display (display,
utf8_str, &gdk_type, &prop_format,
(guchar **)&prop_text, &prop_length);
prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
is_compound_text = TRUE;
}
if (prop_text)
{
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
xwindow,
property,
prop_type, prop_format,
PropModeReplace, (guchar *)prop_text,
prop_length);
if (is_compound_text)
gdk_free_compound_text ((guchar *)prop_text);
else
g_free (prop_text);
}
}
/* Set WM_NAME and _NET_WM_NAME
*/
static void
set_wm_name (GdkDisplay *display,
Window xwindow,
const gchar *name)
{
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
PropModeReplace, (guchar *)name, strlen (name));
set_text_property (display, xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
name);
}
static void
gdk_x11_window_set_title (GdkWindow *window,
const gchar *title)
{
GdkDisplay *display;
Display *xdisplay;
Window xwindow;
g_return_if_fail (title != NULL);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
display = gdk_window_get_display (window);
xdisplay = GDK_DISPLAY_XDISPLAY (display);
xwindow = GDK_WINDOW_XID (window);
set_wm_name (display, xwindow, title);
if (!gdk_window_icon_name_set (window))
{
XChangeProperty (xdisplay, xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
PropModeReplace, (guchar *)title, strlen (title));
set_text_property (display, xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
title);
}
}
static void
gdk_x11_window_set_role (GdkWindow *window,
const gchar *role)
{
GdkDisplay *display;
display = gdk_window_get_display (window);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (role)
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
else
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
}
static void
gdk_x11_window_set_startup_id (GdkWindow *window,
const gchar *startup_id)
{
GdkDisplay *display;
g_return_if_fail (GDK_IS_WINDOW (window));
display = gdk_window_get_display (window);
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (startup_id)
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
else
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
}
static void
gdk_x11_window_set_transient_for (GdkWindow *window,
GdkWindow *parent)
{
if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
GDK_WINDOW_XID (parent));
}
static gboolean
gdk_window_x11_set_back_color (GdkWindow *window,
double red,
double green,
double blue,
double alpha)
{
GdkVisual *visual = gdk_window_get_visual (window);
/* I suppose we could handle these, but that'd require fiddling with
* xrender formats... */
if (alpha != 1.0)
return FALSE;
switch (visual->type)
{
case GDK_VISUAL_DIRECT_COLOR:
case GDK_VISUAL_TRUE_COLOR:
{
/* If bits not used for color are used for something other than padding,
* it's likely alpha, so we set them to 1s.
*/
guint padding, pixel;
/* Shifting by >= width-of-type isn't defined in C */
if (visual->depth >= 32)
padding = 0;
else
padding = ((~(guint32)0)) << visual->depth;
pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
(((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
(((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window), pixel);
}
return TRUE;
/* These require fiddling with the colormap, and as they're essentially unused
* we're just gonna skip them for now.
*/
case GDK_VISUAL_PSEUDO_COLOR:
case GDK_VISUAL_GRAYSCALE:
case GDK_VISUAL_STATIC_GRAY:
case GDK_VISUAL_STATIC_COLOR:
default:
break;
}
return FALSE;
}
static gboolean
matrix_is_identity (cairo_matrix_t *matrix)
{
return matrix->xx == 1.0 && matrix->yy == 1.0 &&
matrix->yx == 0.0 && matrix->xy == 0.0 &&
matrix->x0 == 0.0 && matrix->y0 == 0.0;
}
static void
gdk_window_x11_set_background (GdkWindow *window,
cairo_pattern_t *pattern)
{
double r, g, b, a;
cairo_surface_t *surface;
cairo_matrix_t matrix;
if (GDK_WINDOW_DESTROYED (window))
return;
if (pattern == NULL)
{
GdkWindow *parent;
/* X throws BadMatch if the parent has a different visual when
* using ParentRelative */
parent = gdk_window_get_parent (window);
if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window), ParentRelative);
else
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window), None);
return;
}
switch (cairo_pattern_get_type (pattern))
{
case CAIRO_PATTERN_TYPE_SOLID:
cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
if (gdk_window_x11_set_back_color (window, r, g, b, a))
return;
break;
case CAIRO_PATTERN_TYPE_SURFACE:
cairo_pattern_get_matrix (pattern, &matrix);
if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
matrix_is_identity (&matrix) &&
cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
{
double x, y;
cairo_surface_get_device_offset (surface, &x, &y);
/* XXX: This still bombs for non-pixmaps, but there's no way to
* detect we're not a pixmap in Cairo... */
if (x == 0.0 && y == 0.0)
{
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
cairo_xlib_surface_get_drawable (surface));
return;
}
}
/* fall through */
case CAIRO_PATTERN_TYPE_LINEAR:
case CAIRO_PATTERN_TYPE_RADIAL:
default:
/* fallback: just use black */
break;
}
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window), None);
}
static void
gdk_window_x11_set_device_cursor (GdkWindow *window,
GdkDevice *device,
GdkCursor *cursor)
{
GdkWindowImplX11 *impl;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (GDK_IS_DEVICE (device));
impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (!cursor)
g_hash_table_remove (impl->device_cursor, device);
else
{
_gdk_x11_cursor_update_theme (cursor);
g_hash_table_replace (impl->device_cursor,
device, gdk_cursor_ref (cursor));
}
if (!GDK_WINDOW_DESTROYED (window))
GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
}
GdkCursor *
_gdk_x11_window_get_cursor (GdkWindow *window)
{
GdkWindowImplX11 *impl;
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
impl = GDK_WINDOW_IMPL_X11 (window->impl);
return impl->cursor;
}
static void
gdk_window_x11_get_geometry (GdkWindow *window,
gint *x,
gint *y,
gint *width,
gint *height)
{
Window root;
gint tx;
gint ty;
guint twidth;
guint theight;
guint tborder_width;
guint tdepth;
if (!GDK_WINDOW_DESTROYED (window))
{
XGetGeometry (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
&root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
if (x)
*x = tx;
if (y)
*y = ty;
if (width)
*width = twidth;
if (height)
*height = theight;
}
}
static gint
gdk_window_x11_get_root_coords (GdkWindow *window,
gint x,
gint y,
gint *root_x,
gint *root_y)
{
gint return_val;
Window child;
gint tx;
gint ty;
return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
GDK_WINDOW_XROOTWIN (window),
x, y, &tx, &ty,
&child);
if (root_x)
*root_x = tx;
if (root_y)
*root_y = ty;
return return_val;
}
static void
gdk_x11_window_get_root_origin (GdkWindow *window,
gint *x,
gint *y)
{
GdkRectangle rect;
gdk_window_get_frame_extents (window, &rect);
if (x)
*x = rect.x;
if (y)
*y = rect.y;
}
static void
gdk_x11_window_get_frame_extents (GdkWindow *window,
GdkRectangle *rect)
{
GdkDisplay *display;
GdkWindowImplX11 *impl;
Window xwindow;
Window xparent;
Window root;
Window child;
Window *children;
guchar *data;
Window *vroots;
Atom type_return;
guint nchildren;
guint nvroots;
gulong nitems_return;
gulong bytes_after_return;
gint format_return;
gint i;
guint ww, wh, wb, wd;
gint wx, wy;
gboolean got_frame_extents = FALSE;
g_return_if_fail (rect != NULL);
rect->x = 0;
rect->y = 0;
rect->width = 1;
rect->height = 1;
while (window->parent && (window->parent)->parent)
window = window->parent;
/* Refine our fallback answer a bit using local information */
rect->x = window->x;
rect->y = window->y;
rect->width = window->width;
rect->height = window->height;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (GDK_WINDOW_DESTROYED (window) || impl->override_redirect)
return;
nvroots = 0;
vroots = NULL;
display = gdk_window_get_display (window);
gdk_x11_display_error_trap_push (display);
xwindow = GDK_WINDOW_XID (window);
/* first try: use _NET_FRAME_EXTENTS */
if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
gdk_x11_get_xatom_by_name_for_display (display,
"_NET_FRAME_EXTENTS"),
0, G_MAXLONG, False, XA_CARDINAL, &type_return,
&format_return, &nitems_return, &bytes_after_return,
&data)
== Success)
{
if ((type_return == XA_CARDINAL) && (format_return == 32) &&
(nitems_return == 4) && (data))
{
gulong *ldata = (gulong *) data;
got_frame_extents = TRUE;
/* try to get the real client window geometry */
if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
&root, &wx, &wy, &ww, &wh, &wb, &wd) &&
XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
xwindow, root, 0, 0, &wx, &wy, &child))
{
rect->x = wx;
rect->y = wy;
rect->width = ww;
rect->height = wh;
}
/* _NET_FRAME_EXTENTS format is left, right, top, bottom */
rect->x -= ldata[0];
rect->y -= ldata[2];
rect->width += ldata[0] + ldata[1];
rect->height += ldata[2] + ldata[3];
}
if (data)
XFree (data);
}
if (got_frame_extents)
goto out;
/* no frame extents property available, which means we either have a WM that
is not EWMH compliant or is broken - try fallback and walk up the window
tree to get our window's parent which hopefully is the window frame */
/* use NETWM_VIRTUAL_ROOTS if available */
root = GDK_WINDOW_XROOTWIN (window);
if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
gdk_x11_get_xatom_by_name_for_display (display,
"_NET_VIRTUAL_ROOTS"),
0, G_MAXLONG, False, XA_WINDOW, &type_return,
&format_return, &nitems_return, &bytes_after_return,
&data)
== Success)
{
if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
{
nvroots = nitems_return;
vroots = (Window *)data;
}
}
xparent = GDK_WINDOW_XID (window);
do
{
xwindow = xparent;
if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
&root, &xparent,
&children, &nchildren))
goto out;
if (children)
XFree (children);
/* check virtual roots */
for (i = 0; i < nvroots; i++)
{
if (xparent == vroots[i])
{
root = xparent;
break;
}
}
}
while (xparent != root);
if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
&root, &wx, &wy, &ww, &wh, &wb, &wd))
{
rect->x = wx;
rect->y = wy;
rect->width = ww;
rect->height = wh;
}
out:
if (vroots)
XFree (vroots);
gdk_x11_display_error_trap_pop_ignored (display);
}
static gboolean
gdk_window_x11_get_device_state (GdkWindow *window,
GdkDevice *device,
gint *x,
gint *y,
GdkModifierType *mask)
{
GdkWindow *child;
g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
if (GDK_WINDOW_DESTROYED (window))
return FALSE;
GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
NULL, &child,
NULL, NULL,
x, y, mask);
return child != NULL;
}
static GdkEventMask
gdk_window_x11_get_events (GdkWindow *window)
{
XWindowAttributes attrs;
GdkEventMask event_mask;
GdkEventMask filtered;
if (GDK_WINDOW_DESTROYED (window))
return 0;
else
{
XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
&attrs);
event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
/* if property change was filtered out before, keep it filtered out */
filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
window->event_mask = event_mask & ((window->event_mask & filtered) | ~filtered);
return event_mask;
}
}
static void
gdk_window_x11_set_events (GdkWindow *window,
GdkEventMask event_mask)
{
long xevent_mask = 0;
if (!GDK_WINDOW_DESTROYED (window))
{
GdkDisplayX11 *display_x11;
if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
xevent_mask = StructureNotifyMask | PropertyChangeMask;
display_x11 = GDK_DISPLAY_X11 (gdk_window_get_display (window));
gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
GDK_WINDOW_XID (window), event_mask,
xevent_mask);
}
}
static inline void
do_shape_combine_region (GdkWindow *window,
const cairo_region_t *shape_region,
gint offset_x,
gint offset_y,
gint shape)
{
if (GDK_WINDOW_DESTROYED (window))
return;
if (shape_region == NULL)
{
/* Use NULL mask to unset the shape */
if (shape == ShapeBounding
? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
: gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
{
if (shape == ShapeBounding)
{
_gdk_x11_window_tmp_unset_parent_bg (window);
_gdk_x11_window_tmp_unset_bg (window, TRUE);
}
XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
shape,
0, 0,
None,
ShapeSet);
if (shape == ShapeBounding)
{
_gdk_x11_window_tmp_reset_parent_bg (window);
_gdk_x11_window_tmp_reset_bg (window, TRUE);
}
}
return;
}
if (shape == ShapeBounding
? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
: gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
{
gint n_rects = 0;
XRectangle *xrects = NULL;
_gdk_x11_region_get_xrectangles (shape_region,
0, 0,
&xrects, &n_rects);
if (shape == ShapeBounding)
{
_gdk_x11_window_tmp_unset_parent_bg (window);
_gdk_x11_window_tmp_unset_bg (window, TRUE);
}
XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
shape,
offset_x, offset_y,
xrects, n_rects,
ShapeSet,
YXBanded);
if (shape == ShapeBounding)
{
_gdk_x11_window_tmp_reset_parent_bg (window);
_gdk_x11_window_tmp_reset_bg (window, TRUE);
}
g_free (xrects);
}
}
static void
gdk_window_x11_shape_combine_region (GdkWindow *window,
const cairo_region_t *shape_region,
gint offset_x,
gint offset_y)
{
do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
}
static void
gdk_window_x11_input_shape_combine_region (GdkWindow *window,
const cairo_region_t *shape_region,
gint offset_x,
gint offset_y)
{
#ifdef ShapeInput
do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
#endif
}
static void
gdk_x11_window_set_override_redirect (GdkWindow *window,
gboolean override_redirect)
{
XSetWindowAttributes attr;
if (!GDK_WINDOW_DESTROYED (window) &&
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
{
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
attr.override_redirect = (override_redirect? True : False);
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
CWOverrideRedirect,
&attr);
impl->override_redirect = attr.override_redirect;
}
}
static void
gdk_x11_window_set_accept_focus (GdkWindow *window,
gboolean accept_focus)
{
accept_focus = accept_focus != FALSE;
if (window->accept_focus != accept_focus)
{
window->accept_focus = accept_focus;
if (!GDK_WINDOW_DESTROYED (window) &&
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
update_wm_hints (window, FALSE);
}
}
static void
gdk_x11_window_set_focus_on_map (GdkWindow *window,
gboolean focus_on_map)
{
focus_on_map = focus_on_map != FALSE;
if (window->focus_on_map != focus_on_map)
{
window->focus_on_map = focus_on_map;
if ((!GDK_WINDOW_DESTROYED (window)) &&
(!window->focus_on_map) &&
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
gdk_x11_window_set_user_time (window, 0);
}
}
/**
* gdk_x11_window_set_user_time:
* @window: A toplevel #GdkWindow
* @timestamp: An XServer timestamp to which the property should be set
*
* The application can use this call to update the _NET_WM_USER_TIME
* property on a toplevel window. This property stores an Xserver
* time which represents the time of the last user input event
* received for this window. This property may be used by the window
* manager to alter the focus, stacking, and/or placement behavior of
* windows when they are mapped depending on whether the new window
* was created by a user action or is a "pop-up" window activated by a
* timer or some other event.
*
* Note that this property is automatically updated by GDK, so this
* function should only be used by applications which handle input
* events bypassing GDK.
*
* Since: 2.6
**/
void
gdk_x11_window_set_user_time (GdkWindow *window,
guint32 timestamp)
{
GdkDisplay *display;
GdkDisplayX11 *display_x11;
GdkToplevelX11 *toplevel;
glong timestamp_long = (glong)timestamp;
Window xid;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
display = gdk_window_get_display (window);
display_x11 = GDK_DISPLAY_X11 (display);
toplevel = _gdk_x11_window_get_toplevel (window);
if (!toplevel)
{
g_warning ("gdk_window_set_user_time called on non-toplevel\n");
return;
}
if (toplevel->focus_window != None &&
gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
xid = toplevel->focus_window;
else
xid = GDK_WINDOW_XID (window);
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
XA_CARDINAL, 32, PropModeReplace,
(guchar *)×tamp_long, 1);
if (timestamp_long != GDK_CURRENT_TIME &&
(display_x11->user_time == GDK_CURRENT_TIME ||
XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
display_x11->user_time = timestamp_long;
if (toplevel)
toplevel->user_time = timestamp_long;
}
#define GDK_SELECTION_MAX_SIZE(display) \
MIN(262144, \
XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
: XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
static void
gdk_window_update_icon (GdkWindow *window,
GList *icon_list)
{
GdkToplevelX11 *toplevel;
GdkPixbuf *best_icon;
GList *tmp_list;
int best_size;
toplevel = _gdk_x11_window_get_toplevel (window);
if (toplevel->icon_pixmap != NULL)
{
cairo_surface_destroy (toplevel->icon_pixmap);
toplevel->icon_pixmap = NULL;
}
if (toplevel->icon_mask != NULL)
{
cairo_surface_destroy (toplevel->icon_mask);
toplevel->icon_mask = NULL;
}
#define IDEAL_SIZE 48
best_size = G_MAXINT;
best_icon = NULL;
for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
{
GdkPixbuf *pixbuf = tmp_list->data;
int this;
/* average width and height - if someone passes in a rectangular
* icon they deserve what they get.
*/
this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
this /= 2;
if (best_icon == NULL)
{
best_icon = pixbuf;
best_size = this;
}
else
{
/* icon is better if it's 32 pixels or larger, and closer to
* the ideal size than the current best.
*/
if (this >= 32 &&
(ABS (best_size - IDEAL_SIZE) <
ABS (this - IDEAL_SIZE)))
{
best_icon = pixbuf;
best_size = this;
}
}
}
if (best_icon)
{
int width = gdk_pixbuf_get_width (best_icon);
int height = gdk_pixbuf_get_height (best_icon);
cairo_t *cr;
toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
width,
height);
cr = cairo_create (toplevel->icon_pixmap);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
if (gdk_pixbuf_get_has_alpha (best_icon))
{
/* Saturate the image, so it has bilevel alpha */
cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
cairo_paint (cr);
cairo_pop_group_to_source (cr);
}
cairo_paint (cr);
cairo_destroy (cr);
if (gdk_pixbuf_get_has_alpha (best_icon))
{
toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
width,
height);
cr = cairo_create (toplevel->icon_mask);
gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
cairo_destroy (cr);
}
}
update_wm_hints (window, FALSE);
}
static void
gdk_x11_window_set_icon_list (GdkWindow *window,
GList *pixbufs)
{
gulong *data;
guchar *pixels;
gulong *p;
gint size;
GList *l;
GdkPixbuf *pixbuf;
gint width, height, stride;
gint x, y;
gint n_channels;
GdkDisplay *display;
gint n;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
display = gdk_window_get_display (window);
l = pixbufs;
size = 0;
n = 0;
while (l)
{
pixbuf = l->data;
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
/* silently ignore overlarge icons */
if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
{
g_warning ("gdk_window_set_icon_list: icons too large");
break;
}
n++;
size += 2 + width * height;
l = g_list_next (l);
}
data = g_malloc (size * sizeof (gulong));
l = pixbufs;
p = data;
while (l && n > 0)
{
pixbuf = l->data;
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
stride = gdk_pixbuf_get_rowstride (pixbuf);
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
*p++ = width;
*p++ = height;
pixels = gdk_pixbuf_get_pixels (pixbuf);
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
guchar r, g, b, a;
r = pixels[y*stride + x*n_channels + 0];
g = pixels[y*stride + x*n_channels + 1];
b = pixels[y*stride + x*n_channels + 2];
if (n_channels >= 4)
a = pixels[y*stride + x*n_channels + 3];
else
a = 255;
*p++ = a << 24 | r << 16 | g << 8 | b ;
}
}
l = g_list_next (l);
n--;
}
if (size > 0)
{
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
XA_CARDINAL, 32,
PropModeReplace,
(guchar*) data, size);
}
else
{
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
}
g_free (data);
gdk_window_update_icon (window, pixbufs);
}
static gboolean
gdk_window_icon_name_set (GdkWindow *window)
{
return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
g_quark_from_static_string ("gdk-icon-name-set")));
}
static void
gdk_x11_window_set_icon_name (GdkWindow *window,
const gchar *name)
{
GdkDisplay *display;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
display = gdk_window_get_display (window);
g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
GUINT_TO_POINTER (name != NULL));
if (name != NULL)
{
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
PropModeReplace, (guchar *)name, strlen (name));
set_text_property (display, GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
name);
}
else
{
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
}
}
static void
gdk_x11_window_iconify (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
{
XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
}
else
{
/* Flip our client side flag, the real work happens on map. */
gdk_synthesize_window_state (window,
0,
GDK_WINDOW_STATE_ICONIFIED);
}
}
static void
gdk_x11_window_deiconify (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
{
gdk_window_show (window);
}
else
{
/* Flip our client side flag, the real work happens on map. */
gdk_synthesize_window_state (window,
GDK_WINDOW_STATE_ICONIFIED,
0);
}
}
static void
gdk_x11_window_stick (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
{
/* "stick" means stick to all desktops _and_ do not scroll with the
* viewport. i.e. glue to the monitor glass in all cases.
*/
XClientMessageEvent xclient;
/* Request stick during viewport scroll */
gdk_wmspec_change_state (TRUE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
GDK_NONE);
/* Request desktop 0xFFFFFFFF */
memset (&xclient, 0, sizeof (xclient));
xclient.type = ClientMessage;
xclient.window = GDK_WINDOW_XID (window);
xclient.display = GDK_WINDOW_XDISPLAY (window);
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
"_NET_WM_DESKTOP");
xclient.format = 32;
xclient.data.l[0] = 0xFFFFFFFF;
xclient.data.l[1] = 0;
xclient.data.l[2] = 0;
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient);
}
else
{
/* Flip our client side flag, the real work happens on map. */
gdk_synthesize_window_state (window,
0,
GDK_WINDOW_STATE_STICKY);
}
}
static void
gdk_x11_window_unstick (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
{
/* Request unstick from viewport */
gdk_wmspec_change_state (FALSE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
GDK_NONE);
move_to_current_desktop (window);
}
else
{
/* Flip our client side flag, the real work happens on map. */
gdk_synthesize_window_state (window,
GDK_WINDOW_STATE_STICKY,
0);
}
}
static void
gdk_x11_window_maximize (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (TRUE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
else
gdk_synthesize_window_state (window,
0,
GDK_WINDOW_STATE_MAXIMIZED);
}
static void
gdk_x11_window_unmaximize (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (FALSE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
else
gdk_synthesize_window_state (window,
GDK_WINDOW_STATE_MAXIMIZED,
0);
}
static void
gdk_x11_window_fullscreen (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (TRUE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
GDK_NONE);
else
gdk_synthesize_window_state (window,
0,
GDK_WINDOW_STATE_FULLSCREEN);
}
static void
gdk_x11_window_unfullscreen (GdkWindow *window)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
gdk_wmspec_change_state (FALSE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
GDK_NONE);
else
gdk_synthesize_window_state (window,
GDK_WINDOW_STATE_FULLSCREEN,
0);
}
static void
gdk_x11_window_set_keep_above (GdkWindow *window,
gboolean setting)
{
g_return_if_fail (GDK_IS_WINDOW (window));
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
{
if (setting)
gdk_wmspec_change_state (FALSE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
GDK_NONE);
gdk_wmspec_change_state (setting, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
GDK_NONE);
}
else
gdk_synthesize_window_state (window,
setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
setting ? GDK_WINDOW_STATE_ABOVE : 0);
}
static void
gdk_x11_window_set_keep_below (GdkWindow *window, gboolean setting)
{
g_return_if_fail (GDK_IS_WINDOW (window));
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (GDK_WINDOW_IS_MAPPED (window))
{
if (setting)
gdk_wmspec_change_state (FALSE, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
GDK_NONE);
gdk_wmspec_change_state (setting, window,
gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
GDK_NONE);
}
else
gdk_synthesize_window_state (window,
setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
setting ? GDK_WINDOW_STATE_BELOW : 0);
}
static GdkWindow *
gdk_x11_window_get_group (GdkWindow *window)
{
GdkToplevelX11 *toplevel;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL (window))
return NULL;
toplevel = _gdk_x11_window_get_toplevel (window);
return toplevel->group_leader;
}
static void
gdk_x11_window_set_group (GdkWindow *window,
GdkWindow *leader)
{
GdkToplevelX11 *toplevel;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
if (GDK_WINDOW_DESTROYED (window) ||
(leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
!WINDOW_IS_TOPLEVEL (window))
return;
toplevel = _gdk_x11_window_get_toplevel (window);
if (leader == NULL)
leader = gdk_display_get_default_group (gdk_window_get_display (window));
if (toplevel->group_leader != leader)
{
if (toplevel->group_leader)
g_object_unref (toplevel->group_leader);
toplevel->group_leader = g_object_ref (leader);
(_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
}
update_wm_hints (window, FALSE);
}
static MotifWmHints *
gdk_window_get_mwm_hints (GdkWindow *window)
{
GdkDisplay *display;
Atom hints_atom = None;
guchar *data;
Atom type;
gint format;
gulong nitems;
gulong bytes_after;
if (GDK_WINDOW_DESTROYED (window))
return NULL;
display = gdk_window_get_display (window);
hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
False, AnyPropertyType, &type, &format, &nitems,
&bytes_after, &data);
if (type == None)
return NULL;
return (MotifWmHints *)data;
}
static void
gdk_window_set_mwm_hints (GdkWindow *window,
MotifWmHints *new_hints)
{
GdkDisplay *display;
Atom hints_atom = None;
guchar *data;
MotifWmHints *hints;
Atom type;
gint format;
gulong nitems;
gulong bytes_after;
if (GDK_WINDOW_DESTROYED (window))
return;
display = gdk_window_get_display (window);
hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
False, AnyPropertyType, &type, &format, &nitems,
&bytes_after, &data);
if (type == None)
hints = new_hints;
else
{
hints = (MotifWmHints *)data;
if (new_hints->flags & MWM_HINTS_FUNCTIONS)
{
hints->flags |= MWM_HINTS_FUNCTIONS;
hints->functions = new_hints->functions;
}
if (new_hints->flags & MWM_HINTS_DECORATIONS)
{
hints->flags |= MWM_HINTS_DECORATIONS;
hints->decorations = new_hints->decorations;
}
}
XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
hints_atom, hints_atom, 32, PropModeReplace,
(guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
if (hints != new_hints)
XFree (hints);
}
static void
gdk_x11_window_set_decorations (GdkWindow *window,
GdkWMDecoration decorations)
{
MotifWmHints hints;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
/* initialize to zero to avoid writing uninitialized data to socket */
memset(&hints, 0, sizeof(hints));
hints.flags = MWM_HINTS_DECORATIONS;
hints.decorations = decorations;
gdk_window_set_mwm_hints (window, &hints);
}
static gboolean
gdk_x11_window_get_decorations(GdkWindow *window,
GdkWMDecoration *decorations)
{
MotifWmHints *hints;
gboolean result = FALSE;
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return FALSE;
hints = gdk_window_get_mwm_hints (window);
if (hints)
{
if (hints->flags & MWM_HINTS_DECORATIONS)
{
if (decorations)
*decorations = hints->decorations;
result = TRUE;
}
XFree (hints);
}
return result;
}
static void
gdk_x11_window_set_functions (GdkWindow *window,
GdkWMFunction functions)
{
MotifWmHints hints;
g_return_if_fail (GDK_IS_WINDOW (window));
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
/* initialize to zero to avoid writing uninitialized data to socket */
memset(&hints, 0, sizeof(hints));
hints.flags = MWM_HINTS_FUNCTIONS;
hints.functions = functions;
gdk_window_set_mwm_hints (window, &hints);
}
cairo_region_t *
_gdk_x11_xwindow_get_shape (Display *xdisplay,
Window window,
gint shape_type)
{
cairo_region_t *shape;
GdkRectangle *rl;
XRectangle *xrl;
gint rn, ord, i;
shape = NULL;
rn = 0;
xrl = XShapeGetRectangles (xdisplay,
window,
shape_type, &rn, &ord);
if (xrl == NULL || rn == 0)
return cairo_region_create (); /* Empty */
if (ord != YXBanded)
{
/* This really shouldn't happen with any xserver, as they
generally convert regions to YXBanded internally */
g_warning ("non YXBanded shape masks not supported");
XFree (xrl);
return NULL;
}
rl = g_new (GdkRectangle, rn);
for (i = 0; i < rn; i++)
{
rl[i].x = xrl[i].x;
rl[i].y = xrl[i].y;
rl[i].width = xrl[i].width;
rl[i].height = xrl[i].height;
}
XFree (xrl);
shape = cairo_region_create_rectangles (rl, rn);
g_free (rl);
return shape;
}
static cairo_region_t *
gdk_x11_window_get_shape (GdkWindow *window)
{
if (!GDK_WINDOW_DESTROYED (window) &&
gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
ShapeBounding);
return NULL;
}
static cairo_region_t *
gdk_x11_window_get_input_shape (GdkWindow *window)
{
#if defined(ShapeInput)
if (!GDK_WINDOW_DESTROYED (window) &&
gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
ShapeInput);
#endif
return NULL;
}
static void
gdk_window_set_static_bit_gravity (GdkWindow *window,
gboolean on)
{
XSetWindowAttributes xattributes;
guint xattributes_mask = 0;
g_return_if_fail (GDK_IS_WINDOW (window));
if (window->input_only)
return;
xattributes.bit_gravity = StaticGravity;
xattributes_mask |= CWBitGravity;
xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
CWBitGravity, &xattributes);
}
static void
gdk_window_set_static_win_gravity (GdkWindow *window,
gboolean on)
{
XSetWindowAttributes xattributes;
g_return_if_fail (GDK_IS_WINDOW (window));
xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
CWWinGravity, &xattributes);
}
static gboolean
gdk_window_x11_set_static_gravities (GdkWindow *window,
gboolean use_static)
{
GList *tmp_list;
if (!use_static == !window->guffaw_gravity)
return TRUE;
window->guffaw_gravity = use_static;
if (!GDK_WINDOW_DESTROYED (window))
{
gdk_window_set_static_bit_gravity (window, use_static);
tmp_list = window->children;
while (tmp_list)
{
gdk_window_set_static_win_gravity (tmp_list->data, use_static);
tmp_list = tmp_list->next;
}
}
return TRUE;
}
static void
wmspec_moveresize (GdkWindow *window,
gint direction,
gint root_x,
gint root_y,
guint32 timestamp)
{
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
XClientMessageEvent xclient;
/* Release passive grab */
gdk_display_pointer_ungrab (display, timestamp);
memset (&xclient, 0, sizeof (xclient));
xclient.type = ClientMessage;
xclient.window = GDK_WINDOW_XID (window);
xclient.message_type =
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
xclient.format = 32;
xclient.data.l[0] = root_x;
xclient.data.l[1] = root_y;
xclient.data.l[2] = direction;
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient);
}
typedef struct _MoveResizeData MoveResizeData;
struct _MoveResizeData
{
GdkDisplay *display;
GdkWindow *moveresize_window;
GdkWindow *moveresize_emulation_window;
gboolean is_resize;
GdkWindowEdge resize_edge;
gint moveresize_button;
gint moveresize_x;
gint moveresize_y;
gint moveresize_orig_x;
gint moveresize_orig_y;
gint moveresize_orig_width;
gint moveresize_orig_height;
GdkWindowHints moveresize_geom_mask;
GdkGeometry moveresize_geometry;
Time moveresize_process_time;
XEvent *moveresize_pending_event;
};
/* From the WM spec */
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
#define _NET_WM_MOVERESIZE_SIZE_TOP 1
#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
#define _NET_WM_MOVERESIZE_MOVE 8
static void
wmspec_resize_drag (GdkWindow *window,
GdkWindowEdge edge,
gint button,
gint root_x,
gint root_y,
guint32 timestamp)
{
gint direction;
/* Let the compiler turn a switch into a table, instead
* of doing the table manually, this way is easier to verify.
*/
switch (edge)
{
case GDK_WINDOW_EDGE_NORTH_WEST:
direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
break;
case GDK_WINDOW_EDGE_NORTH:
direction = _NET_WM_MOVERESIZE_SIZE_TOP;
break;
case GDK_WINDOW_EDGE_NORTH_EAST:
direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
break;
case GDK_WINDOW_EDGE_WEST:
direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
break;
case GDK_WINDOW_EDGE_EAST:
direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
break;
case GDK_WINDOW_EDGE_SOUTH_WEST:
direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
break;
case GDK_WINDOW_EDGE_SOUTH:
direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
break;
case GDK_WINDOW_EDGE_SOUTH_EAST:
direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
break;
default:
g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
edge);
return;
}
wmspec_moveresize (window, direction, root_x, root_y, timestamp);
}
static MoveResizeData *
get_move_resize_data (GdkDisplay *display,
gboolean create)
{
MoveResizeData *mv_resize;
static GQuark move_resize_quark = 0;
if (!move_resize_quark)
move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
if (!mv_resize && create)
{
mv_resize = g_new0 (MoveResizeData, 1);
mv_resize->display = display;
g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
}
return mv_resize;
}
static void
update_pos (MoveResizeData *mv_resize,
gint new_root_x,
gint new_root_y)
{
gint dx, dy;
dx = new_root_x - mv_resize->moveresize_x;
dy = new_root_y - mv_resize->moveresize_y;
if (mv_resize->is_resize)
{
gint x, y, w, h;
x = mv_resize->moveresize_orig_x;
y = mv_resize->moveresize_orig_y;
w = mv_resize->moveresize_orig_width;
h = mv_resize->moveresize_orig_height;
switch (mv_resize->resize_edge)
{
case GDK_WINDOW_EDGE_NORTH_WEST:
x += dx;
y += dy;
w -= dx;
h -= dy;
break;
case GDK_WINDOW_EDGE_NORTH:
y += dy;
h -= dy;
break;
case GDK_WINDOW_EDGE_NORTH_EAST:
y += dy;
h -= dy;
w += dx;
break;
case GDK_WINDOW_EDGE_SOUTH_WEST:
h += dy;
x += dx;
w -= dx;
break;
case GDK_WINDOW_EDGE_SOUTH_EAST:
w += dx;
h += dy;
break;
case GDK_WINDOW_EDGE_SOUTH:
h += dy;
break;
case GDK_WINDOW_EDGE_EAST:
w += dx;
break;
case GDK_WINDOW_EDGE_WEST:
x += dx;
w -= dx;
break;
}
x = MAX (x, 0);
y = MAX (y, 0);
w = MAX (w, 1);
h = MAX (h, 1);
if (mv_resize->moveresize_geom_mask)
{
gdk_window_constrain_size (&mv_resize->moveresize_geometry,
mv_resize->moveresize_geom_mask,
w, h, &w, &h);
}
gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
}
else
{
gint x, y;
x = mv_resize->moveresize_orig_x + dx;
y = mv_resize->moveresize_orig_y + dy;
gdk_window_move (mv_resize->moveresize_window, x, y);
}
}
static void
finish_drag (MoveResizeData *mv_resize)
{
gdk_window_destroy (mv_resize->moveresize_emulation_window);
mv_resize->moveresize_emulation_window = NULL;
g_object_unref (mv_resize->moveresize_window);
mv_resize->moveresize_window = NULL;
if (mv_resize->moveresize_pending_event)
{
g_free (mv_resize->moveresize_pending_event);
mv_resize->moveresize_pending_event = NULL;
}
}
static int
lookahead_motion_predicate (Display *xdisplay,
XEvent *event,
XPointer arg)
{
gboolean *seen_release = (gboolean *)arg;
GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
if (*seen_release)
return False;
switch (event->xany.type)
{
case ButtonRelease:
*seen_release = TRUE;
break;
case MotionNotify:
mv_resize->moveresize_process_time = event->xmotion.time;
break;
default:
break;
}
return False;
}
static gboolean
moveresize_lookahead (MoveResizeData *mv_resize,
XEvent *event)
{
XEvent tmp_event;
gboolean seen_release = FALSE;
if (mv_resize->moveresize_process_time)
{
if (event->xmotion.time == mv_resize->moveresize_process_time)
{
mv_resize->moveresize_process_time = 0;
return TRUE;
}
else
return FALSE;
}
XCheckIfEvent (event->xany.display, &tmp_event,
lookahead_motion_predicate, (XPointer) & seen_release);
return mv_resize->moveresize_process_time == 0;
}
gboolean
_gdk_x11_moveresize_handle_event (XEvent *event)
{
guint button_mask = 0;
GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
if (!mv_resize || !mv_resize->moveresize_window)
return FALSE;
button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
switch (event->xany.type)
{
case MotionNotify:
if (mv_resize->moveresize_window->resize_count > 0)
{
if (mv_resize->moveresize_pending_event)
*mv_resize->moveresize_pending_event = *event;
else
mv_resize->moveresize_pending_event =
g_memdup (event, sizeof (XEvent));
break;
}
if (!moveresize_lookahead (mv_resize, event))
break;
update_pos (mv_resize,
event->xmotion.x_root,
event->xmotion.y_root);
/* This should never be triggered in normal cases, but in the
* case where the drag started without an implicit grab being
* in effect, we could miss the release if it occurs before
* we grab the pointer; this ensures that we will never
* get a permanently stuck grab.
*/
if ((event->xmotion.state & button_mask) == 0)
finish_drag (mv_resize);
break;
case ButtonRelease:
update_pos (mv_resize,
event->xbutton.x_root,
event->xbutton.y_root);
if (event->xbutton.button == mv_resize->moveresize_button)
finish_drag (mv_resize);
break;
}
return TRUE;
}
gboolean
_gdk_x11_moveresize_configure_done (GdkDisplay *display,
GdkWindow *window)
{
XEvent *tmp_event;
MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
if (!mv_resize || window != mv_resize->moveresize_window)
return FALSE;
if (mv_resize->moveresize_pending_event)
{
tmp_event = mv_resize->moveresize_pending_event;
mv_resize->moveresize_pending_event = NULL;
_gdk_x11_moveresize_handle_event (tmp_event);
g_free (tmp_event);
}
return TRUE;
}
static void
create_moveresize_window (MoveResizeData *mv_resize,
guint32 timestamp)
{
GdkWindowAttr attributes;
gint attributes_mask;
GdkGrabStatus status;
g_assert (mv_resize->moveresize_emulation_window == NULL);
attributes.x = -100;
attributes.y = -100;
attributes.width = 10;
attributes.height = 10;
attributes.window_type = GDK_WINDOW_TEMP;
attributes.wclass = GDK_INPUT_ONLY;
attributes.override_redirect = TRUE;
attributes.event_mask = 0;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
mv_resize->moveresize_emulation_window =
gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
&attributes,
attributes_mask);
gdk_window_show (mv_resize->moveresize_emulation_window);
status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
FALSE,
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK,
NULL,
NULL,
timestamp);
if (status != GDK_GRAB_SUCCESS)
{
/* If this fails, some other client has grabbed the window
* already.
*/
finish_drag (mv_resize);
}
mv_resize->moveresize_process_time = 0;
}
/*
Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
so that calling XMoveWindow with these coordinates will not move the
window.
Note that this depends on the WM to implement ICCCM-compliant reference
point handling.
*/
static void
calculate_unmoving_origin (MoveResizeData *mv_resize)
{
GdkRectangle rect;
gint width, height;
if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
{
gdk_window_get_origin (mv_resize->moveresize_window,
&mv_resize->moveresize_orig_x,
&mv_resize->moveresize_orig_y);
}
else
{
gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
gdk_window_get_geometry (mv_resize->moveresize_window,
NULL, NULL, &width, &height);
switch (mv_resize->moveresize_geometry.win_gravity)
{
case GDK_GRAVITY_NORTH_WEST:
mv_resize->moveresize_orig_x = rect.x;
mv_resize->moveresize_orig_y = rect.y;
break;
case GDK_GRAVITY_NORTH:
mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
mv_resize->moveresize_orig_y = rect.y;
break;
case GDK_GRAVITY_NORTH_EAST:
mv_resize->moveresize_orig_x = rect.x + rect.width - width;
mv_resize->moveresize_orig_y = rect.y;
break;
case GDK_GRAVITY_WEST:
mv_resize->moveresize_orig_x = rect.x;
mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
break;
case GDK_GRAVITY_CENTER:
mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
break;
case GDK_GRAVITY_EAST:
mv_resize->moveresize_orig_x = rect.x + rect.width - width;
mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
break;
case GDK_GRAVITY_SOUTH_WEST:
mv_resize->moveresize_orig_x = rect.x;
mv_resize->moveresize_orig_y = rect.y + rect.height - height;
break;
case GDK_GRAVITY_SOUTH:
mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
mv_resize->moveresize_orig_y = rect.y + rect.height - height;
break;
case GDK_GRAVITY_SOUTH_EAST:
mv_resize->moveresize_orig_x = rect.x + rect.width - width;
mv_resize->moveresize_orig_y = rect.y + rect.height - height;
break;
default:
mv_resize->moveresize_orig_x = rect.x;
mv_resize->moveresize_orig_y = rect.y;
break;
}
}
}
static void
emulate_resize_drag (GdkWindow *window,
GdkWindowEdge edge,
gint button,
gint root_x,
gint root_y,
guint32 timestamp)
{
MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
mv_resize->is_resize = TRUE;
mv_resize->moveresize_button = button;
mv_resize->resize_edge = edge;
mv_resize->moveresize_x = root_x;
mv_resize->moveresize_y = root_y;
mv_resize->moveresize_window = g_object_ref (window);
mv_resize->moveresize_orig_width = gdk_window_get_width (window);
mv_resize->moveresize_orig_height = gdk_window_get_height (window);
mv_resize->moveresize_geom_mask = 0;
gdk_window_get_geometry_hints (window,
&mv_resize->moveresize_geometry,
&mv_resize->moveresize_geom_mask);
calculate_unmoving_origin (mv_resize);
create_moveresize_window (mv_resize, timestamp);
}
static void
emulate_move_drag (GdkWindow *window,
gint button,
gint root_x,
gint root_y,
guint32 timestamp)
{
MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
mv_resize->is_resize = FALSE;
mv_resize->moveresize_button = button;
mv_resize->moveresize_x = root_x;
mv_resize->moveresize_y = root_y;
mv_resize->moveresize_window = g_object_ref (window);
calculate_unmoving_origin (mv_resize);
create_moveresize_window (mv_resize, timestamp);
}
static void
gdk_x11_window_begin_resize_drag (GdkWindow *window,
GdkWindowEdge edge,
gint button,
gint root_x,
gint root_y,
guint32 timestamp)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
return;
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
else
emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
}
static void
gdk_x11_window_begin_move_drag (GdkWindow *window,
gint button,
gint root_x,
gint root_y,
guint32 timestamp)
{
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL (window))
return;
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
timestamp);
else
emulate_move_drag (window, button, root_x, root_y, timestamp);
}
static void
gdk_x11_window_enable_synchronized_configure (GdkWindow *window)
{
GdkWindowImplX11 *impl;
if (!GDK_IS_WINDOW_IMPL_X11 (window->impl))
return;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (!impl->use_synchronized_configure)
{
/* This basically means you want to do fancy X specific stuff, so
ensure we have a native window */
gdk_window_ensure_native (window);
impl->use_synchronized_configure = TRUE;
ensure_sync_counter (window);
}
}
static void
gdk_x11_window_configure_finished (GdkWindow *window)
{
GdkWindowImplX11 *impl;
if (!WINDOW_IS_TOPLEVEL (window))
return;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
if (!impl->use_synchronized_configure)
return;
#ifdef HAVE_XSYNC
if (!GDK_WINDOW_DESTROYED (window))
{
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
if (toplevel && toplevel->update_counter != None &&
GDK_DISPLAY_X11 (display)->use_sync &&
!XSyncValueIsZero (toplevel->current_counter_value))
{
XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
toplevel->update_counter,
toplevel->current_counter_value);
XSyncIntToValue (&toplevel->current_counter_value, 0);
}
}
#endif
}
static gboolean
gdk_x11_window_beep (GdkWindow *window)
{
GdkDisplay *display;
display = GDK_WINDOW_DISPLAY (window);
#ifdef HAVE_XKB
if (GDK_DISPLAY_X11 (display)->use_xkb)
{
XkbBell (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
0,
None);
return TRUE;
}
#endif
return FALSE;
}
static void
gdk_x11_window_set_opacity (GdkWindow *window,
gdouble opacity)
{
GdkDisplay *display;
guint32 cardinal;
g_return_if_fail (GDK_IS_WINDOW (window));
if (GDK_WINDOW_DESTROYED (window) ||
!WINDOW_IS_TOPLEVEL (window))
return;
display = gdk_window_get_display (window);
if (opacity < 0)
opacity = 0;
else if (opacity > 1)
opacity = 1;
cardinal = opacity * 0xffffffff;
if (cardinal == 0xffffffff)
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
else
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
XA_CARDINAL, 32,
PropModeReplace,
(guchar *) &cardinal, 1);
}
static void
gdk_x11_window_set_composited (GdkWindow *window,
gboolean composited)
{
#if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
GdkWindowImplX11 *impl;
GdkDisplay *display;
Display *dpy;
Window xid;
impl = GDK_WINDOW_IMPL_X11 (window->impl);
display = gdk_window_get_display (window);
dpy = GDK_DISPLAY_XDISPLAY (display);
xid = GDK_WINDOW_XID (window);
if (composited)
{
XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
}
else
{
XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
XDamageDestroy (dpy, impl->damage);
impl->damage = None;
}
#endif
}
static void
gdk_x11_window_process_updates_recurse (GdkWindow *window,
cairo_region_t *region)
{
_gdk_window_process_updates_recurse (window, region);
}
void
_gdk_x11_display_before_process_all_updates (GdkDisplay *display)
{
}
void
_gdk_x11_display_after_process_all_updates (GdkDisplay *display)
{
}
static Bool
timestamp_predicate (Display *display,
XEvent *xevent,
XPointer arg)
{
Window xwindow = GPOINTER_TO_UINT (arg);
GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
if (xevent->type == PropertyNotify &&
xevent->xproperty.window == xwindow &&
xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
"GDK_TIMESTAMP_PROP"))
return True;
return False;
}
/**
* gdk_x11_get_server_time:
* @window: a #GdkWindow, used for communication with the server.
* The window must have GDK_PROPERTY_CHANGE_MASK in its
* events mask or a hang will result.
*
* Routine to get the current X server time stamp.
*
* Return value: the time stamp.
**/
guint32
gdk_x11_get_server_time (GdkWindow *window)
{
Display *xdisplay;
Window xwindow;
guchar c = 'a';
XEvent xevent;
Atom timestamp_prop_atom;
g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
xdisplay = GDK_WINDOW_XDISPLAY (window);
xwindow = GDK_WINDOW_XID (window);
timestamp_prop_atom =
gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
"GDK_TIMESTAMP_PROP");
XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
timestamp_prop_atom,
8, PropModeReplace, &c, 1);
XIfEvent (xdisplay, &xevent,
timestamp_predicate, GUINT_TO_POINTER(xwindow));
return xevent.xproperty.time;
}
/**
* gdk_x11_window_get_xid:
* @window: a native #GdkWindow.
*
* Returns the X resource (window) belonging to a #GdkWindow.
*
* Return value: the ID of @drawable's X resource.
**/
XID
gdk_x11_window_get_xid (GdkWindow *window)
{
/* Try to ensure the window has a native window */
if (!_gdk_window_has_impl (window))
{
gdk_window_ensure_native (window);
/* We sync here to ensure the window is created in the Xserver when
* this function returns. This is required because the returned XID
* for this window must be valid immediately, even with another
* connection to the Xserver */
gdk_display_sync (gdk_window_get_display (window));
}
if (!GDK_WINDOW_IS_X11 (window))
{
g_warning (G_STRLOC " drawable is not a native X11 window");
return None;
}
return GDK_WINDOW_IMPL_X11 (window->impl)->xid;
}
extern GdkDragContext * _gdk_x11_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GList *targets);
static void
gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
object_class->finalize = gdk_window_impl_x11_finalize;
impl_class->ref_cairo_surface = gdk_x11_ref_cairo_surface;
impl_class->show = gdk_window_x11_show;
impl_class->hide = gdk_window_x11_hide;
impl_class->withdraw = gdk_window_x11_withdraw;
impl_class->set_events = gdk_window_x11_set_events;
impl_class->get_events = gdk_window_x11_get_events;
impl_class->raise = gdk_window_x11_raise;
impl_class->lower = gdk_window_x11_lower;
impl_class->restack_under = gdk_window_x11_restack_under;
impl_class->restack_toplevel = gdk_window_x11_restack_toplevel;
impl_class->move_resize = gdk_window_x11_move_resize;
impl_class->set_background = gdk_window_x11_set_background;
impl_class->reparent = gdk_window_x11_reparent;
impl_class->set_device_cursor = gdk_window_x11_set_device_cursor;
impl_class->get_geometry = gdk_window_x11_get_geometry;
impl_class->get_root_coords = gdk_window_x11_get_root_coords;
impl_class->get_device_state = gdk_window_x11_get_device_state;
impl_class->shape_combine_region = gdk_window_x11_shape_combine_region;
impl_class->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
impl_class->set_static_gravities = gdk_window_x11_set_static_gravities;
impl_class->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
impl_class->translate = _gdk_x11_window_translate;
impl_class->destroy = gdk_x11_window_destroy;
impl_class->destroy_foreign = gdk_x11_window_destroy_foreign;
impl_class->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;
impl_class->get_shape = gdk_x11_window_get_shape;
impl_class->get_input_shape = gdk_x11_window_get_input_shape;
impl_class->beep = gdk_x11_window_beep;
impl_class->focus = gdk_x11_window_focus;
impl_class->set_type_hint = gdk_x11_window_set_type_hint;
impl_class->get_type_hint = gdk_x11_window_get_type_hint;
impl_class->set_modal_hint = gdk_x11_window_set_modal_hint;
impl_class->set_skip_taskbar_hint = gdk_x11_window_set_skip_taskbar_hint;
impl_class->set_skip_pager_hint = gdk_x11_window_set_skip_pager_hint;
impl_class->set_urgency_hint = gdk_x11_window_set_urgency_hint;
impl_class->set_geometry_hints = gdk_x11_window_set_geometry_hints;
impl_class->set_title = gdk_x11_window_set_title;
impl_class->set_role = gdk_x11_window_set_role;
impl_class->set_startup_id = gdk_x11_window_set_startup_id;
impl_class->set_transient_for = gdk_x11_window_set_transient_for;
impl_class->get_root_origin = gdk_x11_window_get_root_origin;
impl_class->get_frame_extents = gdk_x11_window_get_frame_extents;
impl_class->set_override_redirect = gdk_x11_window_set_override_redirect;
impl_class->set_accept_focus = gdk_x11_window_set_accept_focus;
impl_class->set_focus_on_map = gdk_x11_window_set_focus_on_map;
impl_class->set_icon_list = gdk_x11_window_set_icon_list;
impl_class->set_icon_name = gdk_x11_window_set_icon_name;
impl_class->iconify = gdk_x11_window_iconify;
impl_class->deiconify = gdk_x11_window_deiconify;
impl_class->stick = gdk_x11_window_stick;
impl_class->unstick = gdk_x11_window_unstick;
impl_class->maximize = gdk_x11_window_maximize;
impl_class->unmaximize = gdk_x11_window_unmaximize;
impl_class->fullscreen = gdk_x11_window_fullscreen;
impl_class->unfullscreen = gdk_x11_window_unfullscreen;
impl_class->set_keep_above = gdk_x11_window_set_keep_above;
impl_class->set_keep_below = gdk_x11_window_set_keep_below;
impl_class->get_group = gdk_x11_window_get_group;
impl_class->set_group = gdk_x11_window_set_group;
impl_class->set_decorations = gdk_x11_window_set_decorations;
impl_class->get_decorations = gdk_x11_window_get_decorations;
impl_class->set_functions = gdk_x11_window_set_functions;
impl_class->set_functions = gdk_x11_window_set_functions;
impl_class->begin_resize_drag = gdk_x11_window_begin_resize_drag;
impl_class->begin_move_drag = gdk_x11_window_begin_move_drag;
impl_class->enable_synchronized_configure = gdk_x11_window_enable_synchronized_configure;
impl_class->configure_finished = gdk_x11_window_configure_finished;
impl_class->set_opacity = gdk_x11_window_set_opacity;
impl_class->set_composited = gdk_x11_window_set_composited;
impl_class->destroy_notify = gdk_x11_window_destroy_notify;
impl_class->register_dnd = _gdk_x11_window_register_dnd;
impl_class->drag_begin = _gdk_x11_window_drag_begin;
impl_class->process_updates_recurse = gdk_x11_window_process_updates_recurse;
}
|