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
| | /* Functions for the pure Gtk+-3.
Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2018 Free Software
Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
GNU Emacs 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
/* This should be the first include, as it may set up #defines affecting
interpretation of even the system includes. */
#include <config.h>
#include <c-strcase.h>
#include <math.h>
#include "lisp.h"
#include "blockinput.h"
#include "buffer.h"
#include "character.h"
#include "font.h"
#include "fontset.h"
#ifndef HAVE_GTK4
#include "gtkutil.h"
#else
#include "pgtksubr.h"
#endif
#include "keyboard.h"
#include "termhooks.h"
#include "window.h"
#include "xsettings.h"
#ifdef HAVE_GTK3
#include "pgtkevent.h"
#endif
#include "pgtkterm.h"
#ifdef HAVE_PGTK
// static EmacsTooltip *pgtk_tooltip = nil;
/* Static variables to handle applescript execution. */
static Lisp_Object as_script, *as_result;
static int as_status;
static ptrdiff_t image_cache_refcount;
static int x_decode_color (struct frame *f, Lisp_Object color_name,
int mono_color);
static struct pgtk_display_info *pgtk_display_info_for_name (Lisp_Object);
static void pgtk_set_name_as_filename (struct frame *);
static const char *pgtk_app_name = "Emacs";
/* ==========================================================================
Internal utility functions
========================================================================== */
struct pgtk_display_info *
check_pgtk_display_info (Lisp_Object object)
{
struct pgtk_display_info *dpyinfo = NULL;
if (NILP (object))
{
struct frame *sf = XFRAME (selected_frame);
if (FRAME_PGTK_P (sf) && FRAME_LIVE_P (sf))
dpyinfo = FRAME_DISPLAY_INFO (sf);
else if (x_display_list != 0)
dpyinfo = x_display_list;
else
error ("Frames are not in use or not initialized");
}
else if (TERMINALP (object))
{
struct terminal *t = decode_live_terminal (object);
if (t->type != output_pgtk)
error ("Terminal %d is not a display", t->id);
dpyinfo = t->display_info.pgtk;
}
else if (STRINGP (object))
dpyinfo = pgtk_display_info_for_name (object);
else
{
struct frame *f = decode_window_system_frame (object);
dpyinfo = FRAME_DISPLAY_INFO (f);
}
return dpyinfo;
}
/* Return the X display structure for the display named NAME.
Open a new connection if necessary. */
static struct pgtk_display_info *
pgtk_display_info_for_name (Lisp_Object name)
{
struct pgtk_display_info *dpyinfo;
CHECK_STRING (name);
for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
if (!NILP (Fstring_equal (XCAR (dpyinfo->name_list_element), name)))
return dpyinfo;
/* Use this general default value to start with. */
Vx_resource_name = Vinvocation_name;
validate_x_resource_name ();
dpyinfo = pgtk_term_init (name, SSDATA (Vx_resource_name));
if (dpyinfo == 0)
error ("Cannot connect to display server %s", SDATA (name));
XSETFASTINT (Vwindow_system_version, 11);
return dpyinfo;
}
/* ==========================================================================
Frame parameter setters
========================================================================== */
static void
x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
Emacs_Color col;
/* Must block_input, because pgtk_lisp_to_color does block/unblock_input
which means that col may be deallocated in its unblock_input if there
is user input, unless we also block_input. */
block_input ();
if (pgtk_lisp_to_color_with_frame (arg, &col, f))
{
store_frame_param (f, Qforeground_color, oldval);
unblock_input ();
error ("Unknown color");
}
FRAME_X_OUTPUT (f)->foreground_color = col.pixel;
FRAME_FOREGROUND_PIXEL (f) = col.pixel;
if (FRAME_GTK_WIDGET (f))
{
update_face_from_frame_parameter (f, Qforeground_color, arg);
/*recompute_basic_faces (f); */
if (FRAME_VISIBLE_P (f))
SET_FRAME_GARBAGED (f);
}
unblock_input ();
}
static void
x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
Emacs_Color col;
block_input ();
if (pgtk_lisp_to_color_with_frame (arg, &col, f))
{
store_frame_param (f, Qbackground_color, oldval);
unblock_input ();
error ("Unknown color");
}
/* clear the frame */
if (FRAME_VISIBLE_P (f))
pgtk_clear_frame (f);
PGTK_TRACE ("x_set_background_color: col.pixel=%08lx.", col.pixel);
FRAME_X_OUTPUT (f)->background_color = col.pixel;
FRAME_BACKGROUND_PIXEL (f)
= ARGB_TO_ULONG ((unsigned int) (0xff), (unsigned int) (col.red >> 8),
(unsigned int) (col.green >> 8),
(unsigned int) (col.blue >> 8));
#ifndef HAVE_GTK4
xg_set_background_color (f, col.pixel);
#else
egtk_set_background_color (f, col.pixel);
#endif
update_face_from_frame_parameter (f, Qbackground_color, arg);
PGTK_TRACE ("visible_p=%d.", FRAME_VISIBLE_P (f));
if (FRAME_VISIBLE_P (f))
SET_FRAME_GARBAGED (f);
unblock_input ();
}
static void
x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int pix;
#ifdef HAVE_GTK3
CHECK_STRING (arg);
pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
FRAME_X_OUTPUT (f)->border_pixel = pix;
pgtk_frame_rehighlight (FRAME_DISPLAY_INFO (f));
#endif
}
static void
x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
unsigned long fore_pixel, pixel;
struct pgtk_output *x = f->output_data.pgtk;
Emacs_Color col;
if (!NILP (Vx_cursor_fore_pixel))
{
if (pgtk_lisp_to_color_with_frame (Vx_cursor_fore_pixel, &col, f))
signal_error ("Undefined color", Vx_cursor_fore_pixel);
fore_pixel = col.pixel;
}
else
fore_pixel = FRAME_BACKGROUND_PIXEL (f);
if (pgtk_lisp_to_color_with_frame (arg, &col, f))
signal_error ("Undefined color", arg);
pixel = col.pixel;
/* Make sure that the cursor color differs from the background color. */
if (pixel == FRAME_BACKGROUND_PIXEL (f))
{
pixel = x->mouse_color;
if (pixel == fore_pixel)
{
fore_pixel = FRAME_BACKGROUND_PIXEL (f);
}
}
x->cursor_foreground_color = fore_pixel;
x->cursor_color = pixel;
if (FRAME_X_WINDOW (f) != 0)
{
x->cursor_xgcv.background = x->cursor_color;
x->cursor_xgcv.foreground = fore_pixel;
if (FRAME_VISIBLE_P (f))
{
gui_update_cursor (f, false);
gui_update_cursor (f, true);
}
}
update_face_from_frame_parameter (f, Qcursor_color, arg);
}
static void
x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f);
PGTK_TRACE ("x_set_icon_name");
if (FRAME_PARENT_FRAME (f))
return;
/* see if it's changed */
if (STRINGP (arg))
{
if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
return;
}
else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
return;
fset_icon_name (f, arg);
if (NILP (arg))
{
if (!NILP (f->title))
arg = f->title;
else
/* Explicit name and no icon-name -> explicit_name. */
if (f->explicit_name)
arg = f->name;
else
{
/* No explicit name and no icon-name ->
name has to be rebuild from icon_title_format. */
windows_or_buffers_changed = 67;
return;
}
}
gtk_window_set_icon_name (GTK_WINDOW (widget), SSDATA (arg));
}
static void
pgtk_set_name_internal (struct frame *f, Lisp_Object name)
{
Lisp_Object encoded_name, encoded_icon_name;
GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f);
#ifdef HAVE_GTK4
if (!GTK_IS_WINDOW (widget))
{
gtk_widget_set_name (widget, SSDATA (ENCODE_UTF_8 (name)));
return;
}
#endif
encoded_name = ENCODE_UTF_8 (name);
gtk_window_set_title (GTK_WINDOW (widget), SSDATA (encoded_name));
if (!STRINGP (f->icon_name))
encoded_icon_name = encoded_name;
else
encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
gtk_window_set_icon_name (GTK_WINDOW (widget), SSDATA (encoded_icon_name));
}
static void
pgtk_set_name (struct frame *f, Lisp_Object name, int explicit)
{
PGTK_TRACE ("pgtk_set_name");
/* Make sure that requests from lisp code override requests from
Emacs redisplay code. */
if (explicit)
{
/* If we're switching from explicit to implicit, we had better
update the mode lines and thereby update the title. */
if (f->explicit_name && NILP (name))
update_mode_lines = 12;
f->explicit_name = !NILP (name);
}
else if (f->explicit_name)
return;
if (NILP (name))
name = build_string (pgtk_app_name);
else
CHECK_STRING (name);
/* Don't change the name if it's already NAME. */
if (!NILP (Fstring_equal (name, f->name)))
return;
fset_name (f, name);
/* Title overrides explicit name. */
if (!NILP (f->title))
name = f->title;
pgtk_set_name_internal (f, name);
}
/* This function should be called when the user's lisp code has
specified a name for the frame; the name will override any set by the
redisplay code. */
static void
x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
PGTK_TRACE ("x_explicitly_set_name");
pgtk_set_name (f, arg, 1);
}
/* This function should be called by Emacs redisplay code to set the
name; names set this way will never override names set by the user's
lisp code. */
void
pgtk_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
PGTK_TRACE ("x_implicitly_set_name");
Lisp_Object frame_title
= buffer_local_value (Qframe_title_format,
XWINDOW (f->selected_window)->contents);
Lisp_Object icon_title
= buffer_local_value (Qicon_title_format,
XWINDOW (f->selected_window)->contents);
if (FRAME_PGTK_P (f)
&& ((FRAME_ICONIFIED_P (f) && EQ (icon_title, Qt))
|| EQ (frame_title, Qt)))
pgtk_set_name_as_filename (f);
else
pgtk_set_name (f, arg, 0);
}
/* Change the title of frame F to NAME.
If NAME is nil, use the frame name as the title. */
static void
x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
{
PGTK_TRACE ("x_set_title");
/* Don't change the title if it's already NAME. */
if (EQ (name, f->title))
return;
update_mode_lines = 22;
fset_title (f, name);
if (NILP (name))
name = f->name;
else
CHECK_STRING (name);
pgtk_set_name_internal (f, name);
}
static void
pgtk_set_name_as_filename (struct frame *f)
{
GtkWidget *widget;
Lisp_Object name, filename;
Lisp_Object buf = XWINDOW (f->selected_window)->contents;
const char *title;
Lisp_Object encoded_name, encoded_filename;
const char *str;
PGTK_TRACE ("pgtk_set_name_as_filename");
if (f->explicit_name || !NILP (f->title))
return;
block_input ();
filename = BVAR (XBUFFER (buf), filename);
name = BVAR (XBUFFER (buf), name);
if (NILP (name))
{
if (!NILP (filename))
name = Ffile_name_nondirectory (filename);
else
name = build_string (pgtk_app_name);
}
encoded_name = ENCODE_UTF_8 (name);
widget = FRAME_GTK_OUTER_WIDGET (f);
if (!widget)
return;
if (!FRAME_LIVE_P (f))
return;
if (FRAME_PARENT_FRAME (f) || !GTK_IS_WINDOW (widget))
return;
title = FRAME_ICONIFIED_P (f) ? gtk_window_get_icon_name (GTK_WINDOW (widget))
: gtk_window_get_title (GTK_WINDOW (widget));
if (title && (!strcmp (title, SSDATA (encoded_name))))
{
unblock_input ();
return;
}
str = SSDATA (encoded_name);
if (str == NULL)
str = "Bad coding";
if (FRAME_ICONIFIED_P (f))
gtk_window_set_icon_name (GTK_WINDOW (widget), str);
else
{
const char *fstr;
if (!NILP (filename))
{
encoded_filename = ENCODE_UTF_8 (filename);
fstr = SSDATA (encoded_filename);
if (fstr == NULL)
fstr = "";
}
else
fstr = "";
if (!FRAME_PARENT_FRAME (f))
gtk_window_set_title (GTK_WINDOW (widget), str);
fset_name (f, name);
}
unblock_input ();
}
void
pgtk_set_doc_edited (void)
{
}
static void
x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
#if defined (HAVE_EXT_MENU_BAR)
int nlines;
/* Right now, menu bars don't work properly in minibuf-only frames;
most of the commands try to apply themselves to the minibuffer
frame itself, and get an error because you can't switch buffers
in or split the minibuffer window. */
if (FRAME_MINIBUF_ONLY_P (f) || FRAME_PARENT_FRAME (f))
return;
if (TYPE_RANGED_FIXNUMP (int, value))
nlines = XFIXNUM (value);
else
nlines = 0;
/* Make sure we redisplay all windows in this frame. */
fset_redisplay (f);
FRAME_MENU_BAR_LINES (f) = 0;
FRAME_MENU_BAR_HEIGHT (f) = 0;
if (nlines)
{
FRAME_EXTERNAL_MENU_BAR (f) = 1;
if (FRAME_PGTK_P (f) &&
#ifndef HAVE_GTK4
f->output_data.pgtk->menubar_widget == 0
#else
FRAME_MENU_BAR (f)
#endif
)
/* Make sure next redisplay shows the menu bar. */
XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = true;
}
else
{
#ifndef HAVE_GTK4
if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
#endif
free_frame_menubar (f);
FRAME_EXTERNAL_MENU_BAR (f) = 0;
#ifndef HAVE_GTK4
if (FRAME_X_P (f))
f->output_data.pgtk->menubar_widget = 0;
#endif
}
adjust_frame_glyphs (f);
#endif
}
/* Set the number of lines used for the tab bar of frame F to VALUE.
VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
is the old number of tab bar lines. This function changes the
height of all windows on frame F to match the new tab bar height.
The frame's height doesn't change. */
static void
x_set_tab_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
int nlines;
/* Treat tab bars like menu bars. */
if (FRAME_MINIBUF_ONLY_P (f))
return;
/* Use VALUE only if an int >= 0. */
if (RANGED_FIXNUMP (0, value, INT_MAX))
nlines = XFIXNAT (value);
else
nlines = 0;
x_change_tab_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));
}
/* Set the pixel height of the tab bar of frame F to HEIGHT. */
void
x_change_tab_bar_height (struct frame *f, int height)
{
int unit = FRAME_LINE_HEIGHT (f);
int old_height = FRAME_TAB_BAR_HEIGHT (f);
int lines = (height + unit - 1) / unit;
Lisp_Object fullscreen;
/* Make sure we redisplay all windows in this frame. */
fset_redisplay (f);
/* Recalculate tab bar and frame text sizes. */
FRAME_TAB_BAR_HEIGHT (f) = height;
FRAME_TAB_BAR_LINES (f) = lines;
/* Store the `tab-bar-lines' and `height' frame parameters. */
store_frame_param (f, Qtab_bar_lines, make_fixnum (lines));
store_frame_param (f, Qheight, make_fixnum (FRAME_LINES (f)));
/* We also have to make sure that the internal border at the top of
the frame, below the menu bar or tab bar, is redrawn when the
tab bar disappears. This is so because the internal border is
below the tab bar if one is displayed, but is below the menu bar
if there isn't a tab bar. The tab bar draws into the area
below the menu bar. */
if (FRAME_X_WINDOW (f) && FRAME_TAB_BAR_HEIGHT (f) == 0)
{
clear_frame (f);
clear_current_matrices (f);
}
if ((height < old_height) && WINDOWP (f->tab_bar_window))
clear_glyph_matrix (XWINDOW (f->tab_bar_window)->current_matrix);
/* Recalculate tabbar height. */
f->n_tab_bar_rows = 0;
if (old_height == 0
&& (!f->after_make_frame || NILP (frame_inhibit_implied_resize)
|| (CONSP (frame_inhibit_implied_resize)
&& NILP (Fmemq (Qtab_bar_lines, frame_inhibit_implied_resize)))))
f->tab_bar_redisplayed = f->tab_bar_resized = false;
adjust_frame_size (f, -1, -1,
((!f->tab_bar_resized
&& (NILP (fullscreen = get_frame_param (f, Qfullscreen))
|| EQ (fullscreen, Qfullwidth)))
? 1
: (old_height == 0 || height == 0) ? 2 : 4),
false, Qtab_bar_lines);
f->tab_bar_resized = f->tab_bar_redisplayed;
block_input ();
/* adjust_frame_size might not have done anything, garbage frame
here. */
adjust_frame_glyphs (f);
SET_FRAME_GARBAGED (f);
if (FRAME_X_WINDOW (f))
pgtk_clear_under_internal_border (f);
FRAME_X_OUTPUT (f)->want_flip = 0;
unblock_input ();
}
/* Set the pixel height of the tool bar of frame F to HEIGHT. */
static void
x_change_tool_bar_height (struct frame *f, int height)
{
#if defined (HAVE_EXT_MENU_BAR)
FRAME_TOOL_BAR_LINES (f) = 0;
FRAME_TOOL_BAR_HEIGHT (f) = 0;
if (height)
{
FRAME_EXTERNAL_TOOL_BAR (f) = true;
if (FRAME_X_P (f) && f->output_data.pgtk->toolbar_widget == 0)
/* Make sure next redisplay shows the tool bar. */
XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = true;
update_frame_tool_bar (f);
}
else
{
free_frame_tool_bar (f);
FRAME_EXTERNAL_TOOL_BAR (f) = false;
}
#endif
}
/* toolbar support */
static void
x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
int nlines;
/* Treat tool bars like menu bars. */
if (FRAME_MINIBUF_ONLY_P (f))
return;
/* Use VALUE only if an int >= 0. */
if (RANGED_FIXNUMP (0, value, INT_MAX))
nlines = XFIXNAT (value);
else
nlines = 0;
x_change_tool_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));
}
static void
x_set_internal_border_width (struct frame *f, Lisp_Object arg,
Lisp_Object oldval)
{
int border = check_int_nonnegative (arg);
if (border != FRAME_INTERNAL_BORDER_WIDTH (f))
{
f->internal_border_width = border;
if (FRAME_PGTK_P (f))
{
adjust_frame_size (f, -1, -1, 3, false, Qinternal_border_width);
if (f->face_cache)
pgtk_clear_under_internal_border (f);
}
}
}
static void
x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
#ifndef HAVE_GTK4
GError *error_ = NULL;
if (NILP (arg) || EQ (arg, Qt))
{
gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), NULL);
return;
}
CHECK_STRING (arg);
gtk_window_set_icon_from_file (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
SSDATA (arg), &error_);
if (error_)
{
Lisp_Object error_string = build_string (error_->message);
g_error_free (error_);
error ("%s", SSDATA (error_string));
}
#endif
}
/* This is the same as the xfns.c definition. */
static void
x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
set_frame_cursor_types (f, arg);
}
/* called to set mouse pointer color, but all other terms use it to
initialize pointer types (and don't set the color ;) */
static void
x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
}
static void
x_icon (struct frame *f, Lisp_Object parms)
/* --------------------------------------------------------------------------
Strangely-named function to set icon position parameters in frame.
This is irrelevant under macOS, but might be needed under GNUstep,
depending on the window manager used. Note, this is not a standard
frame parameter-setter; it is called directly from x-create-frame.
-------------------------------------------------------------------------- */
{
#if 0
Lisp_Object icon_x, icon_y;
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (Qnil);
FRAME_X_OUTPUT(f)->icon_top = -1;
FRAME_X_OUTPUT(f)->icon_left = -1;
/* Set the position of the icon. */
icon_x = gui_display_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
icon_y = gui_display_get_arg (dpyinfo, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
{
CHECK_NUMBER (icon_x);
CHECK_NUMBER (icon_y);
FRAME_X_OUTPUT(f)->icon_top = XFIXNUM (icon_y);
FRAME_X_OUTPUT(f)->icon_left = XFIXNUM (icon_x);
}
else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
error ("Both left and top icon corners of icon must be specified");
#endif
}
/**
* x_set_undecorated:
*
* Set frame F's `undecorated' parameter. If non-nil, F's window-system
* window is drawn without decorations, title, minimize/maximize boxes
* and external borders. This usually means that the window cannot be
* dragged, resized, iconified, maximized or deleted with the mouse. If
* nil, draw the frame with all the elements listed above unless these
* have been suspended via window manager settings.
*
* Some window managers may not honor this parameter.
*/
static void
x_set_undecorated (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
if (!EQ (new_value, old_value))
{
FRAME_UNDECORATED (f) = NILP (new_value) ? false : true;
#ifndef HAVE_GTK4
xg_set_undecorated (f, new_value);
#else
egtk_set_undecorated (f, new_value);
#endif
}
}
/**
* x_set_skip_taskbar:
*
* Set frame F's `skip-taskbar' parameter. If non-nil, this should
* remove F's icon from the taskbar associated with the display of F's
* window-system window and inhibit switching to F's window via
* <Alt>-<TAB>. If nil, lift these restrictions.
*
* Some window managers may not honor this parameter.
*/
static void
x_set_skip_taskbar (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
if (!EQ (new_value, old_value))
{
#ifndef HAVE_GTK4
xg_set_skip_taskbar (f, new_value);
#else
egtk_set_skip_taskbar (f, new_value);
#endif
FRAME_SKIP_TASKBAR (f) = !NILP (new_value);
}
}
/**
* x_set_override_redirect:
*
* Set frame F's `override_redirect' parameter which, if non-nil, hints
* that the window manager doesn't want to deal with F. Usually, such
* frames have no decorations and always appear on top of all frames.
*
* Some window managers may not honor this parameter.
*/
static void
x_set_override_redirect (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
if (!EQ (new_value, old_value))
{
/* Here (xfwm) override_redirect can be changed for invisible
frames only. */
pgtk_make_frame_invisible (f);
#ifndef HAVE_GTK4
xg_set_override_redirect (f, new_value);
#else
egtk_set_override_redirect (f, new_value);
#endif
pgtk_make_frame_visible (f);
FRAME_OVERRIDE_REDIRECT (f) = !NILP (new_value);
}
}
static void
pgtk_set_sticky (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
{
#ifndef HAVE_GTK4
if (!NILP (new_value))
gtk_window_stick (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
else
gtk_window_unstick (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
#endif
}
static void
pgtk_set_tool_bar_position (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
Lisp_Object choice = list4 (Qleft, Qright, Qtop, Qbottom);
if (!NILP (Fmemq (new_value, choice)))
{
if (!EQ (new_value, old_value))
{
#ifndef HAVE_GTK4
xg_change_toolbar_position (f, new_value);
#else
egtk_change_toolbar_position (f, new_value);
#endif
fset_tool_bar_position (f, new_value);
}
}
else
wrong_choice (choice, new_value);
}
static void
pgtk_set_scroll_bar_foreground (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
#ifdef HAVE_GTK3
GtkCssProvider *css_provider
= FRAME_X_OUTPUT (f)->scrollbar_foreground_css_provider;
if (NILP (new_value))
{
#ifndef HAVE_GTK4
gtk_css_provider_load_from_data (css_provider, "", -1, NULL);
#else
gtk_css_provider_load_from_data (css_provider, "", -1);
#endif
}
else if (STRINGP (new_value))
{
Emacs_Color rgb;
if (!pgtk_parse_color (SSDATA (new_value), &rgb))
error ("Unknown color.");
char css[64];
sprintf (css, "scrollbar slider { background-color: #%06x; }",
(unsigned int) rgb.pixel & 0xffffff);
#ifdef HAVE_GTK4
gtk_css_provider_load_from_data (css_provider, css, -1);
#else
gtk_css_provider_load_from_data (css_provider, css, -1, NULL);
#endif
}
else
error ("Invalid scroll-bar-foreground.");
#endif
// TODO for gtk 2
}
static void
pgtk_set_scroll_bar_background (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
#ifdef HAVE_GTK3
GtkCssProvider *css_provider
= FRAME_X_OUTPUT (f)->scrollbar_background_css_provider;
if (NILP (new_value))
{
#ifdef HAVE_GTK4
gtk_css_provider_load_from_data (css_provider, "", -1);
#else
gtk_css_provider_load_from_data (css_provider, "", -1, NULL);
#endif
}
else if (STRINGP (new_value))
{
Emacs_Color rgb;
if (!pgtk_parse_color (SSDATA (new_value), &rgb))
error ("Unknown color.");
char css[64];
sprintf (css, "scrollbar trough { background-color: #%06x; }",
(unsigned int) rgb.pixel & 0xffffff);
#ifdef HAVE_GTK4
gtk_css_provider_load_from_data (css_provider, css, -1);
#else
gtk_css_provider_load_from_data (css_provider, css, -1, NULL);
#endif
}
else
error ("Invalid scroll-bar-background.");
#endif
/* TODO implement for GTK 2 */
}
/* Note: see frame.c for template, also where generic functions are impl */
frame_parm_handler pgtk_frame_parm_handlers[] = {
gui_set_autoraise, /* generic OK */
gui_set_autolower, /* generic OK */
x_set_background_color,
x_set_border_color,
gui_set_border_width,
x_set_cursor_color,
x_set_cursor_type,
gui_set_font, /* generic OK */
x_set_foreground_color,
x_set_icon_name,
x_set_icon_type,
x_set_internal_border_width, /* generic OK */
gui_set_right_divider_width,
gui_set_bottom_divider_width,
x_set_menu_bar_lines,
x_set_mouse_color,
x_explicitly_set_name,
gui_set_scroll_bar_width, /* generic OK */
gui_set_scroll_bar_height, /* generic OK */
x_set_title,
gui_set_unsplittable, /* generic OK */
gui_set_vertical_scroll_bars, /* generic OK */
gui_set_horizontal_scroll_bars, /* generic OK */
gui_set_visibility, /* generic OK */
x_set_tab_bar_lines,
x_set_tool_bar_lines,
pgtk_set_scroll_bar_foreground,
pgtk_set_scroll_bar_background,
gui_set_screen_gamma, /* generic OK */
gui_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
gui_set_left_fringe, /* generic OK */
gui_set_right_fringe, /* generic OK */
0, /* x_set_wait_for_wm */
gui_set_fullscreen, /* generic OK */
gui_set_font_backend, /* generic OK */
gui_set_alpha,
pgtk_set_sticky,
pgtk_set_tool_bar_position,
pgtk_set_inhibit_double_buffering, /* x_set_inhibit_double_buffering */
x_set_undecorated,
x_set_parent_frame, /* x_set_parent_frame, */
x_set_skip_taskbar,
x_set_no_focus_on_map,
x_set_no_accept_focus,
x_set_z_group,
x_set_override_redirect,
gui_set_no_special_glyphs,
};
void
pgtk_set_inhibit_double_buffering (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
#ifndef HAVE_GTK4
if (FRAME_GTK_WIDGET (f))
gtk_widget_set_double_buffered (FRAME_GTK_WIDGET (f), !NILP (new_value));
if (FRAME_GTK_OUTER_WIDGET (f))
gtk_widget_set_double_buffered (FRAME_GTK_OUTER_WIDGET (f),
!NILP (new_value));
#endif
}
/* Handler for signals raised during x_create_frame and
x_create_tip_frame. FRAME is the frame which is partially
constructed. */
static Lisp_Object
unwind_create_frame (Lisp_Object frame)
{
struct frame *f = XFRAME (frame);
/* If frame is already dead, nothing to do. This can happen if the
display is disconnected after the frame has become official, but
before x_create_frame removes the unwind protect. */
if (!FRAME_LIVE_P (f))
return Qnil;
/* If frame is ``official'', nothing to do. */
if (NILP (Fmemq (frame, Vframe_list)))
{
/* If the frame's image cache refcount is still the same as our
private shadow variable, it means we are unwinding a frame
for which we didn't yet call init_frame_faces, where the
refcount is incremented. Therefore, we increment it here, so
that free_frame_faces, called in x_free_frame_resources
below, will not mistakenly decrement the counter that was not
incremented yet to account for this new frame. */
if (FRAME_IMAGE_CACHE (f) != NULL
&& FRAME_IMAGE_CACHE (f)->refcount == image_cache_refcount)
FRAME_IMAGE_CACHE (f)->refcount++;
x_free_frame_resources (f);
free_glyphs (f);
return Qt;
}
return Qnil;
}
static void
do_unwind_create_frame (Lisp_Object frame)
{
unwind_create_frame (frame);
}
/* Return the pixel color value for color COLOR_NAME on frame F. If F
is a monochrome frame, return MONO_COLOR regardless of what ARG says.
Signal an error if color can't be allocated. */
static int
x_decode_color (struct frame *f, Lisp_Object color_name, int mono_color)
{
Emacs_Color cdef;
CHECK_STRING (color_name);
/* Return MONO_COLOR for monochrome frames. */
if (FRAME_DISPLAY_INFO (f)->n_planes == 1)
return mono_color;
/* x_defined_color is responsible for coping with failures
by looking for a near-miss. */
if (pgtk_defined_color (f, SSDATA (color_name), &cdef, true, 0))
return cdef.pixel;
signal_error ("Undefined color", color_name);
}
void
x_set_parent_frame (struct frame *f, Lisp_Object new_value,
Lisp_Object old_value)
{
struct frame *p = NULL;
if (!NILP (new_value)
&& (!FRAMEP (new_value) || !FRAME_LIVE_P (p = XFRAME (new_value))
|| !FRAME_PGTK_P (p)))
{
store_frame_param (f, Qparent_frame, old_value);
error ("Invalid specification of `parent-frame'");
}
#ifdef HAVE_GTK4
if (!EQ (old_value, new_value))
eg_unparent_frame (f);
#endif
if (p != FRAME_PARENT_FRAME (f))
{
block_input ();
fset_parent_frame (f, new_value);
unblock_input ();
}
}
static void
x_default_font_parameter (struct frame *f, Lisp_Object parms)
{
struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
Lisp_Object font_param
= gui_display_get_arg (dpyinfo, parms, Qfont, NULL, NULL, RES_TYPE_STRING);
Lisp_Object font = Qnil;
if (EQ (font_param, Qunbound))
font_param = Qnil;
if (NILP (font_param))
{
/* System font should take precedence over X resources. We suggest this
regardless of font-use-system-font because .emacs may not have been
read yet. */
const char *system_font = xsettings_get_system_font ();
if (system_font)
font = font_open_by_name (f, build_unibyte_string (system_font));
}
if (NILP (font))
font = !NILP (font_param)
? font_param
: gui_display_get_arg (dpyinfo, parms, Qfont, "font", "Font",
RES_TYPE_STRING);
if (!FONTP (font) && !STRINGP (font))
{
const char *names[]
= {"monospace-10",
"-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
"-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
"-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
/* This was formerly the first thing tried, but it finds
too many fonts and takes too long. */
"-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
/* If those didn't work, look for something which will
at least work. */
"-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1", "fixed", NULL};
int i;
for (i = 0; names[i]; i++)
{
font = font_open_by_name (f, build_unibyte_string (names[i]));
if (!NILP (font))
break;
}
if (NILP (font))
error ("No suitable font was found");
}
else if (!NILP (font_param))
{
/* Remember the explicit font parameter, so we can re-apply it after
we've applied the `default' face settings. */
AUTO_FRAME_ARG (arg, Qfont_parameter, font_param);
gui_set_frame_parameters (f, arg);
}
/* This call will make X resources override any system font setting. */
gui_default_parameter (f, parms, Qfont, font, "font", "Font",
RES_TYPE_STRING);
}
/* ==========================================================================
Lisp definitions
========================================================================== */
DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
1, 1, 0,
doc: /* Make a new X window, which is called a "frame" in Emacs terms.
Return an Emacs frame object. PARMS is an alist of frame parameters.
If the parameters specify that the frame should not have a minibuffer,
and do not specify a specific minibuffer window to use, then
`default-minibuffer-frame' must be a frame whose minibuffer can be
shared by the new frame.
This function is an internal primitive--use `make-frame' instead. */)
(Lisp_Object parms)
{
struct frame *f;
Lisp_Object frame, tem;
Lisp_Object name;
bool minibuffer_only = false;
#ifndef HAVE_GTK4
long window_prompting = 0;
#endif
bool undecorated = false, override_redirect = false;
ptrdiff_t count = SPECPDL_INDEX ();
Lisp_Object display;
struct pgtk_display_info *dpyinfo = NULL;
Lisp_Object parent, parent_frame;
struct kboard *kb;
int x_width = 0, x_height = 0;
parms = Fcopy_alist (parms);
/* Use this general default value to start with
until we know if this frame has a specified name. */
Vx_resource_name = Vinvocation_name;
display
= gui_display_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER);
if (EQ (display, Qunbound))
display
= gui_display_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
if (EQ (display, Qunbound))
display = Qnil;
dpyinfo = check_pgtk_display_info (display);
kb = dpyinfo->terminal->kboard;
if (!dpyinfo->terminal->name)
error ("Terminal is not live, can't create new frames on it");
name = gui_display_get_arg (dpyinfo, parms, Qname, "name", "Name",
RES_TYPE_STRING);
if (!STRINGP (name) && !EQ (name, Qunbound) && !NILP (name))
error ("Invalid frame name--not a string or nil");
if (STRINGP (name))
Vx_resource_name = name;
/* See if parent window is specified. */
parent = gui_display_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL,
RES_TYPE_NUMBER);
if (EQ (parent, Qunbound))
parent = Qnil;
if (!NILP (parent))
CHECK_NUMBER (parent);
frame = Qnil;
tem = gui_display_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer",
"Minibuffer", RES_TYPE_SYMBOL);
if (EQ (tem, Qnone) || NILP (tem))
f = make_frame_without_minibuffer (Qnil, kb, display);
else if (EQ (tem, Qonly))
{
f = make_minibuffer_frame ();
minibuffer_only = true;
}
else if (WINDOWP (tem))
f = make_frame_without_minibuffer (tem, kb, display);
else
f = make_frame (true);
parent_frame = gui_display_get_arg (dpyinfo, parms, Qparent_frame, NULL, NULL,
RES_TYPE_SYMBOL);
/* Accept parent-frame iff parent-id was not specified. */
if (!NILP (parent) || EQ (parent_frame, Qunbound) || NILP (parent_frame)
|| !FRAMEP (parent_frame) || !FRAME_LIVE_P (XFRAME (parent_frame))
|| !FRAME_PGTK_P (XFRAME (parent_frame)))
parent_frame = Qnil;
f->terminal = dpyinfo->terminal;
store_frame_param (f, Qparent_frame, parent_frame);
if (!NILP (tem = (gui_display_get_arg (dpyinfo, parms, Qundecorated, NULL,
NULL, RES_TYPE_BOOLEAN)))
&& !(EQ (tem, Qunbound)))
undecorated = true;
FRAME_UNDECORATED (f) = undecorated;
store_frame_param (f, Qundecorated, undecorated ? Qt : Qnil);
if (!NILP (tem = (gui_display_get_arg (dpyinfo, parms, Qoverride_redirect,
NULL, NULL, RES_TYPE_BOOLEAN)))
&& !(EQ (tem, Qunbound)))
override_redirect = true;
FRAME_OVERRIDE_REDIRECT (f) = override_redirect;
store_frame_param (f, Qoverride_redirect, override_redirect ? Qt : Qnil);
store_frame_param (f, Qheader_bar_icons, Qt);
#ifdef HAVE_GTK4
store_frame_param (f, Qheader_bar, Qt);
#endif
XSETFRAME (frame, f);
f->output_method = output_pgtk;
FRAME_X_OUTPUT (f) = xzalloc (sizeof *FRAME_X_OUTPUT (f));
#if 0
FRAME_X_OUTPUT(f)->icon_bitmap = -1;
#endif
FRAME_FONTSET (f) = -1;
FRAME_X_OUTPUT (f)->white_relief.pixel = -1;
FRAME_X_OUTPUT (f)->black_relief.pixel = -1;
FRAME_X_OUTPUT (f)->clip_count = 0;
#ifdef HAVE_GTK3
FRAME_X_OUTPUT (f)->scrollbar_foreground_css_provider
= gtk_css_provider_new ();
FRAME_X_OUTPUT (f)->scrollbar_background_css_provider
= gtk_css_provider_new ();
#endif
FRAME_X_OUTPUT (f)->menubar_or_popup_count = 0;
#ifdef HAVE_GTK4
FRAME_X_OUTPUT (f)->hyper_flag = 0;
FRAME_X_OUTPUT (f)->last_focus_child_frame = 0;
#endif
fset_icon_name (f,
gui_display_get_arg (dpyinfo, parms, Qicon_name, "iconName",
"Title", RES_TYPE_STRING));
if (!STRINGP (f->icon_name))
fset_icon_name (f, Qnil);
FRAME_DISPLAY_INFO (f) = dpyinfo;
/* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
record_unwind_protect (do_unwind_create_frame, frame);
/* These colors will be set anyway later, but it's important
to get the color reference counts right, so initialize them! */
{
Lisp_Object black;
/* Function x_decode_color can signal an error. Make
sure to initialize color slots so that we won't try
to free colors we haven't allocated. */
FRAME_FOREGROUND_PIXEL (f) = -1;
FRAME_BACKGROUND_PIXEL (f) = -1;
FRAME_X_OUTPUT (f)->cursor_color = -1;
FRAME_X_OUTPUT (f)->cursor_foreground_color = -1;
#ifdef HAVE_GTK3
FRAME_X_OUTPUT (f)->border_pixel = -1;
#endif
FRAME_X_OUTPUT (f)->mouse_color = -1;
#ifdef HAVE_GTK4
FRAME_X_OUTPUT (f)->child_frame_order = NULL;
#endif
black = build_string ("black");
FRAME_FOREGROUND_PIXEL (f)
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
FRAME_BACKGROUND_PIXEL (f)
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
FRAME_X_OUTPUT (f)->cursor_color
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
FRAME_X_OUTPUT (f)->cursor_foreground_color
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
#ifdef HAVE_GTK3
FRAME_X_OUTPUT (f)->border_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
#endif
FRAME_X_OUTPUT (f)->mouse_color
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
}
/* Specify the parent under which to make this X window. */
if (!NILP (parent))
{
FRAME_X_OUTPUT (f)->parent_desc = (GWindow) XFIXNAT (parent);
FRAME_X_OUTPUT (f)->explicit_parent = true;
}
else
{
FRAME_X_OUTPUT (f)->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
FRAME_X_OUTPUT (f)->explicit_parent = false;
}
#ifdef HAVE_GTK4
FRAME_X_OUTPUT (f)->mbar_deep_atimer = NULL;
#endif
/* Set the name; the functions to which we pass f expect the name to
be set. */
if (EQ (name, Qunbound) || NILP (name))
{
fset_name (f, build_string (dpyinfo->x_id_name));
f->explicit_name = false;
}
else
{
fset_name (f, name);
f->explicit_name = true;
/* Use the frame's title when getting resources for this frame. */
specbind (Qx_resource_name, name);
}
register_font_driver (&ftcrfont_driver, f);
#ifdef HAVE_HARFBUZZ
register_font_driver (&ftcrhbfont_driver, f);
#endif /* HAVE_HARFBUZZ */
image_cache_refcount
= FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
#if 0
#ifdef GLYPH_DEBUG
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
#endif
gui_default_parameter (f, parms, Qfont_backend, Qnil, "fontBackend",
"FontBackend", RES_TYPE_STRING);
/* Extract the window parameters from the supplied values
that are needed to determine window geometry. */
x_default_font_parameter (f, parms);
if (!FRAME_FONT (f))
{
delete_frame (frame, Qnoelisp);
error ("Invalid frame font");
}
/* Frame contents get displaced if an embedded X window has a border. */
#if 0
if (! FRAME_X_EMBEDDED_P (f))
#endif
gui_default_parameter (f, parms, Qborder_width, make_fixnum (0),
"borderWidth", "BorderWidth", RES_TYPE_NUMBER);
/* This defaults to 1 in order to match xterm. We recognize either
internalBorderWidth or internalBorder (which is what xterm calls
it). */
if (NILP (Fassq (Qinternal_border_width, parms)))
{
Lisp_Object value;
value = gui_display_get_arg (dpyinfo, parms, Qinternal_border_width,
"internalBorder", "internalBorder",
RES_TYPE_NUMBER);
if (!EQ (value, Qunbound))
parms = Fcons (Fcons (Qinternal_border_width, value), parms);
}
gui_default_parameter (f, parms, Qinternal_border_width, make_fixnum (0),
"internalBorderWidth", "internalBorderWidth",
RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qright_divider_width, make_fixnum (0), NULL,
NULL, RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0), NULL,
NULL, RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qvertical_scroll_bars, Qright,
"verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
gui_default_parameter (f, parms, Qhorizontal_scroll_bars, Qnil,
"horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
/* Also do the stuff which must be set before the window exists. */
gui_default_parameter (f, parms, Qforeground_color, build_string ("black"),
"foreground", "Foreground", RES_TYPE_STRING);
gui_default_parameter (f, parms, Qbackground_color, build_string ("white"),
"background", "Background", RES_TYPE_STRING);
gui_default_parameter (f, parms, Qmouse_color, build_string ("black"),
"pointerColor", "Foreground", RES_TYPE_STRING);
gui_default_parameter (f, parms, Qborder_color, build_string ("black"),
"borderColor", "BorderColor", RES_TYPE_STRING);
gui_default_parameter (f, parms, Qscreen_gamma, Qnil, "screenGamma",
"ScreenGamma", RES_TYPE_FLOAT);
gui_default_parameter (f, parms, Qline_spacing, Qnil, "lineSpacing",
"LineSpacing", RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qleft_fringe, Qnil, "leftFringe",
"LeftFringe", RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qright_fringe, Qnil, "rightFringe",
"RightFringe", RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qno_special_glyphs, Qnil, NULL, NULL,
RES_TYPE_BOOLEAN);
gui_default_parameter (f, parms, Qscroll_bar_foreground, Qnil,
"scrollBarForeground", "ScrollBarForeground",
RES_TYPE_STRING);
gui_default_parameter (f, parms, Qscroll_bar_background, Qnil,
"scrollBarBackground", "ScrollBarBackground",
RES_TYPE_STRING);
/* Init faces before gui_default_parameter is called for the
scroll-bar-width parameter because otherwise we end up in
init_iterator with a null face cache, which should not happen. */
init_frame_faces (f);
/* We have to call adjust_frame_size here since otherwise
x_set_tool_bar_lines will already work with the character sizes
installed by init_frame_faces while the frame's pixel size is still
calculated from a character size of 1 and we subsequently hit the
(height >= 0) assertion in window_box_height.
The non-pixelwise code apparently worked around this because it
had one frame line vs one toolbar line which left us with a zero
root window height which was obviously wrong as well ...
Also process `min-width' and `min-height' parameters right here
because `frame-windows-min-size' needs them. */
tem = gui_display_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL,
RES_TYPE_NUMBER);
if (NUMBERP (tem))
store_frame_param (f, Qmin_width, tem);
tem = gui_display_get_arg (dpyinfo, parms, Qmin_height, NULL, NULL,
RES_TYPE_NUMBER);
if (NUMBERP (tem))
store_frame_param (f, Qmin_height, tem);
adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 5, true,
Qx_create_frame_1);
/* Set the menu-bar-lines and tool-bar-lines parameters. We don't
look up the X resources controlling the menu-bar and tool-bar
here; they are processed specially at startup, and reflected in
the values of the mode variables. */
gui_default_parameter (f, parms, Qmenu_bar_lines,
NILP (Vmenu_bar_mode) ? make_fixnum (0)
: make_fixnum (1),
NULL, NULL, RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qtab_bar_lines,
NILP (Vtab_bar_mode) ? make_fixnum (0)
: make_fixnum (1),
NULL, NULL, RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qtool_bar_lines,
NILP (Vtool_bar_mode) ? make_fixnum (0)
: make_fixnum (1),
NULL, NULL, RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
"BufferPredicate", RES_TYPE_SYMBOL);
gui_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
RES_TYPE_STRING);
gui_default_parameter (f, parms, Qwait_for_wm, Qt, "waitForWM", "WaitForWM",
RES_TYPE_BOOLEAN);
gui_default_parameter (f, parms, Qtool_bar_position,
FRAME_TOOL_BAR_POSITION (f), 0, 0, RES_TYPE_SYMBOL);
gui_default_parameter (f, parms, Qinhibit_double_buffering, Qnil,
"inhibitDoubleBuffering", "InhibitDoubleBuffering",
RES_TYPE_BOOLEAN);
#ifndef HAVE_GTK4
/* Compute the size of the X window. */
window_prompting =
#endif
gui_figure_window_size (f, parms, true, true, &x_width, &x_height);
tem = gui_display_get_arg (dpyinfo, parms, Qunsplittable, 0, 0,
RES_TYPE_BOOLEAN);
f->no_split = minibuffer_only || EQ (tem, Qt);
#if 0
x_icon_verify (f, parms);
#endif
#ifdef HAVE_GTK4
egtk_create_frame_widgets (f);
fset_parent_frame (f, parent_frame);
#else
xg_create_frame_widgets (f);
#endif
#if defined(HAVE_GTK3) || defined (HAVE_GTK4)
FRAME_GTK_EV_HANDLER (f) = emacs_gtk_event_handler_new (f);
FRAME_GTK_ES_HANDLER (f) = emacs_gtk_event_handler_new (f);
g_object_ref (FRAME_GTK_EV_HANDLER (f));
g_object_ref (FRAME_GTK_ES_HANDLER (f));
#endif
pgtk_set_event_handler (f);
#ifndef HAVE_GTK4
#define INSTALL_CURSOR(FIELD, NAME) \
FRAME_X_OUTPUT (f)->FIELD \
= gdk_cursor_new_for_display (FRAME_X_DISPLAY (f), GDK_##NAME)
INSTALL_CURSOR (text_cursor, XTERM);
INSTALL_CURSOR (nontext_cursor, LEFT_PTR);
INSTALL_CURSOR (modeline_cursor, XTERM);
INSTALL_CURSOR (hand_cursor, HAND2);
INSTALL_CURSOR (hourglass_cursor, WATCH);
INSTALL_CURSOR (horizontal_drag_cursor, SB_H_DOUBLE_ARROW);
INSTALL_CURSOR (vertical_drag_cursor, SB_V_DOUBLE_ARROW);
INSTALL_CURSOR (left_edge_cursor, LEFT_SIDE);
INSTALL_CURSOR (right_edge_cursor, RIGHT_SIDE);
INSTALL_CURSOR (top_edge_cursor, TOP_SIDE);
INSTALL_CURSOR (bottom_edge_cursor, BOTTOM_SIDE);
INSTALL_CURSOR (top_left_corner_cursor, TOP_LEFT_CORNER);
INSTALL_CURSOR (top_right_corner_cursor, TOP_RIGHT_CORNER);
INSTALL_CURSOR (bottom_right_corner_cursor, BOTTOM_RIGHT_CORNER);
INSTALL_CURSOR (bottom_left_corner_cursor, BOTTOM_LEFT_CORNER);
#undef INSTALL_CURSOR
#else
FRAME_X_OUTPUT (f)->text_cursor = gdk_cursor_new_from_name ("text", NULL);
FRAME_X_OUTPUT (f)->nontext_cursor = gdk_cursor_new_from_name ("default", NULL);
FRAME_X_OUTPUT (f)->modeline_cursor = gdk_cursor_new_from_name ("default", NULL);
FRAME_X_OUTPUT (f)->hand_cursor = gdk_cursor_new_from_name ("pointer", NULL);
FRAME_X_OUTPUT (f)->hourglass_cursor = gdk_cursor_new_from_name ("wait", NULL);
FRAME_X_OUTPUT (f)->horizontal_drag_cursor = gdk_cursor_new_from_name ("col-resize", NULL);
FRAME_X_OUTPUT (f)->vertical_drag_cursor = gdk_cursor_new_from_name ("row-resize", NULL);
FRAME_X_OUTPUT (f)->bottom_right_corner_cursor = gdk_cursor_new_from_name ("se-resize", NULL);
FRAME_X_OUTPUT (f)->bottom_left_corner_cursor = gdk_cursor_new_from_name ("sw-resize", NULL);
FRAME_X_OUTPUT (f)->top_right_corner_cursor = gdk_cursor_new_from_name ("ne-resize", NULL);
FRAME_X_OUTPUT (f)->top_left_corner_cursor = gdk_cursor_new_from_name ("nw-resize", NULL);
FRAME_X_OUTPUT (f)->left_edge_cursor = gdk_cursor_new_from_name ("w-resize", NULL);
FRAME_X_OUTPUT (f)->right_edge_cursor = gdk_cursor_new_from_name ("e-resize", NULL);
FRAME_X_OUTPUT (f)->top_edge_cursor = gdk_cursor_new_from_name ("n-resize", NULL);
FRAME_X_OUTPUT (f)->bottom_edge_cursor = gdk_cursor_new_from_name ("s-resize", NULL);
#endif
x_icon (f, parms);
/* Now consider the frame official. */
f->terminal->reference_count++;
FRAME_DISPLAY_INFO (f)->reference_count++;
Vframe_list = Fcons (frame, Vframe_list);
/* We need to do this after creating the X window, so that the
icon-creation functions can say whose icon they're describing. */
gui_default_parameter (f, parms, Qicon_type, Qt, "bitmapIcon", "BitmapIcon",
RES_TYPE_BOOLEAN);
gui_default_parameter (f, parms, Qauto_raise, Qnil, "autoRaise",
"AutoRaiseLower", RES_TYPE_BOOLEAN);
gui_default_parameter (f, parms, Qauto_lower, Qnil, "autoLower",
"AutoRaiseLower", RES_TYPE_BOOLEAN);
gui_default_parameter (f, parms, Qcursor_type, Qbox, "cursorType",
"CursorType", RES_TYPE_SYMBOL);
gui_default_parameter (f, parms, Qscroll_bar_width, Qnil, "scrollBarWidth",
"ScrollBarWidth", RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qscroll_bar_height, Qnil, "scrollBarHeight",
"ScrollBarHeight", RES_TYPE_NUMBER);
gui_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha",
RES_TYPE_NUMBER);
#if 0
if (!NILP (parent_frame))
{
struct frame *p = XFRAME (parent_frame);
block_input ();
XReparentWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
FRAME_X_WINDOW (p), f->left_pos, f->top_pos);
unblock_input ();
}
#endif
gui_default_parameter (f, parms, Qno_focus_on_map, Qnil, NULL, NULL,
RES_TYPE_BOOLEAN);
gui_default_parameter (f, parms, Qno_accept_focus, Qnil, NULL, NULL,
RES_TYPE_BOOLEAN);
/* Consider frame official, now. */
f->can_set_window_size = true;
if (x_width > 0)
SET_FRAME_WIDTH (f, x_width);
if (x_height > 0)
SET_FRAME_HEIGHT (f, x_height);
/* Tell the server what size and position, etc, we want, and how
badly we want them. This should be done after we have the menu
bar so that its size can be taken into account. */
block_input ();
#ifndef HAVE_GTK4
x_wm_set_size_hint (f, window_prompting, false);
#endif
unblock_input ();
adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 0, true,
Qx_create_frame_2);
/* Process fullscreen parameter here in the hope that normalizing a
fullheight/fullwidth frame will produce the size set by the last
adjust_frame_size call. */
gui_default_parameter (f, parms, Qfullscreen, Qnil, "fullscreen",
"Fullscreen", RES_TYPE_SYMBOL);
/* Make the window appear on the frame and enable display, unless
the caller says not to. However, with explicit parent, Emacs
cannot control visibility, so don't try. */
if (!FRAME_X_OUTPUT (f)->explicit_parent)
{
Lisp_Object visibility = gui_display_get_arg (dpyinfo, parms, Qvisibility,
0, 0, RES_TYPE_SYMBOL);
if (EQ (visibility, Qicon))
pgtk_iconify_frame (f);
else
{
if (EQ (visibility, Qunbound))
visibility = Qt;
if (!NILP (visibility))
pgtk_make_frame_visible (f);
}
store_frame_param (f, Qvisibility, visibility);
}
/* Works iff frame has been already mapped. */
gui_default_parameter (f, parms, Qskip_taskbar, Qnil, NULL, NULL,
RES_TYPE_BOOLEAN);
/* The `z-group' parameter works only for visible frames. */
gui_default_parameter (f, parms, Qz_group, Qnil, NULL, NULL, RES_TYPE_SYMBOL);
/* Initialize `default-minibuffer-frame' in case this is the first
frame on this terminal. */
if (FRAME_HAS_MINIBUF_P (f)
&& (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
|| !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
kset_default_minibuffer_frame (kb, frame);
/* Create the menu bar. */
if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
{
/* If this signals an error, we haven't set size hints for the
frame and we didn't make it visible. */
initialize_frame_menubar (f);
}
/* All remaining specified parameters, which have not been "used"
by gui_display_get_arg and friends, now go in the misc. alist of the frame.
*/
for (tem = parms; CONSP (tem); tem = XCDR (tem))
if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
#ifdef HAVE_GTK4
FRAME_X_OUTPUT (f)->keep_above = NULL;
#endif
#ifdef HAVE_GTK3
FRAME_X_OUTPUT (f)->border_color_css_provider = NULL;
#endif
FRAME_X_OUTPUT (f)->cr_surface_visible_bell = NULL;
FRAME_X_OUTPUT (f)->atimer_visible_bell = NULL;
/* Make sure windows on this frame appear in calls to next-window
and similar functions. */
Vwindow_list = Qnil;
#ifndef HAVE_GTK4
fset_parent_frame (f, parent_frame);
#endif
#ifdef HAVE_GTK4
pgtk_dnd_init (f);
FRAME_X_OUTPUT (f)->ts_up_flag = false;
if (NILP (Vtool_bar_mode))
free_frame_tool_bar (f);
#endif
return unbind_to (count, frame);
}
#if 0
static int
pgtk_window_is_ancestor (PGTKWindow *win, PGTKWindow *candidate)
/* Test whether CANDIDATE is an ancestor window of WIN. */
{
if (candidate == NULL)
return 0;
else if (win == candidate)
return 1;
else
return pgtk_window_is_ancestor(win, [candidate parentWindow]);
}
#endif
/**
* x_frame_restack:
*
* Restack frame F1 below frame F2, above if ABOVE_FLAG is non-nil. In
* practice this is a two-step action: The first step removes F1's
* window-system window from the display. The second step reinserts
* F1's window below (above if ABOVE_FLAG is true) that of F2.
*/
static void
pgtk_frame_restack (struct frame *f1, struct frame *f2, bool above_flag)
{
block_input ();
#ifndef HAVE_GTK4
xg_frame_restack (f1, f2, above_flag);
#else
egtk_frame_restack (f1, f2, above_flag);
#endif
unblock_input ();
}
DEFUN ("pgtk-frame-restack", Fpgtk_frame_restack, Spgtk_frame_restack, 2, 3, 0,
doc: /* Restack FRAME1 below FRAME2.
This means that if both frames are visible and the display areas of
these frames overlap, FRAME2 (partially) obscures FRAME1. If optional
third argument ABOVE is non-nil, restack FRAME1 above FRAME2. This
means that if both frames are visible and the display areas of these
frames overlap, FRAME1 (partially) obscures FRAME2.
This may be thought of as an atomic action performed in two steps: The
first step removes FRAME1's window-step window from the display. The
second step reinserts FRAME1's window below (above if ABOVE is true)
that of FRAME2. Hence the position of FRAME2 in its display's Z
\(stacking) order relative to all other frames excluding FRAME1 remains
unaltered.
Some window managers may refuse to restack windows. */)
(Lisp_Object frame1, Lisp_Object frame2, Lisp_Object above)
{
struct frame *f1 = decode_live_frame (frame1);
struct frame *f2 = decode_live_frame (frame2);
if (!(FRAME_GTK_OUTER_WIDGET (f1) && FRAME_GTK_OUTER_WIDGET (f2)))
error ("Cannot restack frames");
pgtk_frame_restack (f1, f2, !NILP (above));
return Qt;
}
#ifdef HAVE_GSETTINGS
#define RESOURCE_KEY_MAX_LEN 128
#define SCHEMA_ID "org.gnu.emacs.defaults"
#define PATH_FOR_CLASS_TYPE "/org/gnu/emacs/defaults-by-class/"
#define PATH_PREFIX_FOR_NAME_TYPE "/org/gnu/emacs/defaults-by-name/"
static inline int
pgtk_is_lower_char (int c)
{
return c >= 'a' && c <= 'z';
}
static inline int
pgtk_is_upper_char (int c)
{
return c >= 'A' && c <= 'Z';
}
static inline int
pgtk_is_numeric_char (int c)
{
return c >= '0' && c <= '9';
}
#ifndef GLIB_VERSION_2_40
static gboolean
g_settings_schema_has_key (GSettingsSchema *schema, const gchar *key)
{
for (char **keys = g_settings_list_keys (schema); keys; ++keys)
{
if (strcmp (keys[0], key))
return true;
}
return false;
}
#endif
static GSettings *
parse_resource_key (const char *res_key, char *setting_key)
{
char path[32 + RESOURCE_KEY_MAX_LEN];
const char *sp = res_key;
char *dp;
/*
* res_key="emacs.cursorBlink"
* -> path="/org/gnu/emacs/defaults-by-name/emacs/"
* setting_key="cursor-blink"
*
* res_key="Emacs.CursorBlink"
* -> path="/org/gnu/emacs/defaults-by-class/"
* setting_key="cursor-blink"
*
* Returns GSettings* if setting_key exists in schema, otherwise NULL.
*/
/* generate path */
if (pgtk_is_upper_char (*sp))
{
/* First letter is upper case. It should be "Emacs",
* but don't care.
*/
strcpy (path, PATH_FOR_CLASS_TYPE);
while (*sp != '\0')
{
if (*sp == '.')
break;
sp++;
}
}
else
{
strcpy (path, PATH_PREFIX_FOR_NAME_TYPE);
dp = path + strlen (path);
while (*sp != '\0')
{
int c = *sp;
if (c == '.')
break;
if (pgtk_is_lower_char (c))
(void) 0; /* lower -> NOP */
else if (pgtk_is_upper_char (c))
c = c - 'A' + 'a'; /* upper -> lower */
else if (pgtk_is_numeric_char (c))
(void) 0; /* numeric -> NOP */
else
return NULL; /* invalid */
*dp++ = c;
sp++;
}
*dp++ = '/'; /* must ends with '/' */
*dp = '\0';
}
if (*sp++ != '.')
return NULL;
/* generate setting_key */
dp = setting_key;
while (*sp != '\0')
{
int c = *sp;
if (pgtk_is_lower_char (c))
(void) 0; /* lower -> NOP */
else if (pgtk_is_upper_char (c))
{
c = c - 'A' + 'a'; /* upper -> lower */
if (dp != setting_key)
*dp++ = '-'; /* store '-' unless first char */
}
else if (pgtk_is_numeric_char (c))
(void) 0; /* numeric -> NOP */
else
return NULL; /* invalid */
*dp++ = c;
sp++;
}
*dp = '\0';
/* check existence of setting_key */
GSettingsSchemaSource *ssrc = g_settings_schema_source_get_default ();
GSettingsSchema *scm
= g_settings_schema_source_lookup (ssrc, SCHEMA_ID, FALSE);
if (scm == NULL)
{
return NULL;
}
if (!g_settings_schema_has_key (scm, setting_key))
{
g_settings_schema_unref (scm);
return NULL;
}
/* create GSettings, and return it */
GSettings *gs = g_settings_new_full (scm, NULL, path);
g_settings_schema_unref (scm);
return gs;
}
const char *
pgtk_get_defaults_value (const char *key)
{
char skey[(RESOURCE_KEY_MAX_LEN + 1) * 2];
if (strlen (key) >= RESOURCE_KEY_MAX_LEN)
error ("resource key too long.");
GSettings *gs = parse_resource_key (key, skey);
if (gs == NULL)
{
return NULL;
}
gchar *str = g_settings_get_string (gs, skey);
/* There is no timing to free str.
* So, copy it here and free it.
*
* MEMO: Resource values for emacs shouldn't need such a long string value.
*/
static char holder[128];
strncpy (holder, str, 128);
holder[127] = '\0';
g_object_unref (gs);
g_free (str);
return holder[0] != '\0' ? holder : NULL;
}
static void
pgtk_set_defaults_value (const char *key, const char *value)
{
char skey[(RESOURCE_KEY_MAX_LEN + 1) * 2];
if (strlen (key) >= RESOURCE_KEY_MAX_LEN)
error ("resource key too long.");
GSettings *gs = parse_resource_key (key, skey);
if (gs == NULL)
error ("unknown resource key.");
if (value != NULL)
{
g_settings_set_string (gs, skey, value);
}
else
{
g_settings_reset (gs, skey);
}
g_object_unref (gs);
}
#undef RESOURCE_KEY_MAX_LEN
#undef SCHEMA_ID
#undef PATH_FOR_CLASS_TYPE
#undef PATH_PREFIX_FOR_NAME_TYPE
#else /* not HAVE_GSETTINGS */
const char *
pgtk_get_defaults_value (const char *key)
{
return NULL;
}
static void
pgtk_set_defaults_value (const char *key, const char *value)
{
error ("gsettings not supported.");
}
#endif
DEFUN ("pgtk-set-resource", Fpgtk_set_resource, Spgtk_set_resource, 2, 2, 0,
doc: /* Set the value of ATTRIBUTE, of class CLASS, as VALUE, into defaults database. */)
(Lisp_Object attribute, Lisp_Object value)
{
check_window_system (NULL);
CHECK_STRING (attribute);
if (!NILP (value))
CHECK_STRING (value);
char *res = SSDATA (Vx_resource_name);
char *attr = SSDATA (attribute);
if (attr[0] >= 'A' && attr[0] <= 'Z')
res = SSDATA (Vx_resource_class);
char *key = g_strdup_printf ("%s.%s", res, attr);
pgtk_set_defaults_value (key, NILP (value) ? NULL : SSDATA (value));
return Qnil;
}
DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
Sx_server_max_request_size, 0, 1, 0, doc
: /* This function is a no-op. It is only present for completeness. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
/* This function has no real equivalent under PGTK. Return nil to
indicate this. */
return Qnil;
}
DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
doc: /* Read a font using a GTK dialog.
Return either a font spec (for GTK versions >= 3.2) or a string
containing a GTK-style font name.
FRAME is the frame on which to pop up the font chooser. If omitted or
nil, it defaults to the selected frame. */)
(Lisp_Object frame, Lisp_Object ignored)
{
struct frame *f = decode_window_system_frame (frame);
Lisp_Object font;
Lisp_Object font_param;
char *default_name = NULL;
ptrdiff_t count = SPECPDL_INDEX ();
/* Prevent redisplay. */
specbind (Qinhibit_redisplay, Qt);
block_input ();
XSETFONT (font, FRAME_FONT (f));
font_param = Ffont_get (font, QCname);
if (STRINGP (font_param))
default_name = xlispstrdup (font_param);
else
{
font_param = Fframe_parameter (frame, Qfont_parameter);
if (STRINGP (font_param))
default_name = xlispstrdup (font_param);
}
#ifndef HAVE_GTK4
font = xg_get_font (f, default_name);
#else
font = egtk_get_font (f, default_name);
#endif
xfree (default_name);
unblock_input ();
if (NILP (font))
quit ();
return unbind_to (count, font);
}
DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
doc: /* Return the "vendor ID" string of the display server TERMINAL.
\(Labeling every distributor as a "vendor" embodies the false assumption
that operating systems cannot be developed and distributed noncommercially.)
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return build_string ("The GNU project's GTK toolkit.");
}
DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
doc: /* Return the version numbers of the server of display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return list3 (make_fixnum (GTK_MAJOR_VERSION),
make_fixnum (GTK_MINOR_VERSION),
make_fixnum (GTK_MICRO_VERSION));
}
DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
doc: /* Return the number of screens on the display server TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
Note: "screen" here is not in X11's. For the number of physical monitors,
use `(length \(display-monitor-attributes-list TERMINAL))' instead. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return make_fixnum (1);
}
DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
doc: /* Return the height in millimeters of the the display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
On \"multi-monitor\" setups this refers to the height in millimeters for
all physical monitors associated with TERMINAL. To get information
for each physical monitor, use `display-monitor-attributes-list'. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
GdkDisplay *gdpy = dpyinfo->gdpy;
#if defined(GDK_VERSION_3_22) || defined(HAVE_GTK4)
#ifndef HAVE_GTK4
GdkMonitor *gmon = gdk_display_get_monitor_at_point (gdpy, 0, 0);
#else
GdkMonitor *gmon = gdk_display_get_monitor (gdpy, 0);
#endif
return make_fixnum (gdk_monitor_get_height_mm (gmon));
#else
return make_fixnum (
gdk_screen_get_height_mm (gdk_display_get_default_screen (gdpy)));
#endif
}
DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
doc: /* Return the width in millimeters of the the display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
On \"multi-monitor\" setups this refers to the width in millimeters for
all physical monitors associated with TERMINAL. To get information
for each physical monitor, use `display-monitor-attributes-list'. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
GdkDisplay *gdpy = dpyinfo->gdpy;
#if defined(GDK_VERSION_3_22) || defined(HAVE_GTK4)
#ifndef HAVE_GTK4
GdkMonitor *gmon = gdk_display_get_monitor_at_point (gdpy, 0, 0);
#else
GdkMonitor *gmon = gdk_display_get_monitor (gdpy, 0);
#endif
return make_fixnum (gdk_monitor_get_width_mm (gmon));
#else
return make_fixnum (
gdk_screen_get_width_mm (gdk_display_get_default_screen (gdpy)));
#endif
}
DEFUN ("x-display-backing-store", Fx_display_backing_store,
Sx_display_backing_store, 0, 1, 0,
doc: /* Return an indication of whether the the display TERMINAL does backing store.
The value may be `buffered', `retained', or `non-retained'.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return Qnil;
}
DEFUN ("x-display-visual-class", Fx_display_visual_class,
Sx_display_visual_class, 0, 1, 0,
doc: /* Return the visual class of the the display TERMINAL.
The value is one of the symbols `static-gray', `gray-scale',
`static-color', `pseudo-color', `true-color', or `direct-color'.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
On PGTK, always return true-color. */)
(Lisp_Object terminal) { return intern ("true-color"); }
DEFUN ("x-display-save-under", Fx_display_save_under,
Sx_display_save_under, 0, 1, 0,
doc: /* Return t if TERMINAL supports the save-under feature.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return Qnil;
}
DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
1, 3, 0,
doc: /* Open a connection to a display server.
DISPLAY is the name of the display to connect to.
Optional second arg XRM-STRING is a string of resources in xrdb format.
If the optional third arg MUST-SUCCEED is non-nil,
terminate Emacs if we can't open the connection. */)
(Lisp_Object display, Lisp_Object resource_string, Lisp_Object must_succeed)
{
struct pgtk_display_info *dpyinfo;
if (NILP (display))
display = build_string ("");
CHECK_STRING (display);
nxatoms_of_pgtkselect ();
dpyinfo = pgtk_term_init (display, SSDATA (Vx_resource_name));
if (dpyinfo == 0)
{
if (!NILP (must_succeed))
fatal ("Display on %s not responding.\n", SSDATA (display));
else
error ("Display on %s not responding.\n", SSDATA (display));
}
return Qnil;
}
DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
1, 1, 0,
doc: /* Close the connection to TERMINAL's display server.
For TERMINAL, specify a terminal object, a frame or a display name (a
string). If TERMINAL is nil, that stands for the selected frame's
terminal. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
if (dpyinfo->reference_count > 0)
error ("Display still has frames on it");
pgtk_delete_terminal (dpyinfo->terminal);
return Qnil;
}
DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, doc
: /* Return the list of display names that Emacs has connections to. */)
(void)
{
Lisp_Object result = Qnil;
struct pgtk_display_info *ndi;
for (ndi = x_display_list; ndi; ndi = ndi->next)
result = Fcons (XCAR (ndi->name_list_element), result);
return result;
}
DEFUN ("pgtk-hide-others", Fpgtk_hide_others, Spgtk_hide_others, 0, 0, 0, doc
: /* Hides all applications other than Emacs. */)
(void)
{
check_window_system (NULL);
return Qnil;
}
DEFUN ("pgtk-hide-emacs", Fpgtk_hide_emacs, Spgtk_hide_emacs,
1, 1, 0,
doc: /* If ON is non-nil, the entire Emacs application is hidden.
Otherwise if Emacs is hidden, it is unhidden.
If ON is equal to `activate', Emacs is unhidden and becomes
the active application. */)
(Lisp_Object on)
{
check_window_system (NULL);
return Qnil;
}
DEFUN ("pgtk-font-name", Fpgtk_font_name, Spgtk_font_name, 1, 1, 0,
doc: /* Determine font PostScript or family name for font NAME.
NAME should be a string containing either the font name or an XLFD
font descriptor. If string contains `fontset' and not
`fontset-startup', it is left alone. */)
(Lisp_Object name)
{
char *nm;
CHECK_STRING (name);
nm = SSDATA (name);
if (nm[0] != '-')
return name;
if (strstr (nm, "fontset") && !strstr (nm, "fontset-startup"))
return name;
char *str = pgtk_xlfd_to_fontname (SSDATA (name));
name = build_string (str);
xfree (str);
return name;
}
/* ==========================================================================
Miscellaneous functions not called through hooks
========================================================================== */
/* called from frame.c */
struct pgtk_display_info *
check_x_display_info (Lisp_Object frame)
{
return check_pgtk_display_info (frame);
}
void
pgtk_set_scroll_bar_default_width (struct frame *f)
{
int unit = FRAME_COLUMN_WIDTH (f);
int minw =
#ifndef HAVE_GTK4
xg_get_default_scrollbar_width (f);
#else
egtk_get_default_scrollbar_width (f);
#endif
/* A minimum width of 14 doesn't look good for toolkit scroll bars. */
FRAME_CONFIG_SCROLL_BAR_COLS (f) = (minw + unit - 1) / unit;
FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = minw;
}
void
pgtk_set_scroll_bar_default_height (struct frame *f)
{
int height = FRAME_LINE_HEIGHT (f);
int min_height =
#ifndef HAVE_GTK4
xg_get_default_scrollbar_height (f);
#else
egtk_get_default_scrollbar_height (f);
#endif
/* A minimum height of 14 doesn't look good for toolkit scroll bars. */
FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = min_height;
FRAME_CONFIG_SCROLL_BAR_LINES (f) = (min_height + height - 1) / height;
}
/* terms impl this instead of x-get-resource directly */
const char *
pgtk_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
{
check_window_system (NULL);
if (inhibit_x_resources)
/* --quick was passed, so this is a no-op. */
return NULL;
const char *res = pgtk_get_defaults_value (name);
if (res == NULL)
res = pgtk_get_defaults_value (class);
if (res == NULL)
return NULL;
if (c_strncasecmp (res, "YES", 3) == 0)
return "true";
if (c_strncasecmp (res, "NO", 2) == 0)
return "false";
return res;
}
Lisp_Object
x_get_focus_frame (struct frame *frame)
{
struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
Lisp_Object focus;
if (!dpyinfo->x_focus_frame)
return Qnil;
XSETFRAME (focus, dpyinfo->x_focus_frame);
return focus;
}
/* ==========================================================================
Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
========================================================================== */
DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
doc: /* Internal function called by `color-defined-p', which see. */)
(Lisp_Object color, Lisp_Object frame)
{
if (!NILP (frame))
CHECK_FRAME (frame);
Emacs_Color col;
return (NILP (frame)
? pgtk_lisp_to_color (color, &col)
: pgtk_lisp_to_color_with_frame (color, &col, XFRAME (frame)))
? Qnil
: Qt;
}
DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
doc: /* Internal function called by `color-values', which see. */)
(Lisp_Object color, Lisp_Object frame)
{
Emacs_Color col;
CHECK_STRING (color);
if (!NILP (frame))
CHECK_FRAME (frame);
block_input ();
if (NILP (frame)
? pgtk_lisp_to_color (color, &col)
: pgtk_lisp_to_color_with_frame (color, &col, XFRAME (frame)))
{
unblock_input ();
return Qnil;
}
unblock_input ();
return list3i (col.red, col.green, col.blue);
}
DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
doc
: /* Internal function called by `display-color-p', which see. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return Qt;
}
DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
0, 1, 0,
doc: /* Return t if the display supports shades of gray.
Note that color displays do support shades of gray.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal) { return Qnil; }
DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
0, 1, 0,
doc: /* Return the width in pixels of the display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
On \"multi-monitor\" setups this refers to the pixel width for all
physical monitors associated with TERMINAL. To get information for
each physical monitor, use `display-monitor-attributes-list'. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
return make_fixnum (x_display_pixel_width (dpyinfo));
}
DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
Sx_display_pixel_height, 0, 1, 0,
doc: /* Return the height in pixels of the display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
On \"multi-monitor\" setups this refers to the pixel height for all
physical monitors associated with TERMINAL. To get information for
each physical monitor, use `display-monitor-attributes-list'. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
return make_fixnum (x_display_pixel_height (dpyinfo));
}
DEFUN ("pgtk-display-monitor-attributes-list",
Fpgtk_display_monitor_attributes_list,
Spgtk_display_monitor_attributes_list,
0, 1, 0,
doc: /* Return a list of physical monitor attributes on the X display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display.
Internal use only, use `display-monitor-attributes-list' instead. */)
(Lisp_Object terminal)
{
#if defined(GDK_VERSION_3_22) || HAVE_GTK4
struct terminal *term = decode_live_terminal (terminal);
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
GdkDisplay *gdpy = dpyinfo->gdpy;
GdkMonitor **gmons;
int i, n_monitors, primary_index;
struct MonitorInfo *monitors;
Lisp_Object monitor_frames = Qnil;
Lisp_Object frame = Qnil, rest = Qnil;
Lisp_Object rv = Qnil;
if (term->type != output_pgtk)
return Qnil;
n_monitors = gdk_display_get_n_monitors (gdpy);
if (n_monitors == 0)
return Qnil;
gmons = xmalloc (sizeof *gmons * n_monitors);
for (i = 0; i < n_monitors; i++)
gmons[i] = gdk_display_get_monitor (gdpy, i);
monitors = xzalloc (n_monitors * sizeof *monitors);
for (i = 0; i < n_monitors; i++)
{
struct MonitorInfo *mon = &monitors[i];
GdkMonitor *gmon = gmons[i];
if (gmon != NULL)
{
GdkRectangle geom;
gdk_monitor_get_geometry (gmon, &geom);
mon->geom.x = geom.x;
mon->geom.y = geom.y;
mon->geom.width = geom.width;
mon->geom.height = geom.height;
gdk_monitor_get_workarea (gmon, &geom);
mon->work.x = geom.x;
mon->work.y = geom.y;
mon->work.width = geom.width;
mon->work.height = geom.height;
mon->mm_width = gdk_monitor_get_width_mm (gmon);
mon->mm_height = gdk_monitor_get_height_mm (gmon);
mon->name = xstrdup (gdk_monitor_get_model (gmon));
}
}
monitor_frames = Fmake_vector (make_fixnum (n_monitors), Qnil);
FOR_EACH_FRAME (rest, frame)
{
struct frame *f = XFRAME (frame);
if (FRAME_PGTK_P (f))
{
GtkWidget *widget = FRAME_GTK_WIDGET (f);
GdkMonitor *gmon =
#ifdef HAVE_GTK4
gdk_display_get_monitor_at_surface
#else
gdk_display_get_monitor_at_window
#endif
(gdpy,
#ifdef HAVE_GTK4
EGTK_WIDGET_GET_WINDOW (widget)
#else
gtk_widget_get_window (widget)
#endif
);
if (gmon != NULL)
{
for (i = 0; i < n_monitors; i++)
{
if (gmons[i] == gmon)
{
ASET (monitor_frames, i,
Fcons (frame, AREF (monitor_frames, i)));
break;
}
}
}
}
}
primary_index = -1;
for (i = 0; i < n_monitors; i++)
{
if (gmons[i] != NULL &&
#ifndef HAVE_GTK4
gdk_monitor_is_primary (gmons[i])
#else
false
#endif
)
{
primary_index = i;
break;
}
}
rv = make_monitor_attribute_list (monitors, n_monitors, primary_index,
monitor_frames, "Gdk");
free_monitors (monitors, n_monitors);
xfree (gmons);
return rv;
#else
return Qnil;
#endif
}
DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
0, 1, 0,
doc: /* Return the number of bitplanes of the display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
check_pgtk_display_info (terminal);
return make_fixnum (32);
}
DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
0, 1, 0,
doc: /* Returns the number of color cells of the display TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
/* We force 24+ bit depths to 24-bit to prevent an overflow. */
return make_fixnum (1 << min (dpyinfo->n_planes, 24));
}
/***********************************************************************
Tool tips
***********************************************************************/
/* The frame of a currently visible tooltip. */
Lisp_Object tip_frame;
/* If non-nil, a timer started that hides the last tooltip when it
fires. */
static Lisp_Object tip_timer;
/* Compute where to display tip frame F. PARMS is the list of frame
parameters for F. DX and DY are specified offsets from the current
location of the mouse. WIDTH and HEIGHT are the width and height
of the tooltip. Return coordinates relative to the root window of
the display in *ROOT_X, and *ROOT_Y. */
static void
compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx,
Lisp_Object dy, int width, int height,
#ifndef HAVE_GTK4
int *root_x, int *root_y
#else
double *root_x, double *root_y
#endif
)
{
Lisp_Object left, top, right, bottom;
int min_x, min_y, max_x, max_y = -1;
/* User-specified position? */
left = Fcdr (Fassq (Qleft, parms));
top = Fcdr (Fassq (Qtop, parms));
right = Fcdr (Fassq (Qright, parms));
bottom = Fcdr (Fassq (Qbottom, parms));
/* Move the tooltip window where the mouse pointer is. Resize and
show it. */
if ((!INTEGERP (left) && !INTEGERP (right))
|| (!INTEGERP (top) && !INTEGERP (bottom)))
{
Lisp_Object frame, attributes, monitor, geometry;
#ifdef HAVE_GTK3
#if defined(GDK_VERSION_3_20) || defined(HAVE_GTK4)
GdkSeat *seat
= gdk_display_get_default_seat (FRAME_DISPLAY_INFO (f)->gdpy);
GdkDevice *dev = gdk_seat_get_pointer (seat);
#else
GdkDeviceManager *man
= gdk_display_get_device_manager (FRAME_DISPLAY_INFO (f)->gdpy);
GdkDevice *dev = gdk_device_manager_get_client_pointer (man);
#endif
#endif /* HAVE_GTK3 */
#ifndef HAVE_GTK4
GdkScreen *scr;
#endif
block_input ();
#ifdef HAVE_GTK3
#ifndef HAVE_GTK4
gdk_device_get_position (dev, &scr, root_x, root_y);
#else
gdk_device_get_surface_at_position (dev, root_x, root_y);
#endif
#else
gdk_display_get_pointer (FRAME_DISPLAY_INFO (f)->gdpy, &scr, root_x,
root_y, NULL);
#endif
unblock_input ();
XSETFRAME (frame, f);
attributes = Fpgtk_display_monitor_attributes_list (frame);
/* Try to determine the monitor where the mouse pointer is and
its geometry. See bug#22549. */
while (CONSP (attributes))
{
monitor = XCAR (attributes);
geometry = Fassq (Qgeometry, monitor);
if (CONSP (geometry))
{
min_x = XFIXNUM (Fnth (make_fixnum (1), geometry));
min_y = XFIXNUM (Fnth (make_fixnum (2), geometry));
max_x = min_x + XFIXNUM (Fnth (make_fixnum (3), geometry));
max_y = min_y + XFIXNUM (Fnth (make_fixnum (4), geometry));
if (min_x <= *root_x && *root_x < max_x && min_y <= *root_y
&& *root_y < max_y)
{
break;
}
max_y = -1;
}
attributes = XCDR (attributes);
}
}
/* It was not possible to determine the monitor's geometry, so we
assign some sane defaults here: */
if (max_y < 0)
{
min_x = 0;
min_y = 0;
max_x = x_display_pixel_width (FRAME_DISPLAY_INFO (f));
max_y = x_display_pixel_height (FRAME_DISPLAY_INFO (f));
}
if (INTEGERP (top))
*root_y = XFIXNUM (top);
else if (INTEGERP (bottom))
*root_y = XFIXNUM (bottom) - height;
else if (*root_y + XFIXNUM (dy) <= min_y)
*root_y = min_y; /* Can happen for negative dy */
else if (*root_y + XFIXNUM (dy) + height <= max_y)
/* It fits below the pointer */
*root_y += XFIXNUM (dy);
else if (height + XFIXNUM (dy) + min_y <= *root_y)
/* It fits above the pointer. */
*root_y -= height + XFIXNUM (dy);
else
/* Put it on the top. */
*root_y = min_y;
if (INTEGERP (left))
*root_x = XFIXNUM (left);
else if (INTEGERP (right))
*root_x = XFIXNUM (right) - width;
else if (*root_x + XFIXNUM (dx) <= min_x)
*root_x = 0; /* Can happen for negative dx */
else if (*root_x + XFIXNUM (dx) + width <= max_x)
/* It fits to the right of the pointer. */
*root_x += XFIXNUM (dx);
else if (width + XFIXNUM (dx) + min_x <= *root_x)
/* It fits to the left of the pointer. */
*root_x -= width + XFIXNUM (dx);
#ifndef HAVE_GTK4
else
/* Put it left justified on the screen -- it ought to fit that way. */
*root_x = min_x;
#endif
}
/* Hide tooltip. Delete its frame if DELETE is true. */
static Lisp_Object
x_hide_tip (bool delete)
{
if (!NILP (tip_timer))
{
call1 (Qcancel_timer, tip_timer);
tip_timer = Qnil;
}
if (NILP (tip_frame)
|| (!delete &&FRAMEP (tip_frame)
&& !FRAME_VISIBLE_P (XFRAME (tip_frame))))
return Qnil;
else
{
ptrdiff_t count;
Lisp_Object was_open = Qnil;
count = SPECPDL_INDEX ();
specbind (Qinhibit_redisplay, Qt);
specbind (Qinhibit_quit, Qt);
{
/* When using system tooltip, tip_frame is the Emacs frame on
which the tip is shown. */
struct frame *f = XFRAME (tip_frame);
#ifndef HAVE_GTK4
if (FRAME_LIVE_P (f) && xg_hide_tooltip (f))
#else
if (FRAME_LIVE_P (f) && egtk_hide_tooltip (f))
#endif
{
tip_frame = Qnil;
was_open = Qt;
}
}
if (FRAMEP (tip_frame))
{
if (delete)
{
delete_frame (tip_frame, Qnil);
tip_frame = Qnil;
}
else
pgtk_make_frame_invisible (XFRAME (tip_frame));
was_open = Qt;
}
else
tip_frame = Qnil;
return unbind_to (count, was_open);
}
}
DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
doc: /* Show STRING in a "tooltip" window on frame FRAME.
A tooltip window is a small X window displaying a string.
This is an internal function; Lisp code should call `tooltip-show'.
FRAME nil or omitted means use the selected frame.
PARMS is an optional list of frame parameters which can be used to
change the tooltip's appearance.
Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
means use the default timeout of 5 seconds.
If the list of frame parameters PARMS contains a `left' parameter,
display the tooltip at that x-position. If the list of frame parameters
PARMS contains no `left' but a `right' parameter, display the tooltip
right-adjusted at that x-position. Otherwise display it at the
x-position of the mouse, with offset DX added (default is 5 if DX isn't
specified).
Likewise for the y-position: If a `top' frame parameter is specified, it
determines the position of the upper edge of the tooltip window. If a
`bottom' parameter but no `top' frame parameter is specified, it
determines the position of the lower edge of the tooltip window.
Otherwise display the tooltip window at the y-position of the mouse,
with offset DY added (default is -10).
A tooltip's maximum size is specified by `x-max-tooltip-size'.
Text larger than the specified size is clipped. */)
(Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout,
Lisp_Object dx, Lisp_Object dy)
{
struct frame *f;
#ifndef HAVE_GTK4
int
#else
double
#endif
root_x,
root_y;
int width, height;
ptrdiff_t count = SPECPDL_INDEX ();
specbind (Qinhibit_redisplay, Qt);
CHECK_STRING (string);
if (SCHARS (string) == 0)
string = make_unibyte_string (" ", 1);
f = decode_window_system_frame (frame);
if (NILP (timeout))
timeout = make_fixnum (5);
else
CHECK_FIXNAT (timeout);
if (NILP (dx))
dx = make_fixnum (5);
else
CHECK_NUMBER (dx);
if (NILP (dy))
dy = make_fixnum (-10);
else
CHECK_NUMBER (dy);
{
bool ok;
/* Hide a previous tip, if any. */
Fx_hide_tip ();
block_input ();
#ifdef HAVE_GTK4
ok = egtk_prepare_tooltip (f, string, &width, &height);
#else
ok = xg_prepare_tooltip (f, string, &width, &height);
#endif
if (ok)
{
compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
#ifdef HAVE_GTK4
egtk_show_tooltip (f, round (root_x)
- pgtk_get_window_decoration_width (f),
round (root_y)
- pgtk_get_window_inside_decor_height (f));
#else
xg_show_tooltip (f, root_x, root_y);
#endif
/* This is used in Fx_hide_tip. */
XSETFRAME (tip_frame, f);
}
unblock_input ();
if (ok)
goto start_timer;
}
start_timer:
/* Let the tip disappear after timeout seconds. */
tip_timer
= call3 (intern ("run-at-time"), timeout, Qnil, intern ("x-hide-tip"));
return unbind_to (count, Qnil);
}
DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
doc: /* Hide the current tooltip window, if there is any.
Value is t if tooltip was open, nil otherwise. */)
(void) { return x_hide_tip (!tooltip_reuse_hidden_frame); }
/* Return geometric attributes of FRAME. According to the value of
ATTRIBUTES return the outer edges of FRAME (Qouter_edges), the inner
edges of FRAME, the root window edges of frame (Qroot_edges). Any
other value means to return the geometry as returned by
Fx_frame_geometry. */
static Lisp_Object
frame_geometry (Lisp_Object frame, Lisp_Object attribute)
{
struct frame *f = decode_live_frame (frame);
Lisp_Object fullscreen_symbol = Fframe_parameter (frame, Qfullscreen);
bool fullscreen = (EQ (fullscreen_symbol, Qfullboth)
|| EQ (fullscreen_symbol, Qfullscreen));
int border = fullscreen ? 0 : f->border_width;
int title_height = 0;
int native_width = FRAME_PIXEL_WIDTH (f);
int native_height = FRAME_PIXEL_HEIGHT (f);
int outer_width = native_width + 2 * border;
int outer_height = native_height + 2 * border + title_height;
int native_left = f->left_pos + border;
int native_top = f->top_pos + border + title_height;
int native_right = f->left_pos + outer_width - border;
int native_bottom = f->top_pos + outer_height - border;
int internal_border_width = FRAME_INTERNAL_BORDER_WIDTH (f);
int tab_bar_height = 0, tab_bar_width = 0;
int tool_bar_height = FRAME_TOOLBAR_HEIGHT (f);
int tool_bar_width
= (tool_bar_height ? outer_width - 2 * internal_border_width : 0);
tab_bar_height = FRAME_TAB_BAR_HEIGHT (f);
tab_bar_width
= (tab_bar_height ? native_width - 2 * internal_border_width : 0);
// inner_top += tab_bar_height;
/* Construct list. */
if (EQ (attribute, Qouter_edges))
return list4 (make_fixnum (f->left_pos), make_fixnum (f->top_pos),
make_fixnum (f->left_pos + outer_width),
make_fixnum (f->top_pos + outer_height));
else if (EQ (attribute, Qnative_edges))
return list4 (make_fixnum (native_left), make_fixnum (native_top),
make_fixnum (native_right), make_fixnum (native_bottom));
else if (EQ (attribute, Qinner_edges))
return list4 (make_fixnum (native_left + internal_border_width),
make_fixnum (native_top + tool_bar_height
+ internal_border_width),
make_fixnum (native_right - internal_border_width),
make_fixnum (native_bottom - internal_border_width));
else
return list (Fcons (Qouter_position, Fcons (make_fixnum (f->left_pos),
make_fixnum (f->top_pos))),
Fcons (Qouter_size, Fcons (make_fixnum (outer_width),
make_fixnum (outer_height))),
Fcons (Qexternal_border_size,
(fullscreen ? Fcons (make_fixnum (0), make_fixnum (0))
: Fcons (make_fixnum (border),
make_fixnum (border)))),
Fcons (Qtitle_bar_size,
Fcons (make_fixnum (0), make_fixnum (title_height))),
Fcons (Qmenu_bar_external, Qnil),
Fcons (Qmenu_bar_size,
Fcons (make_fixnum (0), make_fixnum (0))),
Fcons (Qtab_bar_size, Fcons (make_fixnum (tab_bar_width),
make_fixnum (tab_bar_height))),
Fcons (Qtool_bar_external,
FRAME_EXTERNAL_TOOL_BAR (f) ? Qt : Qnil),
Fcons (Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f)),
Fcons (Qtool_bar_size, Fcons (make_fixnum (tool_bar_width),
make_fixnum (tool_bar_height))),
Fcons (Qinternal_border_width,
make_fixnum (internal_border_width)));
}
DEFUN ("pgtk-frame-geometry", Fpgtk_frame_geometry, Spgtk_frame_geometry, 0, 1, 0,
doc: /* Return geometric attributes of FRAME.
FRAME must be a live frame and defaults to the selected one. The return
value is an association list of the attributes listed below. All height
and width values are in pixels.
`outer-position' is a cons of the outer left and top edges of FRAME
relative to the origin - the position (0, 0) - of FRAME's display.
`outer-size' is a cons of the outer width and height of FRAME. The
outer size includes the title bar and the external borders as well as
any menu and/or tool bar of frame.
`external-border-size' is a cons of the horizontal and vertical width of
FRAME's external borders as supplied by the window manager.
`title-bar-size' is a cons of the width and height of the title bar of
FRAME as supplied by the window manager. If both of them are zero,
FRAME has no title bar. If only the width is zero, Emacs was not
able to retrieve the width information.
`menu-bar-external', if non-nil, means the menu bar is external (never
included in the inner edges of FRAME).
`menu-bar-size' is a cons of the width and height of the menu bar of
FRAME.
`tool-bar-external', if non-nil, means the tool bar is external (never
included in the inner edges of FRAME).
`tool-bar-position' tells on which side the tool bar on FRAME is and can
be one of `left', `top', `right' or `bottom'. If this is nil, FRAME
has no tool bar.
`tool-bar-size' is a cons of the width and height of the tool bar of
FRAME.
`internal-border-width' is the width of the internal border of
FRAME. */)
(Lisp_Object frame) { return frame_geometry (frame, Qnil); }
DEFUN ("pgtk-frame-edges", Fpgtk_frame_edges, Spgtk_frame_edges, 0, 2, 0,
doc: /* Return edge coordinates of FRAME.
FRAME must be a live frame and defaults to the selected one. The return
value is a list of the form (LEFT, TOP, RIGHT, BOTTOM). All values are
in pixels relative to the origin - the position (0, 0) - of FRAME's
display.
If optional argument TYPE is the symbol `outer-edges', return the outer
edges of FRAME. The outer edges comprise the decorations of the window
manager (like the title bar or external borders) as well as any external
menu or tool bar of FRAME. If optional argument TYPE is the symbol
`native-edges' or nil, return the native edges of FRAME. The native
edges exclude the decorations of the window manager and any external
menu or tool bar of FRAME. If TYPE is the symbol `inner-edges', return
the inner edges of FRAME. These edges exclude title bar, any borders,
menu bar or tool bar of FRAME. */)
(Lisp_Object frame, Lisp_Object type)
{
return frame_geometry (frame,
((EQ (type, Qouter_edges) || EQ (type, Qinner_edges))
? type
: Qnative_edges));
}
DEFUN ("pgtk-set-mouse-absolute-pixel-position",
Fpgtk_set_mouse_absolute_pixel_position,
Spgtk_set_mouse_absolute_pixel_position, 2, 2, 0,
doc: /* Move mouse pointer to absolute pixel position (X, Y).
The coordinates X and Y are interpreted in pixels relative to a position
\(0, 0) of the selected frame's display. */)
(Lisp_Object x, Lisp_Object y)
{
#ifndef HAVE_GTK4
struct frame *f = SELECTED_FRAME ();
GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f);
#ifdef HAVE_GTK4
GdkDisplay *gdpy = gtk_widget_get_display (widget);
#else
GdkWindow *window = gtk_widget_get_window (widget);
GdkDisplay *gdpy = gdk_window_get_display (window);
#endif
#ifndef HAVE_GTK4
GdkScreen *gscr = gdk_window_get_screen (window);
#endif
#ifdef HAVE_GTK3
#if defined(GDK_VERSION_3_22) || HAVE_GTK4
GdkSeat *seat = gdk_display_get_default_seat (gdpy);
GdkDevice *device = gdk_seat_get_pointer (seat);
#else
GdkDeviceManager *mgr = gdk_display_get_device_manager (gdpy);
GdkDevice *device = gdk_device_manager_get_client_pointer (mgr);
#endif
PGTK_TRACE ("pgtk-set-mouse-absolute-pixel-position:");
gdk_device_warp (device, gscr, XFIXNUM (x),
XFIXNUM (y)); /* No effect on wayland. */
#endif
gdk_display_warp_pointer (gdpy, gscr, XFIXNUM (x), XFIXNUM (y));
#endif
return Qnil;
}
DEFUN ("pgtk-mouse-absolute-pixel-position",
Fpgtk_mouse_absolute_pixel_position,
Spgtk_mouse_absolute_pixel_position, 0, 0, 0,
doc: /* Return absolute position of mouse cursor in pixels.
The position is returned as a cons cell (X . Y) of the
coordinates of the mouse cursor position in pixels relative to a
position (0, 0) of the selected frame's terminal. */)
(void)
{
struct frame *f = SELECTED_FRAME ();
GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f);
#ifndef HAVE_GTK4
GdkWindow *window = gtk_widget_get_window (widget);
#else
GdkSurface *window = EGTK_WIDGET_GET_WINDOW (widget);
#endif
#ifndef HAVE_GTK4
GdkDisplay *gdpy = gdk_window_get_display (window);
#else
GdkDisplay *gdpy = gdk_surface_get_display (window);
#endif
#ifndef HAVE_GTK4
GdkScreen *gscr;
#endif
#ifdef HAVE_GTK3
#if defined(GDK_VERSION_3_20) || HAVE_GTK4
GdkSeat *seat = gdk_display_get_default_seat (gdpy);
GdkDevice *device = gdk_seat_get_pointer (seat);
#else
GdkDeviceManager *mgr = gdk_display_get_device_manager (gdpy);
GdkDevice *device = gdk_device_manager_get_client_pointer (mgr);
#endif
#ifndef HAVE_GTK4
int
#else
double
#endif
x
= 0,
y = 0;
#ifndef HAVE_GTK4
gdk_device_get_position (device, &gscr, &x, &y); /* can't get on wayland? */
#else
gdk_device_get_surface_at_position (device, &x, &y);
x -= calculate_child_frame_distance_x (f);
y -= calculate_child_frame_distance_y (f);
#endif
#else
int x = 0, y = 0;
gdk_display_get_pointer (gdpy, &gscr, &x, &y, NULL);
#endif
#ifndef HAVE_GTK4
return Fcons (make_fixnum (x), make_fixnum (y));
#else
return Fcons (make_fixnum (round (x)), make_fixnum (round (y)));
#endif
}
void
pgtk_m_px_pos (struct frame *f, double *_x, double *_y)
{
GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f);
#ifndef HAVE_GTK4
GdkWindow *window = gtk_widget_get_window (widget);
#else
GdkSurface *window = EGTK_WIDGET_GET_WINDOW (widget);
#endif
#ifndef HAVE_GTK4
GdkDisplay *gdpy = gdk_window_get_display (window);
#else
GdkDisplay *gdpy = gdk_surface_get_display (window);
#endif
#ifndef HAVE_GTK4
GdkScreen *gscr;
#endif
#ifdef HAVE_GTK3
#if defined(GDK_VERSION_3_20) || HAVE_GTK4
GdkSeat *seat = gdk_display_get_default_seat (gdpy);
GdkDevice *device = gdk_seat_get_pointer (seat);
#else
GdkDeviceManager *mgr = gdk_display_get_device_manager (gdpy);
GdkDevice *device = gdk_device_manager_get_client_pointer (mgr);
#endif
#ifndef HAVE_GTK4
int
#else
double
#endif
x
= 0,
y = 0;
#ifndef HAVE_GTK4
gdk_device_get_position (device, &gscr, &x, &y); /* can't get on wayland? */
#else
gdk_device_get_surface_at_position (device, &x, &y);
x -= calculate_child_frame_distance_x (f);
y -= calculate_child_frame_distance_y (f);
#endif
#else
int x = 0, y = 0;
gdk_display_get_pointer (gdpy, &gscr, &x, &y, NULL);
#endif
*_x = x;
*_y = y;
}
DEFUN ("pgtk-page-setup-dialog", Fpgtk_page_setup_dialog, Spgtk_page_setup_dialog, 0, 0, 0,
doc: /* Pop up a page setup dialog.
The current page setup can be obtained using `x-get-page-setup'. */)
(void)
{
block_input ();
#ifdef HAVE_GTK4
egtk_page_setup_dialog ();
#else
xg_page_setup_dialog ();
#endif
unblock_input ();
return Qnil;
}
DEFUN ("pgtk-get-page-setup", Fpgtk_get_page_setup, Spgtk_get_page_setup, 0, 0, 0,
doc: /* Return the value of the current page setup.
The return value is an alist containing the following keys:
orientation: page orientation (symbol `portrait', `landscape',
`reverse-portrait', or `reverse-landscape').
width, height: page width/height in points not including margins.
left-margin, right-margin, top-margin, bottom-margin: print margins,
which is the parts of the page that the printer cannot print
on, in points.
The paper width can be obtained as the sum of width, left-margin, and
right-margin values if the page orientation is `portrait' or
`reverse-portrait'. Otherwise, it is the sum of width, top-margin,
and bottom-margin values. Likewise, the paper height is the sum of
height, top-margin, and bottom-margin values if the page orientation
is `portrait' or `reverse-portrait'. Otherwise, it is the sum of
height, left-margin, and right-margin values. */)
(void)
{
Lisp_Object result;
block_input ();
#ifdef HAVE_GTK4
result = egtk_get_page_setup ();
#else
result = xg_get_page_setup ();
#endif
unblock_input ();
return result;
}
DEFUN ("pgtk-print-frames-dialog", Fpgtk_print_frames_dialog, Spgtk_print_frames_dialog, 0, 1, "",
doc: /* Pop up a print dialog to print the current contents of FRAMES.
FRAMES should be nil (the selected frame), a frame, or a list of
frames (each of which corresponds to one page). Each frame should be
visible. */)
(Lisp_Object frames)
{
Lisp_Object rest, tmp;
int count;
if (!CONSP (frames))
frames = list1 (frames);
tmp = Qnil;
for (rest = frames; CONSP (rest); rest = XCDR (rest))
{
struct frame *f = decode_window_system_frame (XCAR (rest));
Lisp_Object frame;
XSETFRAME (frame, f);
if (!FRAME_VISIBLE_P (f))
error ("Frames to be printed must be visible.");
tmp = Fcons (frame, tmp);
}
frames = Fnreverse (tmp);
/* Make sure the current matrices are up-to-date. */
count = SPECPDL_INDEX ();
specbind (Qredisplay_dont_pause, Qt);
redisplay_preserve_echo_area (32);
unbind_to (count, Qnil);
block_input ();
#ifndef HAVE_GTK4
xg_print_frames_dialog (frames);
#else
egtk_print_frames_dialog (frames);
#endif
unblock_input ();
return Qnil;
}
#ifdef HAVE_GTK3
static GtkWindow *
locate_nonchild_window (struct frame *child)
{
while (FRAME_PARENT_FRAME (child))
child = FRAME_PARENT_FRAME (child);
return GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (child));
}
#endif
#ifdef HAVE_GTK3
DEFUN ("pgtk-color-dialog", Fpgtk_color_dialog, Spgtk_color_dialog, 0, 4, 0,
doc: /* Display a window-system color picker dialog on FRAME,
or on the selected frame if FRAME is nil. A hex string containing the
selected (A)RGB color will be returned, or nil if no color was selected.
The title of the dialog will be set to PROMPT, or "Pick color" if
PROMPT is nil. The color string is an hexedecimal RGB color, or an ARGB
color if USE-ALPHA is not nil. PALETTE_ITEMS is an alist containing a pair of
(symbol . (r g b a)). */
attributes: const)
(Lisp_Object frame, Lisp_Object prompt, Lisp_Object use_alpha, Lisp_Object palette_items)
{
if (NILP (frame))
frame = Fselected_frame ();
CHECK_LIVE_FRAME (frame);
if (!FRAME_PGTK_P (XFRAME (frame)))
error ("Color picker dialogs can only be displayed on GTK frames.");
GtkColorChooserDialog *ccd = GTK_COLOR_CHOOSER_DIALOG
(gtk_color_chooser_dialog_new (NILP (prompt) ? "Pick color" :
SSDATA (ENCODE_UTF_8 (prompt)),
locate_nonchild_window (XFRAME (frame))));
#if GTK_CHECK_VERSION (3, 22, 0)
GtkContainer *vbox_1 = GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (ccd)));
GList *l = gtk_container_get_children (vbox_1);
GtkColorChooserWidget *widget = l->data;
g_object_ref (widget);
GtkScrolledWindow *window =
GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
GtkViewport *vp = GTK_VIEWPORT (gtk_viewport_new (NULL, NULL));
gtk_scrolled_window_set_max_content_height (window, 800);
gtk_scrolled_window_set_propagate_natural_width (window, true);
gtk_scrolled_window_set_propagate_natural_height (window, true);
gtk_container_remove (vbox_1, GTK_WIDGET (widget));
gtk_container_add (GTK_CONTAINER (vp), GTK_WIDGET (widget));
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vp));
gtk_container_add (GTK_CONTAINER (vbox_1), GTK_WIDGET (window));
#endif
#ifndef HAVE_GTK4
gtk_widget_show_all (GTK_WIDGET (window));
#endif
GdkRGBA *amtz = NULL;
if (!NILP (palette_items))
{
size_t amt = 0;
amtz = xmalloc (XFIXNUM (Flength (palette_items)) * sizeof (GdkRGBA));
GdkRGBA *cur = amtz;
for (; !NILP (palette_items); palette_items = XCDR (palette_items))
{
eassert (amtz);
((char *) amtz)[amt * sizeof (GdkRGBA)] = '\0';
CHECK_CONS (XCAR (palette_items));
Lisp_Object symbol = XCAR (XCAR (palette_items));
CHECK_SYMBOL (symbol);
Lisp_Object r = Fcar (XCDR (XCAR (palette_items)));
Lisp_Object g = Fcar (Fcdr (XCDR (XCAR (palette_items))));
Lisp_Object b = Fcar (Fcdr (Fcdr (XCDR (XCAR (palette_items)))));
Lisp_Object a = Fcar (Fcdr (Fcdr (Fcdr (XCDR (XCAR (palette_items))))));
if (NILP (a))
a = make_float (255.00);
CHECK_NUMBER (r);
CHECK_NUMBER (g);
CHECK_NUMBER (b);
CHECK_NUMBER (a);
GdkRGBA *grgba = cur++;
grgba->alpha = XFLOATINT (a);
grgba->blue = XFLOATINT (b);
grgba->green = XFLOATINT (g);
grgba->red = XFLOATINT (r);
++amt;
}
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (ccd),
GTK_ORIENTATION_HORIZONTAL,
9, amt, amtz);
}
gtk_widget_queue_allocate (GTK_WIDGET (vp));
if (gtk_dialog_run (GTK_DIALOG (ccd)) != GTK_RESPONSE_OK)
{
gtk_widget_destroy (GTK_WIDGET (ccd));
if (amtz)
xfree (amtz);
return Qnil;
}
GdkRGBA *rgba = g_malloc (sizeof (GdkRGBA));
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (ccd), !NILP (use_alpha));
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (ccd), rgba);
gchar *str = g_malloc (NILP (use_alpha) ?
sizeof ("#FFFFFF") :
sizeof ("#FFFFFFFF"));
#pragma GCC diagnostic ignored "-Wformat-overflow"
if (NILP (use_alpha))
sprintf (str,
"#%02x%02x%02x",
(unsigned short) round (rgba->red * 255),
(unsigned short) round (rgba->green * 255),
(unsigned short) round (rgba->blue * 255));
else
sprintf (str,
"#%02x%02x%02x%02x",
(unsigned short) round (rgba->alpha * 255),
(unsigned short) round (rgba->red * 255),
(unsigned short) round (rgba->green * 255),
(unsigned short) round (rgba->blue * 255));
#pragma GCC diagnostic push
g_free (rgba);
Lisp_Object strz = build_string (str);
gtk_widget_destroy (GTK_WIDGET (ccd));
g_free (str);
if (amtz)
xfree (amtz);
return strz;
}
#endif
#ifdef HAVE_GTK4
DEFUN ("pgtk-show-selection-options", Fpgtk_show_selection_options, Spgtk_show_selection_options,
1, 1, 0, doc: /* Display the touchscreen selection options popover on FRAME. */)
(Lisp_Object frame)
{
CHECK_LIVE_FRAME (frame);
if (!FRAME_PGTK_P (XFRAME (frame)))
error ("Not a pgtk frame.");
emacs_resizable_drawing_area_show_selection_options
((gpointer) FRAME_GTK_WIDGET (XFRAME (frame)));
return Qnil;
}
#endif
DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
doc: /* Read file name, prompting with PROMPT in directory DIR.
Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
selection box, if specified. If MUSTMATCH is non-nil, the returned file
or directory must exist.
This function is defined only on PGTK, NS, MS Windows, and X Windows with the
Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
Otherwise, if ONLY-DIR-P is non-nil, the user can select only directories.
On MS Windows 7 and later, the file selection dialog "remembers" the last
directory where the user selected a file, and will open that directory
instead of DIR on subsequent invocations of this function with the same
value of DIR as in previous invocations; this is standard MS Windows behavior. */)
(Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename,
Lisp_Object mustmatch, Lisp_Object only_dir_p)
{
struct frame *f = SELECTED_FRAME ();
char *fn;
Lisp_Object file = Qnil;
Lisp_Object decoded_file;
ptrdiff_t count = SPECPDL_INDEX ();
char *cdef_file;
check_window_system (f);
CHECK_STRING (prompt);
CHECK_STRING (dir);
/* Prevent redisplay. */
specbind (Qinhibit_redisplay, Qt);
#if 0
record_unwind_protect_void (clean_up_dialog);
#endif
block_input ();
if (STRINGP (default_filename))
cdef_file = SSDATA (default_filename);
else
cdef_file = SSDATA (dir);
#ifndef HAVE_GTK4
fn = xg_get_file_name (f, SSDATA (prompt), cdef_file, !NILP (mustmatch),
!NILP (only_dir_p));
#else
fn = egtk_get_file_name (f, SSDATA (prompt), cdef_file, !NILP (mustmatch),
!NILP (only_dir_p));
#endif
if (fn)
{
file = build_string (fn);
#ifndef HAVE_GTK4
xfree (fn);
#else
g_free (fn);
#endif
}
unblock_input ();
/* Make "Cancel" equivalent to C-g. */
if (NILP (file))
quit ();
decoded_file = DECODE_FILE (file);
return unbind_to (count, decoded_file);
}
#ifdef HAVE_GTK4
/* We implement most of this in C code, so
GC doesn't go crazy when this is called. */
void
pgtk_vpixoffset_scroll (int pixels, struct window *window)
{
pixels += 1;
int vs_begin = 0;
int vs_stop = pixels;
while (vs_begin != vs_stop)
{
int old_vs = window->vpixoffset;
if (window->vpixoffset < 0 && window->vpixoffset < old_vs)
adjust_frame_glyphs (XFRAME (window->frame));
if (vs_begin >= 0)
{
window->vpixoffset -= vs_begin;
Lisp_Object window_;
XSETWINDOW (window_, window);
Fset_window_point (window_,
make_fixnum
((MATRIX_FIRST_TEXT_ROW
(window->current_matrix) + 2)->start.pos.charpos));
}
else
{
redisplay ();
int specbind_ = SPECPDL_INDEX ();
record_unwind_protect_excursion ();
Fgoto_char (Fwindow_start (Qnil));
ptrdiff_t res;
Lisp_Object window_;
XSETWINDOW (window_, window);
if (!NILP (Fbobp ()))
{
res = BEGV;
}
else
{
if (MATRIX_FIRST_TEXT_ROW (window->current_matrix)->y >= 0)
{
int specindex_b = SPECPDL_INDEX ();
Lisp_Object symb = intern_c_string ("line-move-visual");
Fset_window_point (window_, Fwindow_start (Qnil));
Fvertical_motion (make_fixnum (-1), Qnil, Qnil);
specbind (symb, Qt);
Fbeginning_of_line (Qnil);
res = PT;
unbind_to (specindex_b, Qnil);
}
else
{
res = XFIXNUM (window->start);
}
}
unbind_to (specbind_, Qnil);
Lisp_Object tmp;
XSETFASTINT (tmp, res);
set_marker_restricted (window->start, tmp, window->contents);
window->start_at_line_beg = false;
window->force_start = true;
window->update_mode_line = true;
window->redisplay = true;
window->window_end_valid = false;
Fset_window_point (window_, CALLN (Fplus, tmp, make_fixnum (100)));
struct glyph_row *mr = MATRIX_FIRST_TEXT_ROW (window->current_matrix);
while (mr->y < FRAME_LINE_HEIGHT (XFRAME (window->frame)))
++mr;
int begin_row_height = mr->height;
if (!window->vpixoffset)
window->vpixoffset = -begin_row_height;
window->vpixoffset -= vs_begin;
if (window->vpixoffset >= 0)
{
window->vpixoffset = 0;
Fset_window_start (Qnil, tmp, Qt);
}
}
if (vs_begin > vs_stop)
--vs_begin;
else
++vs_begin;
XBUFFER (window->contents)->prevent_redisplay_optimizations_p = true;
redisplay ();
}
}
DEFUN ("pgtk-pixel-scroll-up", Fpgtk_pixel_scroll_up, Spgtk_pixel_scroll_up,
1, 1, 0, doc: /* Pixel-scroll the selected window by PIXELS. */)
(Lisp_Object pixels)
{
if (NILP (Fwindow_system (Qnil)))
error ("No window system");
pgtk_vpixoffset_scroll (XFIXNUM (pixels),
XWINDOW (selected_window));
return Qnil;
}
#endif
DEFUN ("pgtk-backend-display-class", Fpgtk_backend_display_class, Spgtk_backend_display_class,
0, 1, "",
doc: /* Returns the name of the Gdk backend display class of the TERMINAL.
The optional argument TERMINAL specifies which display to ask about.
TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object terminal)
{
struct pgtk_display_info *dpyinfo = check_pgtk_display_info (terminal);
GdkDisplay *gdpy = dpyinfo->gdpy;
const gchar *type_name = G_OBJECT_TYPE_NAME (G_OBJECT (gdpy));
return build_string (type_name);
}
#ifdef HAVE_GTK3
DEFUN ("pgtk-show-inspector", Fpgtk_show_inspector, Spgtk_show_inspector,
0, 0, "", doc: /* Show the GTK inspector debug tool. */)
(void)
{
if (NILP (Fwindow_system (Qnil)))
error ("No window system");
#if defined (GDK_VERSION_3_14) || defined (HAVE_GTK4)
gtk_window_set_interactive_debugging (TRUE);
#endif
return Qnil;
}
#endif
#ifdef HAVE_GTK4
DEFUN ("pgtk-default-font-family", Fpgtk_default_font_family,
Spgtk_default_font_family, 1, 1, 0,
doc: /* Returns the default GTK font family if MONO is nil,
or the default monospace family if MONO is non-nil. */)
(Lisp_Object mono)
{
return eg_get_font_family (!NILP (mono));
}
DEFUN ("pgtk-get-text-caret-width", Fpgtk_get_text_caret_width,
Spgtk_get_text_caret_width, 0, 0, 0,
doc: /* Return the width of GTK text carets in pixels. */)
(void)
{
return eg_get_caret_px_width ();
}
DEFUN ("pgtk-get-separator-width", Fpgtk_get_separator_width,
Spgtk_get_separator_width, 0, 0, 0,
doc: /* Return the width of GTK separators, in pixels. */)
(void)
{
return eg_get_divider_width ();
}
#endif
/* ==========================================================================
Lisp interface declaration
========================================================================== */
void
syms_of_pgtkfns (void)
{
DEFSYM (Qfont_parameter, "font-parameter");
DEFSYM (Qfontsize, "fontsize");
DEFSYM (Qcancel_timer, "cancel-timer");
DEFSYM (Qframe_title_format, "frame-title-format");
DEFSYM (Qicon_title_format, "icon-title-format");
DEFSYM (Qdark, "dark");
#ifdef HAVE_GTK4
DEFSYM (Qload_theme, "load-theme");
DEFSYM (Qgtk, "gtk");
DEFSYM (Qcustom_theme_enabled_p, "custom-theme-enabled-p");
#endif
DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel, doc: /* A string indicating the foreground color of the cursor box. */);
Vx_cursor_fore_pixel = Qnil;
DEFVAR_LISP ("pgtk-icon-type-alist", Vpgtk_icon_type_alist,
doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
If the title of a frame matches REGEXP, then IMAGE.tiff is
selected as the image of the icon representing the frame when it's
miniaturized. If an element is t, then Emacs tries to select an icon
based on the filetype of the visited file.
The images have to be installed in a folder called English.lproj in the
Emacs folder. You have to restart Emacs after installing new icons.
Example: Install an icon Gnus.tiff and execute the following code
(setq pgtk-icon-type-alist
(append pgtk-icon-type-alist
\\='((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
. \"Gnus\"))))
When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
be used as the image of the icon representing the frame. */);
Vpgtk_icon_type_alist = list1 (Qt);
/* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
But for a user it is a toolkit for X, and indeed, configure
accepts --with-x-toolkit=gtk. */
Fprovide (intern_c_string ("x-toolkit"), Qnil);
Fprovide (intern_c_string ("gtk"), Qnil);
Fprovide (intern_c_string ("move-toolbar"), Qnil);
DEFVAR_LISP ("gtk-version-string", Vgtk_version_string,
doc: /* Version info for GTK+. */);
{
char *ver = g_strdup_printf ("%d.%d.%d", GTK_MAJOR_VERSION,
GTK_MINOR_VERSION, GTK_MICRO_VERSION);
int len = strlen (ver);
Vgtk_version_string = make_pure_string (ver, len, len, false);
g_free (ver);
}
Fprovide (intern_c_string ("cairo"), Qnil);
DEFVAR_LISP ("cairo-version-string", Vcairo_version_string,
doc: /* Version info for cairo. */);
{
char *ver = g_strdup_printf ("%d.%d.%d", CAIRO_VERSION_MAJOR,
CAIRO_VERSION_MINOR, CAIRO_VERSION_MICRO);
int len = strlen (ver);
Vcairo_version_string = make_pure_string (ver, len, len, false);
g_free (ver);
}
defsubr (&Sx_select_font);
defsubr (&Spgtk_set_resource);
defsubr (&Sxw_display_color_p); /* this and next called directly by C code */
defsubr (&Sx_display_grayscale_p);
defsubr (&Spgtk_font_name);
defsubr (&Sxw_color_defined_p);
defsubr (&Sxw_color_values);
defsubr (&Sx_server_max_request_size);
defsubr (&Sx_server_vendor);
defsubr (&Sx_server_version);
defsubr (&Sx_display_pixel_width);
defsubr (&Sx_display_pixel_height);
defsubr (&Spgtk_display_monitor_attributes_list);
defsubr (&Spgtk_frame_geometry);
defsubr (&Spgtk_frame_edges);
defsubr (&Spgtk_frame_restack);
defsubr (&Spgtk_set_mouse_absolute_pixel_position);
defsubr (&Spgtk_mouse_absolute_pixel_position);
defsubr (&Sx_display_mm_width);
defsubr (&Sx_display_mm_height);
defsubr (&Sx_display_screens);
defsubr (&Sx_display_planes);
defsubr (&Sx_display_color_cells);
defsubr (&Sx_display_visual_class);
defsubr (&Sx_display_backing_store);
defsubr (&Sx_display_save_under);
defsubr (&Sx_create_frame);
defsubr (&Sx_open_connection);
defsubr (&Sx_close_connection);
defsubr (&Sx_display_list);
#ifdef HAVE_GTK4
defsubr (&Spgtk_default_font_family);
defsubr (&Spgtk_get_text_caret_width);
defsubr (&Spgtk_get_separator_width);
#endif
#ifdef HAVE_GTK3
defsubr (&Spgtk_show_inspector);
#endif
defsubr (&Spgtk_hide_others);
defsubr (&Spgtk_hide_emacs);
defsubr (&Sx_show_tip);
defsubr (&Sx_hide_tip);
// defsubr (&Spgtk_export_frames);
defsubr (&Spgtk_page_setup_dialog);
defsubr (&Spgtk_get_page_setup);
defsubr (&Spgtk_print_frames_dialog);
defsubr (&Spgtk_backend_display_class);
#ifdef HAVE_GTK3
defsubr (&Spgtk_color_dialog);
#endif
#ifdef HAVE_GTK4
defsubr (&Spgtk_pixel_scroll_up);
defsubr (&Spgtk_show_selection_options);
#endif
defsubr (&Sx_file_dialog);
as_status = 0;
as_script = Qnil;
as_result = 0;
tip_frame = Qnil;
staticpro (&tip_frame);
tip_timer = Qnil;
staticpro (&tip_timer);
/* This is not ifdef:ed, so other builds than GTK can customize it. */
DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog,
doc: /* Non-nil means prompt with the old GTK file selection dialog.
If nil or if the file selection dialog is not available, the new GTK file
chooser is used instead. To turn off all file dialogs set the
variable `use-file-dialog'. */);
x_gtk_use_old_file_dialog = false;
DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files,
doc: /* If non-nil, the GTK file chooser will by default show hidden files.
Note that this is just the default, there is a toggle button on the file
chooser to show or not show hidden files on a case by case basis. */);
x_gtk_show_hidden_files = false;
DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text,
doc: /* If non-nil, the GTK file chooser will show additional help text.
If more space for files in the file chooser dialog is wanted, set this to nil
to turn the additional text off. */);
x_gtk_file_dialog_help_text = true;
DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips,
doc: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
Otherwise use Emacs own tooltip implementation.
When using Gtk+ tooltips, the tooltip face is not used. */);
x_gtk_use_system_tooltips = true;
DEFVAR_BOOL ("x-gtk-use-color-dialogs", x_gtk_use_color_dialogs,
doc: /* If non-nil with a GTK+ built Emacs, GTK color dialogs
will be used by read-color. */);
x_gtk_use_color_dialogs = true;
DEFSYM (Qmono, "mono");
DEFSYM (Qpdf, "pdf");
DEFSYM (Qorientation, "orientation");
DEFSYM (Qtop_margin, "top-margin");
DEFSYM (Qbottom_margin, "bottom-margin");
DEFSYM (Qportrait, "portrait");
DEFSYM (Qlandscape, "landscape");
DEFSYM (Qreverse_portrait, "reverse-portrait");
DEFSYM (Qreverse_landscape, "reverse-landscape");
}
#ifdef PGTK_DEBUG
#include <stdarg.h>
#include <time.h>
void
pgtk_log (const char *file, int lineno, const char *fmt, ...)
{
struct timespec ts;
struct tm tm;
char timestr[32];
va_list ap;
clock_gettime (CLOCK_REALTIME, &ts);
localtime_r (&ts.tv_sec, &tm);
strftime (timestr, sizeof timestr, "%H:%M:%S", &tm);
fprintf (stderr, "%s.%06ld %.10s:%04d ", timestr, ts.tv_nsec / 1000, file,
lineno);
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
}
void
pgtk_backtrace (const char *file, int lineno)
{
Lisp_Object bt = make_uninit_vector (10);
for (int i = 0; i < 10; i++)
ASET (bt, i, Qnil);
struct timespec ts;
struct tm tm;
char timestr[32];
clock_gettime (CLOCK_REALTIME, &ts);
localtime_r (&ts.tv_sec, &tm);
strftime (timestr, sizeof timestr, "%H:%M:%S", &tm);
fprintf (stderr, "%s.%06ld %.10s:%04d ********\n", timestr, ts.tv_nsec / 1000,
file, lineno);
get_backtrace (bt);
for (int i = 0; i < 10; i++)
{
Lisp_Object stk = AREF (bt, i);
if (!NILP (stk))
{
Lisp_Object args[2] = {build_string ("%S"), stk};
Lisp_Object str = Fformat (2, args);
fprintf (stderr, "%s %.10s:%04d %s\n", timestr, file, lineno,
SSDATA (str));
}
}
fprintf (stderr, "%s %.10s:%04d ********\n", timestr, file, lineno);
}
#endif
#endif
|