1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
|
/* Functions for the X window system.
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdio.h>
#include <math.h>
#include <setjmp.h>
#include <ctype.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* This makes the fields of a Display accessible, in Xlib header files. */
#define XLIB_ILLEGAL_ACCESS
#include "lisp.h"
#include "xterm.h"
#include "frame.h"
#include "window.h"
#include "buffer.h"
#include "intervals.h"
#include "dispextern.h"
#include "keyboard.h"
#include "blockinput.h"
#include <epaths.h>
#include "character.h"
#include "charset.h"
#include "coding.h"
#include "fontset.h"
#include "systime.h"
#include "termhooks.h"
#include "atimer.h"
#include "termchar.h"
#include "font.h"
#ifdef HAVE_X_WINDOWS
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
#include "bitmaps/gray.xbm"
#else
#include <X11/bitmaps/gray>
#endif
#include "xsettings.h"
#ifdef USE_GTK
#include "gtkutil.h"
#endif
#ifdef USE_X_TOOLKIT
#include <X11/Shell.h>
#ifndef USE_MOTIF
#ifdef HAVE_XAW3D
#include <X11/Xaw3d/Paned.h>
#include <X11/Xaw3d/Label.h>
#else /* !HAVE_XAW3D */
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/Label.h>
#endif /* HAVE_XAW3D */
#endif /* USE_MOTIF */
#ifdef USG
#undef USG /* ####KLUDGE for Solaris 2.2 and up */
#include <X11/Xos.h>
#define USG
#else
#include <X11/Xos.h>
#endif
#include "widget.h"
#include "../lwlib/lwlib.h"
#ifdef USE_MOTIF
#include <Xm/Xm.h>
#include <Xm/DialogS.h>
#include <Xm/FileSB.h>
#endif
#ifdef USE_LUCID
#include "../lwlib/xlwmenu.h"
#endif
#if !defined(NO_EDITRES)
#define HACK_EDITRES
extern void _XEditResCheckMessages ();
#endif /* not defined NO_EDITRES */
/* Unique id counter for widgets created by the Lucid Widget Library. */
extern LWLIB_ID widget_id_tick;
extern void free_frame_menubar ();
extern double atof ();
#ifdef USE_MOTIF
/* LessTif/Motif version info. */
static Lisp_Object Vmotif_version_string;
#endif /* USE_MOTIF */
#endif /* USE_X_TOOLKIT */
#ifdef USE_GTK
/* GTK+ version info */
static Lisp_Object Vgtk_version_string;
#endif /* USE_GTK */
#define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
/* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
it, and including `bitmaps/gray' more than once is a problem when
config.h defines `static' as an empty replacement string. */
int gray_bitmap_width = gray_width;
int gray_bitmap_height = gray_height;
char *gray_bitmap_bits = gray_bits;
/* Non-zero means prompt with the old GTK file selection dialog. */
int x_gtk_use_old_file_dialog;
/* If non-zero, by default show hidden files in the GTK file chooser. */
int x_gtk_show_hidden_files;
/* If non-zero, don't show additional help text in the GTK file chooser. */
int x_gtk_file_dialog_help_text;
/* If non-zero, don't collapse to tool bar when it is detached. */
int x_gtk_whole_detached_tool_bar;
/* If non-zero, use Gtk+ tooltips. */
static int x_gtk_use_system_tooltips;
/* The background and shape of the mouse pointer, and shape when not
over text or in the modeline. */
Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
Lisp_Object Vx_hourglass_pointer_shape;
/* The shape when over mouse-sensitive text. */
Lisp_Object Vx_sensitive_text_pointer_shape;
/* If non-nil, the pointer shape to indicate that windows can be
dragged horizontally. */
Lisp_Object Vx_window_horizontal_drag_shape;
/* Color of chars displayed in cursor box. */
Lisp_Object Vx_cursor_fore_pixel;
/* Nonzero if using X. */
static int x_in_use;
/* Non nil if no window manager is in use. */
Lisp_Object Vx_no_window_manager;
/* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
Lisp_Object Vx_pixel_size_width_font_regexp;
Lisp_Object Qnone;
Lisp_Object Qsuppress_icon;
Lisp_Object Qundefined_color;
Lisp_Object Qcompound_text, Qcancel_timer;
Lisp_Object Qfont_param;
#if GLYPH_DEBUG
int image_cache_refcount, dpyinfo_refcount;
#endif
#if defined (USE_GTK) && defined (HAVE_FREETYPE)
char *x_last_font_name;
#endif
/* Error if we are not connected to X. */
void
check_x (void)
{
if (! x_in_use)
error ("X windows are not in use or not initialized");
}
/* Nonzero if we can use mouse menus.
You should not call this unless HAVE_MENUS is defined. */
int
have_menus_p (void)
{
return x_in_use;
}
/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
and checking validity for X. */
FRAME_PTR
check_x_frame (Lisp_Object frame)
{
FRAME_PTR f;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
if (! FRAME_X_P (f))
error ("Non-X frame used");
return f;
}
/* Let the user specify an X display with a Lisp object.
OBJECT may be nil, a frame or a terminal object.
nil stands for the selected frame--or, if that is not an X frame,
the first X display on the list. */
struct x_display_info *
check_x_display_info (Lisp_Object object)
{
struct x_display_info *dpyinfo = NULL;
if (NILP (object))
{
struct frame *sf = XFRAME (selected_frame);
if (FRAME_X_P (sf) && FRAME_LIVE_P (sf))
dpyinfo = FRAME_X_DISPLAY_INFO (sf);
else if (x_display_list != 0)
dpyinfo = x_display_list;
else
error ("X windows are not in use or not initialized");
}
else if (TERMINALP (object))
{
struct terminal *t = get_terminal (object, 1);
if (t->type != output_x_window)
error ("Terminal %d is not an X display", XINT (object));
dpyinfo = t->display_info.x;
}
else if (STRINGP (object))
dpyinfo = x_display_info_for_name (object);
else
{
FRAME_PTR f = check_x_frame (object);
dpyinfo = FRAME_X_DISPLAY_INFO (f);
}
return dpyinfo;
}
/* Return the Emacs frame-object corresponding to an X window.
It could be the frame's main window or an icon window. */
/* This function can be called during GC, so use GC_xxx type test macros. */
struct frame *
x_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
{
Lisp_Object tail, frame;
struct frame *f;
if (wdesc == None) return 0;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame);
if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
continue;
if (f->output_data.x->hourglass_window == wdesc)
return f;
#ifdef USE_X_TOOLKIT
if ((f->output_data.x->edit_widget
&& XtWindow (f->output_data.x->edit_widget) == wdesc)
/* A tooltip frame? */
|| (!f->output_data.x->edit_widget
&& FRAME_X_WINDOW (f) == wdesc)
|| f->output_data.x->icon_desc == wdesc)
return f;
#else /* not USE_X_TOOLKIT */
#ifdef USE_GTK
if (f->output_data.x->edit_widget)
{
GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
struct x_output *x = f->output_data.x;
if (gwdesc != 0 && gwdesc == x->edit_widget)
return f;
}
#endif /* USE_GTK */
if (FRAME_X_WINDOW (f) == wdesc
|| f->output_data.x->icon_desc == wdesc)
return f;
#endif /* not USE_X_TOOLKIT */
}
return 0;
}
#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
/* Like x_window_to_frame but also compares the window with the widget's
windows. */
struct frame *
x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
{
Lisp_Object tail, frame;
struct frame *f, *found;
struct x_output *x;
if (wdesc == None) return NULL;
found = NULL;
for (tail = Vframe_list; CONSP (tail) && !found; tail = XCDR (tail))
{
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame);
if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
{
/* This frame matches if the window is any of its widgets. */
x = f->output_data.x;
if (x->hourglass_window == wdesc)
found = f;
else if (x->widget)
{
#ifdef USE_GTK
GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
if (gwdesc != 0
&& gtk_widget_get_toplevel (gwdesc) == x->widget)
found = f;
#else
if (wdesc == XtWindow (x->widget)
|| wdesc == XtWindow (x->column_widget)
|| wdesc == XtWindow (x->edit_widget))
found = f;
/* Match if the window is this frame's menubar. */
else if (lw_window_is_in_menubar (wdesc, x->menubar_widget))
found = f;
#endif
}
else if (FRAME_X_WINDOW (f) == wdesc)
/* A tooltip frame. */
found = f;
}
}
return found;
}
/* Likewise, but consider only the menu bar widget. */
struct frame *
x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event)
{
Window wdesc = event->xany.window;
Lisp_Object tail, frame;
struct frame *f;
struct x_output *x;
if (wdesc == None) return 0;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame);
if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
continue;
x = f->output_data.x;
#ifdef USE_GTK
if (x->menubar_widget && xg_event_is_for_menubar (f, event))
return f;
#else
/* Match if the window is this frame's menubar. */
if (x->menubar_widget
&& lw_window_is_in_menubar (wdesc, x->menubar_widget))
return f;
#endif
}
return 0;
}
/* Return the frame whose principal (outermost) window is WDESC.
If WDESC is some other (smaller) window, we return 0. */
struct frame *
x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
{
Lisp_Object tail, frame;
struct frame *f;
struct x_output *x;
if (wdesc == None) return 0;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame);
if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
continue;
x = f->output_data.x;
if (x->widget)
{
/* This frame matches if the window is its topmost widget. */
#ifdef USE_GTK
GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
if (gwdesc == x->widget)
return f;
#else
if (wdesc == XtWindow (x->widget))
return f;
#if 0 /* I don't know why it did this,
but it seems logically wrong,
and it causes trouble for MapNotify events. */
/* Match if the window is this frame's menubar. */
if (x->menubar_widget
&& wdesc == XtWindow (x->menubar_widget))
return f;
#endif
#endif
}
else if (FRAME_X_WINDOW (f) == wdesc)
/* Tooltip frame. */
return f;
}
return 0;
}
#endif /* USE_X_TOOLKIT || USE_GTK */
static void x_default_font_parameter (struct frame *, Lisp_Object);
static Lisp_Object unwind_create_frame (Lisp_Object);
static Lisp_Object unwind_create_tip_frame (Lisp_Object);
void x_set_foreground_color (struct frame *, Lisp_Object, Lisp_Object);
static void x_set_wait_for_wm (struct frame *, Lisp_Object, Lisp_Object);
void x_set_background_color (struct frame *, Lisp_Object, Lisp_Object);
void x_set_mouse_color (struct frame *, Lisp_Object, Lisp_Object);
void x_set_cursor_color (struct frame *, Lisp_Object, Lisp_Object);
void x_set_border_color (struct frame *, Lisp_Object, Lisp_Object);
void x_set_cursor_type (struct frame *, Lisp_Object, Lisp_Object);
void x_set_icon_type (struct frame *, Lisp_Object, Lisp_Object);
void x_set_icon_name (struct frame *, Lisp_Object, Lisp_Object);
void x_explicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
void x_set_title (struct frame *, Lisp_Object, Lisp_Object);
void x_set_tool_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
void x_set_scroll_bar_foreground (struct frame *, Lisp_Object,
Lisp_Object);
void x_set_scroll_bar_background (struct frame *, Lisp_Object,
Lisp_Object);
static Lisp_Object x_default_scroll_bar_color_parameter (struct frame *,
Lisp_Object,
Lisp_Object,
const char *, const char *,
int);
/* Store the screen positions of frame F into XPTR and YPTR.
These are the positions of the containing window manager window,
not Emacs's own window. */
void
x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
{
int win_x, win_y, outer_x, outer_y;
int real_x = 0, real_y = 0;
int had_errors = 0;
Window win = f->output_data.x->parent_desc;
BLOCK_INPUT;
x_catch_errors (FRAME_X_DISPLAY (f));
if (win == FRAME_X_DISPLAY_INFO (f)->root_window)
win = FRAME_OUTER_WINDOW (f);
/* This loop traverses up the containment tree until we hit the root
window. Window managers may intersect many windows between our window
and the root window. The window we find just before the root window
should be the outer WM window. */
for (;;)
{
Window wm_window, rootw;
Window *tmp_children;
unsigned int tmp_nchildren;
int success;
success = XQueryTree (FRAME_X_DISPLAY (f), win, &rootw,
&wm_window, &tmp_children, &tmp_nchildren);
had_errors = x_had_errors_p (FRAME_X_DISPLAY (f));
/* Don't free tmp_children if XQueryTree failed. */
if (! success)
break;
XFree ((char *) tmp_children);
if (wm_window == rootw || had_errors)
break;
win = wm_window;
}
if (! had_errors)
{
unsigned int ign;
Window child, rootw;
/* Get the real coordinates for the WM window upper left corner */
XGetGeometry (FRAME_X_DISPLAY (f), win,
&rootw, &real_x, &real_y, &ign, &ign, &ign, &ign);
/* Translate real coordinates to coordinates relative to our
window. For our window, the upper left corner is 0, 0.
Since the upper left corner of the WM window is outside
our window, win_x and win_y will be negative:
------------------ ---> x
| title |
| ----------------- v y
| | our window
*/
XTranslateCoordinates (FRAME_X_DISPLAY (f),
/* From-window, to-window. */
FRAME_X_DISPLAY_INFO (f)->root_window,
FRAME_X_WINDOW (f),
/* From-position, to-position. */
real_x, real_y, &win_x, &win_y,
/* Child of win. */
&child);
if (FRAME_X_WINDOW (f) == FRAME_OUTER_WINDOW (f))
{
outer_x = win_x;
outer_y = win_y;
}
else
{
XTranslateCoordinates (FRAME_X_DISPLAY (f),
/* From-window, to-window. */
FRAME_X_DISPLAY_INFO (f)->root_window,
FRAME_OUTER_WINDOW (f),
/* From-position, to-position. */
real_x, real_y, &outer_x, &outer_y,
/* Child of win. */
&child);
}
had_errors = x_had_errors_p (FRAME_X_DISPLAY (f));
}
x_uncatch_errors ();
UNBLOCK_INPUT;
if (had_errors) return;
f->x_pixels_diff = -win_x;
f->y_pixels_diff = -win_y;
FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x;
FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y;
*xptr = real_x;
*yptr = real_y;
}
/* Gamma-correct COLOR on frame F. */
void
gamma_correct (struct frame *f, XColor *color)
{
if (f->gamma)
{
color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5;
color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5;
color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5;
}
}
/* Decide if color named COLOR_NAME is valid for use on frame F. If
so, return the RGB values in COLOR. If ALLOC_P is non-zero,
allocate the color. Value is zero if COLOR_NAME is invalid, or
no color could be allocated. */
int
x_defined_color (struct frame *f, const char *color_name,
XColor *color, int alloc_p)
{
int success_p = 0;
Display *dpy = FRAME_X_DISPLAY (f);
Colormap cmap = FRAME_X_COLORMAP (f);
BLOCK_INPUT;
#ifdef USE_GTK
success_p = xg_check_special_colors (f, color_name, color);
#endif
if (!success_p)
success_p = XParseColor (dpy, cmap, color_name, color);
if (success_p && alloc_p)
success_p = x_alloc_nearest_color (f, cmap, color);
UNBLOCK_INPUT;
return success_p;
}
/* 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. */
int
x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color)
{
XColor cdef;
CHECK_STRING (color_name);
#if 0 /* Don't do this. It's wrong when we're not using the default
colormap, it makes freeing difficult, and it's probably not
an important optimization. */
if (strcmp (SDATA (color_name), "black") == 0)
return BLACK_PIX_DEFAULT (f);
else if (strcmp (SDATA (color_name), "white") == 0)
return WHITE_PIX_DEFAULT (f);
#endif
/* Return MONO_COLOR for monochrome frames. */
if (FRAME_X_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 (x_defined_color (f, SDATA (color_name), &cdef, 1))
return cdef.pixel;
signal_error ("Undefined color", color_name);
}
/* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
the previous value of that parameter, NEW_VALUE is the new value.
See also the comment of wait_for_wm in struct x_output. */
static void
x_set_wait_for_wm (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
{
f->output_data.x->wait_for_wm = !NILP (new_value);
}
static void
x_set_tool_bar_position (struct frame *f,
Lisp_Object new_value,
Lisp_Object old_value)
{
if (! EQ (new_value, Qleft) && ! EQ (new_value, Qright)
&& ! EQ (new_value, Qbottom) && ! EQ (new_value, Qtop))
return;
if (EQ (new_value, old_value)) return;
#ifdef USE_GTK
if (xg_change_toolbar_position (f, new_value))
f->tool_bar_position = new_value;
#endif
}
#ifdef USE_GTK
/* Set icon from FILE for frame F. By using GTK functions the icon
may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
int
xg_set_icon (FRAME_PTR f, Lisp_Object file)
{
int result = 0;
Lisp_Object found;
found = x_find_image_file (file);
if (! NILP (found))
{
GdkPixbuf *pixbuf;
GError *err = NULL;
char *filename = (char *) SDATA (found);
BLOCK_INPUT;
pixbuf = gdk_pixbuf_new_from_file (filename, &err);
if (pixbuf)
{
gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
pixbuf);
g_object_unref (pixbuf);
result = 1;
}
else
g_error_free (err);
UNBLOCK_INPUT;
}
return result;
}
int
xg_set_icon_from_xpm_data (FRAME_PTR f, const char **data)
{
int result = 0;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data);
if (!pixbuf)
return 0;
gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), pixbuf);
g_object_unref (pixbuf);
return 1;
}
#endif /* USE_GTK */
/* Functions called only from `x_set_frame_param'
to set individual parameters.
If FRAME_X_WINDOW (f) is 0,
the frame is being created and its X-window does not exist yet.
In that case, just record the parameter's new value
in the standard place; do not attempt to change the window. */
void
x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
struct x_output *x = f->output_data.x;
unsigned long fg, old_fg;
fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
old_fg = FRAME_FOREGROUND_PIXEL (f);
FRAME_FOREGROUND_PIXEL (f) = fg;
if (FRAME_X_WINDOW (f) != 0)
{
Display *dpy = FRAME_X_DISPLAY (f);
BLOCK_INPUT;
XSetForeground (dpy, x->normal_gc, fg);
XSetBackground (dpy, x->reverse_gc, fg);
if (x->cursor_pixel == old_fg)
{
unload_color (f, x->cursor_pixel);
x->cursor_pixel = x_copy_color (f, fg);
XSetBackground (dpy, x->cursor_gc, x->cursor_pixel);
}
UNBLOCK_INPUT;
update_face_from_frame_parameter (f, Qforeground_color, arg);
if (FRAME_VISIBLE_P (f))
redraw_frame (f);
}
unload_color (f, old_fg);
}
void
x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
struct x_output *x = f->output_data.x;
unsigned long bg;
bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
unload_color (f, FRAME_BACKGROUND_PIXEL (f));
FRAME_BACKGROUND_PIXEL (f) = bg;
if (FRAME_X_WINDOW (f) != 0)
{
Display *dpy = FRAME_X_DISPLAY (f);
BLOCK_INPUT;
XSetBackground (dpy, x->normal_gc, bg);
XSetForeground (dpy, x->reverse_gc, bg);
XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg);
XSetForeground (dpy, x->cursor_gc, bg);
#ifdef USE_GTK
xg_set_background_color (f, bg);
#endif
#ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
toolkit scroll bars. */
{
Lisp_Object bar;
for (bar = FRAME_SCROLL_BARS (f);
!NILP (bar);
bar = XSCROLL_BAR (bar)->next)
{
Window window = XSCROLL_BAR (bar)->x_window;
XSetWindowBackground (dpy, window, bg);
}
}
#endif /* USE_TOOLKIT_SCROLL_BARS */
UNBLOCK_INPUT;
update_face_from_frame_parameter (f, Qbackground_color, arg);
if (FRAME_VISIBLE_P (f))
redraw_frame (f);
}
}
static Cursor
make_invisible_cursor (struct frame *f)
{
Display *dpy = FRAME_X_DISPLAY (f);
static char const no_data[] = { 0 };
Pixmap pix;
XColor col;
Cursor c;
x_catch_errors (dpy);
pix = XCreateBitmapFromData (dpy, FRAME_X_DISPLAY_INFO (f)->root_window,
no_data, 1, 1);
if (! x_had_errors_p (dpy) && pix != None)
{
col.pixel = 0;
col.red = col.green = col.blue = 0;
col.flags = DoRed | DoGreen | DoBlue;
c = XCreatePixmapCursor (dpy, pix, pix, &col, &col, 0, 0);
if (x_had_errors_p (dpy) || c == None)
c = 0;
XFreePixmap (dpy, pix);
}
x_uncatch_errors ();
return c;
}
void
x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
struct x_output *x = f->output_data.x;
Display *dpy = FRAME_X_DISPLAY (f);
Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
Cursor hourglass_cursor, horizontal_drag_cursor;
unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
/* Don't let pointers be invisible. */
if (mask_color == pixel)
{
x_free_colors (f, &pixel, 1);
pixel = x_copy_color (f, FRAME_FOREGROUND_PIXEL (f));
}
unload_color (f, x->mouse_pixel);
x->mouse_pixel = pixel;
BLOCK_INPUT;
/* It's not okay to crash if the user selects a screwy cursor. */
x_catch_errors (dpy);
if (!NILP (Vx_pointer_shape))
{
CHECK_NUMBER (Vx_pointer_shape);
cursor = XCreateFontCursor (dpy, XINT (Vx_pointer_shape));
}
else
cursor = XCreateFontCursor (dpy, XC_xterm);
x_check_errors (dpy, "bad text pointer cursor: %s");
if (!NILP (Vx_nontext_pointer_shape))
{
CHECK_NUMBER (Vx_nontext_pointer_shape);
nontext_cursor
= XCreateFontCursor (dpy, XINT (Vx_nontext_pointer_shape));
}
else
nontext_cursor = XCreateFontCursor (dpy, XC_left_ptr);
x_check_errors (dpy, "bad nontext pointer cursor: %s");
if (!NILP (Vx_hourglass_pointer_shape))
{
CHECK_NUMBER (Vx_hourglass_pointer_shape);
hourglass_cursor
= XCreateFontCursor (dpy, XINT (Vx_hourglass_pointer_shape));
}
else
hourglass_cursor = XCreateFontCursor (dpy, XC_watch);
x_check_errors (dpy, "bad hourglass pointer cursor: %s");
if (!NILP (Vx_mode_pointer_shape))
{
CHECK_NUMBER (Vx_mode_pointer_shape);
mode_cursor = XCreateFontCursor (dpy, XINT (Vx_mode_pointer_shape));
}
else
mode_cursor = XCreateFontCursor (dpy, XC_xterm);
x_check_errors (dpy, "bad modeline pointer cursor: %s");
if (!NILP (Vx_sensitive_text_pointer_shape))
{
CHECK_NUMBER (Vx_sensitive_text_pointer_shape);
hand_cursor
= XCreateFontCursor (dpy, XINT (Vx_sensitive_text_pointer_shape));
}
else
hand_cursor = XCreateFontCursor (dpy, XC_hand2);
if (!NILP (Vx_window_horizontal_drag_shape))
{
CHECK_NUMBER (Vx_window_horizontal_drag_shape);
horizontal_drag_cursor
= XCreateFontCursor (dpy, XINT (Vx_window_horizontal_drag_shape));
}
else
horizontal_drag_cursor
= XCreateFontCursor (dpy, XC_sb_h_double_arrow);
/* Check and report errors with the above calls. */
x_check_errors (dpy, "can't set cursor shape: %s");
x_uncatch_errors ();
{
XColor fore_color, back_color;
fore_color.pixel = x->mouse_pixel;
x_query_color (f, &fore_color);
back_color.pixel = mask_color;
x_query_color (f, &back_color);
XRecolorCursor (dpy, cursor, &fore_color, &back_color);
XRecolorCursor (dpy, nontext_cursor, &fore_color, &back_color);
XRecolorCursor (dpy, mode_cursor, &fore_color, &back_color);
XRecolorCursor (dpy, hand_cursor, &fore_color, &back_color);
XRecolorCursor (dpy, hourglass_cursor, &fore_color, &back_color);
XRecolorCursor (dpy, horizontal_drag_cursor, &fore_color, &back_color);
}
if (FRAME_X_WINDOW (f) != 0)
XDefineCursor (dpy, FRAME_X_WINDOW (f),
f->output_data.x->current_cursor = cursor);
if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor == 0)
FRAME_X_DISPLAY_INFO (f)->invisible_cursor = make_invisible_cursor (f);
if (cursor != x->text_cursor
&& x->text_cursor != 0)
XFreeCursor (dpy, x->text_cursor);
x->text_cursor = cursor;
if (nontext_cursor != x->nontext_cursor
&& x->nontext_cursor != 0)
XFreeCursor (dpy, x->nontext_cursor);
x->nontext_cursor = nontext_cursor;
if (hourglass_cursor != x->hourglass_cursor
&& x->hourglass_cursor != 0)
XFreeCursor (dpy, x->hourglass_cursor);
x->hourglass_cursor = hourglass_cursor;
if (mode_cursor != x->modeline_cursor
&& x->modeline_cursor != 0)
XFreeCursor (dpy, f->output_data.x->modeline_cursor);
x->modeline_cursor = mode_cursor;
if (hand_cursor != x->hand_cursor
&& x->hand_cursor != 0)
XFreeCursor (dpy, x->hand_cursor);
x->hand_cursor = hand_cursor;
if (horizontal_drag_cursor != x->horizontal_drag_cursor
&& x->horizontal_drag_cursor != 0)
XFreeCursor (dpy, x->horizontal_drag_cursor);
x->horizontal_drag_cursor = horizontal_drag_cursor;
XFlush (dpy);
UNBLOCK_INPUT;
update_face_from_frame_parameter (f, Qmouse_color, arg);
}
void
x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
unsigned long fore_pixel, pixel;
int fore_pixel_allocated_p = 0, pixel_allocated_p = 0;
struct x_output *x = f->output_data.x;
if (!NILP (Vx_cursor_fore_pixel))
{
fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
WHITE_PIX_DEFAULT (f));
fore_pixel_allocated_p = 1;
}
else
fore_pixel = FRAME_BACKGROUND_PIXEL (f);
pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
pixel_allocated_p = 1;
/* Make sure that the cursor color differs from the background color. */
if (pixel == FRAME_BACKGROUND_PIXEL (f))
{
if (pixel_allocated_p)
{
x_free_colors (f, &pixel, 1);
pixel_allocated_p = 0;
}
pixel = x->mouse_pixel;
if (pixel == fore_pixel)
{
if (fore_pixel_allocated_p)
{
x_free_colors (f, &fore_pixel, 1);
fore_pixel_allocated_p = 0;
}
fore_pixel = FRAME_BACKGROUND_PIXEL (f);
}
}
unload_color (f, x->cursor_foreground_pixel);
if (!fore_pixel_allocated_p)
fore_pixel = x_copy_color (f, fore_pixel);
x->cursor_foreground_pixel = fore_pixel;
unload_color (f, x->cursor_pixel);
if (!pixel_allocated_p)
pixel = x_copy_color (f, pixel);
x->cursor_pixel = pixel;
if (FRAME_X_WINDOW (f) != 0)
{
BLOCK_INPUT;
XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel);
XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel);
UNBLOCK_INPUT;
if (FRAME_VISIBLE_P (f))
{
x_update_cursor (f, 0);
x_update_cursor (f, 1);
}
}
update_face_from_frame_parameter (f, Qcursor_color, arg);
}
/* Set the border-color of frame F to pixel value PIX.
Note that this does not fully take effect if done before
F has an x-window. */
void
x_set_border_pixel (struct frame *f, int pix)
{
unload_color (f, f->output_data.x->border_pixel);
f->output_data.x->border_pixel = pix;
if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0)
{
BLOCK_INPUT;
XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
(unsigned long)pix);
UNBLOCK_INPUT;
if (FRAME_VISIBLE_P (f))
redraw_frame (f);
}
}
/* Set the border-color of frame F to value described by ARG.
ARG can be a string naming a color.
The border-color is used for the border that is drawn by the X server.
Note that this does not fully take effect if done before
F has an x-window; it must be redone when the window is created.
Note: this is done in two routines because of the way X10 works.
Note: under X11, this is normally the province of the window manager,
and so emacs' border colors may be overridden. */
void
x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int pix;
CHECK_STRING (arg);
pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
x_set_border_pixel (f, pix);
update_face_from_frame_parameter (f, Qborder_color, arg);
}
void
x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
{
set_frame_cursor_types (f, arg);
/* Make sure the cursor gets redrawn. */
cursor_type_changed = 1;
}
void
x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int result;
if (STRINGP (arg))
{
if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
return;
}
else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
return;
BLOCK_INPUT;
if (NILP (arg))
result = x_text_icon (f,
(char *) SDATA ((!NILP (f->icon_name)
? f->icon_name
: f->name)));
else
result = x_bitmap_icon (f, arg);
if (result)
{
UNBLOCK_INPUT;
error ("No icon window available");
}
XFlush (FRAME_X_DISPLAY (f));
UNBLOCK_INPUT;
}
void
x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int result;
if (STRINGP (arg))
{
if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
return;
}
else if (!NILP (arg) || NILP (oldval))
return;
f->icon_name = arg;
if (f->output_data.x->icon_bitmap != 0)
return;
BLOCK_INPUT;
result = x_text_icon (f,
(char *) SDATA ((!NILP (f->icon_name)
? f->icon_name
: !NILP (f->title)
? f->title
: f->name)));
if (result)
{
UNBLOCK_INPUT;
error ("No icon window available");
}
XFlush (FRAME_X_DISPLAY (f));
UNBLOCK_INPUT;
}
void
x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
int nlines;
#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
int olines = FRAME_MENU_BAR_LINES (f);
#endif
/* 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))
return;
if (INTEGERP (value))
nlines = XINT (value);
else
nlines = 0;
/* Make sure we redisplay all windows in this frame. */
windows_or_buffers_changed++;
#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
FRAME_MENU_BAR_LINES (f) = 0;
if (nlines)
{
FRAME_EXTERNAL_MENU_BAR (f) = 1;
if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0)
/* Make sure next redisplay shows the menu bar. */
XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt;
}
else
{
if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
free_frame_menubar (f);
FRAME_EXTERNAL_MENU_BAR (f) = 0;
if (FRAME_X_P (f))
f->output_data.x->menubar_widget = 0;
}
#else /* not USE_X_TOOLKIT && not USE_GTK */
FRAME_MENU_BAR_LINES (f) = nlines;
change_window_heights (f->root_window, nlines - olines);
/* If the menu bar height gets changed, the internal border below
the top margin has to be cleared. Also, if the menu bar gets
larger, the area for the added lines has to be cleared except for
the first menu bar line that is to be drawn later. */
if (nlines != olines)
{
int height = FRAME_INTERNAL_BORDER_WIDTH (f);
int width = FRAME_PIXEL_WIDTH (f);
int y;
/* height can be zero here. */
if (height > 0 && width > 0)
{
y = FRAME_TOP_MARGIN_HEIGHT (f);
BLOCK_INPUT;
x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
0, y, width, height, False);
UNBLOCK_INPUT;
}
if (nlines > 1 && nlines > olines)
{
y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f);
height = nlines * FRAME_LINE_HEIGHT (f) - y;
BLOCK_INPUT;
x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
0, y, width, height, False);
UNBLOCK_INPUT;
}
if (nlines == 0 && WINDOWP (f->menu_bar_window))
clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
}
#endif /* not USE_X_TOOLKIT && not USE_GTK */
adjust_glyphs (f);
}
/* Set the number of lines used for the tool bar of frame F to VALUE.
VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
is the old number of tool bar lines. This function changes the
height of all windows on frame F to match the new tool bar height.
The frame's height doesn't change. */
void
x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
int delta, nlines, root_height;
Lisp_Object root_window;
/* Treat tool bars like menu bars. */
if (FRAME_MINIBUF_ONLY_P (f))
return;
/* Use VALUE only if an integer >= 0. */
if (INTEGERP (value) && XINT (value) >= 0)
nlines = XFASTINT (value);
else
nlines = 0;
#ifdef USE_GTK
FRAME_TOOL_BAR_LINES (f) = 0;
if (nlines)
{
FRAME_EXTERNAL_TOOL_BAR (f) = 1;
if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0)
/* Make sure next redisplay shows the tool bar. */
XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt;
update_frame_tool_bar (f);
}
else
{
if (FRAME_EXTERNAL_TOOL_BAR (f))
free_frame_tool_bar (f);
FRAME_EXTERNAL_TOOL_BAR (f) = 0;
}
return;
#endif
/* Make sure we redisplay all windows in this frame. */
++windows_or_buffers_changed;
delta = nlines - FRAME_TOOL_BAR_LINES (f);
/* Don't resize the tool-bar to more than we have room for. */
root_window = FRAME_ROOT_WINDOW (f);
root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window));
if (root_height - delta < 1)
{
delta = root_height - 1;
nlines = FRAME_TOOL_BAR_LINES (f) + delta;
}
FRAME_TOOL_BAR_LINES (f) = nlines;
change_window_heights (root_window, delta);
adjust_glyphs (f);
/* We also have to make sure that the internal border at the top of
the frame, below the menu bar or tool bar, is redrawn when the
tool bar disappears. This is so because the internal border is
below the tool bar if one is displayed, but is below the menu bar
if there isn't a tool bar. The tool bar draws into the area
below the menu bar. */
if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
{
clear_frame (f);
clear_current_matrices (f);
}
/* If the tool bar gets smaller, the internal border below it
has to be cleared. It was formerly part of the display
of the larger tool bar, and updating windows won't clear it. */
if (delta < 0)
{
int height = FRAME_INTERNAL_BORDER_WIDTH (f);
int width = FRAME_PIXEL_WIDTH (f);
int y = (FRAME_MENU_BAR_LINES (f) + nlines) * FRAME_LINE_HEIGHT (f);
/* height can be zero here. */
if (height > 0 && width > 0)
{
BLOCK_INPUT;
x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
0, y, width, height, False);
UNBLOCK_INPUT;
}
if (WINDOWP (f->tool_bar_window))
clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
}
}
/* Set the foreground color for scroll bars on frame F to VALUE.
VALUE should be a string, a color name. If it isn't a string or
isn't a valid color name, do nothing. OLDVAL is the old value of
the frame parameter. */
void
x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
unsigned long pixel;
if (STRINGP (value))
pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f));
else
pixel = -1;
if (f->output_data.x->scroll_bar_foreground_pixel != -1)
unload_color (f, f->output_data.x->scroll_bar_foreground_pixel);
f->output_data.x->scroll_bar_foreground_pixel = pixel;
if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
{
/* Remove all scroll bars because they have wrong colors. */
if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
(*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
(*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
redraw_frame (f);
}
}
/* Set the background color for scroll bars on frame F to VALUE VALUE
should be a string, a color name. If it isn't a string or isn't a
valid color name, do nothing. OLDVAL is the old value of the frame
parameter. */
void
x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
unsigned long pixel;
if (STRINGP (value))
pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f));
else
pixel = -1;
if (f->output_data.x->scroll_bar_background_pixel != -1)
unload_color (f, f->output_data.x->scroll_bar_background_pixel);
#ifdef USE_TOOLKIT_SCROLL_BARS
/* Scrollbar shadow colors. */
if (f->output_data.x->scroll_bar_top_shadow_pixel != -1)
{
unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel);
f->output_data.x->scroll_bar_top_shadow_pixel = -1;
}
if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1)
{
unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel);
f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
}
#endif /* USE_TOOLKIT_SCROLL_BARS */
f->output_data.x->scroll_bar_background_pixel = pixel;
if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
{
/* Remove all scroll bars because they have wrong colors. */
if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
(*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
(*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
update_face_from_frame_parameter (f, Qscroll_bar_background, value);
redraw_frame (f);
}
}
/* Encode Lisp string STRING as a text in a format appropriate for
XICCC (X Inter Client Communication Conventions).
This can call Lisp code, so callers must GCPRO.
If STRING contains only ASCII characters, do no conversion and
return the string data of STRING. Otherwise, encode the text by
CODING_SYSTEM, and return a newly allocated memory area which
should be freed by `xfree' by a caller.
SELECTIONP non-zero means the string is being encoded for an X
selection, so it is safe to run pre-write conversions (which
may run Lisp code).
Store the byte length of resulting text in *TEXT_BYTES.
If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
which means that the `encoding' of the result can be `STRING'.
Otherwise store 0 in *STRINGP, which means that the `encoding' of
the result should be `COMPOUND_TEXT'. */
static unsigned char *
x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp, int *text_bytes, int *stringp, int *freep)
{
int result = string_xstring_p (string);
struct coding_system coding;
if (result == 0)
{
/* No multibyte character in OBJ. We need not encode it. */
*text_bytes = SBYTES (string);
*stringp = 1;
*freep = 0;
return SDATA (string);
}
setup_coding_system (coding_system, &coding);
coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK);
/* We suppress producing escape sequences for composition. */
coding.common_flags &= ~CODING_ANNOTATION_MASK;
coding.dst_bytes = SCHARS (string) * 2;
coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
encode_coding_object (&coding, string, 0, 0,
SCHARS (string), SBYTES (string), Qnil);
*text_bytes = coding.produced;
*stringp = (result == 1 || !EQ (coding_system, Qcompound_text));
*freep = 1;
return coding.destination;
}
/* Set the WM name to NAME for frame F. Also set the icon name.
If the frame already has an icon name, use that, otherwise set the
icon name to NAME. */
static void
x_set_name_internal (FRAME_PTR f, Lisp_Object name)
{
if (FRAME_X_WINDOW (f))
{
BLOCK_INPUT;
{
XTextProperty text, icon;
int bytes, stringp;
int do_free_icon_value = 0, do_free_text_value = 0;
Lisp_Object coding_system;
Lisp_Object encoded_name;
Lisp_Object encoded_icon_name;
struct gcpro gcpro1;
/* As ENCODE_UTF_8 may cause GC and relocation of string data,
we use it before x_encode_text that may return string data. */
GCPRO1 (name);
encoded_name = ENCODE_UTF_8 (name);
UNGCPRO;
coding_system = Qcompound_text;
/* Note: Encoding strategy
We encode NAME by compound-text and use "COMPOUND-TEXT" in
text.encoding. But, there are non-internationalized window
managers which don't support that encoding. So, if NAME
contains only ASCII and 8859-1 characters, encode it by
iso-latin-1, and use "STRING" in text.encoding hoping that
such window managers at least analyze this format correctly,
i.e. treat 8-bit bytes as 8859-1 characters.
We may also be able to use "UTF8_STRING" in text.encoding
in the future which can encode all Unicode characters.
But, for the moment, there's no way to know that the
current window manager supports it or not.
Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
properties. Per the EWMH specification, those two properties
are always UTF8_STRING. This matches what gtk_window_set_title()
does in the USE_GTK case. */
text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp,
&do_free_text_value);
text.encoding = (stringp ? XA_STRING
: FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
text.format = 8;
text.nitems = bytes;
if (!STRINGP (f->icon_name))
{
icon = text;
encoded_icon_name = encoded_name;
}
else
{
/* See the above comment "Note: Encoding strategy". */
icon.value = x_encode_text (f->icon_name, coding_system, 0,
&bytes, &stringp, &do_free_icon_value);
icon.encoding = (stringp ? XA_STRING
: FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
icon.format = 8;
icon.nitems = bytes;
encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
}
#ifdef USE_GTK
gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
(char *) SDATA (encoded_name));
#else /* not USE_GTK */
XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_name,
FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
8, PropModeReplace,
(char *) SDATA (encoded_name),
SBYTES (encoded_name));
#endif /* not USE_GTK */
XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_icon_name,
FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
8, PropModeReplace,
(char *) SDATA (encoded_icon_name),
SBYTES (encoded_icon_name));
if (do_free_icon_value)
xfree (icon.value);
if (do_free_text_value)
xfree (text.value);
}
UNBLOCK_INPUT;
}
}
/* Change the name of frame F to NAME. If NAME is nil, set F's name to
x_id_name.
If EXPLICIT is non-zero, that indicates that lisp code is setting the
name; if NAME is a string, set F's name to NAME and set
F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
If EXPLICIT is zero, that indicates that Emacs redisplay code is
suggesting a new name, which lisp code should override; if
F->explicit_name is set, ignore the new name; otherwise, set it. */
void
x_set_name (struct frame *f, Lisp_Object name, int explicit)
{
/* 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 = 1;
f->explicit_name = ! NILP (name);
}
else if (f->explicit_name)
return;
/* If NAME is nil, set the name to the x_id_name. */
if (NILP (name))
{
/* Check for no change needed in this very common case
before we do any consing. */
if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
SDATA (f->name)))
return;
name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
}
else
CHECK_STRING (name);
/* Don't change the name if it's already NAME. */
if (! NILP (Fstring_equal (name, f->name)))
return;
f->name = name;
/* For setting the frame title, the title parameter should override
the name parameter. */
if (! NILP (f->title))
name = f->title;
x_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. */
void
x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
{
x_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
x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
{
x_set_name (f, arg, 0);
}
/* Change the title of frame F to NAME.
If NAME is nil, use the frame name as the title. */
void
x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
{
/* Don't change the title if it's already NAME. */
if (EQ (name, f->title))
return;
update_mode_lines = 1;
f->title = name;
if (NILP (name))
name = f->name;
else
CHECK_STRING (name);
x_set_name_internal (f, name);
}
void
x_set_scroll_bar_default_width (struct frame *f)
{
int wid = FRAME_COLUMN_WIDTH (f);
#ifdef USE_TOOLKIT_SCROLL_BARS
/* A minimum width of 14 doesn't look good for toolkit scroll bars. */
int width = 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM;
FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid;
FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width;
#else
/* Make the actual width at least 14 pixels and a multiple of a
character width. */
FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
/* Use all of that space (aside from required margins) for the
scroll bar. */
FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0;
#endif
}
/* Record in frame F the specified or default value according to ALIST
of the parameter named PROP (a Lisp symbol). If no value is
specified for PROP, look for an X default for XPROP on the frame
named NAME. If that is not found either, use the value DEFLT. */
static Lisp_Object
x_default_scroll_bar_color_parameter (struct frame *f,
Lisp_Object alist, Lisp_Object prop,
const char *xprop, const char *xclass,
int foreground_p)
{
struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
Lisp_Object tem;
tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING);
if (EQ (tem, Qunbound))
{
#ifdef USE_TOOLKIT_SCROLL_BARS
/* See if an X resource for the scroll bar color has been
specified. */
tem = display_x_get_resource (dpyinfo,
build_string (foreground_p
? "foreground"
: "background"),
empty_unibyte_string,
build_string ("verticalScrollBar"),
empty_unibyte_string);
if (!STRINGP (tem))
{
/* If nothing has been specified, scroll bars will use a
toolkit-dependent default. Because these defaults are
difficult to get at without actually creating a scroll
bar, use nil to indicate that no color has been
specified. */
tem = Qnil;
}
#else /* not USE_TOOLKIT_SCROLL_BARS */
tem = Qnil;
#endif /* not USE_TOOLKIT_SCROLL_BARS */
}
x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
return tem;
}
#ifdef USE_X_TOOLKIT
/* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
already be present because of the toolkit (Motif adds some of them,
for example, but Xt doesn't). */
static void
hack_wm_protocols (FRAME_PTR f, Widget widget)
{
Display *dpy = XtDisplay (widget);
Window w = XtWindow (widget);
int need_delete = 1;
int need_focus = 1;
int need_save = 1;
BLOCK_INPUT;
{
Atom type;
unsigned char *catoms;
int format = 0;
unsigned long nitems = 0;
unsigned long bytes_after;
if ((XGetWindowProperty (dpy, w,
FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
(long)0, (long)100, False, XA_ATOM,
&type, &format, &nitems, &bytes_after,
&catoms)
== Success)
&& format == 32 && type == XA_ATOM)
{
Atom *atoms = (Atom *) catoms;
while (nitems > 0)
{
nitems--;
if (atoms[nitems]
== FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window)
need_delete = 0;
else if (atoms[nitems]
== FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus)
need_focus = 0;
else if (atoms[nitems]
== FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself)
need_save = 0;
}
}
if (catoms)
XFree (catoms);
}
{
Atom props [10];
int count = 0;
if (need_delete)
props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
if (need_focus)
props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus;
if (need_save)
props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
if (count)
XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
XA_ATOM, 32, PropModeAppend,
(unsigned char *) props, count);
}
UNBLOCK_INPUT;
}
#endif
/* Support routines for XIC (X Input Context). */
#ifdef HAVE_X_I18N
static XFontSet xic_create_xfontset (struct frame *);
static XIMStyle best_xim_style (XIMStyles *, XIMStyles *);
/* Supported XIM styles, ordered by preference. */
static XIMStyle supported_xim_styles[] =
{
XIMPreeditPosition | XIMStatusArea,
XIMPreeditPosition | XIMStatusNothing,
XIMPreeditPosition | XIMStatusNone,
XIMPreeditNothing | XIMStatusArea,
XIMPreeditNothing | XIMStatusNothing,
XIMPreeditNothing | XIMStatusNone,
XIMPreeditNone | XIMStatusArea,
XIMPreeditNone | XIMStatusNothing,
XIMPreeditNone | XIMStatusNone,
0,
};
/* Create an X fontset on frame F with base font name BASE_FONTNAME. */
const char xic_defaut_fontset[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
/* Create an Xt fontset spec from the name of a base font.
If `motif' is True use the Motif syntax. */
char *
xic_create_fontsetname (const char *base_fontname, int motif)
{
const char *sep = motif ? ";" : ",";
char *fontsetname;
/* Make a fontset name from the base font name. */
if (xic_defaut_fontset == base_fontname)
{ /* There is no base font name, use the default. */
int len = strlen (base_fontname) + 2;
fontsetname = xmalloc (len);
memset (fontsetname, 0, len);
strcpy (fontsetname, base_fontname);
}
else
{
/* Make a fontset name from the base font name.
The font set will be made of the following elements:
- the base font.
- the base font where the charset spec is replaced by -*-*.
- the same but with the family also replaced with -*-*-. */
const char *p = base_fontname;
int i;
for (i = 0; *p; p++)
if (*p == '-') i++;
if (i != 14)
{ /* As the font name doesn't conform to XLFD, we can't
modify it to generalize it to allcs and allfamilies.
Use the specified font plus the default. */
int len = strlen (base_fontname) + strlen (xic_defaut_fontset) + 3;
fontsetname = xmalloc (len);
memset (fontsetname, 0, len);
strcpy (fontsetname, base_fontname);
strcat (fontsetname, sep);
strcat (fontsetname, xic_defaut_fontset);
}
else
{
int len;
const char *p1 = NULL, *p2 = NULL, *p3 = NULL;
char *font_allcs = NULL;
char *font_allfamilies = NULL;
char *font_all = NULL;
const char *allcs = "*-*-*-*-*-*-*";
const char *allfamilies = "-*-*-";
const char *all = "*-*-*-*-";
char *base;
for (i = 0, p = base_fontname; i < 8; p++)
{
if (*p == '-')
{
i++;
if (i == 3)
p1 = p + 1;
else if (i == 7)
p2 = p + 1;
else if (i == 6)
p3 = p + 1;
}
}
/* If base_fontname specifies ADSTYLE, make it a
wildcard. */
if (*p3 != '*')
{
int diff = (p2 - p3) - 2;
base = alloca (strlen (base_fontname) + 1);
memcpy (base, base_fontname, p3 - base_fontname);
base[p3 - base_fontname] = '*';
base[(p3 - base_fontname) + 1] = '-';
strcpy (base + (p3 - base_fontname) + 2, p2);
p = base + (p - base_fontname) - diff;
p1 = base + (p1 - base_fontname);
p2 = base + (p2 - base_fontname) - diff;
base_fontname = base;
}
/* Build the font spec that matches all charsets. */
len = p - base_fontname + strlen (allcs) + 1;
font_allcs = (char *) alloca (len);
memset (font_allcs, 0, len);
memcpy (font_allcs, base_fontname, p - base_fontname);
strcat (font_allcs, allcs);
/* Build the font spec that matches all families and
add-styles. */
len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1;
font_allfamilies = (char *) alloca (len);
memset (font_allfamilies, 0, len);
strcpy (font_allfamilies, allfamilies);
memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1);
strcat (font_allfamilies, allcs);
/* Build the font spec that matches all. */
len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1;
font_all = (char *) alloca (len);
memset (font_all, 0, len);
strcpy (font_all, allfamilies);
strcat (font_all, all);
memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2);
strcat (font_all, allcs);
/* Build the actual font set name. */
len = strlen (base_fontname) + strlen (font_allcs)
+ strlen (font_allfamilies) + strlen (font_all) + 5;
fontsetname = xmalloc (len);
memset (fontsetname, 0, len);
strcpy (fontsetname, base_fontname);
strcat (fontsetname, sep);
strcat (fontsetname, font_allcs);
strcat (fontsetname, sep);
strcat (fontsetname, font_allfamilies);
strcat (fontsetname, sep);
strcat (fontsetname, font_all);
}
}
if (motif)
strcat (fontsetname, ":");
return fontsetname;
}
#ifdef DEBUG_XIC_FONTSET
static void
print_fontset_result (xfs, name, missing_list, missing_count)
XFontSet xfs;
char *name;
char **missing_list;
int missing_count;
{
if (xfs)
fprintf (stderr, "XIC Fontset created: %s\n", name);
else
{
fprintf (stderr, "XIC Fontset failed: %s\n", name);
while (missing_count-- > 0)
{
fprintf (stderr, " missing: %s\n", *missing_list);
missing_list++;
}
}
}
#endif
static XFontSet
xic_create_xfontset (struct frame *f)
{
XFontSet xfs = NULL;
struct font *font = FRAME_FONT (f);
int pixel_size = font->pixel_size;
Lisp_Object rest, frame;
/* See if there is another frame already using same fontset. */
FOR_EACH_FRAME (rest, frame)
{
struct frame *cf = XFRAME (frame);
if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
&& FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
&& FRAME_FONT (f)
&& FRAME_FONT (f)->pixel_size == pixel_size)
{
xfs = FRAME_XIC_FONTSET (cf);
break;
}
}
if (! xfs)
{
char buf[256];
char **missing_list;
int missing_count;
char *def_string;
const char *xlfd_format = "-*-*-medium-r-normal--%d-*-*-*-*-*";
sprintf (buf, xlfd_format, pixel_size);
missing_list = NULL;
xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf,
&missing_list, &missing_count, &def_string);
#ifdef DEBUG_XIC_FONTSET
print_fontset_result (xfs, buf, missing_list, missing_count);
#endif
if (missing_list)
XFreeStringList (missing_list);
if (! xfs)
{
/* List of pixel sizes most likely available. Find one that
is closest to pixel_size. */
int sizes[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
int *smaller, *larger;
for (smaller = sizes; smaller[1]; smaller++)
if (smaller[1] >= pixel_size)
break;
larger = smaller + 1;
if (*larger == pixel_size)
larger++;
while (*smaller || *larger)
{
int this_size;
if (! *larger)
this_size = *smaller--;
else if (! *smaller)
this_size = *larger++;
else if (pixel_size - *smaller < *larger - pixel_size)
this_size = *smaller--;
else
this_size = *larger++;
sprintf (buf, xlfd_format, this_size);
missing_list = NULL;
xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf,
&missing_list, &missing_count, &def_string);
#ifdef DEBUG_XIC_FONTSET
print_fontset_result (xfs, buf, missing_list, missing_count);
#endif
if (missing_list)
XFreeStringList (missing_list);
if (xfs)
break;
}
}
if (! xfs)
{
const char *last_resort = "-*-*-*-r-normal--*-*-*-*-*-*";
missing_list = NULL;
xfs = XCreateFontSet (FRAME_X_DISPLAY (f), last_resort,
&missing_list, &missing_count, &def_string);
#ifdef DEBUG_XIC_FONTSET
print_fontset_result (xfs, last_resort, missing_list, missing_count);
#endif
if (missing_list)
XFreeStringList (missing_list);
}
}
return xfs;
}
/* Free the X fontset of frame F if it is the last frame using it. */
void
xic_free_xfontset (struct frame *f)
{
Lisp_Object rest, frame;
int shared_p = 0;
if (!FRAME_XIC_FONTSET (f))
return;
/* See if there is another frame sharing the same fontset. */
FOR_EACH_FRAME (rest, frame)
{
struct frame *cf = XFRAME (frame);
if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
&& FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
&& FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
{
shared_p = 1;
break;
}
}
if (!shared_p)
/* The fontset is not used anymore. It is safe to free it. */
XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
if (FRAME_XIC_BASE_FONTNAME (f))
xfree (FRAME_XIC_BASE_FONTNAME (f));
FRAME_XIC_BASE_FONTNAME (f) = NULL;
FRAME_XIC_FONTSET (f) = NULL;
}
/* Value is the best input style, given user preferences USER (already
checked to be supported by Emacs), and styles supported by the
input method XIM. */
static XIMStyle
best_xim_style (XIMStyles *user, XIMStyles *xim)
{
int i, j;
for (i = 0; i < user->count_styles; ++i)
for (j = 0; j < xim->count_styles; ++j)
if (user->supported_styles[i] == xim->supported_styles[j])
return user->supported_styles[i];
/* Return the default style. */
return XIMPreeditNothing | XIMStatusNothing;
}
/* Create XIC for frame F. */
static XIMStyle xic_style;
void
create_frame_xic (struct frame *f)
{
XIM xim;
XIC xic = NULL;
XFontSet xfs = NULL;
if (FRAME_XIC (f))
return;
/* Create X fontset. */
xfs = xic_create_xfontset (f);
xim = FRAME_X_XIM (f);
if (xim)
{
XRectangle s_area;
XPoint spot;
XVaNestedList preedit_attr;
XVaNestedList status_attr;
s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1;
spot.x = 0; spot.y = 1;
/* Determine XIC style. */
if (xic_style == 0)
{
XIMStyles supported_list;
supported_list.count_styles = (sizeof supported_xim_styles
/ sizeof supported_xim_styles[0]);
supported_list.supported_styles = supported_xim_styles;
xic_style = best_xim_style (&supported_list,
FRAME_X_XIM_STYLES (f));
}
preedit_attr = XVaCreateNestedList (0,
XNFontSet, xfs,
XNForeground,
FRAME_FOREGROUND_PIXEL (f),
XNBackground,
FRAME_BACKGROUND_PIXEL (f),
(xic_style & XIMPreeditPosition
? XNSpotLocation
: NULL),
&spot,
NULL);
status_attr = XVaCreateNestedList (0,
XNArea,
&s_area,
XNFontSet,
xfs,
XNForeground,
FRAME_FOREGROUND_PIXEL (f),
XNBackground,
FRAME_BACKGROUND_PIXEL (f),
NULL);
xic = XCreateIC (xim,
XNInputStyle, xic_style,
XNClientWindow, FRAME_X_WINDOW (f),
XNFocusWindow, FRAME_X_WINDOW (f),
XNStatusAttributes, status_attr,
XNPreeditAttributes, preedit_attr,
NULL);
XFree (preedit_attr);
XFree (status_attr);
}
FRAME_XIC (f) = xic;
FRAME_XIC_STYLE (f) = xic_style;
FRAME_XIC_FONTSET (f) = xfs;
}
/* Destroy XIC and free XIC fontset of frame F, if any. */
void
free_frame_xic (struct frame *f)
{
if (FRAME_XIC (f) == NULL)
return;
XDestroyIC (FRAME_XIC (f));
xic_free_xfontset (f);
FRAME_XIC (f) = NULL;
}
/* Place preedit area for XIC of window W's frame to specified
pixel position X/Y. X and Y are relative to window W. */
void
xic_set_preeditarea (struct window *w, int x, int y)
{
struct frame *f = XFRAME (w->frame);
XVaNestedList attr;
XPoint spot;
spot.x = WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w);
spot.y = WINDOW_TO_FRAME_PIXEL_Y (w, y) + FONT_BASE (FRAME_FONT (f));
attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
XFree (attr);
}
/* Place status area for XIC in bottom right corner of frame F.. */
void
xic_set_statusarea (struct frame *f)
{
XIC xic = FRAME_XIC (f);
XVaNestedList attr;
XRectangle area;
XRectangle *needed;
/* Negotiate geometry of status area. If input method has existing
status area, use its current size. */
area.x = area.y = area.width = area.height = 0;
attr = XVaCreateNestedList (0, XNAreaNeeded, &area, NULL);
XSetICValues (xic, XNStatusAttributes, attr, NULL);
XFree (attr);
attr = XVaCreateNestedList (0, XNAreaNeeded, &needed, NULL);
XGetICValues (xic, XNStatusAttributes, attr, NULL);
XFree (attr);
if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */
{
attr = XVaCreateNestedList (0, XNArea, &needed, NULL);
XGetICValues (xic, XNStatusAttributes, attr, NULL);
XFree (attr);
}
area.width = needed->width;
area.height = needed->height;
area.x = FRAME_PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f);
area.y = (FRAME_PIXEL_HEIGHT (f) - area.height
- FRAME_MENUBAR_HEIGHT (f)
- FRAME_TOOLBAR_TOP_HEIGHT (f)
- FRAME_INTERNAL_BORDER_WIDTH (f));
XFree (needed);
attr = XVaCreateNestedList (0, XNArea, &area, NULL);
XSetICValues (xic, XNStatusAttributes, attr, NULL);
XFree (attr);
}
/* Set X fontset for XIC of frame F, using base font name
BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
void
xic_set_xfontset (struct frame *f, const char *base_fontname)
{
XVaNestedList attr;
XFontSet xfs;
xic_free_xfontset (f);
xfs = xic_create_xfontset (f);
attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL);
if (FRAME_XIC_STYLE (f) & XIMPreeditPosition)
XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
if (FRAME_XIC_STYLE (f) & XIMStatusArea)
XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL);
XFree (attr);
FRAME_XIC_FONTSET (f) = xfs;
}
#endif /* HAVE_X_I18N */
#ifdef USE_X_TOOLKIT
/* Create and set up the X widget for frame F. */
static void
x_window (struct frame *f, long window_prompting, int minibuffer_only)
{
XClassHint class_hints;
XSetWindowAttributes attributes;
unsigned long attribute_mask;
Widget shell_widget;
Widget pane_widget;
Widget frame_widget;
Arg al [25];
int ac;
BLOCK_INPUT;
/* Use the resource name as the top-level widget name
for looking up resources. Make a non-Lisp copy
for the window manager, so GC relocation won't bother it.
Elsewhere we specify the window name for the window manager. */
{
char *str = (char *) SDATA (Vx_resource_name);
f->namebuf = (char *) xmalloc (strlen (str) + 1);
strcpy (f->namebuf, str);
}
ac = 0;
XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
XtSetArg (al[ac], XtNinput, 1); ac++;
XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++;
XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS,
applicationShellWidgetClass,
FRAME_X_DISPLAY (f), al, ac);
f->output_data.x->widget = shell_widget;
/* maybe_set_screen_title_format (shell_widget); */
pane_widget = lw_create_widget ("main", "pane", widget_id_tick++,
(widget_value *) NULL,
shell_widget, False,
(lw_callback) NULL,
(lw_callback) NULL,
(lw_callback) NULL,
(lw_callback) NULL);
ac = 0;
XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
XtSetArg (al[ac], XtNborderWidth, 0); ac++;
XtSetValues (pane_widget, al, ac);
f->output_data.x->column_widget = pane_widget;
/* mappedWhenManaged to false tells to the paned window to not map/unmap
the emacs screen when changing menubar. This reduces flickering. */
ac = 0;
XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
XtSetArg (al[ac], XtNshowGrip, 0); ac++;
XtSetArg (al[ac], XtNallowResize, 1); ac++;
XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
XtSetArg (al[ac], XtNemacsFrame, f); ac++;
XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
XtSetArg (al[ac], XtNborderWidth, 0); ac++;
frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget,
al, ac);
f->output_data.x->edit_widget = frame_widget;
XtManageChild (frame_widget);
/* Do some needed geometry management. */
{
int len;
char *tem, shell_position[32];
Arg al[10];
int ac = 0;
int extra_borders = 0;
int menubar_size
= (f->output_data.x->menubar_widget
? (f->output_data.x->menubar_widget->core.height
+ f->output_data.x->menubar_widget->core.border_width)
: 0);
#if 0 /* Experimentally, we now get the right results
for -geometry -0-0 without this. 24 Aug 96, rms. */
if (FRAME_EXTERNAL_MENU_BAR (f))
{
Dimension ibw = 0;
XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL);
menubar_size += ibw;
}
#endif
f->output_data.x->menubar_height = menubar_size;
#ifndef USE_LUCID
/* Motif seems to need this amount added to the sizes
specified for the shell widget. The Athena/Lucid widgets don't.
Both conclusions reached experimentally. -- rms. */
XtVaGetValues (f->output_data.x->edit_widget, XtNinternalBorderWidth,
&extra_borders, NULL);
extra_borders *= 2;
#endif
/* Convert our geometry parameters into a geometry string
and specify it.
Note that we do not specify here whether the position
is a user-specified or program-specified one.
We pass that information later, in x_wm_set_size_hints. */
{
int left = f->left_pos;
int xneg = window_prompting & XNegative;
int top = f->top_pos;
int yneg = window_prompting & YNegative;
if (xneg)
left = -left;
if (yneg)
top = -top;
if (window_prompting & USPosition)
sprintf (shell_position, "=%dx%d%c%d%c%d",
FRAME_PIXEL_WIDTH (f) + extra_borders,
FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders,
(xneg ? '-' : '+'), left,
(yneg ? '-' : '+'), top);
else
{
sprintf (shell_position, "=%dx%d",
FRAME_PIXEL_WIDTH (f) + extra_borders,
FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders);
/* Setting x and y when the position is not specified in
the geometry string will set program position in the WM hints.
If Emacs had just one program position, we could set it in
fallback resources, but since each make-frame call can specify
different program positions, this is easier. */
XtSetArg (al[ac], XtNx, left); ac++;
XtSetArg (al[ac], XtNy, top); ac++;
}
}
len = strlen (shell_position) + 1;
/* We don't free this because we don't know whether
it is safe to free it while the frame exists.
It isn't worth the trouble of arranging to free it
when the frame is deleted. */
tem = (char *) xmalloc (len);
strncpy (tem, shell_position, len);
XtSetArg (al[ac], XtNgeometry, tem); ac++;
XtSetValues (shell_widget, al, ac);
}
XtManageChild (pane_widget);
XtRealizeWidget (shell_widget);
if (FRAME_X_EMBEDDED_P (f))
XReparentWindow (FRAME_X_DISPLAY (f), XtWindow (shell_widget),
f->output_data.x->parent_desc, 0, 0);
FRAME_X_WINDOW (f) = XtWindow (frame_widget);
validate_x_resource_name ();
class_hints.res_name = (char *) SDATA (Vx_resource_name);
class_hints.res_class = (char *) SDATA (Vx_resource_class);
XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints);
#ifdef HAVE_X_I18N
FRAME_XIC (f) = NULL;
if (use_xim)
create_frame_xic (f);
#endif
f->output_data.x->wm_hints.input = True;
f->output_data.x->wm_hints.flags |= InputHint;
XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
&f->output_data.x->wm_hints);
hack_wm_protocols (f, shell_widget);
#ifdef HACK_EDITRES
XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0);
#endif
/* Do a stupid property change to force the server to generate a
PropertyNotify event so that the event_stream server timestamp will
be initialized to something relevant to the time we created the window.
*/
XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
XA_ATOM, 32, PropModeAppend,
(unsigned char*) NULL, 0);
/* Make all the standard events reach the Emacs frame. */
attributes.event_mask = STANDARD_EVENT_SET;
#ifdef HAVE_X_I18N
if (FRAME_XIC (f))
{
/* XIM server might require some X events. */
unsigned long fevent = NoEventMask;
XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
attributes.event_mask |= fevent;
}
#endif /* HAVE_X_I18N */
attribute_mask = CWEventMask;
XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget),
attribute_mask, &attributes);
XtMapWidget (frame_widget);
/* x_set_name normally ignores requests to set the name if the
requested name is the same as the current name. This is the one
place where that assumption isn't correct; f->name is set, but
the X server hasn't been told. */
{
Lisp_Object name;
int explicit = f->explicit_name;
f->explicit_name = 0;
name = f->name;
f->name = Qnil;
x_set_name (f, name, explicit);
}
XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
f->output_data.x->current_cursor
= f->output_data.x->text_cursor);
UNBLOCK_INPUT;
/* This is a no-op, except under Motif. Make sure main areas are
set to something reasonable, in case we get an error later. */
lw_set_main_areas (pane_widget, 0, frame_widget);
}
#else /* not USE_X_TOOLKIT */
#ifdef USE_GTK
void
x_window (FRAME_PTR f)
{
if (! xg_create_frame_widgets (f))
error ("Unable to create window");
#ifdef HAVE_X_I18N
FRAME_XIC (f) = NULL;
if (use_xim)
{
BLOCK_INPUT;
create_frame_xic (f);
if (FRAME_XIC (f))
{
/* XIM server might require some X events. */
unsigned long fevent = NoEventMask;
XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
if (fevent != NoEventMask)
{
XSetWindowAttributes attributes;
XWindowAttributes wattr;
unsigned long attribute_mask;
XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
&wattr);
attributes.event_mask = wattr.your_event_mask | fevent;
attribute_mask = CWEventMask;
XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
attribute_mask, &attributes);
}
}
UNBLOCK_INPUT;
}
#endif
}
#else /*! USE_GTK */
/* Create and set up the X window for frame F. */
void
x_window (struct frame *f)
{
XClassHint class_hints;
XSetWindowAttributes attributes;
unsigned long attribute_mask;
attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f);
attributes.border_pixel = f->output_data.x->border_pixel;
attributes.bit_gravity = StaticGravity;
attributes.backing_store = NotUseful;
attributes.save_under = True;
attributes.event_mask = STANDARD_EVENT_SET;
attributes.colormap = FRAME_X_COLORMAP (f);
attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
| CWColormap);
BLOCK_INPUT;
FRAME_X_WINDOW (f)
= XCreateWindow (FRAME_X_DISPLAY (f),
f->output_data.x->parent_desc,
f->left_pos,
f->top_pos,
FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f),
f->border_width,
CopyFromParent, /* depth */
InputOutput, /* class */
FRAME_X_VISUAL (f),
attribute_mask, &attributes);
#ifdef HAVE_X_I18N
if (use_xim)
{
create_frame_xic (f);
if (FRAME_XIC (f))
{
/* XIM server might require some X events. */
unsigned long fevent = NoEventMask;
XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
attributes.event_mask |= fevent;
attribute_mask = CWEventMask;
XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
attribute_mask, &attributes);
}
}
#endif /* HAVE_X_I18N */
validate_x_resource_name ();
class_hints.res_name = (char *) SDATA (Vx_resource_name);
class_hints.res_class = (char *) SDATA (Vx_resource_class);
XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints);
/* The menubar is part of the ordinary display;
it does not count in addition to the height of the window. */
f->output_data.x->menubar_height = 0;
/* This indicates that we use the "Passive Input" input model.
Unless we do this, we don't get the Focus{In,Out} events that we
need to draw the cursor correctly. Accursed bureaucrats.
XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
f->output_data.x->wm_hints.input = True;
f->output_data.x->wm_hints.flags |= InputHint;
XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
&f->output_data.x->wm_hints);
f->output_data.x->wm_hints.icon_pixmap = None;
/* Request "save yourself" and "delete window" commands from wm. */
{
Atom protocols[2];
protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2);
}
/* x_set_name normally ignores requests to set the name if the
requested name is the same as the current name. This is the one
place where that assumption isn't correct; f->name is set, but
the X server hasn't been told. */
{
Lisp_Object name;
int explicit = f->explicit_name;
f->explicit_name = 0;
name = f->name;
f->name = Qnil;
x_set_name (f, name, explicit);
}
XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
f->output_data.x->current_cursor
= f->output_data.x->text_cursor);
UNBLOCK_INPUT;
if (FRAME_X_WINDOW (f) == 0)
error ("Unable to create window");
}
#endif /* not USE_GTK */
#endif /* not USE_X_TOOLKIT */
/* Verify that the icon position args for this window are valid. */
static void
x_icon_verify (struct frame *f, Lisp_Object parms)
{
Lisp_Object icon_x, icon_y;
/* Set the position of the icon. Note that twm groups all
icons in an icon window. */
icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
icon_y = x_frame_get_and_record_arg (f, 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);
}
else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
error ("Both left and top icon corners of icon must be specified");
}
/* Handle the icon stuff for this window. Perhaps later we might
want an x_set_icon_position which can be called interactively as
well. */
static void
x_icon (struct frame *f, Lisp_Object parms)
{
Lisp_Object icon_x, icon_y;
#if 0
struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
#endif
/* Set the position of the icon. Note that twm groups all
icons in an icon window. */
icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
icon_y = x_frame_get_and_record_arg (f, 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);
}
else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
error ("Both left and top icon corners of icon must be specified");
BLOCK_INPUT;
if (! EQ (icon_x, Qunbound))
x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
#if 0 /* x_get_arg removes the visibility parameter as a side effect,
but x_create_frame still needs it. */
/* Start up iconic or window? */
x_wm_set_window_state
(f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL),
Qicon)
? IconicState
: NormalState));
#endif
x_text_icon (f, (char *) SDATA ((!NILP (f->icon_name)
? f->icon_name
: f->name)));
UNBLOCK_INPUT;
}
/* Make the GCs needed for this window, setting the
background, border and mouse colors; also create the
mouse cursor and the gray border tile. */
static void
x_make_gc (struct frame *f)
{
XGCValues gc_values;
BLOCK_INPUT;
/* Create the GCs of this frame.
Note that many default values are used. */
gc_values.foreground = FRAME_FOREGROUND_PIXEL (f);
gc_values.background = FRAME_BACKGROUND_PIXEL (f);
gc_values.line_width = 0; /* Means 1 using fast algorithm. */
f->output_data.x->normal_gc
= XCreateGC (FRAME_X_DISPLAY (f),
FRAME_X_WINDOW (f),
GCLineWidth | GCForeground | GCBackground,
&gc_values);
/* Reverse video style. */
gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
gc_values.background = FRAME_FOREGROUND_PIXEL (f);
f->output_data.x->reverse_gc
= XCreateGC (FRAME_X_DISPLAY (f),
FRAME_X_WINDOW (f),
GCForeground | GCBackground | GCLineWidth,
&gc_values);
/* Cursor has cursor-color background, background-color foreground. */
gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
gc_values.background = f->output_data.x->cursor_pixel;
gc_values.fill_style = FillOpaqueStippled;
f->output_data.x->cursor_gc
= XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
(GCForeground | GCBackground
| GCFillStyle | GCLineWidth),
&gc_values);
/* Reliefs. */
f->output_data.x->white_relief.gc = 0;
f->output_data.x->black_relief.gc = 0;
/* Create the gray border tile used when the pointer is not in
the frame. Since this depends on the frame's pixel values,
this must be done on a per-frame basis. */
f->output_data.x->border_tile
= (XCreatePixmapFromBitmapData
(FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
gray_bits, gray_width, gray_height,
FRAME_FOREGROUND_PIXEL (f),
FRAME_BACKGROUND_PIXEL (f),
DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
UNBLOCK_INPUT;
}
/* Free what was allocated in x_make_gc. */
void
x_free_gcs (struct frame *f)
{
Display *dpy = FRAME_X_DISPLAY (f);
BLOCK_INPUT;
if (f->output_data.x->normal_gc)
{
XFreeGC (dpy, f->output_data.x->normal_gc);
f->output_data.x->normal_gc = 0;
}
if (f->output_data.x->reverse_gc)
{
XFreeGC (dpy, f->output_data.x->reverse_gc);
f->output_data.x->reverse_gc = 0;
}
if (f->output_data.x->cursor_gc)
{
XFreeGC (dpy, f->output_data.x->cursor_gc);
f->output_data.x->cursor_gc = 0;
}
if (f->output_data.x->border_tile)
{
XFreePixmap (dpy, f->output_data.x->border_tile);
f->output_data.x->border_tile = 0;
}
UNBLOCK_INPUT;
}
/* Handler for signals raised during x_create_frame and
x_create_top_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 (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
{
#if GLYPH_DEBUG
struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
#endif
x_free_frame_resources (f);
#if GLYPH_DEBUG
/* Check that reference counts are indeed correct. */
xassert (dpyinfo->reference_count == dpyinfo_refcount);
xassert (dpyinfo->image_cache->refcount == image_cache_refcount);
#endif
return Qt;
}
return Qnil;
}
static void
x_default_font_parameter (struct frame *f, Lisp_Object parms)
{
struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
Lisp_Object font_param = x_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 precedendce 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)
{
char *name = xstrdup (system_font);
font = font_open_by_name (f, name);
free (name);
}
}
if (NILP (font))
font = !NILP (font_param) ? font_param
: x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
if (! FONTP (font) && ! STRINGP (font))
{
const char *names[]
= {
#ifdef HAVE_XFT
/* This will find the normal Xft font. */
"monospace-10",
#endif
"-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, 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. */
x_set_frame_parameters (f, Fcons (Fcons (Qfont_param, font_param), Qnil));
}
/* This call will make X resources override any system font setting. */
x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
}
DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint, Sx_wm_set_size_hint,
0, 1, 0,
doc: /* Send the size hints for frame FRAME to the window manager.
If FRAME is nil, use the selected frame. */)
(Lisp_Object frame)
{
struct frame *f;
if (NILP (frame))
frame = selected_frame;
f = XFRAME (frame);
BLOCK_INPUT;
if (FRAME_X_P (f))
x_wm_set_size_hint (f, 0, 0);
UNBLOCK_INPUT;
return Qnil;
}
static void
set_machine_and_pid_properties (struct frame *f)
{
/* See the above comment "Note: Encoding strategy". */
XTextProperty text;
int bytes, stringp;
int do_free_text_value = 0;
long pid = (long) getpid ();
text.value = x_encode_text (Vsystem_name,
Qcompound_text, 0, &bytes, &stringp,
&do_free_text_value);
text.encoding = (stringp ? XA_STRING
: FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
text.format = 8;
text.nitems = bytes;
XSetWMClientMachine (FRAME_X_DISPLAY (f),
FRAME_OUTER_WINDOW (f),
&text);
if (do_free_text_value)
xfree (text.value);
XChangeProperty (FRAME_X_DISPLAY (f),
FRAME_OUTER_WINDOW (f),
XInternAtom (FRAME_X_DISPLAY (f),
"_NET_WM_PID",
False),
XA_CARDINAL, 32, PropModeReplace,
(unsigned char *) &pid, 1);
}
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;
int minibuffer_only = 0;
long window_prompting = 0;
int width, height;
int count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
Lisp_Object display;
struct x_display_info *dpyinfo = NULL;
Lisp_Object parent;
struct kboard *kb;
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 = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER);
if (EQ (display, Qunbound))
display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
if (EQ (display, Qunbound))
display = Qnil;
dpyinfo = check_x_display_info (display);
kb = dpyinfo->terminal->kboard;
if (!dpyinfo->terminal->name)
error ("Terminal is not live, can't create new frames on it");
name = x_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 = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER);
if (EQ (parent, Qunbound))
parent = Qnil;
if (! NILP (parent))
CHECK_NUMBER (parent);
/* make_frame_without_minibuffer can run Lisp code and garbage collect. */
/* No need to protect DISPLAY because that's not used after passing
it to make_frame_without_minibuffer. */
frame = Qnil;
GCPRO4 (parms, parent, name, frame);
tem = x_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 = 1;
}
else if (WINDOWP (tem))
f = make_frame_without_minibuffer (tem, kb, display);
else
f = make_frame (1);
XSETFRAME (frame, f);
/* Note that X Windows does support scroll bars. */
FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
f->terminal = dpyinfo->terminal;
f->terminal->reference_count++;
f->output_method = output_x_window;
f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
memset (f->output_data.x, 0, sizeof (struct x_output));
f->output_data.x->icon_bitmap = -1;
FRAME_FONTSET (f) = -1;
f->output_data.x->scroll_bar_foreground_pixel = -1;
f->output_data.x->scroll_bar_background_pixel = -1;
#ifdef USE_TOOLKIT_SCROLL_BARS
f->output_data.x->scroll_bar_top_shadow_pixel = -1;
f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
#endif /* USE_TOOLKIT_SCROLL_BARS */
f->icon_name
= x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
RES_TYPE_STRING);
if (! STRINGP (f->icon_name))
f->icon_name = Qnil;
FRAME_X_DISPLAY_INFO (f) = dpyinfo;
/* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
record_unwind_protect (unwind_create_frame, frame);
#if GLYPH_DEBUG
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
/* These colors will be set anyway later, but it's important
to get the color reference counts right, so initialize them! */
{
Lisp_Object black;
struct gcpro gcpro1;
/* 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;
f->output_data.x->cursor_pixel = -1;
f->output_data.x->cursor_foreground_pixel = -1;
f->output_data.x->border_pixel = -1;
f->output_data.x->mouse_pixel = -1;
black = build_string ("black");
GCPRO1 (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));
f->output_data.x->cursor_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
f->output_data.x->cursor_foreground_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
f->output_data.x->border_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
f->output_data.x->mouse_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
UNGCPRO;
}
/* Specify the parent under which to make this X window. */
if (!NILP (parent))
{
f->output_data.x->parent_desc = (Window) XFASTINT (parent);
f->output_data.x->explicit_parent = 1;
}
else
{
f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
f->output_data.x->explicit_parent = 0;
}
/* Set the name; the functions to which we pass f expect the name to
be set. */
if (EQ (name, Qunbound) || NILP (name))
{
f->name = build_string (dpyinfo->x_id_name);
f->explicit_name = 0;
}
else
{
f->name = name;
f->explicit_name = 1;
/* use the frame's title when getting resources for this frame. */
specbind (Qx_resource_name, name);
}
f->resx = dpyinfo->resx;
f->resy = dpyinfo->resy;
#ifdef HAVE_FREETYPE
#ifdef HAVE_XFT
register_font_driver (&xftfont_driver, f);
#else /* not HAVE_XFT */
register_font_driver (&ftxfont_driver, f);
#endif /* not HAVE_XFT */
#endif /* HAVE_FREETYPE */
register_font_driver (&xfont_driver, f);
x_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 (! FRAME_X_EMBEDDED_P (f))
x_default_parameter (f, parms, Qborder_width, make_number (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 = x_get_arg (dpyinfo, parms, Qinternal_border_width,
"internalBorder", "internalBorder", RES_TYPE_NUMBER);
if (! EQ (value, Qunbound))
parms = Fcons (Fcons (Qinternal_border_width, value),
parms);
}
x_default_parameter (f, parms, Qinternal_border_width,
#ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
make_number (0),
#else
make_number (1),
#endif
"internalBorderWidth", "internalBorderWidth",
RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qvertical_scroll_bars,
#if defined(USE_GTK) && defined(USE_TOOLKIT_SCROLL_BARS)
Qright,
#else
Qleft,
#endif
"verticalScrollBars", "ScrollBars",
RES_TYPE_SYMBOL);
/* Also do the stuff which must be set before the window exists. */
x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
"foreground", "Foreground", RES_TYPE_STRING);
x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
"background", "Background", RES_TYPE_STRING);
x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
"pointerColor", "Foreground", RES_TYPE_STRING);
x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
"cursorColor", "Foreground", RES_TYPE_STRING);
x_default_parameter (f, parms, Qborder_color, build_string ("black"),
"borderColor", "BorderColor", RES_TYPE_STRING);
x_default_parameter (f, parms, Qscreen_gamma, Qnil,
"screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
x_default_parameter (f, parms, Qline_spacing, Qnil,
"lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qleft_fringe, Qnil,
"leftFringe", "LeftFringe", RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qright_fringe, Qnil,
"rightFringe", "RightFringe", RES_TYPE_NUMBER);
x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
"scrollBarForeground",
"ScrollBarForeground", 1);
x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background,
"scrollBarBackground",
"ScrollBarBackground", 0);
/* Init faces before x_default_parameter is called for scroll-bar
parameters because that function calls x_set_scroll_bar_width,
which calls change_frame_size, which calls Fset_window_buffer,
which runs hooks, which call Fvertical_motion. At the end, we
end up in init_iterator with a null face cache, which should not
happen. */
init_frame_faces (f);
/* The X resources controlling the menu-bar and tool-bar are
processed specially at startup, and reflected in the mode
variables; ignore them here. */
x_default_parameter (f, parms, Qmenu_bar_lines,
NILP (Vmenu_bar_mode)
? make_number (0) : make_number (1),
NULL, NULL, RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qtool_bar_lines,
NILP (Vtool_bar_mode)
? make_number (0) : make_number (1),
NULL, NULL, RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
"bufferPredicate", "BufferPredicate",
RES_TYPE_SYMBOL);
x_default_parameter (f, parms, Qtitle, Qnil,
"title", "Title", RES_TYPE_STRING);
x_default_parameter (f, parms, Qwait_for_wm, Qt,
"waitForWM", "WaitForWM", RES_TYPE_BOOLEAN);
x_default_parameter (f, parms, Qfullscreen, Qnil,
"fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
x_default_parameter (f, parms, Qtool_bar_position,
f->tool_bar_position, 0, 0, RES_TYPE_SYMBOL);
/* Compute the size of the X window. */
window_prompting = x_figure_window_size (f, parms, 1);
tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
f->no_split = minibuffer_only || EQ (tem, Qt);
x_icon_verify (f, parms);
/* Create the X widget or window. */
#ifdef USE_X_TOOLKIT
x_window (f, window_prompting, minibuffer_only);
#else
x_window (f);
#endif
x_icon (f, parms);
x_make_gc (f);
/* Now consider the frame official. */
FRAME_X_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. */
x_default_parameter (f, parms, Qicon_type, Qt,
"bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
x_default_parameter (f, parms, Qauto_raise, Qnil,
"autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
x_default_parameter (f, parms, Qauto_lower, Qnil,
"autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
x_default_parameter (f, parms, Qcursor_type, Qbox,
"cursorType", "CursorType", RES_TYPE_SYMBOL);
x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
"scrollBarWidth", "ScrollBarWidth",
RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qalpha, Qnil,
"alpha", "Alpha", RES_TYPE_NUMBER);
/* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
Change will not be effected unless different from the current
FRAME_LINES (f). */
width = FRAME_COLS (f);
height = FRAME_LINES (f);
SET_FRAME_COLS (f, 0);
FRAME_LINES (f) = 0;
change_frame_size (f, height, width, 1, 0, 0);
#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
/* 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);
#ifndef USE_GTK
/* This is a no-op, except under Motif where it arranges the
main window for the widgets on it. */
lw_set_main_areas (f->output_data.x->column_widget,
f->output_data.x->menubar_widget,
f->output_data.x->edit_widget);
#endif /* not USE_GTK */
}
#endif /* USE_X_TOOLKIT || USE_GTK */
/* 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;
x_wm_set_size_hint (f, window_prompting, 0);
UNBLOCK_INPUT;
/* 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 (! f->output_data.x->explicit_parent)
{
Lisp_Object visibility;
visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
RES_TYPE_SYMBOL);
if (EQ (visibility, Qunbound))
visibility = Qt;
if (EQ (visibility, Qicon))
x_iconify_frame (f);
else if (! NILP (visibility))
x_make_frame_visible (f);
else
/* Must have been Qnil. */
;
}
BLOCK_INPUT;
/* Set machine name and pid for the purpose of window managers. */
set_machine_and_pid_properties(f);
/* Set the WM leader property. GTK does this itself, so this is not
needed when using GTK. */
if (dpyinfo->client_leader_window != 0)
{
XChangeProperty (FRAME_X_DISPLAY (f),
FRAME_OUTER_WINDOW (f),
dpyinfo->Xatom_wm_client_leader,
XA_WINDOW, 32, PropModeReplace,
(unsigned char *) &dpyinfo->client_leader_window, 1);
}
UNBLOCK_INPUT;
/* Initialize `default-minibuffer-frame' in case this is the first
frame on this terminal. */
if (FRAME_HAS_MINIBUF_P (f)
&& (!FRAMEP (kb->Vdefault_minibuffer_frame)
|| !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))))
kb->Vdefault_minibuffer_frame = frame;
/* All remaining specified parameters, which have not been "used"
by x_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))))
f->param_alist = Fcons (XCAR (tem), f->param_alist);
UNGCPRO;
/* Make sure windows on this frame appear in calls to next-window
and similar functions. */
Vwindow_list = Qnil;
return unbind_to (count, frame);
}
/* FRAME is used only to get a handle on the X display. We don't pass the
display info directly because we're called from frame.c, which doesn't
know about that structure. */
Lisp_Object
x_get_focus_frame (struct frame *frame)
{
struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame);
Lisp_Object xfocus;
if (! dpyinfo->x_focus_frame)
return Qnil;
XSETFRAME (xfocus, dpyinfo->x_focus_frame);
return xfocus;
}
/* In certain situations, when the window manager follows a
click-to-focus policy, there seems to be no way around calling
XSetInputFocus to give another frame the input focus .
In an ideal world, XSetInputFocus should generally be avoided so
that applications don't interfere with the window manager's focus
policy. But I think it's okay to use when it's clearly done
following a user-command. */
DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
doc: /* Set the input focus to FRAME.
FRAME nil means use the selected frame. */)
(Lisp_Object frame)
{
struct frame *f = check_x_frame (frame);
Display *dpy = FRAME_X_DISPLAY (f);
BLOCK_INPUT;
x_catch_errors (dpy);
XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
RevertToParent, CurrentTime);
x_ewmh_activate_frame (f);
x_uncatch_errors ();
UNBLOCK_INPUT;
return Qnil;
}
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)
{
XColor foo;
FRAME_PTR f = check_x_frame (frame);
CHECK_STRING (color);
if (x_defined_color (f, SDATA (color), &foo, 0))
return Qt;
else
return Qnil;
}
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)
{
XColor foo;
FRAME_PTR f = check_x_frame (frame);
CHECK_STRING (color);
if (x_defined_color (f, SDATA (color), &foo, 0))
return list3 (make_number (foo.red),
make_number (foo.green),
make_number (foo.blue));
else
return Qnil;
}
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)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
if (dpyinfo->n_planes <= 2)
return Qnil;
switch (dpyinfo->visual->class)
{
case StaticColor:
case PseudoColor:
case TrueColor:
case DirectColor:
return Qt;
default:
return Qnil;
}
}
DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
0, 1, 0,
doc: /* Return t if the X 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)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
if (dpyinfo->n_planes <= 1)
return Qnil;
switch (dpyinfo->visual->class)
{
case StaticColor:
case PseudoColor:
case TrueColor:
case DirectColor:
case StaticGray:
case GrayScale:
return Qt;
default:
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 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (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 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (x_display_pixel_height (dpyinfo));
}
DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
0, 1, 0,
doc: /* Return the number of bitplanes of 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (dpyinfo->n_planes);
}
DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
0, 1, 0,
doc: /* Return the number of color cells of 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
int nr_planes = DisplayPlanes (dpyinfo->display,
XScreenNumberOfScreen (dpyinfo->screen));
/* Truncate nr_planes to 24 to avoid integer overflow.
Some displays says 32, but only 24 bits are actually significant.
There are only very few and rare video cards that have more than
24 significant bits. Also 24 bits is more than 16 million colors,
it "should be enough for everyone". */
if (nr_planes > 24) nr_planes = 24;
return make_number (1 << nr_planes);
}
DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
Sx_server_max_request_size,
0, 1, 0,
doc: /* Return the maximum request size of the X 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)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (MAXREQUEST (dpyinfo->display));
}
DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
doc: /* Return the "vendor ID" string of the X server of display TERMINAL.
\(Labelling 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)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
const char *vendor = ServerVendor (dpyinfo->display);
if (! vendor) vendor = "";
return build_string (vendor);
}
DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
doc: /* Return the version numbers of the X server of display TERMINAL.
The value is a list of three integers: the major and minor
version numbers of the X Protocol in use, and the distributor-specific release
number. See also the function `x-server-vendor'.
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 x_display_info *dpyinfo = check_x_display_info (terminal);
Display *dpy = dpyinfo->display;
return Fcons (make_number (ProtocolVersion (dpy)),
Fcons (make_number (ProtocolRevision (dpy)),
Fcons (make_number (VendorRelease (dpy)), Qnil)));
}
DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
doc: /* Return the number of screens on the X 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)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (ScreenCount (dpyinfo->display));
}
DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
doc: /* Return the height in millimeters of 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (HeightMMOfScreen (dpyinfo->screen));
}
DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
doc: /* Return the width in millimeters of 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
return make_number (WidthMMOfScreen (dpyinfo->screen));
}
DEFUN ("x-display-backing-store", Fx_display_backing_store,
Sx_display_backing_store, 0, 1, 0,
doc: /* Return an indication of whether X display TERMINAL does backing store.
The value may be `always', `when-mapped', or `not-useful'.
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 x_display_info *dpyinfo = check_x_display_info (terminal);
Lisp_Object result;
switch (DoesBackingStore (dpyinfo->screen))
{
case Always:
result = intern ("always");
break;
case WhenMapped:
result = intern ("when-mapped");
break;
case NotUseful:
result = intern ("not-useful");
break;
default:
error ("Strange value for BackingStore parameter of screen");
result = Qnil;
}
return result;
}
DEFUN ("x-display-visual-class", Fx_display_visual_class,
Sx_display_visual_class, 0, 1, 0,
doc: /* Return the visual class of the X 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. */)
(Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
Lisp_Object result;
switch (dpyinfo->visual->class)
{
case StaticGray:
result = intern ("static-gray");
break;
case GrayScale:
result = intern ("gray-scale");
break;
case StaticColor:
result = intern ("static-color");
break;
case PseudoColor:
result = intern ("pseudo-color");
break;
case TrueColor:
result = intern ("true-color");
break;
case DirectColor:
result = intern ("direct-color");
break;
default:
error ("Display has an unknown visual class");
result = Qnil;
}
return result;
}
DEFUN ("x-display-save-under", Fx_display_save_under,
Sx_display_save_under, 0, 1, 0,
doc: /* Return t if the X display 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)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
if (DoesSaveUnders (dpyinfo->screen) == True)
return Qt;
else
return Qnil;
}
int
x_pixel_width (register struct frame *f)
{
return FRAME_PIXEL_WIDTH (f);
}
int
x_pixel_height (register struct frame *f)
{
return FRAME_PIXEL_HEIGHT (f);
}
int
x_char_width (register struct frame *f)
{
return FRAME_COLUMN_WIDTH (f);
}
int
x_char_height (register struct frame *f)
{
return FRAME_LINE_HEIGHT (f);
}
int
x_screen_planes (register struct frame *f)
{
return FRAME_X_DISPLAY_INFO (f)->n_planes;
}
/************************************************************************
X Displays
************************************************************************/
/* Mapping visual names to visuals. */
static struct visual_class
{
const char *name;
int class;
}
visual_classes[] =
{
{"StaticGray", StaticGray},
{"GrayScale", GrayScale},
{"StaticColor", StaticColor},
{"PseudoColor", PseudoColor},
{"TrueColor", TrueColor},
{"DirectColor", DirectColor},
{NULL, 0}
};
#ifndef HAVE_XSCREENNUMBEROFSCREEN
/* Value is the screen number of screen SCR. This is a substitute for
the X function with the same name when that doesn't exist. */
int
XScreenNumberOfScreen (scr)
register Screen *scr;
{
Display *dpy = scr->display;
int i;
for (i = 0; i < dpy->nscreens; ++i)
if (scr == dpy->screens + i)
break;
return i;
}
#endif /* not HAVE_XSCREENNUMBEROFSCREEN */
/* Select the visual that should be used on display DPYINFO. Set
members of DPYINFO appropriately. Called from x_term_init. */
void
select_visual (struct x_display_info *dpyinfo)
{
Display *dpy = dpyinfo->display;
Screen *screen = dpyinfo->screen;
Lisp_Object value;
/* See if a visual is specified. */
value = display_x_get_resource (dpyinfo,
build_string ("visualClass"),
build_string ("VisualClass"),
Qnil, Qnil);
if (STRINGP (value))
{
/* VALUE should be of the form CLASS-DEPTH, where CLASS is one
of `PseudoColor', `TrueColor' etc. and DEPTH is the color
depth, a decimal number. NAME is compared with case ignored. */
char *s = (char *) alloca (SBYTES (value) + 1);
char *dash;
int i, class = -1;
XVisualInfo vinfo;
strcpy (s, SDATA (value));
dash = strchr (s, '-');
if (dash)
{
dpyinfo->n_planes = atoi (dash + 1);
*dash = '\0';
}
else
/* We won't find a matching visual with depth 0, so that
an error will be printed below. */
dpyinfo->n_planes = 0;
/* Determine the visual class. */
for (i = 0; visual_classes[i].name; ++i)
if (xstrcasecmp (s, visual_classes[i].name) == 0)
{
class = visual_classes[i].class;
break;
}
/* Look up a matching visual for the specified class. */
if (class == -1
|| !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen),
dpyinfo->n_planes, class, &vinfo))
fatal ("Invalid visual specification `%s'", SDATA (value));
dpyinfo->visual = vinfo.visual;
}
else
{
int n_visuals;
XVisualInfo *vinfo, vinfo_template;
dpyinfo->visual = DefaultVisualOfScreen (screen);
vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual);
vinfo_template.screen = XScreenNumberOfScreen (screen);
vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask,
&vinfo_template, &n_visuals);
if (n_visuals <= 0)
fatal ("Can't get proper X visual info");
dpyinfo->n_planes = vinfo->depth;
XFree ((char *) vinfo);
}
}
/* Return the X display structure for the display named NAME.
Open a new connection if necessary. */
struct x_display_info *
x_display_info_for_name (Lisp_Object name)
{
Lisp_Object names;
struct x_display_info *dpyinfo;
CHECK_STRING (name);
#if 0
if (! EQ (Vinitial_window_system, intern ("x")))
error ("Not using X Windows"); /* That doesn't stop us anymore. */
#endif
for (dpyinfo = x_display_list, names = x_display_name_list;
dpyinfo;
dpyinfo = dpyinfo->next, names = XCDR (names))
{
Lisp_Object tem;
tem = Fstring_equal (XCAR (XCAR (names)), name);
if (!NILP (tem))
return dpyinfo;
}
/* Use this general default value to start with. */
Vx_resource_name = Vinvocation_name;
validate_x_resource_name ();
dpyinfo = x_term_init (name, (char *)0,
(char *) SDATA (Vx_resource_name));
if (dpyinfo == 0)
error ("Cannot connect to X server %s", SDATA (name));
x_in_use = 1;
XSETFASTINT (Vwindow_system_version, 11);
return dpyinfo;
}
DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
1, 3, 0,
doc: /* Open a connection to an X 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 xrm_string, Lisp_Object must_succeed)
{
unsigned char *xrm_option;
struct x_display_info *dpyinfo;
CHECK_STRING (display);
if (! NILP (xrm_string))
CHECK_STRING (xrm_string);
#if 0
if (! EQ (Vinitial_window_system, intern ("x")))
error ("Not using X Windows"); /* That doesn't stop us anymore. */
#endif
if (! NILP (xrm_string))
xrm_option = (unsigned char *) SDATA (xrm_string);
else
xrm_option = (unsigned char *) 0;
validate_x_resource_name ();
/* This is what opens the connection and sets x_current_display.
This also initializes many symbols, such as those used for input. */
dpyinfo = x_term_init (display, xrm_option,
(char *) SDATA (Vx_resource_name));
if (dpyinfo == 0)
{
if (!NILP (must_succeed))
fatal ("Cannot connect to X server %s.\n\
Check the DISPLAY environment variable or use `-d'.\n\
Also use the `xauth' program to verify that you have the proper\n\
authorization information needed to connect the X server.\n\
An insecure way to solve the problem may be to use `xhost'.\n",
SDATA (display));
else
error ("Cannot connect to X server %s", SDATA (display));
}
x_in_use = 1;
XSETFASTINT (Vwindow_system_version, 11);
return Qnil;
}
DEFUN ("x-close-connection", Fx_close_connection,
Sx_close_connection, 1, 1, 0,
doc: /* Close the connection to TERMINAL's X 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 x_display_info *dpyinfo = check_x_display_info (terminal);
if (dpyinfo->reference_count > 0)
error ("Display still has frames on it");
x_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 tail, result;
result = Qnil;
for (tail = x_display_name_list; CONSP (tail); tail = XCDR (tail))
result = Fcons (XCAR (XCAR (tail)), result);
return result;
}
DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0,
doc: /* If ON is non-nil, report X errors as soon as the erring request is made.
If ON is nil, allow buffering of requests.
Turning on synchronization prohibits the Xlib routines from buffering
requests and seriously degrades performance, but makes debugging much
easier.
The optional second argument TERMINAL specifies which display to act on.
TERMINAL should be a terminal object, a frame or a display name (a string).
If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object on, Lisp_Object terminal)
{
struct x_display_info *dpyinfo = check_x_display_info (terminal);
XSynchronize (dpyinfo->display, !EQ (on, Qnil));
return Qnil;
}
/* Wait for responses to all X commands issued so far for frame F. */
void
x_sync (FRAME_PTR f)
{
BLOCK_INPUT;
XSync (FRAME_X_DISPLAY (f), False);
UNBLOCK_INPUT;
}
/***********************************************************************
Window properties
***********************************************************************/
DEFUN ("x-change-window-property", Fx_change_window_property,
Sx_change_window_property, 2, 6, 0,
doc: /* Change window property PROP to VALUE on the X window of FRAME.
PROP must be a string.
VALUE may be a string or a list of conses, numbers and/or strings.
If an element in the list is a string, it is converted to
an Atom and the value of the Atom is used. If an element is a cons,
it is converted to a 32 bit number where the car is the 16 top bits and the
cdr is the lower 16 bits.
FRAME nil or omitted means use the selected frame.
If TYPE is given and non-nil, it is the name of the type of VALUE.
If TYPE is not given or nil, the type is STRING.
FORMAT gives the size in bits of each element if VALUE is a list.
It must be one of 8, 16 or 32.
If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
If OUTER_P is non-nil, the property is changed for the outer X window of
FRAME. Default is to change on the edit X window.
Value is VALUE. */)
(Lisp_Object prop, Lisp_Object value, Lisp_Object frame, Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
{
struct frame *f = check_x_frame (frame);
Atom prop_atom;
Atom target_type = XA_STRING;
int element_format = 8;
unsigned char *data;
int nelements;
Window w;
CHECK_STRING (prop);
if (! NILP (format))
{
CHECK_NUMBER (format);
element_format = XFASTINT (format);
if (element_format != 8 && element_format != 16
&& element_format != 32)
error ("FORMAT must be one of 8, 16 or 32");
}
if (CONSP (value))
{
nelements = x_check_property_data (value);
if (nelements == -1)
error ("Bad data in VALUE, must be number, string or cons");
if (element_format == 8)
data = (unsigned char *) xmalloc (nelements);
else if (element_format == 16)
data = (unsigned char *) xmalloc (nelements*2);
else /* format == 32 */
/* The man page for XChangeProperty:
"If the specified format is 32, the property data must be a
long array."
This applies even if long is more than 64 bits. The X library
converts to 32 bits before sending to the X server. */
data = (unsigned char *) xmalloc (nelements * sizeof(long));
x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format);
}
else
{
CHECK_STRING (value);
data = SDATA (value);
nelements = SCHARS (value);
}
BLOCK_INPUT;
prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
if (! NILP (type))
{
CHECK_STRING (type);
target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False);
}
if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f);
else w = FRAME_X_WINDOW (f);
XChangeProperty (FRAME_X_DISPLAY (f), w,
prop_atom, target_type, element_format, PropModeReplace,
data, nelements);
if (CONSP (value)) xfree (data);
/* Make sure the property is set when we return. */
XFlush (FRAME_X_DISPLAY (f));
UNBLOCK_INPUT;
return value;
}
DEFUN ("x-delete-window-property", Fx_delete_window_property,
Sx_delete_window_property, 1, 2, 0,
doc: /* Remove window property PROP from X window of FRAME.
FRAME nil or omitted means use the selected frame. Value is PROP. */)
(Lisp_Object prop, Lisp_Object frame)
{
struct frame *f = check_x_frame (frame);
Atom prop_atom;
CHECK_STRING (prop);
BLOCK_INPUT;
prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom);
/* Make sure the property is removed when we return. */
XFlush (FRAME_X_DISPLAY (f));
UNBLOCK_INPUT;
return prop;
}
DEFUN ("x-window-property", Fx_window_property, Sx_window_property,
1, 6, 0,
doc: /* Value is the value of window property PROP on FRAME.
If FRAME is nil or omitted, use the selected frame.
If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
is the name of the Atom that denotes the type expected.
If SOURCE is non-nil, get the property on that window instead of from
FRAME. The number 0 denotes the root window.
If DELETE_P is non-nil, delete the property after retreiving it.
If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
Value is nil if FRAME hasn't a property with name PROP or if PROP has
no value of TYPE. */)
(Lisp_Object prop, Lisp_Object frame, Lisp_Object type, Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
{
struct frame *f = check_x_frame (frame);
Atom prop_atom;
int rc;
Lisp_Object prop_value = Qnil;
unsigned char *tmp_data = NULL;
Atom actual_type;
Atom target_type = XA_STRING;
int actual_format;
unsigned long actual_size, bytes_remaining;
Window target_window = FRAME_X_WINDOW (f);
struct gcpro gcpro1;
GCPRO1 (prop_value);
CHECK_STRING (prop);
if (! NILP (source))
{
if (NUMBERP (source))
{
if (FLOATP (source))
target_window = (Window) XFLOAT (source);
else
target_window = XFASTINT (source);
if (target_window == 0)
target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
}
else if (CONSP (source))
target_window = cons_to_long (source);
}
BLOCK_INPUT;
if (STRINGP (type))
{
if (strcmp ("AnyPropertyType", SDATA (type)) == 0)
target_type = AnyPropertyType;
else
target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False);
}
prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window,
prop_atom, 0, 0, False, target_type,
&actual_type, &actual_format, &actual_size,
&bytes_remaining, &tmp_data);
if (rc == Success)
{
int size = bytes_remaining;
XFree (tmp_data);
tmp_data = NULL;
rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window,
prop_atom, 0, bytes_remaining,
! NILP (delete_p), target_type,
&actual_type, &actual_format,
&actual_size, &bytes_remaining,
&tmp_data);
if (rc == Success && tmp_data)
{
/* The man page for XGetWindowProperty says:
"If the returned format is 32, the returned data is represented
as a long array and should be cast to that type to obtain the
elements."
This applies even if long is more than 32 bits, the X library
converts from 32 bit elements received from the X server to long
and passes the long array to us. Thus, for that case memcpy can not
be used. We convert to a 32 bit type here, because so much code
assume on that.
The bytes and offsets passed to XGetWindowProperty refers to the
property and those are indeed in 32 bit quantities if format is
32. */
if (actual_format == 32 && actual_format < BITS_PER_LONG)
{
unsigned long i;
int *idata = (int *) tmp_data;
long *ldata = (long *) tmp_data;
for (i = 0; i < actual_size; ++i)
idata[i] = (int) ldata[i];
}
if (NILP (vector_ret_p))
prop_value = make_string (tmp_data, size);
else
prop_value = x_property_data_to_lisp (f,
tmp_data,
actual_type,
actual_format,
actual_size);
}
if (tmp_data) XFree (tmp_data);
}
UNBLOCK_INPUT;
UNGCPRO;
return prop_value;
}
/***********************************************************************
Busy cursor
***********************************************************************/
/* Timer function of hourglass_atimer. TIMER is equal to
hourglass_atimer.
Display an hourglass pointer on all frames by mapping the frames'
hourglass_window. Set the hourglass_p flag in the frames'
output_data.x structure to indicate that an hourglass cursor is
shown on the frames. */
void
show_hourglass (struct atimer *timer)
{
/* The timer implementation will cancel this timer automatically
after this function has run. Set hourglass_atimer to null
so that we know the timer doesn't have to be canceled. */
hourglass_atimer = NULL;
if (!hourglass_shown_p)
{
Lisp_Object rest, frame;
BLOCK_INPUT;
FOR_EACH_FRAME (rest, frame)
{
struct frame *f = XFRAME (frame);
if (FRAME_LIVE_P (f) && FRAME_X_P (f) && FRAME_X_DISPLAY (f))
{
Display *dpy = FRAME_X_DISPLAY (f);
#ifdef USE_X_TOOLKIT
if (f->output_data.x->widget)
#else
if (FRAME_OUTER_WINDOW (f))
#endif
{
f->output_data.x->hourglass_p = 1;
if (!f->output_data.x->hourglass_window)
{
unsigned long mask = CWCursor;
XSetWindowAttributes attrs;
#ifdef USE_GTK
Window parent = FRAME_X_WINDOW (f);
#else
Window parent = FRAME_OUTER_WINDOW (f);
#endif
attrs.cursor = f->output_data.x->hourglass_cursor;
f->output_data.x->hourglass_window
= XCreateWindow (dpy, parent,
0, 0, 32000, 32000, 0, 0,
InputOnly,
CopyFromParent,
mask, &attrs);
}
XMapRaised (dpy, f->output_data.x->hourglass_window);
XFlush (dpy);
}
}
}
hourglass_shown_p = 1;
UNBLOCK_INPUT;
}
}
/* Hide the hourglass pointer on all frames, if it is currently
shown. */
void
hide_hourglass (void)
{
if (hourglass_shown_p)
{
Lisp_Object rest, frame;
BLOCK_INPUT;
FOR_EACH_FRAME (rest, frame)
{
struct frame *f = XFRAME (frame);
if (FRAME_X_P (f)
/* Watch out for newly created frames. */
&& f->output_data.x->hourglass_window)
{
XUnmapWindow (FRAME_X_DISPLAY (f),
f->output_data.x->hourglass_window);
/* Sync here because XTread_socket looks at the
hourglass_p flag that is reset to zero below. */
XSync (FRAME_X_DISPLAY (f), False);
f->output_data.x->hourglass_p = 0;
}
}
hourglass_shown_p = 0;
UNBLOCK_INPUT;
}
}
/***********************************************************************
Tool tips
***********************************************************************/
static Lisp_Object x_create_tip_frame (struct x_display_info *,
Lisp_Object, Lisp_Object);
static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object,
Lisp_Object, int, int, int *, int *);
/* 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. */
Lisp_Object tip_timer;
Window tip_window;
/* If non-nil, a vector of 3 elements containing the last args
with which x-show-tip was called. See there. */
Lisp_Object last_show_tip_args;
/* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
Lisp_Object Vx_max_tooltip_size;
static Lisp_Object
unwind_create_tip_frame (Lisp_Object frame)
{
Lisp_Object deleted;
deleted = unwind_create_frame (frame);
if (EQ (deleted, Qt))
{
tip_window = None;
tip_frame = Qnil;
}
return deleted;
}
/* Create a frame for a tooltip on the display described by DPYINFO.
PARMS is a list of frame parameters. TEXT is the string to
display in the tip frame. Value is the frame.
Note that functions called here, esp. x_default_parameter can
signal errors, for instance when a specified color name is
undefined. We have to make sure that we're in a consistent state
when this happens. */
static Lisp_Object
x_create_tip_frame (struct x_display_info *dpyinfo,
Lisp_Object parms,
Lisp_Object text)
{
struct frame *f;
Lisp_Object frame, tem;
Lisp_Object name;
long window_prompting = 0;
int width, height;
int count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3;
int face_change_count_before = face_change_count;
Lisp_Object buffer;
struct buffer *old_buffer;
check_x ();
if (!dpyinfo->terminal->name)
error ("Terminal is not live, can't create new frames on it");
parms = Fcopy_alist (parms);
/* Get the name of the frame to use for resource lookup. */
name = x_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");
frame = Qnil;
GCPRO3 (parms, name, frame);
f = make_frame (1);
XSETFRAME (frame, f);
buffer = Fget_buffer_create (build_string (" *tip*"));
Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil);
old_buffer = current_buffer;
set_buffer_internal_1 (XBUFFER (buffer));
current_buffer->truncate_lines = Qnil;
specbind (Qinhibit_read_only, Qt);
specbind (Qinhibit_modification_hooks, Qt);
Ferase_buffer ();
Finsert (1, &text);
set_buffer_internal_1 (old_buffer);
FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
record_unwind_protect (unwind_create_tip_frame, frame);
f->terminal = dpyinfo->terminal;
f->terminal->reference_count++;
/* By setting the output method, we're essentially saying that
the frame is live, as per FRAME_LIVE_P. If we get a signal
from this point on, x_destroy_window might screw up reference
counts etc. */
f->output_method = output_x_window;
f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
memset (f->output_data.x, 0, sizeof (struct x_output));
f->output_data.x->icon_bitmap = -1;
FRAME_FONTSET (f) = -1;
f->output_data.x->scroll_bar_foreground_pixel = -1;
f->output_data.x->scroll_bar_background_pixel = -1;
#ifdef USE_TOOLKIT_SCROLL_BARS
f->output_data.x->scroll_bar_top_shadow_pixel = -1;
f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
#endif /* USE_TOOLKIT_SCROLL_BARS */
f->icon_name = Qnil;
FRAME_X_DISPLAY_INFO (f) = dpyinfo;
#if GLYPH_DEBUG
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
f->output_data.x->explicit_parent = 0;
/* These colors will be set anyway later, but it's important
to get the color reference counts right, so initialize them! */
{
Lisp_Object black;
struct gcpro gcpro1;
/* 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;
f->output_data.x->cursor_pixel = -1;
f->output_data.x->cursor_foreground_pixel = -1;
f->output_data.x->border_pixel = -1;
f->output_data.x->mouse_pixel = -1;
black = build_string ("black");
GCPRO1 (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));
f->output_data.x->cursor_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
f->output_data.x->cursor_foreground_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
f->output_data.x->border_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
f->output_data.x->mouse_pixel
= x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
UNGCPRO;
}
/* Set the name; the functions to which we pass f expect the name to
be set. */
if (EQ (name, Qunbound) || NILP (name))
{
f->name = build_string (dpyinfo->x_id_name);
f->explicit_name = 0;
}
else
{
f->name = name;
f->explicit_name = 1;
/* use the frame's title when getting resources for this frame. */
specbind (Qx_resource_name, name);
}
f->resx = dpyinfo->resx;
f->resy = dpyinfo->resy;
register_font_driver (&xfont_driver, f);
#ifdef HAVE_FREETYPE
#ifdef HAVE_XFT
register_font_driver (&xftfont_driver, f);
#else /* not HAVE_XFT */
register_font_driver (&ftxfont_driver, f);
#endif /* not HAVE_XFT */
#endif /* HAVE_FREETYPE */
x_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);
x_default_parameter (f, parms, Qborder_width, make_number (0),
"borderWidth", "BorderWidth", RES_TYPE_NUMBER);
/* This defaults to 2 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 = x_get_arg (dpyinfo, parms, Qinternal_border_width,
"internalBorder", "internalBorder", RES_TYPE_NUMBER);
if (! EQ (value, Qunbound))
parms = Fcons (Fcons (Qinternal_border_width, value),
parms);
}
x_default_parameter (f, parms, Qinternal_border_width, make_number (1),
"internalBorderWidth", "internalBorderWidth",
RES_TYPE_NUMBER);
/* Also do the stuff which must be set before the window exists. */
x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
"foreground", "Foreground", RES_TYPE_STRING);
x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
"background", "Background", RES_TYPE_STRING);
x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
"pointerColor", "Foreground", RES_TYPE_STRING);
x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
"cursorColor", "Foreground", RES_TYPE_STRING);
x_default_parameter (f, parms, Qborder_color, build_string ("black"),
"borderColor", "BorderColor", RES_TYPE_STRING);
/* Init faces before x_default_parameter is called for scroll-bar
parameters because that function calls x_set_scroll_bar_width,
which calls change_frame_size, which calls Fset_window_buffer,
which runs hooks, which call Fvertical_motion. At the end, we
end up in init_iterator with a null face cache, which should not
happen. */
init_frame_faces (f);
f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
window_prompting = x_figure_window_size (f, parms, 0);
{
XSetWindowAttributes attrs;
unsigned long mask;
Atom type = FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip;
BLOCK_INPUT;
mask = CWBackPixel | CWOverrideRedirect | CWEventMask;
if (DoesSaveUnders (dpyinfo->screen))
mask |= CWSaveUnder;
/* Window managers look at the override-redirect flag to determine
whether or net to give windows a decoration (Xlib spec, chapter
3.2.8). */
attrs.override_redirect = True;
attrs.save_under = True;
attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f);
/* Arrange for getting MapNotify and UnmapNotify events. */
attrs.event_mask = StructureNotifyMask;
tip_window
= FRAME_X_WINDOW (f)
= XCreateWindow (FRAME_X_DISPLAY (f),
FRAME_X_DISPLAY_INFO (f)->root_window,
/* x, y, width, height */
0, 0, 1, 1,
/* Border. */
f->border_width,
CopyFromParent, InputOutput, CopyFromParent,
mask, &attrs);
XChangeProperty (FRAME_X_DISPLAY (f), tip_window,
FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type,
XA_ATOM, 32, PropModeReplace,
(unsigned char *)&type, 1);
UNBLOCK_INPUT;
}
x_make_gc (f);
x_default_parameter (f, parms, Qauto_raise, Qnil,
"autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
x_default_parameter (f, parms, Qauto_lower, Qnil,
"autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
x_default_parameter (f, parms, Qcursor_type, Qbox,
"cursorType", "CursorType", RES_TYPE_SYMBOL);
/* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
Change will not be effected unless different from the current
FRAME_LINES (f). */
width = FRAME_COLS (f);
height = FRAME_LINES (f);
SET_FRAME_COLS (f, 0);
FRAME_LINES (f) = 0;
change_frame_size (f, height, width, 1, 0, 0);
/* Add `tooltip' frame parameter's default value. */
if (NILP (Fframe_parameter (frame, Qtooltip)))
Fmodify_frame_parameters (frame, Fcons (Fcons (Qtooltip, Qt), Qnil));
/* FIXME - can this be done in a similar way to normal frames?
http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
/* Set the `display-type' frame parameter before setting up faces. */
{
Lisp_Object disptype;
if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
disptype = intern ("mono");
else if (FRAME_X_DISPLAY_INFO (f)->visual->class == GrayScale
|| FRAME_X_DISPLAY_INFO (f)->visual->class == StaticGray)
disptype = intern ("grayscale");
else
disptype = intern ("color");
if (NILP (Fframe_parameter (frame, Qdisplay_type)))
Fmodify_frame_parameters (frame, Fcons (Fcons (Qdisplay_type, disptype),
Qnil));
}
/* Set up faces after all frame parameters are known. This call
also merges in face attributes specified for new frames.
Frame parameters may be changed if .Xdefaults contains
specifications for the default font. For example, if there is an
`Emacs.default.attributeBackground: pink', the `background-color'
attribute of the frame get's set, which let's the internal border
of the tooltip frame appear in pink. Prevent this. */
{
Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
/* Set tip_frame here, so that */
tip_frame = frame;
call2 (Qface_set_after_frame_default, frame, Qnil);
if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg),
Qnil));
}
f->no_split = 1;
UNGCPRO;
/* It is now ok to make the frame official even if we get an error
below. And the frame needs to be on Vframe_list or making it
visible won't work. */
Vframe_list = Fcons (frame, Vframe_list);
/* Now that the frame is official, it counts as a reference to
its display. */
FRAME_X_DISPLAY_INFO (f)->reference_count++;
/* Setting attributes of faces of the tooltip frame from resources
and similar will increment face_change_count, which leads to the
clearing of all current matrices. Since this isn't necessary
here, avoid it by resetting face_change_count to the value it
had before we created the tip frame. */
face_change_count = face_change_count_before;
/* Discard the unwind_protect. */
return unbind_to (count, frame);
}
/* 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, int *root_x, int *root_y)
{
Lisp_Object left, top;
int win_x, win_y;
Window root, child;
unsigned pmask;
/* User-specified position? */
left = Fcdr (Fassq (Qleft, parms));
top = Fcdr (Fassq (Qtop, parms));
/* Move the tooltip window where the mouse pointer is. Resize and
show it. */
if (!INTEGERP (left) || !INTEGERP (top))
{
BLOCK_INPUT;
XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
&root, &child, root_x, root_y, &win_x, &win_y, &pmask);
UNBLOCK_INPUT;
}
if (INTEGERP (top))
*root_y = XINT (top);
else if (*root_y + XINT (dy) <= 0)
*root_y = 0; /* Can happen for negative dy */
else if (*root_y + XINT (dy) + height
<= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f)))
/* It fits below the pointer */
*root_y += XINT (dy);
else if (height + XINT (dy) <= *root_y)
/* It fits above the pointer. */
*root_y -= height + XINT (dy);
else
/* Put it on the top. */
*root_y = 0;
if (INTEGERP (left))
*root_x = XINT (left);
else if (*root_x + XINT (dx) <= 0)
*root_x = 0; /* Can happen for negative dx */
else if (*root_x + XINT (dx) + width
<= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f)))
/* It fits to the right of the pointer. */
*root_x += XINT (dx);
else if (width + XINT (dx) <= *root_x)
/* It fits to the left of the pointer. */
*root_x -= width + XINT (dx);
else
/* Put it left-justified on the screen--it ought to fit that way. */
*root_x = 0;
}
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 PARAMS contains a `left' parameters,
the tooltip is displayed at that x-position. Otherwise it is
displayed at the mouse position, 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 y-position of the tooltip
window, otherwise it is displayed at the mouse position, 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;
struct window *w;
int root_x, root_y;
struct buffer *old_buffer;
struct text_pos pos;
int i, width, height;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
int old_windows_or_buffers_changed = windows_or_buffers_changed;
int count = SPECPDL_INDEX ();
specbind (Qinhibit_redisplay, Qt);
GCPRO4 (string, parms, frame, timeout);
CHECK_STRING (string);
if (SCHARS (string) == 0)
string = make_unibyte_string (" ", 1);
f = check_x_frame (frame);
if (NILP (timeout))
timeout = make_number (5);
else
CHECK_NATNUM (timeout);
if (NILP (dx))
dx = make_number (5);
else
CHECK_NUMBER (dx);
if (NILP (dy))
dy = make_number (-10);
else
CHECK_NUMBER (dy);
#ifdef USE_GTK
if (x_gtk_use_system_tooltips)
{
int ok;
/* Hide a previous tip, if any. */
Fx_hide_tip ();
BLOCK_INPUT;
if ((ok = xg_prepare_tooltip (f, string, &width, &height)) != 0)
{
compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
xg_show_tooltip (f, root_x, root_y);
/* This is used in Fx_hide_tip. */
XSETFRAME (tip_frame, f);
}
UNBLOCK_INPUT;
if (ok) goto start_timer;
}
#endif /* USE_GTK */
if (NILP (last_show_tip_args))
last_show_tip_args = Fmake_vector (make_number (3), Qnil);
if (!NILP (tip_frame))
{
Lisp_Object last_string = AREF (last_show_tip_args, 0);
Lisp_Object last_frame = AREF (last_show_tip_args, 1);
Lisp_Object last_parms = AREF (last_show_tip_args, 2);
if (EQ (frame, last_frame)
&& !NILP (Fequal (last_string, string))
&& !NILP (Fequal (last_parms, parms)))
{
struct frame *f = XFRAME (tip_frame);
/* Only DX and DY have changed. */
if (!NILP (tip_timer))
{
Lisp_Object timer = tip_timer;
tip_timer = Qnil;
call1 (Qcancel_timer, timer);
}
BLOCK_INPUT;
compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
root_x, root_y);
UNBLOCK_INPUT;
goto start_timer;
}
}
/* Hide a previous tip, if any. */
Fx_hide_tip ();
ASET (last_show_tip_args, 0, string);
ASET (last_show_tip_args, 1, frame);
ASET (last_show_tip_args, 2, parms);
/* Add default values to frame parameters. */
if (NILP (Fassq (Qname, parms)))
parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
if (NILP (Fassq (Qinternal_border_width, parms)))
parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
if (NILP (Fassq (Qborder_width, parms)))
parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
if (NILP (Fassq (Qborder_color, parms)))
parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
if (NILP (Fassq (Qbackground_color, parms)))
parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
parms);
/* Create a frame for the tooltip, and record it in the global
variable tip_frame. */
frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string);
f = XFRAME (frame);
/* Set up the frame's root window. */
w = XWINDOW (FRAME_ROOT_WINDOW (f));
w->left_col = w->top_line = make_number (0);
if (CONSP (Vx_max_tooltip_size)
&& INTEGERP (XCAR (Vx_max_tooltip_size))
&& XINT (XCAR (Vx_max_tooltip_size)) > 0
&& INTEGERP (XCDR (Vx_max_tooltip_size))
&& XINT (XCDR (Vx_max_tooltip_size)) > 0)
{
w->total_cols = XCAR (Vx_max_tooltip_size);
w->total_lines = XCDR (Vx_max_tooltip_size);
}
else
{
w->total_cols = make_number (80);
w->total_lines = make_number (40);
}
FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
adjust_glyphs (f);
w->pseudo_window_p = 1;
/* Display the tooltip text in a temporary buffer. */
old_buffer = current_buffer;
set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
current_buffer->truncate_lines = Qnil;
clear_glyph_matrix (w->desired_matrix);
clear_glyph_matrix (w->current_matrix);
SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
/* Compute width and height of the tooltip. */
width = height = 0;
for (i = 0; i < w->desired_matrix->nrows; ++i)
{
struct glyph_row *row = &w->desired_matrix->rows[i];
struct glyph *last;
int row_width;
/* Stop at the first empty row at the end. */
if (!row->enabled_p || !row->displays_text_p)
break;
/* Let the row go over the full width of the frame. */
row->full_width_p = 1;
row_width = row->pixel_width;
/* There's a glyph at the end of rows that is used to place
the cursor there. Don't include the width of this glyph. */
if (row->used[TEXT_AREA])
{
last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
if (INTEGERP (last->object))
row_width -= last->pixel_width;
}
height += row->height;
width = max (width, row_width);
}
/* Add the frame's internal border to the width and height the X
window should have. */
height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
/* Move the tooltip window where the mouse pointer is. Resize and
show it. */
compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
BLOCK_INPUT;
XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
root_x, root_y, width, height);
XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
UNBLOCK_INPUT;
/* Draw into the window. */
w->must_be_updated_p = 1;
update_single_window (w, 1);
/* Restore original current buffer. */
set_buffer_internal_1 (old_buffer);
windows_or_buffers_changed = old_windows_or_buffers_changed;
start_timer:
/* Let the tip disappear after timeout seconds. */
tip_timer = call3 (intern ("run-at-time"), timeout, Qnil,
intern ("x-hide-tip"));
UNGCPRO;
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)
{
int count;
Lisp_Object deleted, frame, timer;
struct gcpro gcpro1, gcpro2;
struct frame *f;
/* Return quickly if nothing to do. */
if (NILP (tip_timer) && NILP (tip_frame))
return Qnil;
frame = tip_frame;
timer = tip_timer;
GCPRO2 (frame, timer);
tip_frame = tip_timer = deleted = Qnil;
count = SPECPDL_INDEX ();
specbind (Qinhibit_redisplay, Qt);
specbind (Qinhibit_quit, Qt);
if (!NILP (timer))
call1 (Qcancel_timer, timer);
#ifdef USE_GTK
/* When using system tooltip, tip_frame is the Emacs frame on which
the tip is shown. */
f = XFRAME (frame);
if (FRAME_LIVE_P (f) && xg_hide_tooltip (f))
frame = Qnil;
#endif
if (FRAMEP (frame))
{
delete_frame (frame, Qnil);
deleted = Qt;
#ifdef USE_LUCID
/* Bloodcurdling hack alert: The Lucid menu bar widget's
redisplay procedure is not called when a tip frame over menu
items is unmapped. Redisplay the menu manually... */
{
Widget w;
f = SELECTED_FRAME ();
w = f->output_data.x->menubar_widget;
if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
&& w != NULL)
{
BLOCK_INPUT;
xlwmenu_redisplay (w);
UNBLOCK_INPUT;
}
}
#endif /* USE_LUCID */
}
UNGCPRO;
return unbind_to (count, deleted);
}
/***********************************************************************
File selection dialog
***********************************************************************/
DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog,
Sx_uses_old_gtk_dialog,
0, 0, 0,
doc: /* Return t if the old Gtk+ file selection dialog is used. */)
(void)
{
#ifdef USE_GTK
if (use_dialog_box
&& use_file_dialog
&& have_menus_p ()
&& xg_uses_old_file_dialog ())
return Qt;
#endif
return Qnil;
}
#ifdef USE_MOTIF
/* Callback for "OK" and "Cancel" on file selection dialog. */
static void
file_dialog_cb (widget, client_data, call_data)
Widget widget;
XtPointer call_data, client_data;
{
int *result = (int *) client_data;
XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
*result = cb->reason;
}
/* Callback for unmapping a file selection dialog. This is used to
capture the case where a dialog is closed via a window manager's
closer button, for example. Using a XmNdestroyCallback didn't work
in this case. */
static void
file_dialog_unmap_cb (widget, client_data, call_data)
Widget widget;
XtPointer call_data, client_data;
{
int *result = (int *) client_data;
*result = XmCR_CANCEL;
}
static Lisp_Object
clean_up_file_dialog (arg)
Lisp_Object arg;
{
struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
Widget dialog = (Widget) p->pointer;
/* Clean up. */
BLOCK_INPUT;
XtUnmanageChild (dialog);
XtDestroyWidget (dialog);
x_menu_set_in_use (0);
UNBLOCK_INPUT;
return Qnil;
}
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. ONLY-DIR-P is ignored." */)
(Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
{
int result;
struct frame *f = SELECTED_FRAME ();
Lisp_Object file = Qnil;
Lisp_Object decoded_file;
Widget dialog, text, help;
Arg al[10];
int ac = 0;
XmString dir_xmstring, pattern_xmstring;
int count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
check_x ();
GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
if (popup_activated ())
error ("Trying to use a menu from within a menu-entry");
CHECK_STRING (prompt);
CHECK_STRING (dir);
/* Prevent redisplay. */
specbind (Qinhibit_redisplay, Qt);
BLOCK_INPUT;
/* Create the dialog with PROMPT as title, using DIR as initial
directory and using "*" as pattern. */
dir = Fexpand_file_name (dir, Qnil);
dir_xmstring = XmStringCreateLocalized (SDATA (dir));
pattern_xmstring = XmStringCreateLocalized ("*");
XtSetArg (al[ac], XmNtitle, SDATA (prompt)); ++ac;
XtSetArg (al[ac], XmNdirectory, dir_xmstring); ++ac;
XtSetArg (al[ac], XmNpattern, pattern_xmstring); ++ac;
XtSetArg (al[ac], XmNresizePolicy, XmRESIZE_GROW); ++ac;
XtSetArg (al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ++ac;
dialog = XmCreateFileSelectionDialog (f->output_data.x->widget,
"fsb", al, ac);
XmStringFree (dir_xmstring);
XmStringFree (pattern_xmstring);
/* Add callbacks for OK and Cancel. */
XtAddCallback (dialog, XmNokCallback, file_dialog_cb,
(XtPointer) &result);
XtAddCallback (dialog, XmNcancelCallback, file_dialog_cb,
(XtPointer) &result);
XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb,
(XtPointer) &result);
/* Remove the help button since we can't display help. */
help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (help);
/* Mark OK button as default. */
XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON),
XmNshowAsDefault, True, NULL);
/* If MUSTMATCH is non-nil, disable the file entry field of the
dialog, so that the user must select a file from the files list
box. We can't remove it because we wouldn't have a way to get at
the result file name, then. */
text = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
if (!NILP (mustmatch))
{
Widget label;
label = XmFileSelectionBoxGetChild (dialog, XmDIALOG_SELECTION_LABEL);
XtSetSensitive (text, False);
XtSetSensitive (label, False);
}
/* Manage the dialog, so that list boxes get filled. */
XtManageChild (dialog);
if (STRINGP (default_filename))
{
XmString default_xmstring;
Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST);
XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext);
XmTextFieldReplace (wtext, 0, last_pos,
(SDATA (Ffile_name_nondirectory (default_filename))));
/* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
must include the path for this to work. */
default_xmstring = XmStringCreateLocalized (SDATA (default_filename));
if (XmListItemExists (list, default_xmstring))
{
int item_pos = XmListItemPos (list, default_xmstring);
/* Select the item and scroll it into view. */
XmListSelectPos (list, item_pos, True);
XmListSetPos (list, item_pos);
}
XmStringFree (default_xmstring);
}
record_unwind_protect (clean_up_file_dialog, make_save_value (dialog, 0));
/* Process events until the user presses Cancel or OK. */
x_menu_set_in_use (1);
result = 0;
while (result == 0)
{
XEvent event;
x_menu_wait_for_event (0);
XtAppNextEvent (Xt_app_con, &event);
if (event.type == KeyPress
&& FRAME_X_DISPLAY (f) == event.xkey.display)
{
KeySym keysym = XLookupKeysym (&event.xkey, 0);
/* Pop down on C-g. */
if (keysym == XK_g && (event.xkey.state & ControlMask) != 0)
XtUnmanageChild (dialog);
}
(void) x_dispatch_event (&event, FRAME_X_DISPLAY (f));
}
/* Get the result. */
if (result == XmCR_OK)
{
XmString text;
String data;
XtVaGetValues (dialog, XmNtextString, &text, NULL);
XmStringGetLtoR (text, XmFONTLIST_DEFAULT_TAG, &data);
XmStringFree (text);
file = build_string (data);
XtFree (data);
}
else
file = Qnil;
UNBLOCK_INPUT;
UNGCPRO;
/* Make "Cancel" equivalent to C-g. */
if (NILP (file))
Fsignal (Qquit, Qnil);
decoded_file = DECODE_FILE (file);
return unbind_to (count, decoded_file);
}
#endif /* USE_MOTIF */
#ifdef USE_GTK
static Lisp_Object
clean_up_dialog (Lisp_Object arg)
{
x_menu_set_in_use (0);
return Qnil;
}
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. If ONLY-DIR-P is non-nil, the user can only select
directories. */)
(Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
{
FRAME_PTR f = SELECTED_FRAME ();
char *fn;
Lisp_Object file = Qnil;
Lisp_Object decoded_file;
int count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
char *cdef_file;
check_x ();
GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
if (popup_activated ())
error ("Trying to use a menu from within a menu-entry");
CHECK_STRING (prompt);
CHECK_STRING (dir);
/* Prevent redisplay. */
specbind (Qinhibit_redisplay, Qt);
record_unwind_protect (clean_up_dialog, Qnil);
BLOCK_INPUT;
if (STRINGP (default_filename))
cdef_file = SDATA (default_filename);
else
cdef_file = SDATA (dir);
fn = xg_get_file_name (f, SDATA (prompt), cdef_file,
! NILP (mustmatch),
! NILP (only_dir_p));
if (fn)
{
file = build_string (fn);
xfree (fn);
}
UNBLOCK_INPUT;
UNGCPRO;
/* Make "Cancel" equivalent to C-g. */
if (NILP (file))
Fsignal (Qquit, Qnil);
decoded_file = DECODE_FILE (file);
return unbind_to (count, decoded_file);
}
#ifdef HAVE_FREETYPE
DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
doc: /* Read a font name using a GTK font selection dialog.
Return a GTK-style font string corresponding to the selection.
If FRAME is omitted or nil, it defaults to the selected frame. */)
(Lisp_Object frame, Lisp_Object ignored)
{
FRAME_PTR f = check_x_frame (frame);
char *name;
Lisp_Object font;
Lisp_Object font_param;
char *default_name = NULL;
struct gcpro gcpro1, gcpro2;
int count = SPECPDL_INDEX ();
check_x ();
if (popup_activated ())
error ("Trying to use a menu from within a menu-entry");
/* Prevent redisplay. */
specbind (Qinhibit_redisplay, Qt);
record_unwind_protect (clean_up_dialog, Qnil);
BLOCK_INPUT;
GCPRO2(font_param, font);
XSETFONT (font, FRAME_FONT (f));
font_param = Ffont_get (font, intern (":name"));
if (STRINGP (font_param))
default_name = xstrdup (SDATA (font_param));
else
{
font_param = Fframe_parameter (frame, Qfont_param);
if (STRINGP (font_param))
default_name = xstrdup (SDATA (font_param));
}
if (default_name == NULL && x_last_font_name != NULL)
default_name = xstrdup (x_last_font_name);
/* Convert fontconfig names to Gtk names, i.e. remove - before number */
if (default_name)
{
char *p = strrchr (default_name, '-');
if (p)
{
char *ep = p+1;
while (isdigit (*ep))
++ep;
if (*ep == '\0') *p = ' ';
}
}
name = xg_get_font_name (f, default_name);
xfree (default_name);
if (name)
{
font = build_string (name);
g_free (x_last_font_name);
x_last_font_name = name;
}
UNBLOCK_INPUT;
if (NILP (font))
Fsignal (Qquit, Qnil);
return unbind_to (count, font);
}
#endif /* HAVE_FREETYPE */
#endif /* USE_GTK */
/***********************************************************************
Keyboard
***********************************************************************/
#ifdef HAVE_XKBGETKEYBOARD
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#endif
DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p,
Sx_backspace_delete_keys_p, 0, 1, 0,
doc: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
FRAME nil means use the selected frame.
Value is t if we know that both keys are present, and are mapped to the
usual X keysyms. Value is `lambda' if we cannot determine if both keys are
present and mapped to the usual X keysyms. */)
(Lisp_Object frame)
{
#ifdef HAVE_XKBGETKEYBOARD
XkbDescPtr kb;
struct frame *f = check_x_frame (frame);
Display *dpy = FRAME_X_DISPLAY (f);
Lisp_Object have_keys;
int major, minor, op, event, error;
BLOCK_INPUT;
/* Check library version in case we're dynamically linked. */
major = XkbMajorVersion;
minor = XkbMinorVersion;
if (!XkbLibraryVersion (&major, &minor))
{
UNBLOCK_INPUT;
return Qlambda;
}
/* Check that the server supports XKB. */
major = XkbMajorVersion;
minor = XkbMinorVersion;
if (!XkbQueryExtension (dpy, &op, &event, &error, &major, &minor))
{
UNBLOCK_INPUT;
return Qlambda;
}
/* In this code we check that the keyboard has physical keys with names
that start with BKSP (Backspace) and DELE (Delete), and that they
generate keysym XK_BackSpace and XK_Delete respectively.
This function is used to test if normal-erase-is-backspace should be
turned on.
An alternative approach would be to just check if XK_BackSpace and
XK_Delete are mapped to any key. But if any of those are mapped to
some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
user doesn't know about it, it is better to return false here.
It is more obvious to the user what to do if she/he has two keys
clearly marked with names/symbols and one key does something not
expected (i.e. she/he then tries the other).
The cases where Backspace/Delete is mapped to some other key combination
are rare, and in those cases, normal-erase-is-backspace can be turned on
manually. */
have_keys = Qnil;
kb = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd);
if (kb)
{
int delete_keycode = 0, backspace_keycode = 0, i;
if (XkbGetNames (dpy, XkbAllNamesMask, kb) == Success)
{
for (i = kb->min_key_code;
(i < kb->max_key_code
&& (delete_keycode == 0 || backspace_keycode == 0));
++i)
{
/* The XKB symbolic key names can be seen most easily in
the PS file generated by `xkbprint -label name
$DISPLAY'. */
if (memcmp ("DELE", kb->names->keys[i].name, 4) == 0)
delete_keycode = i;
else if (memcmp ("BKSP", kb->names->keys[i].name, 4) == 0)
backspace_keycode = i;
}
XkbFreeNames (kb, 0, True);
}
XkbFreeClientMap (kb, 0, True);
if (delete_keycode
&& backspace_keycode
&& XKeysymToKeycode (dpy, XK_Delete) == delete_keycode
&& XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode)
have_keys = Qt;
}
UNBLOCK_INPUT;
return have_keys;
#else /* not HAVE_XKBGETKEYBOARD */
return Qlambda;
#endif /* not HAVE_XKBGETKEYBOARD */
}
/***********************************************************************
Initialization
***********************************************************************/
/* Keep this list in the same order as frame_parms in frame.c.
Use 0 for unsupported frame parameters. */
frame_parm_handler x_frame_parm_handlers[] =
{
x_set_autoraise,
x_set_autolower,
x_set_background_color,
x_set_border_color,
x_set_border_width,
x_set_cursor_color,
x_set_cursor_type,
x_set_font,
x_set_foreground_color,
x_set_icon_name,
x_set_icon_type,
x_set_internal_border_width,
x_set_menu_bar_lines,
x_set_mouse_color,
x_explicitly_set_name,
x_set_scroll_bar_width,
x_set_title,
x_set_unsplittable,
x_set_vertical_scroll_bars,
x_set_visibility,
x_set_tool_bar_lines,
x_set_scroll_bar_foreground,
x_set_scroll_bar_background,
x_set_screen_gamma,
x_set_line_spacing,
x_set_fringe_width,
x_set_fringe_width,
x_set_wait_for_wm,
x_set_fullscreen,
x_set_font_backend,
x_set_alpha,
x_set_sticky,
x_set_tool_bar_position,
};
void
syms_of_xfns (void)
{
/* This is zero if not using X windows. */
x_in_use = 0;
/* The section below is built by the lisp expression at the top of the file,
just above where these variables are declared. */
/*&&& init symbols here &&&*/
Qnone = intern_c_string ("none");
staticpro (&Qnone);
Qsuppress_icon = intern_c_string ("suppress-icon");
staticpro (&Qsuppress_icon);
Qundefined_color = intern_c_string ("undefined-color");
staticpro (&Qundefined_color);
Qcompound_text = intern_c_string ("compound-text");
staticpro (&Qcompound_text);
Qcancel_timer = intern_c_string ("cancel-timer");
staticpro (&Qcancel_timer);
Qfont_param = intern_c_string ("font-parameter");
staticpro (&Qfont_param);
/* This is the end of symbol initialization. */
/* Text property `display' should be nonsticky by default. */
Vtext_property_default_nonsticky
= Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky);
Fput (Qundefined_color, Qerror_conditions,
pure_cons (Qundefined_color, pure_cons (Qerror, Qnil)));
Fput (Qundefined_color, Qerror_message,
make_pure_c_string ("Undefined color"));
DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape,
doc: /* The shape of the pointer when over text.
Changing the value does not affect existing frames
unless you set the mouse color. */);
Vx_pointer_shape = Qnil;
#if 0 /* This doesn't really do anything. */
DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape,
doc: /* The shape of the pointer when not over text.
This variable takes effect when you create a new frame
or when you set the mouse color. */);
#endif
Vx_nontext_pointer_shape = Qnil;
DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape,
doc: /* The shape of the pointer when Emacs is busy.
This variable takes effect when you create a new frame
or when you set the mouse color. */);
Vx_hourglass_pointer_shape = Qnil;
#if 0 /* This doesn't really do anything. */
DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape,
doc: /* The shape of the pointer when over the mode line.
This variable takes effect when you create a new frame
or when you set the mouse color. */);
#endif
Vx_mode_pointer_shape = Qnil;
DEFVAR_LISP ("x-sensitive-text-pointer-shape",
&Vx_sensitive_text_pointer_shape,
doc: /* The shape of the pointer when over mouse-sensitive text.
This variable takes effect when you create a new frame
or when you set the mouse color. */);
Vx_sensitive_text_pointer_shape = Qnil;
DEFVAR_LISP ("x-window-horizontal-drag-cursor",
&Vx_window_horizontal_drag_shape,
doc: /* Pointer shape to use for indicating a window can be dragged horizontally.
This variable takes effect when you create a new frame
or when you set the mouse color. */);
Vx_window_horizontal_drag_shape = Qnil;
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 ("x-max-tooltip-size", &Vx_max_tooltip_size,
doc: /* Maximum size for tooltips.
Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
Vx_max_tooltip_size = Fcons (make_number (80), make_number (40));
DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
doc: /* Non-nil if no X window manager is in use.
Emacs doesn't try to figure this out; this is always nil
unless you set it to something else. */);
/* We don't have any way to find this out, so set it to nil
and maybe the user would like to set it to t. */
Vx_no_window_manager = Qnil;
DEFVAR_LISP ("x-pixel-size-width-font-regexp",
&Vx_pixel_size_width_font_regexp,
doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
Since Emacs gets width of a font matching with this regexp from
PIXEL_SIZE field of the name, font finding mechanism gets faster for
such a font. This is especially effective for such large fonts as
Chinese, Japanese, and Korean. */);
Vx_pixel_size_width_font_regexp = Qnil;
/* 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 = 0;
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 = 0;
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 = 1;
DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", &x_gtk_whole_detached_tool_bar,
doc: /* *If non-nil, a detached tool bar is shown in full.
The default is to just show an arrow and pressing on that arrow shows
the tool bar buttons. */);
x_gtk_whole_detached_tool_bar = 0;
DEFVAR_BOOL ("x-gtk-use-system-tooltips", &x_gtk_use_system_tooltips,
doc: /* *If non-nil with a Gtk+ built Emacs, the Gtk+ toolip is used.
Otherwise use Emacs own tooltip implementation.
When using Gtk+ tooltips, the tooltip face is not used. */);
x_gtk_use_system_tooltips = 1;
Fprovide (intern_c_string ("x"), Qnil);
#ifdef USE_X_TOOLKIT
Fprovide (intern_c_string ("x-toolkit"), Qnil);
#ifdef USE_MOTIF
Fprovide (intern_c_string ("motif"), Qnil);
DEFVAR_LISP ("motif-version-string", &Vmotif_version_string,
doc: /* Version info for LessTif/Motif. */);
Vmotif_version_string = build_string (XmVERSION_STRING);
#endif /* USE_MOTIF */
#endif /* USE_X_TOOLKIT */
#ifdef USE_GTK
/* 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 gtk_version[40];
g_snprintf (gtk_version, sizeof (gtk_version), "%u.%u.%u",
GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
Vgtk_version_string = make_pure_string (gtk_version, strlen (gtk_version), strlen (gtk_version), 0);
}
#endif /* USE_GTK */
/* X window properties. */
defsubr (&Sx_change_window_property);
defsubr (&Sx_delete_window_property);
defsubr (&Sx_window_property);
defsubr (&Sxw_display_color_p);
defsubr (&Sx_display_grayscale_p);
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 (&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_wm_set_size_hint);
defsubr (&Sx_create_frame);
defsubr (&Sx_open_connection);
defsubr (&Sx_close_connection);
defsubr (&Sx_display_list);
defsubr (&Sx_synchronize);
defsubr (&Sx_focus_frame);
defsubr (&Sx_backspace_delete_keys_p);
/* Setting callback functions for fontset handler. */
check_window_system_func = check_x;
defsubr (&Sx_show_tip);
defsubr (&Sx_hide_tip);
tip_timer = Qnil;
staticpro (&tip_timer);
tip_frame = Qnil;
staticpro (&tip_frame);
last_show_tip_args = Qnil;
staticpro (&last_show_tip_args);
defsubr (&Sx_uses_old_gtk_dialog);
#if defined (USE_MOTIF) || defined (USE_GTK)
defsubr (&Sx_file_dialog);
#endif
#if defined (USE_GTK) && defined (HAVE_FREETYPE)
defsubr (&Sx_select_font);
x_last_font_name = NULL;
#endif
}
#endif /* HAVE_X_WINDOWS */
/* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
(do not change this comment) */
|