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
| | @c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
@c Copyright (C) 1990--1995, 1998--1999, 2001--2024 Free Software
@c Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@node Frames
@chapter Frames
@cindex frame
A @dfn{frame} is a screen object that contains one or more Emacs
windows (@pxref{Windows}). It is the kind of object called a
``window'' in the terminology of graphical environments; but we can't
call it a ``window'' here, because Emacs uses that word in a different
way. In Emacs Lisp, a @dfn{frame object} is a Lisp object that
represents a frame on the screen. @xref{Frame Type}.
A frame initially contains a single main window and/or a minibuffer
window; you can subdivide the main window vertically or horizontally
into smaller windows. @xref{Splitting Windows}.
@cindex terminal
A @dfn{terminal} is a display device capable of displaying one or
more Emacs frames. In Emacs Lisp, a @dfn{terminal object} is a Lisp
object that represents a terminal. @xref{Terminal Type}.
@cindex text terminal
@cindex graphical terminal
@cindex graphical display
There are two classes of terminals: @dfn{text terminals} and
@dfn{graphical terminals}. Text terminals are non-graphics-capable
displays, including @command{xterm} and other terminal emulators. On
a text terminal, each Emacs frame occupies the terminal's entire
screen; although you can create additional frames and switch between
them, the terminal only shows one frame at a time. Graphical
terminals, on the other hand, are managed by graphical display systems
such as the X Window System, which allow Emacs to show multiple frames
simultaneously on the same display.
On GNU and Unix systems, you can create additional frames on any
available terminal, within a single Emacs session, regardless of
whether Emacs was started on a text or graphical terminal. Emacs can
display on both graphical and text terminals simultaneously. This
comes in handy, for instance, when you connect to the same session
from several remote locations. @xref{Multiple Terminals}.
@defun framep object
This predicate returns a non-@code{nil} value if @var{object} is a
frame, and @code{nil} otherwise. For a frame, the value indicates which
kind of display the frame uses:
@table @code
@item t
The frame is displayed on a text terminal.
@item x
The frame is displayed on an X graphical terminal.
@item w32
The frame is displayed on a MS-Windows graphical terminal.
@item ns
The frame is displayed on a GNUstep or Macintosh Cocoa graphical
terminal.
@item pc
The frame is displayed on an MS-DOS terminal.
@item haiku
The frame is displayed using the Haiku Application Kit.
@item pgtk
The frame is displayed using pure GTK facilities.
@item android
The frame is displayed on an Android device.
@end table
@end defun
@defun frame-terminal &optional frame
This function returns the terminal object that displays @var{frame}.
If @var{frame} is @code{nil} or unspecified, it defaults to the
selected frame.
@end defun
@defun terminal-live-p object
This predicate returns a non-@code{nil} value if @var{object} is a
terminal that is live (i.e., not deleted), and @code{nil} otherwise.
For live terminals, the return value indicates what kind of frames are
displayed on that terminal; the list of possible values is the same as
for @code{framep} above.
@end defun
@cindex top-level frame
On a graphical terminal we distinguish two types of frames: A normal
@dfn{top-level frame} is a frame whose window-system window is a child
of the window-system's root window for that terminal. A child frame is
a frame whose window-system window is the child of the window-system
window of another Emacs frame. @xref{Child Frames}.
@menu
* Creating Frames:: Creating additional frames.
* Multiple Terminals:: Displaying on several different devices.
* Frame Geometry:: Geometric properties of frames.
* Frame Parameters:: Controlling frame size, position, font, etc.
* Terminal Parameters:: Parameters common for all frames on terminal.
* Frame Titles:: Automatic updating of frame titles.
* Deleting Frames:: Frames last until explicitly deleted.
* Finding All Frames:: How to examine all existing frames.
* Minibuffers and Frames:: How a frame finds the minibuffer to use.
* Input Focus:: Specifying the selected frame.
* Visibility of Frames:: Frames may be visible or invisible, or icons.
* Raising and Lowering:: Raising, Lowering and Restacking Frames.
* Frame Configurations:: Saving the state of all frames.
* Child Frames:: Making a frame the child of another.
* Mouse Tracking:: Getting events that say when the mouse moves.
* Mouse Position:: Asking where the mouse is, or moving it.
* Pop-Up Menus:: Displaying a menu for the user to select from.
* On-Screen Keyboards:: Displaying the virtual keyboard.
* Dialog Boxes:: Displaying a box to ask yes or no.
* Pointer Shape:: Specifying the shape of the mouse pointer.
* Window System Selections:: Transferring text to and from other X clients.
* Accessing Selections:: The multiple different kinds of selections.
* Yanking Media:: Yanking things that aren't plain text.
* Drag and Drop:: Internals of Drag-and-Drop implementation.
* Color Names:: Getting the definitions of color names.
* Text Terminal Colors:: Defining colors for text terminals.
* Resources:: Getting resource values from the server.
* Display Feature Testing:: Determining the features of a terminal.
@end menu
@node Creating Frames
@section Creating Frames
@cindex frame creation
To create a new frame, call the function @code{make-frame}.
@deffn Command make-frame &optional parameters
This function creates and returns a new frame, displaying the current
buffer.
The @var{parameters} argument is an alist that specifies frame
parameters for the new frame. @xref{Frame Parameters}. If you specify
the @code{terminal} parameter in @var{parameters}, the new frame is
created on that terminal. Otherwise, if you specify the
@code{window-system} frame parameter in @var{parameters}, that
determines whether the frame should be displayed on a text terminal or a
graphical terminal. @xref{Window Systems}. If neither is specified,
the new frame is created in the same terminal as the selected frame.
Any parameters not mentioned in @var{parameters} default to the values
in the alist @code{default-frame-alist} (@pxref{Initial Parameters});
parameters not specified there default from the X resources or its
equivalent on your operating system (@pxref{X Resources,, X Resources,
emacs, The GNU Emacs Manual}). After the frame is created, this
function applies any parameters specified in
@code{frame-inherited-parameters} (see below) it has no assigned yet,
taking the values from the frame that was selected when
@code{make-frame} was called.
Note that on multi-monitor displays (@pxref{Multiple Terminals}), the
window manager might position the frame differently than specified by
the positional parameters in @var{parameters} (@pxref{Position
Parameters}). For example, some window managers have a policy of
displaying the frame on the monitor that contains the largest part of
the window (a.k.a.@: the @dfn{dominating} monitor).
This function itself does not make the new frame the selected frame.
@xref{Input Focus}. The previously selected frame remains selected.
On graphical terminals, however, the window system may select the
new frame for its own reasons.
@end deffn
@defvar before-make-frame-hook
A normal hook run by @code{make-frame} before it creates the frame.
@end defvar
@defvar after-make-frame-functions
An abnormal hook run by @code{make-frame} after it created the frame.
Each function in @code{after-make-frame-functions} receives one
argument, the frame just created.
@end defvar
Note that any functions added to these hooks by your initial file are
usually not run for the initial frame, since Emacs reads the initial
file only after creating that frame. However, if the initial frame is
specified to use a separate minibuffer frame (@pxref{Minibuffers and
Frames}), the functions will be run for both, the minibuffer-less and
the minibuffer frame. Alternatively, you can add functions to these
hooks in your ``early init file'' (@pxref{Init File}), in which case
they will be in effect for the initial frame as well.
@defvar frame-inherited-parameters
This variable specifies the list of frame parameters that a newly
created frame inherits from the currently selected frame. For each
parameter (a symbol) that is an element in this list and has not been
assigned earlier when processing @code{make-frame}, the function sets
the value of that parameter in the created frame to its value in the
selected frame.
@end defvar
@defopt server-after-make-frame-hook
A normal hook run when the Emacs server starts using a client frame.
When this hook is called, the client frame is the selected one. Note
that, depending on how @command{emacsclient} was invoked
(@pxref{Invoking emacsclient,,, emacs, The GNU Emacs Manual}), this
client frame could be a new frame created for the client, or it could
be an existing frame that the server reused for handling the client
commands. @xref{Emacs Server,,, emacs, The GNU Emacs Manual}.
@end defopt
@node Multiple Terminals
@section Multiple Terminals
@cindex multiple terminals
@cindex multi-tty
@cindex multiple X displays
@cindex displays, multiple
Emacs represents each terminal as a @dfn{terminal object} data type
(@pxref{Terminal Type}). On GNU and Unix systems, Emacs can use
multiple terminals simultaneously in each session. On other systems,
it can only use a single terminal. Each terminal object has the
following attributes:
@itemize @bullet
@item
The name of the device used by the terminal (e.g., @samp{:0.0} or
@file{/dev/tty}).
@item
The terminal and keyboard coding systems used on the terminal.
@xref{Terminal I/O Encoding}.
@item
The kind of display associated with the terminal. This is the symbol
returned by the function @code{terminal-live-p} (i.e., @code{x},
@code{t}, @code{w32}, @code{ns}, @code{pc}, @code{haiku}, @code{pgtk},
or @code{android}). @xref{Frames}.
@item
A list of terminal parameters. @xref{Terminal Parameters}.
@end itemize
There is no primitive for creating terminal objects. Emacs creates
them as needed, such as when you call @code{make-frame-on-display}
(described below).
@defun terminal-name &optional terminal
This function returns the file name of the device used by
@var{terminal}. If @var{terminal} is omitted or @code{nil}, it
defaults to the selected frame's terminal. @var{terminal} can also be
a frame, meaning that frame's terminal.
@end defun
@defun terminal-list
This function returns a list of all live terminal objects.
@end defun
@defun get-device-terminal device
This function returns a terminal whose device name is given by
@var{device}. If @var{device} is a string, it can be either the file
name of a terminal device, or the name of an X display of the form
@samp{@var{host}:@var{server}.@var{screen}}. If @var{device} is a
frame, this function returns that frame's terminal; @code{nil} means
the selected frame. Finally, if @var{device} is a terminal object
that represents a live terminal, that terminal is returned. The
function signals an error if its argument is none of the above.
@end defun
@defun delete-terminal &optional terminal force
This function deletes all frames on @var{terminal} and frees the
resources used by it. It runs the abnormal hook
@code{delete-terminal-functions}, passing @var{terminal} as the
argument to each function.
If @var{terminal} is omitted or @code{nil}, it defaults to the
selected frame's terminal. @var{terminal} can also be a frame,
meaning that frame's terminal.
Normally, this function signals an error if you attempt to delete the
sole active terminal, but if @var{force} is non-@code{nil}, you are
allowed to do so. Emacs automatically calls this function when the
last frame on a terminal is deleted (@pxref{Deleting Frames}).
@end defun
@defvar delete-terminal-functions
An abnormal hook run by @code{delete-terminal}. Each function
receives one argument, the @var{terminal} argument passed to
@code{delete-terminal}. Due to technical details, the functions may
be called either just before the terminal is deleted, or just
afterwards.
@end defvar
@cindex terminal-local variables
A few Lisp variables are @dfn{terminal-local}; that is, they have a
separate binding for each terminal. The binding in effect at any time
is the one for the terminal that the currently selected frame belongs
to. These variables include @code{default-minibuffer-frame},
@code{defining-kbd-macro}, @code{last-kbd-macro}, and
@code{system-key-alist}. They are always terminal-local, and can
never be buffer-local (@pxref{Buffer-Local Variables}).
On GNU and Unix systems, each X display is a separate graphical
terminal. When Emacs is started from within the X window system, it
uses the X display specified by the @env{DISPLAY} environment
variable, or by the @samp{--display} option (@pxref{Initial Options,,,
emacs, The GNU Emacs Manual}). Emacs can connect to other X displays
via the command @code{make-frame-on-display}. Each X display has its
own selected frame and its own minibuffer windows; however, only one
of those frames is @emph{the} selected frame at any given moment
(@pxref{Input Focus}). Emacs can even connect to other text
terminals, by interacting with the @command{emacsclient} program.
@xref{Emacs Server,,, emacs, The GNU Emacs Manual}.
@cindex X display names
@cindex display name on X
A single X server can handle more than one display. Each X display
has a three-part name,
@samp{@var{hostname}:@var{displaynumber}.@var{screennumber}}. The
first part, @var{hostname}, specifies the name of the machine to which
the display is physically connected. The second part,
@var{displaynumber}, is a zero-based number that identifies one or
more monitors connected to that machine that share a common keyboard
and pointing device (mouse, tablet, etc.). The third part,
@var{screennumber}, identifies a zero-based screen number (a separate
monitor) that is part of a single monitor collection on that X server.
When you use two or more screens belonging to one server, Emacs knows
by the similarity in their names that they share a single keyboard.
Systems that don't use the X window system, such as MS-Windows,
don't support the notion of X displays, and have only one display on
each host. The display name on these systems doesn't follow the above
3-part format; for example, the display name on MS-Windows systems is
a constant string @samp{w32}, and exists for compatibility, so that
you could pass it to functions that expect a display name.
@deffn Command make-frame-on-display display &optional parameters
This function creates and returns a new frame on @var{display}, taking
the other frame parameters from the alist @var{parameters}.
@var{display} should be the name of an X display (a string).
Before creating the frame, this function ensures that Emacs is set
up to display graphics. For instance, if Emacs has not processed X
resources (e.g., if it was started on a text terminal), it does so at
this time. In all other respects, this function behaves like
@code{make-frame} (@pxref{Creating Frames}).
@end deffn
@defun x-display-list
This function returns a list that indicates which X displays Emacs has
a connection to. The elements of the list are strings, and each one
is a display name.
@end defun
@defun x-open-connection display &optional xrm-string must-succeed
This function opens a connection to the X display @var{display},
without creating a frame on that display. Normally, Emacs Lisp
programs need not call this function, as @code{make-frame-on-display}
calls it automatically. The only reason for calling it is to check
whether communication can be established with a given X display.
The optional argument @var{xrm-string}, if not @code{nil}, is a string
of resource names and values, in the same format used in the
@file{.Xresources} file. @xref{X Resources,, X Resources, emacs, The
GNU Emacs Manual}. These values apply to all Emacs frames created on
this display, overriding the resource values recorded in the X server.
Here's an example of what this string might look like:
@example
"*BorderWidth: 3\n*InternalBorder: 2\n"
@end example
If @var{must-succeed} is non-@code{nil}, failure to open the connection
terminates Emacs. Otherwise, it is an ordinary Lisp error.
@end defun
@defun x-close-connection display
This function closes the connection to display @var{display}. Before
you can do this, you must first delete all the frames that were open
on that display (@pxref{Deleting Frames}).
@end defun
@cindex multi-monitor
On some multi-monitor setups, a single X display outputs to more
than one physical monitor. You can use the functions
@code{display-monitor-attributes-list} and @code{frame-monitor-attributes}
to obtain information about such setups.
@defun display-monitor-attributes-list &optional display
This function returns a list of physical monitor attributes on
@var{display}, which can be a display name (a string), a terminal, or
a frame; if omitted or @code{nil}, it defaults to the selected frame's
display. Each element of the list is an association list,
representing the attributes of a physical monitor. The first element
corresponds to the primary monitor. The attribute keys and values
are:
@table @samp
@item geometry
Position of the top-left corner of the monitor's screen and its size,
in pixels, as @samp{(@var{x} @var{y} @var{width} @var{height})}. Note
that, if the monitor is not the primary monitor, some of the
coordinates might be negative.
@item workarea
Position of the top-left corner and size of the work area (usable
space) in pixels as @samp{(@var{x} @var{y} @var{width} @var{height})}.
This may be different from @samp{geometry} in that space occupied by
various window manager features (docks, taskbars, etc.)@: may be
excluded from the work area. Whether or not such features actually
subtract from the work area depends on the platform and environment.
Again, if the monitor is not the primary monitor, some of the
coordinates might be negative.
@item mm-size
Width and height in millimeters as @samp{(@var{width} @var{height})}
@item frames
List of frames that this physical monitor dominates (see below).
@item name
Name of the physical monitor as @var{string}.
@item source
Source of the multi-monitor information as @var{string};
e.g., @samp{XRandR 1.5}, @samp{XRandr} or @samp{Xinerama}.
@end table
@var{x}, @var{y}, @var{width}, and @var{height} are integers.
@samp{name} and @samp{source} may be absent.
A frame is @dfn{dominated} by a physical monitor when either the
largest area of the frame resides in that monitor, or (if the frame
does not intersect any physical monitors) that monitor is the closest
to the frame. Every (non-tooltip) frame (whether visible or not) in a
graphical display is dominated by exactly one physical monitor at a
time, though the frame can span multiple (or no) physical monitors.
Here's an example of the data produced by this function on a 2-monitor
display:
@lisp
(display-monitor-attributes-list)
@result{}
(((geometry 0 0 1920 1080) ;; @r{Left-hand, primary monitor}
(workarea 0 0 1920 1050) ;; @r{A taskbar occupies some of the height}
(mm-size 677 381)
(name . "DISPLAY1")
(frames #<frame emacs@@host *Messages* 0x11578c0>
#<frame emacs@@host *scratch* 0x114b838>))
((geometry 1920 0 1680 1050) ;; @r{Right-hand monitor}
(workarea 1920 0 1680 1050) ;; @r{Whole screen can be used}
(mm-size 593 370)
(name . "DISPLAY2")
(frames)))
@end lisp
@end defun
@defun frame-monitor-attributes &optional frame
This function returns the attributes of the physical monitor
dominating (see above) @var{frame}, which defaults to the selected frame.
@end defun
On multi-monitor displays it is possible to use the command
@code{make-frame-on-monitor} to make frames on the specified monitor.
@deffn Command make-frame-on-monitor monitor &optional display parameters
This function creates and returns a new frame on @var{monitor} located
on @var{display}, taking the other frame parameters from the alist
@var{parameters}. @var{monitor} should be the name of the physical
monitor, the same string as returned by the function
@code{display-monitor-attributes-list} in the attribute @code{name}.
@var{display} should be the name of an X display (a string).
@end deffn
@cindex monitor change functions
@defvar display-monitors-changed-functions
This variable is an abnormal hook run when the monitor configuration
changes, which can happen if a monitor is rotated, moved, added or
removed from a multiple-monitor setup, if the primary monitor changes,
or if the resolution of a monitor changes. It is called with a single
argument consisting of the terminal on which the monitor configuration
changed. Programs should call @code{display-monitor-attributes-list}
with the terminal as the argument to retrieve the new monitor
configuration on that terminal.
@end defvar
@node Frame Geometry
@section Frame Geometry
@cindex frame geometry
@cindex frame position
@cindex position of frame
@cindex frame size
@cindex size of frame
The geometry of a frame depends on the toolkit that was used to build
this instance of Emacs and the terminal that displays the frame. This
chapter describes these dependencies and some of the functions to deal
with them. Note that the @var{frame} argument of all of these functions
has to specify a live frame (@pxref{Deleting Frames}). If omitted or
@code{nil}, it specifies the selected frame (@pxref{Input Focus}).
@menu
* Frame Layout:: Basic layout of frames.
* Frame Font:: The default font of a frame and how to set it.
* Frame Position:: The position of a frame on its display.
* Frame Size:: Specifying and retrieving a frame's size.
* Implied Frame Resizing:: Implied resizing of frames and how to prevent it.
@end menu
@node Frame Layout
@subsection Frame Layout
@cindex frame layout
@cindex layout of frame
A visible frame occupies a rectangular area on its terminal's display.
This area may contain a number of nested rectangles, each serving a
different purpose. The drawing below sketches the layout of a frame on
a graphical terminal:
@smallexample
@group
<------------ Outer Frame Width ----------->
____________________________________________
^(0) ________ External/Outer Border _______ |
| | |_____________ Title Bar ______________| |
| | (1)_____________ Menu Bar ______________| | ^
| | (2)_____________ Tool Bar ______________| | ^
| | (3)_____________ Tab Bar _______________| | ^
| | | _________ Internal Border ________ | | ^
| | | | ^ | | | |
| | | | | | | | |
Outer | | | Inner | | | Native
Frame | | | Frame | | | Frame
Height | | | Height | | | Height
| | | | | | | | |
| | | |<--+--- Inner Frame Width ------->| | | |
| | | | | | | | |
| | | |___v______________________________| | | |
| | |___________ Internal Border __________| | |
| | (4)__________ Bottom Tool Bar __________| | v
v |___________ External/Outer Border __________|
<-------- Native Frame Width -------->
@end group
@end smallexample
In practice not all of the areas shown in the drawing will or may be
present. The meaning of these areas is described below.
@table @asis
@item Outer Frame
@cindex outer frame
@cindex outer edges
@cindex outer width
@cindex outer height
@cindex outer size
The @dfn{outer frame} is a rectangle comprising all areas shown in the
drawing. The edges of that rectangle are called the @dfn{outer edges}
of the frame. Together, the @dfn{outer width} and @dfn{outer height} of
the frame specify the @dfn{outer size} of that rectangle.
Knowing the outer size of a frame is useful for fitting a frame into the
working area of its display (@pxref{Multiple Terminals}) or for placing
two frames adjacent to each other on the screen. Usually, the outer
size of a frame is available only after the frame has been mapped (made
visible, @pxref{Visibility of Frames}) at least once. For the initial
frame or a frame that has not been created yet, the outer size can be
only estimated or must be calculated from the window-system's or window
manager's defaults. One workaround is to obtain the differences of the
outer and native (see below) sizes of a mapped frame and use them for
calculating the outer size of the new frame.
@cindex outer position
The position of the upper left corner of the outer frame (indicated by
@samp{(0)} in the drawing above) is the @dfn{outer position} of the
frame. The outer position of a graphical frame is also referred to as
``the position'' of the frame because it usually remains unchanged on
its display whenever the frame is resized or its layout is changed.
The outer position is specified by and can be set via the @code{left}
and @code{top} frame parameters (@pxref{Position Parameters}). For a
normal, top-level frame these parameters usually represent its absolute
position (see below) with respect to its display's origin. For a child
frame (@pxref{Child Frames}) these parameters represent its position
relative to the native position (see below) of its parent frame. For
frames on text terminals the values of these parameters are meaningless
and always zero.
@item External Border
@cindex external border
The @dfn{external border} is part of the decorations supplied by the
window manager. It is typically used for resizing the frame with the
mouse and is therefore not shown on ``fullboth'' and maximized frames
(@pxref{Size Parameters}). Its width is determined by the window
manager and cannot be changed by Emacs's functions.
External borders don't exist on text terminal frames. For graphical
frames, their display can be suppressed by setting the
@code{override-redirect} or @code{undecorated} frame parameter
(@pxref{Management Parameters}).
@item Outer Border
@cindex outer border
The @dfn{outer border} is a separate border whose width can be specified
with the @code{border-width} frame parameter (@pxref{Layout
Parameters}). In practice, either the external or the outer border of a
frame are displayed but never both at the same time. Usually, the outer
border is shown only for special frames that are not (fully) controlled
by the window manager like tooltip frames (@pxref{Tooltips}), child
frames (@pxref{Child Frames}) and @code{undecorated} or
@code{override-redirect} frames (@pxref{Management Parameters}).
Outer borders are never shown on text terminal frames and on frames
generated by GTK+ routines. On MS-Windows, the outer border is emulated
with the help of a one pixel wide external border. Non-toolkit builds
on X allow changing the color of the outer border by setting the
@code{border-color} frame parameter (@pxref{Layout Parameters}).
@item Title Bar
@cindex title bar
@cindex caption bar
The @dfn{title bar}, a.k.a.@ @dfn{caption bar}, is also part of the
window manager's decorations and typically displays the title of the
frame (@pxref{Frame Titles}) as well as buttons for minimizing,
maximizing and deleting the frame. It can be also used for dragging
the frame with the mouse. The title bar is usually not displayed for
fullboth (@pxref{Size Parameters}), tooltip (@pxref{Tooltips}) and
child frames (@pxref{Child Frames}) and doesn't exist for terminal
frames. Display of the title bar can be suppressed by setting the
@code{override-redirect} or the @code{undecorated} frame parameters
(@pxref{Management Parameters}).
@item Menu Bar
@cindex internal menu bar
@cindex external menu bar
The menu bar (@pxref{Menu Bar}) can be either internal (drawn by Emacs
itself) or external (drawn by the toolkit). Most builds (GTK+, Lucid,
Motif and MS-Windows) rely on an external menu bar. NS also uses an
external menu bar which, however, is not part of the outer frame.
Non-toolkit builds can provide an internal menu bar. On text terminal
frames, the menu bar is part of the frame's root window (@pxref{Windows
and Frames}). As a rule, menu bars are never shown on child frames
(@pxref{Child Frames}). Display of the menu bar can be suppressed by
setting the @code{menu-bar-lines} parameter (@pxref{Layout Parameters})
to zero.
Whether the menu bar is wrapped or truncated whenever its width
becomes too large to fit on its frame depends on the toolkit .
Usually, only Motif and MS-Windows builds can wrap the menu bar. When
they (un-)wrap the menu bar, they try to keep the outer height of the
frame unchanged, so the native height of the frame (see below) will
change instead.
@item Tool Bar
@cindex internal tool bar
@cindex external tool bar
Like the menu bar, the tool bar (@pxref{Tool Bar}) can be either
internal (drawn by Emacs itself) or external (drawn by a toolkit). The
GTK+ and NS builds have the tool bar drawn by the toolkit. The
remaining builds use internal tool bars. With GTK+ the tool bar can be
located on either side of the frame, immediately outside the internal
border, see below. Tool bars are usually not shown for child frames
(@pxref{Child Frames}). Display of the tool bar can be suppressed by
setting the @code{tool-bar-lines} parameter (@pxref{Layout
Parameters}) to zero.
If the variable @code{auto-resize-tool-bars} is non-@code{nil}, Emacs
wraps the internal tool bar when its width becomes too large for its
frame. If and when Emacs (un-)wraps the internal tool bar, it by
default keeps the outer height of the frame unchanged, so the native
height of the frame (see below) will change instead. Emacs built with
GTK+, on the other hand, never wraps the tool bar but may
automatically increase the outer width of a frame in order to
accommodate an overlong tool bar.
@item Tab Bar
@cindex tab bar
The tab bar (@pxref{Tab Bars,,,emacs, The GNU Emacs Manual}) is always
drawn by Emacs itself. The tab bar appears above the tool bar in
Emacs built with an internal tool bar, and below the tool bar in
builds with an external tool bar.
Display of the tab bar can be suppressed by setting the
@code{tab-bar-lines} parameter (@pxref{Layout Parameters}) to zero.
@item Native Frame
@cindex native frame
@cindex native edges
@cindex native width
@cindex native height
@cindex native size
The @dfn{native frame} is a rectangle located entirely within the outer
frame. It excludes the areas occupied by an external or outer border,
the title bar and any external menu or tool bar. The edges of the
native frame are called the @dfn{native edges} of the frame. Together,
the @dfn{native width} and @dfn{native height} of a frame specify the
@dfn{native size} of the frame.
The native size of a frame is the size Emacs passes to the window-system
or window manager when creating or resizing the frame from within Emacs.
It is also the size Emacs receives from the window-system or window
manager whenever these resize the frame's window-system window, for
example, after maximizing the frame by clicking on the corresponding
button in the title bar or when dragging its external border with the
mouse.
@cindex native position
The position of the top left corner of the native frame specifies the
@dfn{native position} of the frame. (1)--(3) in the drawing above
indicate that position for the various builds:
@itemize @w{}
@item (1) non-toolkit, Android, Haiku, and terminal frames
@item (2) Lucid, Motif, and MS-Windows frames
@item (3) GTK+ and NS frames
@end itemize
Accordingly, the native height of a frame may include the height of the
tool bar but not that of the menu bar (Lucid, Motif, MS-Windows) or
those of the menu bar and the tool bar (non-toolkit and text terminal
frames).
If the native position would otherwise be (2), but the tool bar is
placed at the bottom of the frame as depicted in (4), the native
position of the frame becomes that of the tab bar.
The native position of a frame is the reference position for functions
that set or return the current position of the mouse (@pxref{Mouse
Position}) and for functions dealing with the position of windows like
@code{window-edges}, @code{window-at} or @code{coordinates-in-window-p}
(@pxref{Coordinates and Windows}). It also specifies the (0, 0) origin
for locating and positioning child frames within this frame
(@pxref{Child Frames}).
Note also that the native position of a frame usually remains unaltered
on its display when removing or adding the window manager decorations by
changing the frame's @code{override-redirect} or @code{undecorated}
parameter (@pxref{Management Parameters}).
@item Internal Border
The internal border is a border drawn by Emacs around the inner frame
(see below). The specification of its appearance depends on whether
or not the given frame is a child frame (@pxref{Child Frames}).
For normal frames its width is specified by the @code{internal-border-width}
frame parameter (@pxref{Layout Parameters}), and its color is specified by the
background of the @code{internal-border} face.
For child frames its width is specified by the @code{child-frame-border-width}
frame parameter (but will use the @code{internal-border-width} parameter as
fallback), and its color is specified by the background of the
@code{child-frame-border} face.
@item Inner Frame
@cindex inner frame
@cindex inner edges
@cindex inner width
@cindex inner height
@cindex inner size
@cindex display area
The @dfn{inner frame} is the rectangle reserved for the frame's windows.
It's enclosed by the internal border which, however, is not part of the
inner frame. Its edges are called the @dfn{inner edges} of the frame.
The @dfn{inner width} and @dfn{inner height} specify the @dfn{inner
size} of the rectangle. The inner frame is sometimes also referred to
as the @dfn{display area} of the frame.
@cindex minibuffer-less frame
@cindex minibuffer-only frame
As a rule, the inner frame is subdivided into the frame's root window
(@pxref{Windows and Frames}) and the frame's minibuffer window
(@pxref{Minibuffer Windows}). There are two notable exceptions to this
rule: A @dfn{minibuffer-less frame} contains a root window only and does
not contain a minibuffer window. A @dfn{minibuffer-only frame} contains
only a minibuffer window which also serves as that frame's root window.
See @ref{Initial Parameters} for how to create such frame
configurations.
@item Text Area
@cindex text area
The @dfn{text area} of a frame is a somewhat fictitious area that can be
embedded in the native frame. Its position is unspecified. Its width
can be obtained by removing from that of the native width the widths of
the internal border, one vertical scroll bar, and one left and one right
fringe if they are specified for this frame, see @ref{Layout
Parameters}. Its height can be obtained by removing from that of the
native height the widths of the internal border and the heights of the
frame's internal menu and tool bars, the tab bar and one horizontal
scroll bar if specified for this frame.
@end table
@cindex absolute position
@cindex absolute frame position
@cindex absolute edges
@cindex absolute frame edges
@cindex display origin
@cindex origin of display
The @dfn{absolute position} of a frame is given as a pair (X, Y) of
horizontal and vertical pixel offsets relative to an origin (0, 0) of
the frame's display. Correspondingly, the @dfn{absolute edges} of a
frame are given as pixel offsets from that origin.
Note that with multiple monitors, the origin of the display does not
necessarily coincide with the top-left corner of the entire usable
display area of the terminal. Hence the absolute position of a frame
can be negative in such an environment even when that frame is
completely visible.
By convention, vertical offsets increase ``downwards''. This means
that the height of a frame is obtained by subtracting the offset of its
top edge from that of its bottom edge. Horizontal offsets increase
``rightwards'', as expected, so a frame's width is calculated by
subtracting the offset of its left edge from that of its right edge.
For a frame on a graphical terminal the following function returns the
sizes of the areas described above:
@defun frame-geometry &optional frame
This function returns geometric attributes of @var{frame}. The return
value is an association list of the attributes listed below. All
coordinate, height and width values are integers counting pixels. Note
that if @var{frame} has not been mapped yet, (@pxref{Visibility of
Frames}) some of the return values may only represent approximations of
the actual values---those that can be seen after the frame has been
mapped.
@table @code
@item outer-position
A cons representing the absolute position of the outer @var{frame},
relative to the origin at position (0, 0) of @var{frame}'s display.
@item outer-size
A cons of the outer width and height of @var{frame}.
@item external-border-size
A cons of the horizontal and vertical width of @var{frame}'s external
borders as supplied by the window manager. If the window manager
doesn't supply these values, Emacs will try to guess them from the
coordinates of the outer and inner frame.
@item outer-border-width
The width of the outer border of @var{frame}. The value is meaningful
for non-GTK+ X builds only.
@item title-bar-size
A cons of the width and height of the title bar of @var{frame} as
supplied by the window manager or operating system. If both of them are
zero, the frame has no title bar. If only the width is zero, Emacs was
not able to retrieve the width information.
@item menu-bar-external
If non-@code{nil}, this means the menu bar is external (not part of the
native frame of @var{frame}).
@item menu-bar-size
A cons of the width and height of the menu bar of @var{frame}.
@item tool-bar-external
If non-@code{nil}, this means the tool bar is external (not part of the
native frame of @var{frame}).
@item tool-bar-position
This tells on which side the tool bar on @var{frame} is and can be one
of @code{left}, @code{top}, @code{right} or @code{bottom}.
The values @code{left} and @code{right} are only supported on builds
using the GTK+ toolkit; @code{bottom} is supported on all builds other
than NS, and @code{top} is supported everywhere.
@item tool-bar-size
A cons of the width and height of the tool bar of @var{frame}.
@item internal-border-width
The width of the internal border of @var{frame}.
@end table
@end defun
The following function can be used to retrieve the edges of the outer,
native and inner frame.
@defun frame-edges &optional frame type
This function returns the absolute edges of the outer, native or inner
frame of @var{frame}. @var{frame} must be a live frame and defaults to
the selected one. The returned list has the form @w{@code{(@var{left}
@var{top} @var{right} @var{bottom})}} where all values are in pixels
relative to the origin of @var{frame}'s display. For terminal frames
the values returned for @var{left} and @var{top} are always zero.
Optional argument @var{type} specifies the type of the edges to return:
@code{outer-edges} means to return the outer edges of @var{frame},
@code{native-edges} (or @code{nil}) means to return its native edges and
@code{inner-edges} means to return its inner edges.
By convention, the pixels of the display at the values returned for
@var{left} and @var{top} are considered to be inside (part of)
@var{frame}. Hence, if @var{left} and @var{top} are both zero, the
pixel at the display's origin is part of @var{frame}. The pixels at
@var{bottom} and @var{right}, on the other hand, are considered to lie
immediately outside @var{frame}. This means that if you have, for
example, two side-by-side frames positioned such that the right outer
edge of the frame on the left equals the left outer edge of the frame on
the right, the pixels at that edge show a part of the frame on the
right.
@end defun
@node Frame Font
@subsection Frame Font
@cindex default font
@cindex default character size
@cindex default character width
@cindex default width of character
@cindex default character height
@cindex default height of character
Each frame has a @dfn{default font} which specifies the default
character size for that frame. This size is meant when retrieving or
changing the size of a frame in terms of columns or lines
(@pxref{Size Parameters}). It is also used when resizing (@pxref{Window
Sizes}) or splitting (@pxref{Splitting Windows}) windows.
@cindex line height
@cindex column width
@cindex canonical character height
@cindex canonical character width
The terms @dfn{line height} and @dfn{canonical character height} are
sometimes used instead of ``default character height''. Similarly, the
terms @dfn{column width} and @dfn{canonical character width} are used
instead of ``default character width''.
@defun frame-char-height &optional frame
@defunx frame-char-width &optional frame
These functions return the default height and width of a character in
@var{frame}, measured in pixels. Together, these values establish the
size of the default font on @var{frame}. The values depend on the
choice of font for @var{frame}, see @ref{Font and Color Parameters}.
@end defun
The default font can be also set directly with the following function:
@deffn Command set-frame-font font &optional keep-size frames
This sets the default font to @var{font}. When called interactively, it
prompts for the name of a font, and uses that font on the selected
frame. When called from Lisp, @var{font} should be a font name (a
string), a font object, font entity, or a font spec.
If the optional argument @var{keep-size} is @code{nil}, this keeps the
number of frame lines and columns fixed. (If non-@code{nil}, the option
@code{frame-inhibit-implied-resize} described in the next section will
override this.) If @var{keep-size} is non-@code{nil} (or with a prefix
argument), it tries to keep the size of the display area of the current
frame fixed by adjusting the number of lines and columns.
If the optional argument @var{frames} is @code{nil}, this applies the
font to the selected frame only. If @var{frames} is non-@code{nil}, it
should be a list of frames to act upon, or @code{t} meaning all existing
and all future graphical frames.
@end deffn
@node Frame Position
@subsection Frame Position
@cindex frame position
@cindex position of frame
On graphical systems, the position of a normal top-level frame is
specified as the absolute position of its outer frame (@pxref{Frame
Geometry}). The position of a child frame (@pxref{Child Frames}) is
specified via pixel offsets of its outer edges relative to the native
position of its parent frame.
You can access or change the position of a frame using the frame
parameters @code{left} and @code{top} (@pxref{Position Parameters}).
Here are two additional functions for working with the positions of an
existing, visible frame. For both functions, the argument @var{frame}
must denote a live frame and defaults to the selected frame.
@defun frame-position &optional frame
For a normal, non-child frame this function returns a cons of the pixel
coordinates of its outer position (@pxref{Frame Layout}) with respect to
the origin @code{(0, 0)} of its display. For a child frame
(@pxref{Child Frames}) this function returns the pixel coordinates of
its outer position with respect to an origin @code{(0, 0)} at the native
position of @var{frame}'s parent.
Negative values never indicate an offset from the right or bottom
edge of @var{frame}'s display or parent frame. Rather, they mean that
@var{frame}'s outer position is on the left and/or above the origin of
its display or the native position of its parent frame. This usually
means that @var{frame} is only partially visible (or completely
invisible). However, on systems where the display's origin does not
coincide with its top-left corner, the frame may be visible on a
secondary monitor.
On a text terminal frame both values are zero.
@end defun
@defun set-frame-position frame x y
This function sets the outer frame position of @var{frame} to (@var{x},
@var{y}). The latter arguments specify pixels and normally count from
the origin at the position (0, 0) of @var{frame}'s display. For child
frames, they count from the native position of @var{frame}'s parent
frame.
Negative parameter values position the right edge of the outer frame by
@var{-x} pixels left from the right edge of the screen (or the parent
frame's native rectangle) and the bottom edge by @var{-y} pixels up from
the bottom edge of the screen (or the parent frame's native rectangle).
Note that negative values do not permit aligning the right or bottom
edge of @var{frame} exactly at the right or bottom edge of its display
or parent frame. Neither do they allow specifying a position that does
not lie within the edges of the display or parent frame. The frame
parameters @code{left} and @code{top} (@pxref{Position Parameters})
allow doing that, but may still fail to provide good results for the
initial or a new frame.
This function has no effect on text terminal frames.
@end defun
@defvar move-frame-functions
@cindex frame position changes, a hook
This hook specifies the functions that are run when an Emacs frame is moved
(assigned a new position) by the window-system or window manager. The
functions are run with one argument, the frame that moved. For a child
frame (@pxref{Child Frames}), the functions are run only when the
position of the frame changes in relation to that of its parent frame.
@end defvar
@node Frame Size
@subsection Frame Size
@cindex frame size
@cindex text width of a frame
@cindex text height of a frame
@cindex text size of a frame
The canonical way to specify the @dfn{size of a frame} from within Emacs
is by specifying its @dfn{text size}---a tuple of the width and height
of the frame's text area (@pxref{Frame Layout}). It can be measured
either in pixels or in terms of the frame's canonical character size
(@pxref{Frame Font}).
For frames with an internal menu or tool bar, the frame's native
height cannot be told exactly before the frame has been actually drawn.
This means that in general you cannot use the native size to specify the
initial size of a frame. As soon as you know the native size of a
visible frame, you can calculate its outer size (@pxref{Frame Layout})
by adding in the remaining components from the return value of
@code{frame-geometry}. For invisible frames or for frames that have
yet to be created, however, the outer size can only be estimated. This
also means that calculating an exact initial position of a frame
specified via offsets from the right or bottom edge of the screen
(@pxref{Frame Position}) is impossible.
The text size of any frame can be set and retrieved with the help of
the @code{height} and @code{width} frame parameters (@pxref{Size
Parameters}). The text size of the initial frame can be also set with
the help of an X-style geometry specification. @xref{Emacs Invocation,,
Command Line Arguments for Emacs Invocation, emacs, The GNU Emacs
Manual}. Below we list some functions to access and set the size of an
existing, visible frame, by default the selected one.
@defun frame-height &optional frame
@defunx frame-width &optional frame
These functions return the height and width of the text area of
@var{frame}, measured in units of the default font height and width of
@var{frame} (@pxref{Frame Font}). These functions are plain shorthands
for writing @code{(frame-parameter frame 'height)} and
@code{(frame-parameter frame 'width)}.
If the text area of @var{frame} measured in pixels is not a multiple of
its default font size, the values returned by these functions are
rounded down to the number of characters of the default font that fully
fit into the text area.
@end defun
The functions following next return the pixel widths and heights of the
native, outer and inner frame and the text area (@pxref{Frame Layout})
of a given frame. For a text terminal, the results are in characters
rather than pixels.
@defun frame-outer-width &optional frame
@defunx frame-outer-height &optional frame
These functions return the outer width and height of @var{frame} in
pixels.
@end defun
@defun frame-native-height &optional frame
@defunx frame-native-width &optional frame
These functions return the native width and height of @var{frame} in
pixels.
@end defun
@defun frame-inner-width &optional frame
@defunx frame-inner-height &optional frame
These functions return the inner width and height of @var{frame} in
pixels.
@end defun
@defun frame-text-width &optional frame
@defunx frame-text-height &optional frame
These functions return the width and height of the text area of
@var{frame} in pixels.
@end defun
On window systems that support it, Emacs tries by default to make the
text size of a frame measured in pixels a multiple of the frame's
character size. This, however, usually means that a frame can be
resized only in character size increments when dragging its external
borders. It also may break attempts to truly maximize the frame or
making it ``fullheight'' or ``fullwidth'' (@pxref{Size Parameters})
leaving some empty space below and/or on the right of the frame. The
following option may help in that case.
@defopt frame-resize-pixelwise
If this option is @code{nil} (the default), a frame's text pixel size is
usually rounded to a multiple of the current values of that frame's
@code{frame-char-height} and @code{frame-char-width} whenever the frame
is resized. If this is non-@code{nil}, no rounding occurs, hence frame
sizes can increase/decrease by one pixel.
Setting this variable usually causes the next resize operation to pass
the corresponding size hints to the window manager. This means that
this variable should be set only in a user's initial file; applications
should never bind it temporarily.
The precise meaning of a value of @code{nil} for this option depends on
the toolkit used. Dragging the external border with the mouse is done
character-wise provided the window manager is willing to process the
corresponding size hints. Calling @code{set-frame-size} (see below)
with arguments that do not specify the frame size as an integer multiple
of its character size, however, may: be ignored, cause a rounding
(GTK+), or be accepted (Lucid, Motif, MS-Windows).
With some window managers you may have to set this to non-@code{nil} in
order to make a frame appear truly maximized or full-screen.
@end defopt
@defun set-frame-size frame width height &optional pixelwise
This function sets the size of the text area of @var{frame}, measured in
terms of the canonical height and width of a character on @var{frame}
(@pxref{Frame Font}).
The optional argument @var{pixelwise} non-@code{nil} means to measure
the new width and height in units of pixels instead. Note that if
@code{frame-resize-pixelwise} is @code{nil}, some toolkits may refuse to
truly honor the request if it does not increase/decrease the frame size
to a multiple of its character size.
@end defun
@defun set-frame-height frame height &optional pretend pixelwise
This function resizes the text area of @var{frame} to a height of
@var{height} lines. The sizes of existing windows in @var{frame} are
altered proportionally to fit.
If @var{pretend} is non-@code{nil}, then Emacs displays @var{height}
lines of output in @var{frame}, but does not change its value for the
actual height of the frame. This is only useful on text terminals.
Using a smaller height than the terminal actually implements may be
useful to reproduce behavior observed on a smaller screen, or if the
terminal malfunctions when using its whole screen. Setting the frame
height directly does not always work, because knowing the correct
actual size may be necessary for correct cursor positioning on
text terminals.
The optional fourth argument @var{pixelwise} non-@code{nil} means that
@var{frame} should be @var{height} pixels high. Note that if
@code{frame-resize-pixelwise} is @code{nil}, some window managers may
refuse to truly honor the request if it does not increase/decrease the
frame height to a multiple of its character height.
When used interactively, this command will ask the user for the number
of lines to set the height of the currently selected frame. You can
also provide this value with a numeric prefix.
@end defun
@defun set-frame-width frame width &optional pretend pixelwise
This function sets the width of the text area of @var{frame}, measured
in characters. The argument @var{pretend} has the same meaning as in
@code{set-frame-height}.
The optional fourth argument @var{pixelwise} non-@code{nil} means that
@var{frame} should be @var{width} pixels wide. Note that if
@code{frame-resize-pixelwise} is @code{nil}, some window managers may
refuse to fully honor the request if it does not increase/decrease the
frame width to a multiple of its character width.
When used interactively, this command will ask the user for the number
of columns to set the width of the currently selected frame. You can
also provide this value with a numeric prefix.
@end defun
None of these three functions will make a frame smaller than needed to
display all of its windows together with their scroll bars, fringes,
margins, dividers, mode and header lines. This contrasts with requests
by the window manager triggered, for example, by dragging the external
border of a frame with the mouse. Such requests are always honored by
clipping, if necessary, portions that cannot be displayed at the right,
bottom corner of the frame. The parameters @code{min-width} and
@code{min-height} (@pxref{Size Parameters}) can be used to obtain a
similar behavior when changing the frame size from within Emacs.
@cindex tracking frame size changes
The abnormal hook @code{window-size-change-functions} (@pxref{Window
Hooks}) tracks all changes of the inner size of a frame including those
induced by request of the window-system or window manager. To rule out
false positives that might occur when changing only the sizes of a
frame's windows without actually changing the size of the inner frame,
use the following function.
@defun frame-size-changed-p &optional frame
This function returns non-@code{nil} when the inner width or height of
@var{frame} has changed since @code{window-size-change-functions} was
run the last time for @var{frame}. It always returns @code{nil}
immediately after running @code{window-size-change-functions} for
@var{frame}.
@end defun
@node Implied Frame Resizing
@subsection Implied Frame Resizing
@cindex implied frame resizing
@cindex implied resizing of frame
By default, Emacs tries to keep the number of lines and columns of a
frame's text area unaltered when, for example, toggling its menu or
tool bar, changing its default font or setting the width of any of its
scroll bars. This means that in such case Emacs must ask the window
manager to resize the frame's window in order to accommodate the size
change.
Occasionally, such @dfn{implied frame resizing} may be unwanted, for
example, when a frame has been maximized or made full-screen (where
it's turned off by default). In general, users can disable implied
resizing with the following option:
@defopt frame-inhibit-implied-resize
If this option is @code{nil}, changing a frame's font, menu bar, tool
bar, internal borders, fringes or scroll bars may resize its outer
frame in order to keep the number of columns or lines of its text area
unaltered. If this option is @code{t}, no such resizing is done.
The value of this option can be also a list of frame parameters. In
that case, implied resizing is inhibited for the change of a parameter
that appears in this list. Parameters currently handled by this
option are @code{font}, @code{font-backend},
@code{internal-border-width}, @code{menu-bar-lines} and
@code{tool-bar-lines}.
Changing any of the @code{scroll-bar-width}, @code{scroll-bar-height},
@code{vertical-scroll-bars}, @code{horizontal-scroll-bars},
@code{left-fringe} and @code{right-fringe} frame parameters is handled
as if the frame contained just one live window. This means, for
example, that removing vertical scroll bars on a frame containing
several side by side windows will shrink the outer frame width by the
width of one scroll bar provided this option is @code{nil} and keep it
unchanged if this option is @code{t} or a list containing
@code{vertical-scroll-bars}.
The default value is @code{(tab-bar-lines tool-bar-lines)} for Lucid,
Motif and MS-Windows (which means that adding/removing a tool or tab
bar there does not change the outer frame height),
@code{(tab-bar-lines)} on all other window systems including GTK+
(which means that changing any of the parameters listed above with the
exception of @code{tab-bar-lines} may change the size of the outer
frame), and @code{t} otherwise (which means the outer frame size never
changes implicitly when there's no window system support).
Note that when a frame is not large enough to accommodate a change of
any of the parameters listed above, Emacs may try to enlarge the frame
even if this option is non-@code{nil}.
Note also that window managers usually do not ask for resizing a frame
when they change the number of lines occupied by an external menu or
tool bar. Typically, such ``wrappings'' occur when a user shrinks a
frame horizontally, making it impossible to display all elements of
its menu or tool bar. They may also result from a change of the major
mode altering the number of items of a menu or tool bar. Any such
wrappings may implicitly alter the number of lines of a frame's text
area and are unaffected by the setting of this option.
@end defopt
@node Frame Parameters
@section Frame Parameters
@cindex frame parameters
A frame has many parameters that control its appearance and behavior.
Just what parameters a frame has depends on what display mechanism it
uses.
Frame parameters exist mostly for the sake of graphical displays.
Most frame parameters have no effect when applied to a frame on a text
terminal; only the @code{height}, @code{width}, @code{name},
@code{title}, @code{menu-bar-lines}, @code{buffer-list} and
@code{buffer-predicate} parameters do something special. If the
terminal supports colors, the parameters @code{foreground-color},
@code{background-color}, @code{background-mode} and
@code{display-type} are also meaningful. If the terminal supports
frame transparency, the parameter @code{alpha} is also meaningful.
By default, frame parameters are saved and restored by the desktop
library functions (@pxref{Desktop Save Mode}) when the variable
@code{desktop-restore-frames} is non-@code{nil}. It's the
responsibility of applications that their parameters are included in
@code{frameset-persistent-filter-alist} to avoid that they get
meaningless or even harmful values in restored sessions.
@menu
* Parameter Access:: How to change a frame's parameters.
* Initial Parameters:: Specifying frame parameters when you make a frame.
* Window Frame Parameters:: List of frame parameters for window systems.
* Geometry:: Parsing geometry specifications.
@end menu
@node Parameter Access
@subsection Access to Frame Parameters
These functions let you read and change the parameter values of a
frame.
@defun frame-parameter frame parameter
This function returns the value of the parameter @var{parameter} (a
symbol) of @var{frame}. If @var{frame} is @code{nil}, it returns the
selected frame's parameter. If @var{frame} has no setting for
@var{parameter}, this function returns @code{nil}.
@end defun
@defun frame-parameters &optional frame
The function @code{frame-parameters} returns an alist listing all the
parameters of @var{frame} and their values. If @var{frame} is
@code{nil} or omitted, this returns the selected frame's parameters
@end defun
@defun modify-frame-parameters frame alist
This function alters the frame @var{frame} based on the elements of
@var{alist}. Each element of @var{alist} has the form
@code{(@var{parm} . @var{value})}, where @var{parm} is a symbol naming
a parameter. If you don't mention a parameter in @var{alist}, its
value doesn't change. If @var{frame} is @code{nil}, it defaults to
the selected frame.
Some parameters are only meaningful for frames on certain kinds of
display (@pxref{Frames}). If @var{alist} includes parameters that are
not meaningful for the @var{frame}'s display, this function will
change its value in the frame's parameter list, but will otherwise
ignore it.
When @var{alist} specifies more than one parameter whose value can
affect the new size of @var{frame}, the final size of the frame may
differ according to the toolkit used. For example, specifying that a
frame should from now on have a menu and/or tool bar instead of none and
simultaneously specifying the new height of the frame will inevitably
lead to a recalculation of the frame's height. Conceptually, in such
case, this function will try to have the explicit height specification
prevail. It cannot be excluded, however, that the addition (or removal)
of the menu or tool bar, when eventually performed by the toolkit, will
defeat this intention.
Sometimes, binding @code{frame-inhibit-implied-resize} (@pxref{Implied
Frame Resizing}) to a non-@code{nil} value around calls to this function
may fix the problem sketched here. Sometimes, however, exactly such
binding may be hit by the problem.
@end defun
@defun set-frame-parameter frame parm value
This function sets the frame parameter @var{parm} to the specified
@var{value}. If @var{frame} is @code{nil}, it defaults to the selected
frame.
@end defun
@defun modify-all-frames-parameters alist
This function alters the frame parameters of all existing frames
according to @var{alist}, then modifies @code{default-frame-alist}
(and, if necessary, @code{initial-frame-alist}) to apply the same
parameter values to frames that will be created henceforth.
@end defun
@node Initial Parameters
@subsection Initial Frame Parameters
@cindex parameters of initial frame
You can specify the parameters for the initial startup frame by
setting @code{initial-frame-alist} in your init file (@pxref{Init
File}).
@defopt initial-frame-alist
This variable's value is an alist of parameter values used when
creating the initial frame. You can set this variable to specify the
appearance of the initial frame without altering subsequent frames.
Each element has the form:
@example
(@var{parameter} . @var{value})
@end example
Emacs creates the initial frame before it reads your init
file. After reading that file, Emacs checks @code{initial-frame-alist},
and applies the parameter settings in the altered value to the already
created initial frame.
If these settings affect the frame geometry and appearance, you'll see
the frame appear with the wrong ones and then change to the specified
ones. If that bothers you, you can specify the same geometry and
appearance with X resources; those do take effect before the frame is
created. @xref{X Resources,, X Resources, emacs, The GNU Emacs Manual}.
X resource settings typically apply to all frames. If you want to
specify some X resources solely for the sake of the initial frame, and
you don't want them to apply to subsequent frames, here's how to achieve
this. Specify parameters in @code{default-frame-alist} to override the
X resources for subsequent frames; then, to prevent these from affecting
the initial frame, specify the same parameters in
@code{initial-frame-alist} with values that match the X resources.
@end defopt
@cindex minibuffer-only frame
If these parameters include @code{(minibuffer . nil)}, that indicates
that the initial frame should have no minibuffer. In this case, Emacs
creates a separate @dfn{minibuffer-only frame} as well.
@defopt minibuffer-frame-alist
This variable's value is an alist of parameter values used when
creating an initial minibuffer-only frame (i.e., the minibuffer-only
frame that Emacs creates if @code{initial-frame-alist} specifies a
frame with no minibuffer).
@end defopt
@defopt default-frame-alist
This is an alist specifying default values of frame parameters for all
Emacs frames---the first frame, and subsequent frames. When using the X
Window System, you can get the same results by means of X resources
in many cases.
Setting this variable does not affect existing frames. Furthermore,
functions that display a buffer in a separate frame may override the
default parameters by supplying their own parameters.
@end defopt
If you invoke Emacs with command-line options that specify frame
appearance, those options take effect by adding elements to either
@code{initial-frame-alist} or @code{default-frame-alist}. Options
which affect just the initial frame, such as @samp{--geometry} and
@samp{--maximized}, add to @code{initial-frame-alist}; the others add
to @code{default-frame-alist}. @pxref{Emacs Invocation,, Command Line
Arguments for Emacs Invocation, emacs, The GNU Emacs Manual}.
@node Window Frame Parameters
@subsection Window Frame Parameters
@cindex frame parameters for windowed displays
Just what parameters a frame has depends on what display mechanism
it uses. This section describes the parameters that have special
meanings on some or all kinds of terminals. Of these, @code{name},
@code{title}, @code{height}, @code{width}, @code{buffer-list} and
@code{buffer-predicate} provide meaningful information in terminal
frames, and @code{tty-color-mode} is meaningful only for frames on
text terminals.
@menu
* Basic Parameters:: Parameters that are fundamental.
* Position Parameters:: The position of the frame on the screen.
* Size Parameters:: Frame's size.
* Layout Parameters:: Size of parts of the frame, and
enabling or disabling some parts.
* Buffer Parameters:: Which buffers have been or should be shown.
* Frame Interaction Parameters:: Parameters for interacting with other
frames.
* Mouse Dragging Parameters:: Parameters for resizing and moving
frames with the mouse.
* Management Parameters:: Communicating with the window manager.
* Cursor Parameters:: Controlling the cursor appearance.
* Font and Color Parameters:: Fonts and colors for the frame text.
@end menu
@node Basic Parameters
@subsubsection Basic Parameters
These frame parameters give the most basic information about the
frame. @code{title} and @code{name} are meaningful on all terminals.
@table @code
@vindex display@r{, a frame parameter}
@item display
The display on which to open this frame. It should be a string of the
form @samp{@var{host}:@var{dpy}.@var{screen}}, just like the
@env{DISPLAY} environment variable. @xref{Multiple Terminals}, for
more details about display names.
@vindex display-type@r{, a frame parameter}
@item display-type
This parameter describes the range of possible colors that can be used
in this frame. Its value is @code{color}, @code{grayscale} or
@code{mono}.
@vindex title@r{, a frame parameter}
@item title
If a frame has a non-@code{nil} title, that title appears in the window
system's title bar at the top of the frame, and also in the mode line
of windows in that frame if @code{mode-line-frame-identification} uses
@samp{%F} (@pxref{%-Constructs}). This is normally the case when
Emacs is not using a window system, and can only display one frame at
a time. When Emacs is using a window system, this parameter, if
non-@code{nil}, overrides the title determined by the @code{name}
parameter and the implicit title calculated according to
@code{frame-title-format}. It also overrides the title determined by
@code{icon-title-format} for iconified frames. @xref{Frame Titles}.
@vindex name@r{, a frame parameter}
@item name
The name of the frame. If you don't specify a name via this
parameter, Emacs sets the frame name automatically, as specified by
@code{frame-title-format} and @code{icon-title-format}, and that is
the frame's title that will appear on display when Emacs uses a window
system (unless the @code{title} parameter overrides it).
If you specify the frame name explicitly when you create the frame, the
name is also used (instead of the name of the Emacs executable) when
looking up X resources for the frame.
@vindex explicit-name@r{, a frame parameter}
@item explicit-name
If the frame name was specified explicitly when the frame was created,
this parameter will be that name. If the frame wasn't explicitly
named, this parameter will be @code{nil}.
@end table
@node Position Parameters
@subsubsection Position Parameters
@cindex window position on display
@cindex frame position
Parameters describing the X- and Y-offsets of a frame are always
measured in pixels. For a normal, non-child frame they specify the
frame's outer position (@pxref{Frame Geometry}) relative to its
display's origin. For a child frame (@pxref{Child Frames}) they specify
the frame's outer position relative to the native position of the
frame's parent frame. (Note that none of these parameters is meaningful
on TTY frames.)
@table @code
@vindex left@r{, a frame parameter}
@item left
The position, in pixels, of the left outer edge of the frame with
respect to the left edge of the frame's display or parent frame. It can
be specified in one of the following ways.
@table @asis
@item an integer
A positive integer always relates the left edge of the frame to the left
edge of its display or parent frame. A negative integer relates the
right frame edge to the right edge of the display or parent frame.
@item @code{(+ @var{pos})}
This specifies the position of the left frame edge relative to the left
edge of its display or parent frame. The integer @var{pos} may be
positive or negative; a negative value specifies a position outside the
screen or parent frame or on a monitor other than the primary one (for
multi-monitor displays).
@item @code{(- @var{pos})}
This specifies the position of the right frame edge relative to the
right edge of the display or parent frame. The integer @var{pos} may be
positive or negative; a negative value specifies a position outside the
screen or parent frame or on a monitor other than the primary one (for
multi-monitor displays).
@cindex left position ratio
@cindex top position ratio
@item a floating-point value
A floating-point value in the range 0.0 to 1.0 specifies the left edge's
offset via the @dfn{left position ratio} of the frame---the ratio of the
left edge of its outer frame to the width of the frame's workarea
(@pxref{Multiple Terminals}) or its parent's native frame (@pxref{Child
Frames}) minus the width of the outer frame. Thus, a left position
ratio of 0.0 flushes a frame to the left, a ratio of 0.5 centers it and
a ratio of 1.0 flushes it to the right of its display or parent frame.
Similarly, the @dfn{top position ratio} of a frame is the ratio of the
frame's top position to the height of its workarea or parent frame minus
the height of the frame.
Emacs will try to keep the position ratios of a child frame unaltered if
that frame has a non-@code{nil} @code{keep-ratio} parameter
(@pxref{Frame Interaction Parameters}) and its parent frame is resized.
Since the outer size of a frame (@pxref{Frame Geometry}) is usually
unavailable before a frame has been made visible, it is generally not
advisable to use floating-point values when creating decorated frames.
Floating-point values are more suited for ensuring that an (undecorated)
child frame is positioned nicely within the area of its parent frame.
@end table
Some window managers ignore program-specified positions. If you want to
be sure the position you specify is not ignored, specify a
non-@code{nil} value for the @code{user-position} parameter as in the
following example:
@example
(modify-frame-parameters
nil '((user-position . t) (left . (+ -4))))
@end example
In general, it is not a good idea to position a frame relative to the
right or bottom edge of its display. Positioning the initial or a new
frame is either not accurate (because the size of the outer frame is not
yet fully known before the frame has been made visible) or will cause
additional flicker (if the frame has to be repositioned after becoming
visible).
Note also, that positions specified relative to the right/bottom edge
of a display, workarea or parent frame as well as floating-point offsets
are stored internally as integer offsets relative to the left/top edge
of the display, workarea or parent frame edge. They are also returned
as such by functions like @code{frame-parameters} and restored as such
by the desktop saving routines.
@vindex top@r{, a frame parameter}
@item top
The screen position of the top (or bottom) edge, in pixels, with respect
to the top (or bottom) edge of the display or parent frame. It works
just like @code{left}, except vertically instead of horizontally.
@vindex icon-left@r{, a frame parameter}
@item icon-left
The screen position of the left edge of the frame's icon, in pixels,
counting from the left edge of the screen. This takes effect when the
frame is iconified, if the window manager supports this feature. If
you specify a value for this parameter, then you must also specify a
value for @code{icon-top} and vice versa.
@vindex icon-top@r{, a frame parameter}
@item icon-top
The screen position of the top edge of the frame's icon, in pixels,
counting from the top edge of the screen. This takes effect when the
frame is iconified, if the window manager supports this feature.
@vindex user-position@r{, a frame parameter}
@item user-position
When you create a frame and specify its screen position with the
@code{left} and @code{top} parameters, use this parameter to say whether
the specified position was user-specified (explicitly requested in some
way by a human user) or merely program-specified (chosen by a program).
A non-@code{nil} value says the position was user-specified.
@cindex window positions and window managers
Window managers generally heed user-specified positions, and some heed
program-specified positions too. But many ignore program-specified
positions, placing the window in a default fashion or letting the user
place it with the mouse. Some window managers, including @code{twm},
let the user specify whether to obey program-specified positions or
ignore them.
When you call @code{make-frame}, you should specify a non-@code{nil}
value for this parameter if the values of the @code{left} and @code{top}
parameters represent the user's stated preference; otherwise, use
@code{nil}.
@vindex z-group@r{, a frame parameter}
@item z-group
This parameter specifies a relative position of the frame's
window-system window in the stacking (Z-) order of the frame's display.
If this is @code{above}, the window-system will display the window
that corresponds to the frame above all other window-system windows
that do not have the @code{above} property set. If this is
@code{nil}, the frame's window is displayed below all windows that
have the @code{above} property set and above all windows that have the
@code{below} property set. If this is @code{below}, the frame's
window is displayed below all windows that do not have the
@code{below} property set.
To position the frame above or below a specific other frame use the
function @code{frame-restack} (@pxref{Raising and Lowering}).
@end table
@node Size Parameters
@subsubsection Size Parameters
@cindex window size on display
Frame parameters usually specify frame sizes in character units. On
graphical displays, the @code{default} face determines the actual pixel
sizes of these character units (@pxref{Face Attributes}).
@table @code
@vindex width@r{, a frame parameter}
@item width
This parameter specifies the width of the frame. It can be specified as
in the following ways:
@table @asis
@item an integer
A positive integer specifies the width of the frame's text area
(@pxref{Frame Geometry}) in characters.
@item a cons cell
If this is a cons cell with the symbol @code{text-pixels} in its
@sc{car}, the @sc{cdr} of that cell specifies the width of the frame's
text area in pixels.
@cindex frame width ratio
@cindex frame height ratio
@item a floating-point value
A floating-point number between 0.0 and 1.0 can be used to specify the
width of a frame via its @dfn{width ratio}---the ratio of its outer
width (@pxref{Frame Geometry}) to the width of the frame's workarea
(@pxref{Multiple Terminals}) or its parent frame's (@pxref{Child
Frames}) native frame. Thus, a value of 0.5 makes the frame occupy half
of the width of its workarea or parent frame, a value of 1.0 the full
width. Similarly, the @dfn{height ratio} of a frame is the ratio of its
outer height to the height of its workarea or its parent's native frame.
Emacs will try to keep the width and height ratio of a child frame
unaltered if that frame has a non-@code{nil} @code{keep-ratio} parameter
(@pxref{Frame Interaction Parameters}) and its parent frame is resized.
Since the outer size of a frame is usually unavailable before a frame
has been made visible, it is generally not advisable to use
floating-point values when creating decorated frames. Floating-point
values are more suited to ensure that a child frame always fits within
the area of its parent frame as, for example, when customizing
@code{display-buffer-alist} (@pxref{Choosing Window}) via
@code{display-buffer-in-child-frame}.
@end table
Regardless of how this parameter was specified, functions reporting the
value of this parameter like @code{frame-parameters} always report the
width of the frame's text area in characters as an integer rounded, if
necessary, to a multiple of the frame's default character width. That
value is also used by the desktop saving routines.
@vindex height@r{, a frame parameter}
@item height
This parameter specifies the height of the frame. It works just like
@code{width}, except vertically instead of horizontally.
@vindex user-size@r{, a frame parameter}
@item user-size
This does for the size parameters @code{height} and @code{width} what
the @code{user-position} parameter (@pxref{Position Parameters,
user-position}) does for the position parameters @code{top} and
@code{left}.
@vindex min-width@r{, a frame parameter}
@item min-width
This parameter specifies the minimum native width (@pxref{Frame
Geometry}) of the frame, in characters. Normally, the functions that
establish a frame's initial width or resize a frame horizontally make
sure that all the frame's windows, vertical scroll bars, fringes,
margins and vertical dividers can be displayed. This parameter, if
non-@code{nil} enables making a frame narrower than that with the
consequence that any components that do not fit will be clipped by the
window manager.
@vindex min-height@r{, a frame parameter}
@item min-height
This parameter specifies the minimum native height (@pxref{Frame
Geometry}) of the frame, in characters. Normally, the functions that
establish a frame's initial size or resize a frame make sure that all
the frame's windows, horizontal scroll bars and dividers, mode and
header lines, the echo area and the internal menu and tool bar can be
displayed. This parameter, if non-@code{nil} enables making a frame
smaller than that with the consequence that any components that do not
fit will be clipped by the window manager.
@cindex fullboth frames
@cindex fullheight frames
@cindex fullwidth frames
@cindex maximized frames
@vindex fullscreen@r{, a frame parameter}
@item fullscreen
This parameter specifies whether to maximize the frame's width, height
or both. Its value can be @code{fullwidth}, @code{fullheight},
@code{fullboth}, or @code{maximized}.@footnote{On PGTK frames, setting
the values @code{fullheight} and @code{fullwidth} has no effect.} A
@dfn{fullwidth} frame is as wide as possible, a @dfn{fullheight} frame
is as tall as possible, and a @dfn{fullboth} frame is both as wide and
as tall as possible. A @dfn{maximized} frame is like a ``fullboth''
frame, except that it usually keeps its title bar and the buttons for
resizing and closing the frame. Also, maximized frames typically
avoid hiding any task bar or panels displayed on the desktop. A
``fullboth'' frame, on the other hand, usually omits the title bar and
occupies the entire available screen space.
Full-height and full-width frames are more similar to maximized
frames in this regard. However, these typically display an external
border which might be absent with maximized frames. Hence the heights
of maximized and full-height frames and the widths of maximized and
full-width frames often differ by a few pixels.
With some window managers you may have to customize the variable
@code{frame-resize-pixelwise} (@pxref{Frame Size}) in order to make a
frame truly appear maximized or full-screen. Moreover, some window
managers might not support smooth transition between the various
full-screen or maximization states. Customizing the variable
@code{x-frame-normalize-before-maximize} can help to overcome that.
Full-screen on macOS hides both the tool-bar and the menu-bar, however
both will be displayed if the mouse pointer is moved to the top of the
screen.
@vindex fullscreen-restore@r{, a frame parameter}
@item fullscreen-restore
This parameter specifies the desired fullscreen state of the frame
after invoking the @code{toggle-frame-fullscreen} command (@pxref{Frame
Commands,,, emacs, The GNU Emacs Manual}) in the ``fullboth'' state.
Normally this parameter is installed automatically by that command when
toggling the state to fullboth. If, however, you start Emacs in the
``fullboth'' state, you have to specify the desired behavior in your initial
file as, for example
@example
(setq default-frame-alist
'((fullscreen . fullboth)
(fullscreen-restore . fullheight)))
@end example
This will give a new frame full height after typing in it @key{F11} for
the first time.
@vindex fit-frame-to-buffer-margins@r{, a frame parameter}
@item fit-frame-to-buffer-margins
This parameter enables overriding the value of the option
@code{fit-frame-to-buffer-margins} when fitting this frame to the
buffer of its root window with @code{fit-frame-to-buffer}
(@pxref{Resizing Windows}).
@vindex fit-frame-to-buffer-sizes@r{, a frame parameter}
@item fit-frame-to-buffer-sizes
This parameter enables overriding the value of the option
@code{fit-frame-to-buffer-sizes} when fitting this frame to the buffer
of its root window with @code{fit-frame-to-buffer} (@pxref{Resizing
Windows}).
@end table
@node Layout Parameters
@subsubsection Layout Parameters
@cindex layout parameters of frames
@cindex frame layout parameters
These frame parameters enable or disable various parts of the
frame, or control their sizes.
@table @code
@vindex border-width@r{, a frame parameter}
@item border-width
The width in pixels of the frame's outer border (@pxref{Frame Geometry}).
@vindex internal-border-width@r{, a frame parameter}
@item internal-border-width
The width in pixels of the frame's internal border (@pxref{Frame
Geometry}).
@vindex child-frame-border-width@r{, a frame parameter}
@item child-frame-border-width
The width in pixels of the frame's internal border (@pxref{Frame
Geometry}) if the given frame is a child frame (@pxref{Child Frames}).
If this is @code{nil}, the value specified by the
@code{internal-border-width} parameter is used instead.
@vindex vertical-scroll-bars@r{, a frame parameter}
@item vertical-scroll-bars
Whether the frame has scroll bars (@pxref{Scroll Bars}) for vertical
scrolling, and which side of the frame they should be on. The possible
values are @code{left}, @code{right}, and @code{nil} for no scroll bars.
@vindex horizontal-scroll-bars@r{, a frame parameter}
@item horizontal-scroll-bars
Whether the frame has scroll bars for horizontal scrolling (@code{t} and
@code{bottom} mean yes, @code{nil} means no).
@vindex scroll-bar-width@r{, a frame parameter}
@item scroll-bar-width
The width of vertical scroll bars, in pixels, or @code{nil} meaning to
use the default width.
@vindex scroll-bar-height@r{, a frame parameter}
@item scroll-bar-height
The height of horizontal scroll bars, in pixels, or @code{nil} meaning
to use the default height.
@vindex left-fringe@r{, a frame parameter}
@vindex right-fringe@r{, a frame parameter}
@item left-fringe
@itemx right-fringe
The default width of the left and right fringes of windows in this
frame (@pxref{Fringes}). If either of these is zero, that effectively
removes the corresponding fringe.
When you use @code{frame-parameter} to query the value of either of
these two frame parameters, the return value is always an integer.
When using @code{set-frame-parameter}, passing a @code{nil} value
imposes an actual default value of 8 pixels.
@vindex right-divider-width@r{, a frame parameter}
@item right-divider-width
The width (thickness) reserved for the right divider (@pxref{Window
Dividers}) of any window on the frame, in pixels. A value of zero means
to not draw right dividers.
@vindex bottom-divider-width@r{, a frame parameter}
@item bottom-divider-width
The width (thickness) reserved for the bottom divider (@pxref{Window
Dividers}) of any window on the frame, in pixels. A value of zero means
to not draw bottom dividers.
@vindex menu-bar-lines@r{, a frame parameter}
@item menu-bar-lines
The number of lines to allocate at the top of the frame for a menu bar
(@pxref{Menu Bar}). The default is one if Menu Bar mode is enabled
and zero otherwise. @xref{Menu Bars,,,emacs, The GNU Emacs Manual}.
For an external menu bar (@pxref{Frame Layout}), this value remains
unchanged even when the menu bar wraps to two or more lines. In that
case, the @code{menu-bar-size} value returned by @code{frame-geometry}
(@pxref{Frame Geometry}) enables you to establish whether the menu bar
actually occupies one or more lines.
@vindex tool-bar-lines@r{, a frame parameter}
@item tool-bar-lines
The number of lines to use for the tool bar (@pxref{Tool Bar}). The
default is one if Tool Bar mode is enabled and zero otherwise.
@xref{Tool Bars,,,emacs, The GNU Emacs Manual}. This value may change
whenever the tool bar wraps (@pxref{Frame Layout}).
@vindex tool-bar-position@r{, a frame parameter}
@item tool-bar-position
The position of the tool bar. Its value can be one of @code{top},
@code{bottom} @code{left}, @code{right}. The default is @code{top}.
It can be set to @code{bottom} on Emacs built with any toolkit other
than Nextstep, and @code{left} or @code{right} on builds using GTK+.
@vindex tab-bar-lines@r{, a frame parameter}
@item tab-bar-lines
The number of lines to use for the tab bar (@pxref{Tab Bars,,,emacs, The
GNU Emacs Manual}). The default is one if Tab Bar mode is enabled and
zero otherwise. This value may change whenever the tab bar wraps
(@pxref{Frame Layout}).
@vindex line-spacing@r{, a frame parameter}
@item line-spacing
Additional space to leave below each text line, in pixels (a positive
integer). @xref{Line Height}, for more information.
@vindex no-special-glyphs@r{, a frame parameter}
@item no-special-glyphs
If this is non-@code{nil}, it suppresses the display of any truncation
(@pxref{Truncation}) and continuation glyphs for all the buffers
displayed by this frame. This is useful to eliminate such glyphs when
fitting a frame to its buffer via @code{fit-frame-to-buffer}
(@pxref{Resizing Windows}). This frame parameter has effect only for
GUI frames shown on graphical displays, and only if the fringes are
disabled. This parameter is intended as a purely-presentation
feature, and in particular should not be used for frames where the
user can interactively insert text, or more generally where the cursor
is shown. A notable example of frames where this is used is tooltip
frames (@pxref{Tooltips}).
@end table
@node Buffer Parameters
@subsubsection Buffer Parameters
@cindex frame, which buffers to display
@cindex buffers to display on frame
These frame parameters, meaningful on all kinds of terminals, deal
with which buffers have been, or should, be displayed in the frame.
@table @code
@vindex minibuffer@r{, a frame parameter}
@item minibuffer
Whether this frame has its own minibuffer. The value @code{t} means
yes, @code{nil} means no, @code{only} means this frame is just a
minibuffer. If the value is a minibuffer window (in some other
frame), the frame uses that minibuffer.
This parameter takes effect when the frame is created. If specified as
@code{nil}, Emacs will try to set it to the minibuffer window of
@code{default-minibuffer-frame} (@pxref{Minibuffers and Frames}). For
an existing frame, this parameter can be used exclusively to specify
another minibuffer window. It is not allowed to change it from a
minibuffer window to @code{t} and vice-versa, or from @code{t} to
@code{nil}. If the parameter specifies a minibuffer window already,
setting it to @code{nil} has no effect.
The special value @code{child-frame} means to make a minibuffer-only
child frame (@pxref{Child Frames}) whose parent becomes the frame
created. As if specified as @code{nil}, Emacs will set this parameter
to the minibuffer window of the child frame but will not select the
child frame after its creation.
@vindex buffer-predicate@r{, a frame parameter}
@item buffer-predicate
The buffer-predicate function for this frame. The function
@code{other-buffer} uses this predicate (from the selected frame) to
decide which buffers it should consider, if the predicate is not
@code{nil}. It calls the predicate with one argument, a buffer, once for
each buffer; if the predicate returns a non-@code{nil} value, it
considers that buffer.
@vindex buffer-list@r{, a frame parameter}
@item buffer-list
A list of buffers that have been selected in this frame, ordered
most-recently-selected first.
@vindex unsplittable@r{, a frame parameter}
@item unsplittable
If non-@code{nil}, this frame's window is never split automatically.
@end table
@node Frame Interaction Parameters
@subsubsection Frame Interaction Parameters
@cindex frame interaction parameters
@cindex interaction parameters between frames
These parameters supply forms of interactions between different frames.
@table @code
@vindex parent-frame@r{, a frame parameter}
@item parent-frame
If non-@code{nil}, this means that this frame is a child frame
(@pxref{Child Frames}), and this parameter specifies its parent frame.
If @code{nil}, this means that this frame is a normal, top-level frame.
@vindex delete-before@r{, a frame parameter}
@item delete-before
If non-@code{nil}, this parameter specifies another frame whose deletion
will automatically trigger the deletion of this frame. @xref{Deleting
Frames}.
@vindex mouse-wheel-frame@r{, a frame parameter}
@item mouse-wheel-frame
If non-@code{nil}, this parameter specifies the frame whose windows will
be scrolled whenever the mouse wheel is scrolled with the mouse pointer
hovering over this frame, see @ref{Mouse Commands,,, emacs, The GNU
Emacs Manual}.
@vindex no-other-frame@r{, a frame parameter}
@item no-other-frame
If this is non-@code{nil}, then this frame is not eligible as candidate
for the functions @code{next-frame}, @code{previous-frame}
(@pxref{Finding All Frames}) and @code{other-frame}, see @ref{Frame
Commands,,, emacs, The GNU Emacs Manual}.
@vindex auto-hide-function@r{, a frame parameter}
@item auto-hide-function
When this parameter specifies a function, that function will be called
instead of the function specified by the variable
@code{frame-auto-hide-function} when quitting the frame's only window
(@pxref{Quitting Windows}) and there are other frames left.
@vindex minibuffer-exit@r{, a frame parameter}
@item minibuffer-exit
When this parameter is non-@code{nil}, Emacs will by default make this
frame invisible whenever the minibuffer (@pxref{Minibuffers}) is exited.
Alternatively, it can specify the functions @code{iconify-frame} and
@code{delete-frame}. This parameter is useful to make a child frame
disappear automatically (similar to how Emacs deals with a window) when
exiting the minibuffer.
@vindex keep-ratio@r{, a frame parameter}
@item keep-ratio
This parameter is currently meaningful for child frames (@pxref{Child
Frames}) only. If it is non-@code{nil}, then Emacs will try to keep the
frame's size (width and height) ratios (@pxref{Size Parameters}) as well
as its left and right position ratios (@pxref{Position Parameters})
unaltered whenever its parent frame is resized.
If the value of this parameter is @code{nil}, the frame's position and
size remain unaltered when the parent frame is resized, so the position
and size ratios may change. If the value of this parameter is @code{t},
Emacs will try to preserve the frame's size and position ratios, hence
the frame's size and position relative to its parent frame may change.
More individual control is possible by using a cons cell: In that case
the frame's width ratio is preserved if the @sc{car} of the cell is
either @code{t} or @code{width-only}. The height ratio is preserved if
the @sc{car} of the cell is either @code{t} or @code{height-only}. The
left position ratio is preserved if the @sc{cdr} of the cell is either
@code{t} or @code{left-only}. The top position ratio is preserved if
the @sc{cdr} of the cell is either @code{t} or @code{top-only}.
@end table
@node Mouse Dragging Parameters
@subsubsection Mouse Dragging Parameters
@cindex mouse dragging parameters
@cindex parameters for resizing frames with the mouse
@cindex parameters for moving frames with the mouse
The parameters described below provide support for resizing a frame by
dragging its internal borders with the mouse. They also allow moving a
frame with the mouse by dragging the header or tab line of its topmost
or the mode line of its bottommost window.
These parameters are mostly useful for child frames (@pxref{Child
Frames}) that come without window manager decorations. If necessary,
they can be used for undecorated top-level frames as well.
@table @code
@vindex drag-internal-border@r{, a frame parameter}
@item drag-internal-border
If non-@code{nil}, the frame can be resized by dragging its internal
borders, if present, with the mouse.
@vindex drag-with-header-line@r{, a frame parameter}
@item drag-with-header-line
If non-@code{nil}, the frame can be moved with the mouse by dragging the
header line of its topmost window.
@vindex drag-with-tab-line@r{, a frame parameter}
@item drag-with-tab-line
If non-@code{nil}, the frame can be moved with the mouse by dragging the
tab line of its topmost window.
@vindex drag-with-mode-line@r{, a frame parameter}
@item drag-with-mode-line
If non-@code{nil}, the frame can be moved with the mouse by dragging the
mode line of its bottommost window. Note that such a frame is not
allowed to have its own minibuffer window.
@vindex snap-width@r{, a frame parameter}
@item snap-width
A frame that is moved with the mouse will ``snap'' at the border(s) of
the display or its parent frame whenever it is dragged as near to such
an edge as the number of pixels specified by this parameter.
@vindex top-visible@r{, a frame parameter}
@item top-visible
If this parameter is a number, the top edge of the frame never appears
above the top edge of its display or parent frame. Moreover, as many
pixels of the frame as specified by that number will remain visible when
the frame is moved against any of the remaining edges of its display or
parent frame. Setting this parameter is useful to guard against
dragging a child frame with a non-@code{nil}
@code{drag-with-header-line} parameter completely out of the area
of its parent frame.
@vindex bottom-visible@r{, a frame parameter}
@item bottom-visible
If this parameter is a number, the bottom edge of the frame never
appears below the bottom edge of its display or parent frame. Moreover,
as many pixels of the frame as specified by that number will remain
visible when the frame is moved against any of the remaining edges of
its display or parent frame. Setting this parameter is useful to guard
against dragging a child frame with a non-@code{nil}
@code{drag-with-mode-line} parameter completely out of the area of
its parent frame.
@end table
@node Management Parameters
@subsubsection Window Management Parameters
@cindex window manager interaction, and frame parameters
The following frame parameters control various aspects of the frame's
interaction with the window manager or window system. They have no
effect on text terminals.
@table @code
@vindex visibility@r{, a frame parameter}
@item visibility
The state of visibility of the frame. There are three possibilities:
@code{nil} for invisible, @code{t} for visible, and @code{icon} for
iconified. @xref{Visibility of Frames}.
@vindex auto-raise@r{, a frame parameter}
@item auto-raise
If non-@code{nil}, Emacs automatically raises the frame when it is
selected. Some window managers do not allow this.
@vindex auto-lower@r{, a frame parameter}
@item auto-lower
If non-@code{nil}, Emacs automatically lowers the frame when it is
deselected. Some window managers do not allow this.
@vindex icon-type@r{, a frame parameter}
@item icon-type
The type of icon to use for this frame. If the value is a string,
that specifies a file containing a bitmap to use; @code{nil} specifies
no icon (in which case the window manager decides what to show); any
other non-@code{nil} value specifies the default Emacs icon.
@vindex icon-name@r{, a frame parameter}
@item icon-name
The name to use in the icon for this frame, when and if the icon
appears. If this is @code{nil}, the frame's title is used.
@vindex window-id@r{, a frame parameter}
@item window-id
The ID number which the graphical display uses for this frame. Emacs
assigns this parameter when the frame is created; changing the
parameter has no effect on the actual ID number.
@vindex outer-window-id@r{, a frame parameter}
@item outer-window-id
The ID number of the outermost window-system window in which the frame
exists. As with @code{window-id}, changing this parameter has no
actual effect.
@vindex wait-for-wm@r{, a frame parameter}
@item wait-for-wm
If non-@code{nil}, tell Xt to wait for the window manager to confirm
geometry changes. Some window managers, including versions of Fvwm2
and KDE, fail to confirm, so Xt hangs. Set this to @code{nil} to
prevent hanging with those window managers.
@vindex sticky@r{, a frame parameter}
@item sticky
If non-@code{nil}, the frame is visible on all virtual desktops on systems
with virtual desktops.
@vindex shaded@r{, a frame parameter}
@item shaded
If non-@code{nil}, tell the window manager to display the frame in a
way that its contents are hidden, leaving only the title bar.
@vindex use-frame-synchronization@r{, a frame parameter}
@item use-frame-synchronization
If non-@code{nil}, synchronize the frame redisplay with the refresh
rate of the monitor to avoid graphics tearing. At present, this is
only implemented on Haiku and the X window system inside no-toolkit
and X toolkit builds, does not work correctly with toolkit scroll
bars, and requires a compositing manager supporting the relevant
display synchronization protocols. The @code{synchronizeResize} X
resource must also be set to the string @code{"extended"}.
@vindex inhibit-double-buffering@r{, a frame parameter}
@item inhibit-double-buffering
If non-@code{nil}, the frame is drawn to the screen without double
buffering. Emacs normally attempts to use double buffering, where
available, to reduce flicker; nevertheless, this parameter is provided
for circumstances where double-buffering induces display corruption,
and for those eccentrics wistful for the immemorial flicker that once
beset Emacs.
@vindex skip-taskbar@r{, a frame parameter}
@item skip-taskbar
If non-@code{nil}, this tells the window manager to remove the frame's
icon from the taskbar associated with the frame's display and inhibit
switching to the frame's window via the combination @kbd{Alt-@key{TAB}}.
On MS-Windows, iconifying such a frame will "roll in" its window-system
window at the bottom of the desktop. Some window managers may not honor
this parameter.
@vindex no-focus-on-map@r{, a frame parameter}
@item no-focus-on-map
If non-@code{nil}, this means that the frame does not want to receive
input focus when it is mapped (@pxref{Visibility of Frames}). Some
window managers may not honor this parameter.
@vindex no-accept-focus@r{, a frame parameter}
@item no-accept-focus
If non-@code{nil}, this means that the frame does not want to receive
input focus via explicit mouse clicks or when moving the mouse into it
either via @code{focus-follows-mouse} (@pxref{Input Focus}) or
@code{mouse-autoselect-window} (@pxref{Mouse Window Auto-selection}).
This may have the unwanted side-effect that a user cannot scroll a
non-selected frame with the mouse. Some window managers may not honor
this parameter. On Haiku, it also has the side-effect that the window
will not be able to receive any keyboard input from the user, not even
if the user switches to the frame using the key combination
@kbd{Alt-@key{TAB}}.
@vindex undecorated@r{, a frame parameter}
@item undecorated
If non-@code{nil}, this frame's window-system window is drawn without
decorations, like the title, minimize/maximize boxes and external
borders. This usually means that the window cannot be dragged, resized,
iconified, maximized or deleted with the mouse. If @code{nil}, the frame's
window is usually drawn with all the elements listed above unless their
display has been suspended via window manager settings.
Under X, Emacs uses the Motif window manager hints to turn off
decorations. Some window managers may not honor these hints.
NS builds consider the tool bar to be a decoration, and therefore hide
it on an undecorated frame.
@vindex override-redirect@r{, a frame parameter}
@item override-redirect
@cindex override redirect frames
If non-@code{nil}, this means that this is an @dfn{override redirect}
frame---a frame not handled by window managers under X@. Override
redirect frames have no window manager decorations, can be positioned
and resized only via Emacs's positioning and resizing functions and are
usually drawn on top of all other frames. Setting this parameter has
no effect on MS-Windows.
@ignore
@vindex parent-id@r{, a frame parameter}
@item parent-id
@c ??? Not yet working.
The X window number of the window that should be the parent of this one.
Specifying this lets you create an Emacs window inside some other
application's window. (It is not certain this will be implemented; try
it and see if it works.)
@end ignore
@vindex ns-appearance@r{, a frame parameter}
@item ns-appearance
Only available on macOS, if set to @code{dark} draw this frame's
window-system window using the ``vibrant dark'' theme, and if set to
@code{light} use the ``aqua'' theme, otherwise use the system default.
The ``vibrant dark'' theme can be used to set the toolbar and
scrollbars to a dark appearance when using an Emacs theme with a dark
background.
@vindex ns-transparent-titlebar@r{, a frame parameter}
@item ns-transparent-titlebar
Only available on macOS, if non-@code{nil}, set the titlebar and
toolbar to be transparent. This effectively sets the background color
of both to match the Emacs background color.
@end table
@node Cursor Parameters
@subsubsection Cursor Parameters
@cindex cursor, and frame parameters
This frame parameter controls the way the cursor looks.
@table @code
@vindex cursor-type@r{, a frame parameter}
@item cursor-type
How to display the cursor. Legitimate values are:
@table @code
@item box
Display a filled box. (This is the default.)
@item (box . @var{size})
Display a filled box. However, display it as a hollow box if point is
under masked image larger than @var{size} pixels in either dimension.
@item hollow
Display a hollow box.
@item nil
Don't display a cursor.
@item bar
Display a vertical bar between characters.
@item (bar . @var{width})
Display a vertical bar @var{width} pixels wide between characters.
@item hbar
Display a horizontal bar.
@item (hbar . @var{height})
Display a horizontal bar @var{height} pixels high.
@end table
@end table
@vindex cursor-type
The @code{cursor-type} frame parameter may be overridden by
@code{set-window-cursor-type} (@pxref{Window Point}), and by the
variables @code{cursor-type} and @code{cursor-in-non-selected-windows}:
@defopt cursor-type
This buffer-local variable controls how the cursor looks in a selected
window showing the buffer. If its value is @code{t}, that means to
use the cursor specified by the @code{cursor-type} frame parameter.
Otherwise, the value should be one of the cursor types listed above,
and it overrides the @code{cursor-type} frame parameter.
@end defopt
@defopt cursor-in-non-selected-windows
This buffer-local variable controls how the cursor looks in a window
that is not selected. It supports the same values as the
@code{cursor-type} frame parameter; also, @code{nil} means don't
display a cursor in nonselected windows, and @code{t} (the default)
means use a standard modification of the usual cursor type (solid box
becomes hollow box, and bar becomes a narrower bar).
@end defopt
@defopt x-stretch-cursor
This variable controls the width of the block cursor displayed on
extra-wide glyphs such as a tab or a stretch of white space. By
default, the block cursor is only as wide as the font's default
character, and will not cover all of the width of the glyph under it
if that glyph is extra-wide. A non-@code{nil} value of this variable
means draw the block cursor as wide as the glyph under it. The
default value is @code{nil}.
This variable has no effect on text-mode frames, since the text-mode
cursor is drawn by the terminal out of Emacs's control.
@end defopt
@defopt blink-cursor-alist
This variable specifies how to blink the cursor. Each element has the
form @code{(@var{on-state} . @var{off-state})}. Whenever the cursor
type equals @var{on-state} (comparing using @code{equal}), the
corresponding @var{off-state} specifies what the cursor looks like
when it blinks off. Both @var{on-state} and @var{off-state}
should be suitable values for the @code{cursor-type} frame parameter.
There are various defaults for how to blink each type of cursor, if
the type is not mentioned as an @var{on-state} here. Changes in this
variable do not take effect immediately, only when you specify the
@code{cursor-type} frame parameter.
@end defopt
@node Font and Color Parameters
@subsubsection Font and Color Parameters
@cindex font and color, frame parameters
These frame parameters control the use of fonts and colors.
@table @code
@vindex font-backend@r{, a frame parameter}
@item font-backend
A list of symbols, specifying the @dfn{font backends} to use for
drawing characters on the frame, in order of priority. In Emacs built
without Cairo drawing on X, there are currently three potentially
available font backends: @code{x} (the X core font driver), @code{xft}
(the Xft font driver), and @code{xfthb} (the Xft font driver with
HarfBuzz text shaping). If built with Cairo drawing, there are also
three potentially available font backends on X: @code{x}, @code{ftcr}
(the FreeType font driver on Cairo), and @code{ftcrhb} (the FreeType
font driver on Cairo with HarfBuzz text shaping). When Emacs is built
with HarfBuzz, the default font driver is @code{ftcrhb}, although use
of the @code{ftcr} driver is still possible, but not recommended. On
MS-Windows, there are currently three available font backends:
@code{gdi} (the core MS-Windows font driver), @code{uniscribe} (font
driver for OTF and TTF fonts with text shaping by the Uniscribe
engine), and @code{harfbuzz} (font driver for OTF and TTF fonts with
HarfBuzz text shaping) (@pxref{Windows Fonts,,, emacs, The GNU Emacs
Manual}). The @code{harfbuzz} driver is similarly recommended. On
Haiku, there can be several font drivers (@pxref{Haiku Fonts,,, emacs,
The GNU Emacs Manual}), as on Android (@pxref{Android Fonts,,, emacs,
The GNU Emacs Manual}).
On other systems, there is only one available font backend, so it does
not make sense to modify this frame parameter.
@vindex background-mode@r{, a frame parameter}
@item background-mode
This parameter is either @code{dark} or @code{light}, according
to whether the background color is a light one or a dark one.
@vindex tty-color-mode@r{, a frame parameter}
@item tty-color-mode
@cindex standard colors for character terminals
This parameter overrides the terminal's color support as given by the
system's terminal capabilities database in that this parameter's value
specifies the color mode to use on a text terminal. The value can be
either a symbol or a number. A number specifies the number of colors
to use (and, indirectly, what commands to issue to produce each
color). For example, @code{(tty-color-mode . 8)} specifies use of the
ANSI escape sequences for 8 standard text colors. A value of @minus{}1 turns
off color support.
If the parameter's value is a symbol, it specifies a number through
the value of @code{tty-color-mode-alist}, and the associated number is
used instead. This parameter supports dynamic changes during a running
Emacs session (but not on MS-Windows and MS-DOS).
@vindex screen-gamma@r{, a frame parameter}
@item screen-gamma
@cindex gamma correction
If this is a number, Emacs performs gamma correction which adjusts
the brightness of all colors. The value should be the screen gamma of
your display.
Usual PC monitors have a screen gamma of 2.2, so color values in
Emacs, and in X windows generally, are calibrated to display properly
on a monitor with that gamma value. If you specify 2.2 for
@code{screen-gamma}, that means no correction is needed. Other values
request correction, designed to make the corrected colors appear on
your screen the way they would have appeared without correction on an
ordinary monitor with a gamma value of 2.2.
If your monitor displays colors too light, you should specify a
@code{screen-gamma} value smaller than 2.2. This requests correction
that makes colors darker. A screen gamma value of 1.5 may give good
results for LCD color displays.
@vindex alpha@r{, a frame parameter}
@item alpha
@cindex opacity, frame
@cindex transparency, frame
@vindex frame-alpha-lower-limit
This parameter specifies the opacity of the frame, on graphical
displays that support variable opacity. It should be an integer
between 0 and 100, where 0 means completely transparent and 100 means
completely opaque. It can also have a @code{nil} value, which tells
Emacs not to set the frame opacity (leaving it to the window manager).
To prevent the frame from disappearing completely from view, the
variable @code{frame-alpha-lower-limit} defines a lower opacity limit.
If the value of the frame parameter is less than the value of this
variable, Emacs uses the latter. By default,
@code{frame-alpha-lower-limit} is 20.
The @code{alpha} frame parameter can also be a cons cell
@code{(@var{active} . @var{inactive})}, where @var{active} is the
opacity of the frame when it is selected, and @var{inactive} is the
opacity when it is not selected.
Some window systems do not support the @code{alpha} parameter for child
frames (@pxref{Child Frames}).
@vindex alpha-background@r{, a frame parameter}
@item alpha-background
@cindex opacity, frame
@cindex transparency, frame
Sets the background transparency of the frame. Unlike the @code{alpha}
frame parameter, this only controls the transparency of the background
while keeping foreground elements such as text fully opaque. It
should be an integer between 0 and 100, where 0 means
completely transparent and 100 means completely opaque (default).
@end table
The following frame parameters are semi-obsolete in that they are
automatically equivalent to particular face attributes of particular
faces (@pxref{Standard Faces,,, emacs, The Emacs Manual}):
@table @code
@vindex font@r{, a frame parameter}
@item font
The name of the font for displaying text in the frame. This is a
string, either a valid font name for your system or the name of an Emacs
fontset (@pxref{Fontsets}). It is equivalent to the @code{font}
attribute of the @code{default} face.
@vindex foreground-color@r{, a frame parameter}
@item foreground-color
The color to use for characters. It is equivalent to
the @code{:foreground} attribute of the @code{default} face.
@vindex background-color@r{, a frame parameter}
@item background-color
The color to use for the background of characters. It is equivalent to
the @code{:background} attribute of the @code{default} face.
@vindex mouse-color@r{, a frame parameter}
@vindex mouse@r{, a face}
@item mouse-color
The color for the mouse pointer. It is equivalent to the @code{:background}
attribute of the @code{mouse} face.
@vindex cursor-color@r{, a frame parameter}
@item cursor-color
The color for the cursor that shows point. It is equivalent to the
@code{:background} attribute of the @code{cursor} face.
@vindex border-color@r{, a frame parameter}
@item border-color
The color for the border of the frame. It is equivalent to the
@code{:background} attribute of the @code{border} face.
@vindex scroll-bar-foreground@r{, a frame parameter}
@item scroll-bar-foreground
If non-@code{nil}, the color for the foreground of scroll bars. It is
equivalent to the @code{:foreground} attribute of the
@code{scroll-bar} face.
@vindex scroll-bar-background@r{, a frame parameter}
@item scroll-bar-background
If non-@code{nil}, the color for the background of scroll bars. It is
equivalent to the @code{:background} attribute of the
@code{scroll-bar} face.
@end table
@node Geometry
@subsection Geometry
Here's how to examine the data in an X-style window geometry
specification:
@defun x-parse-geometry geom
@cindex geometry specification
The function @code{x-parse-geometry} converts a standard X window
geometry string to an alist that you can use as part of the argument to
@code{make-frame}.
The alist describes which parameters were specified in @var{geom}, and
gives the values specified for them. Each element looks like
@code{(@var{parameter} . @var{value})}. The possible @var{parameter}
values are @code{left}, @code{top}, @code{width}, and @code{height}.
For the size parameters, the value must be an integer. The position
parameter names @code{left} and @code{top} are not totally accurate,
because some values indicate the position of the right or bottom edges
instead. The @var{value} possibilities for the position parameters are:
an integer, a list @code{(+ @var{pos})}, or a list @code{(- @var{pos})};
as previously described (@pxref{Position Parameters}).
Here is an example:
@example
(x-parse-geometry "35x70+0-0")
@result{} ((height . 70) (width . 35)
(top - 0) (left . 0))
@end example
@end defun
@node Terminal Parameters
@section Terminal Parameters
@cindex terminal parameters
Each terminal has a list of associated parameters. These
@dfn{terminal parameters} are mostly a convenient way of storage for
terminal-local variables, but some terminal parameters have a special
meaning.
This section describes functions to read and change the parameter values
of a terminal. They all accept as their argument either a terminal or
a frame; the latter means use that frame's terminal. An argument of
@code{nil} means the selected frame's terminal.
@defun terminal-parameters &optional terminal
This function returns an alist listing all the parameters of
@var{terminal} and their values.
@end defun
@defun terminal-parameter terminal parameter
This function returns the value of the parameter @var{parameter} (a
symbol) of @var{terminal}. If @var{terminal} has no setting for
@var{parameter}, this function returns @code{nil}.
@end defun
@defun set-terminal-parameter terminal parameter value
This function sets the parameter @var{parameter} of @var{terminal} to the
specified @var{value}, and returns the previous value of that
parameter.
@end defun
Here's a list of a few terminal parameters that have a special
meaning:
@table @code
@item background-mode
The classification of the terminal's background color, either
@code{light} or @code{dark}.
@item normal-erase-is-backspace
Value is either 1 or 0, depending on whether
@code{normal-erase-is-backspace-mode} is turned on or off on this
terminal. @xref{DEL Does Not Delete,,, emacs, The Emacs Manual}.
@item terminal-initted
After the terminal is initialized, this is set to the
terminal-specific initialization function.
@item tty-mode-set-strings
When present, a list of strings containing escape sequences that Emacs
will output while configuring a tty for rendering. Emacs emits these
strings only when configuring a terminal: if you want to enable a mode
on a terminal that is already active (for example, while in
@code{tty-setup-hook}), explicitly output the necessary escape
sequence using @code{send-string-to-terminal} in addition to adding
the sequence to @code{tty-mode-set-strings}.
@item tty-mode-reset-strings
When present, a list of strings that undo the effects of the strings
in @code{tty-mode-set-strings}. Emacs emits these strings when
exiting, deleting a terminal, or suspending itself.
@end table
@node Frame Titles
@section Frame Titles
@cindex frame title
Every frame has a @code{name} parameter; this serves as the default
for the frame title which window systems typically display at the top of
the frame. You can specify a name explicitly by setting the @code{name}
frame property.
Normally you don't specify the name explicitly, and Emacs computes the
frame name automatically based on a template stored in the variable
@code{frame-title-format}. Emacs recomputes the name each time the
frame is redisplayed.
@defvar frame-title-format
This variable specifies how to compute a name for a frame when you
have not explicitly specified one (via the frame's parameters;
@pxref{Basic Parameters}). The variable's value is actually a mode
line construct, just like @code{mode-line-format}, except that the
@samp{%c}, @samp{%C}, and @samp{%l} constructs are ignored.
@xref{Mode Line Data}.
@end defvar
@defvar icon-title-format
This variable specifies how to compute the name for an iconified frame
when you have not explicitly specified the frame's name via the
frame's parameters. The resulting title appears in the frame's icon
itself. If the value is a string, is should be a mode line construct
like that of @code{frame-title-format}. The value can also be
@code{t}, which means to use @code{frame-title-format} instead; this
avoids problems with some window managers and desktop environments,
where a change in a frame's title (when a frame is iconified) is
interpreted as a request to raise the frame and/or give it input
focus. It is also useful if you want the frame's title to be the same
no matter if the frame is iconified or not. The default value is a
string identical to the default value of @code{frame-title-format}.
@end defvar
@defvar multiple-frames
This variable is set automatically by Emacs. Its value is @code{t} when
there are two or more frames (not counting minibuffer-only frames or
invisible frames). The default value of @code{frame-title-format} uses
@code{multiple-frames} so as to put the buffer name in the frame title
only when there is more than one frame.
The value of this variable is not guaranteed to be accurate except
while processing @code{frame-title-format} or
@code{icon-title-format}.
@end defvar
@node Deleting Frames
@section Deleting Frames
@cindex deleting frames
A @dfn{live frame} is one that has not been deleted. When a frame is
deleted, it is removed from its terminal display, although it may
continue to exist as a Lisp object until there are no more references to
it.
@deffn Command delete-frame &optional frame force
@vindex delete-frame-functions
@vindex after-delete-frame-functions
This function deletes the frame @var{frame}. The argument @var{frame}
must specify a live frame (see below) and defaults to the selected
frame.
It first deletes any child frame of @var{frame} (@pxref{Child Frames})
and any frame whose @code{delete-before} frame parameter (@pxref{Frame
Interaction Parameters}) specifies @var{frame}. All such deletions are
performed recursively; so this step makes sure that no other frames with
@var{frame} as their ancestor will exist. Then, unless @var{frame}
specifies a tooltip, this function runs the hook
@code{delete-frame-functions} (each function getting one argument,
@var{frame}) before actually killing the frame. After actually killing
the frame and removing the frame from the frame list, @code{delete-frame}
runs @code{after-delete-frame-functions}.
Note that a frame cannot be deleted as long as its minibuffer serves as
surrogate minibuffer for another frame (@pxref{Minibuffers and Frames}).
Normally, you cannot delete a frame if all other frames are invisible,
but if @var{force} is non-@code{nil}, then you are allowed to do so.
@end deffn
@defun frame-live-p frame
This function returns non-@code{nil} if the frame @var{frame} has not
been deleted. The possible non-@code{nil} return values are like those
of @code{framep}. @xref{Frames}.
@end defun
Some window managers provide a command to delete a window. These work
by sending a special message to the program that operates the window.
When Emacs gets one of these commands, it generates a
@code{delete-frame} event, whose normal definition is a command that
calls the function @code{delete-frame}. @xref{Misc Events}.
@deffn Command delete-other-frames &optional frame iconify
This command deletes all frames on @var{frame}'s terminal, except
@var{frame}. If @var{frame} uses another frame's minibuffer, that
minibuffer frame is left untouched. The argument @var{frame} must
specify a live frame and defaults to the selected frame. Internally,
this command works by calling @code{delete-frame} with @var{force}
@code{nil} for all frames that shall be deleted.
This function does not delete any of @var{frame}'s child frames
(@pxref{Child Frames}). If @var{frame} is a child frame, it deletes
@var{frame}'s siblings only.
With the prefix argument @var{iconify}, the frames are iconified rather
than deleted.
@end deffn
The following function checks whether a frame can be safely deleted. It
is useful to avoid that a subsequent call of @code{delete-frame} throws
an error.
@defun frame-deletable-p &optional frame
This function returns non-@code{nil} if the frame specified by
@var{frame} can be safely deleted. @var{frame} must be a live frame and
defaults to the selected frame.
A frame cannot be safely deleted in the following cases:
@itemize @bullet
@item
It is the only visible or iconified frame (@pxref{Visibility of
Frames}).
@item
It hosts the active minibuffer window and minibuffer windows do not
follow the selected frame (@pxref{Basic Minibuffer,,, emacs}).
@item
All other visible or iconified frames are either child frames
(@pxref{Child Frames}) or have a non-@code{nil} @code{delete-before}
parameter.
@item
The frame or one of its descendants hosts the minibuffer window of a
frame that is not a descendant of the frame (@pxref{Child Frames}).
@end itemize
These conditions cover most cases where @code{delete-frame} might fail
when called from top-level. They do not catch some special cases like,
for example, deleting a frame during a drag-and-drop operation
(@pxref{Drag and Drop}). In any such case, it will be better to wrap
the @code{delete-frame} call in a @code{condition-case} form.
@end defun
@node Finding All Frames
@section Finding All Frames
@cindex frames, scanning all
@defun frame-list
This function returns a list of all the live frames, i.e., those that
have not been deleted. It is analogous to @code{buffer-list} for
buffers, and includes frames on all terminals. The list that you get
is newly created, so modifying the list doesn't have any effect on the
internals of Emacs.
@end defun
@defun visible-frame-list
This function returns a list of just the currently visible frames.
@xref{Visibility of Frames}. Frames on text terminals always count as
visible, even though only the selected one is actually displayed.
@end defun
@defun frame-list-z-order &optional display
This function returns a list of Emacs's frames, in Z (stacking) order
(@pxref{Raising and Lowering}). The optional argument @var{display}
specifies which display to poll. @var{display} should be either a frame
or a display name (a string). If omitted or @code{nil}, that stands for
the selected frame's display. It returns @code{nil} if @var{display}
contains no Emacs frame.
Frames are listed from topmost (first) to bottommost (last). As a
special case, if @var{display} is non-@code{nil} and specifies a live
frame, it returns the child frames of that frame in Z (stacking) order.
This function is not meaningful on text terminals.
@end defun
@defun next-frame &optional frame minibuf
This function lets you cycle conveniently through all the frames on a
specific terminal from an arbitrary starting point. It returns the
frame following @var{frame}, in the list of all live frames, on
@var{frame}'s terminal. The argument @var{frame} must specify a live
frame and defaults to the selected frame. It never returns a frame
whose @code{no-other-frame} parameter (@pxref{Frame Interaction
Parameters}) is non-@code{nil}.
The second argument, @var{minibuf}, says which frames to consider when
deciding what the next frame should be:
@table @asis
@item @code{nil}
Consider all frames except minibuffer-only frames.
@item @code{visible}
Consider only visible frames.
@item 0
Consider only visible or iconified frames.
@item a window
Consider only the frames using that particular window as their
minibuffer window.
@item anything else
Consider all frames.
@end table
@end defun
@defun previous-frame &optional frame minibuf
Like @code{next-frame}, but cycles through all frames in the opposite
direction.
@end defun
See also @code{next-window} and @code{previous-window}, in @ref{Cyclic
Window Ordering}.
Some Lisp programs need to find one or more frames that satisfy a
given criteria. The function @code{filtered-frame-list} is provided for
this purpose.
@defun filtered-frame-list predicate
This function returns the list of all the live frames which satisfy the
specified @var{predicate}. The argument @var{predicate} must be a
function of one argument, a frame to be tested against the filtering
criteria, and should return non-@code{nil} if the frame satisfies the
criteria.
@end defun
@node Minibuffers and Frames
@section Minibuffers and Frames
Normally, each frame has its own minibuffer window at the bottom, which
is used whenever that frame is selected. You can get that window with
the function @code{minibuffer-window} (@pxref{Minibuffer Windows}).
@cindex frame without a minibuffer
@cindex surrogate minibuffer frame
However, you can also create a frame without a minibuffer. Such a frame
must use the minibuffer window of some other frame. That other frame
will serve as @dfn{surrogate minibuffer frame} for this frame and cannot
be deleted via @code{delete-frame} (@pxref{Deleting Frames}) as long as
this frame is live.
When you create the frame, you can explicitly specify its minibuffer
window (in some other frame) with the @code{minibuffer} frame parameter
(@pxref{Buffer Parameters}). If you don't, then the minibuffer is found
in the frame which is the value of the variable
@code{default-minibuffer-frame}. Its value should be a frame that does
have a minibuffer.
If you use a minibuffer-only frame, you might want that frame to raise
when you enter the minibuffer. If so, set the variable
@code{minibuffer-auto-raise} to @code{t}. @xref{Raising and Lowering}.
@defvar default-minibuffer-frame
This variable specifies the frame to use for the minibuffer window, by
default. It does not affect existing frames. It is always local to
the current terminal and cannot be buffer-local. @xref{Multiple
Terminals}.
@end defvar
@node Input Focus
@section Input Focus
@cindex input focus
@cindex selected frame
At any time, one frame in Emacs is the @dfn{selected frame}. The
selected window (@pxref{Selecting Windows}) always resides on the
selected frame.
When Emacs displays its frames on several terminals (@pxref{Multiple
Terminals}), each terminal has its own selected frame. But only one
of these is @emph{the} selected frame: it's the frame that belongs
to the terminal from which the most recent input came. That is, when
Emacs runs a command that came from a certain terminal, the selected
frame is the one of that terminal. Since Emacs runs only a single
command at any given time, it needs to consider only one selected
frame at a time; this frame is what we call @dfn{the selected frame}
in this manual. The display on which the selected frame is shown is
the @dfn{selected frame's display}.
@defun selected-frame
This function returns the selected frame.
@end defun
Some window systems and window managers direct keyboard input to the
window object that the mouse is in; others require explicit clicks or
commands to @dfn{shift the focus} to various window objects. Either
way, Emacs automatically keeps track of which frames have focus. To
explicitly switch to a different frame from a Lisp function, call
@code{select-frame-set-input-focus}.
The plural ``frames'' in the previous paragraph is deliberate: while
Emacs itself has only one selected frame, Emacs can have frames on
many different terminals (recall that a connection to a window system
counts as a terminal), and each terminal has its own idea of which
frame has input focus. Under the X Window System, where user input is
organized into individual ``seats'' of input, each seat in turn can
have its own specific input focus. When you set the input focus to a
frame, you set the focus for that frame's terminal on the last seat
which interacted with Emacs, but frames on other terminals and seats
may still remain focused.
If the input focus is set before any user interaction has occurred on
the specified terminal, then the X server picks a random seat
(normally the one with the lowest number) and sets the input focus
there.
Lisp programs can switch frames temporarily by calling the function
@code{select-frame}. This does not alter the window system's concept
of focus; rather, it escapes from the window manager's control until
that control is somehow reasserted.
When using a text terminal, only one frame can be displayed at a time
on the terminal, so after a call to @code{select-frame}, the next
redisplay actually displays the newly selected frame. This frame
remains selected until a subsequent call to @code{select-frame}. Each
frame on a text terminal has a number which appears in the mode line
before the buffer name (@pxref{Mode Line Variables}).
@defun select-frame-set-input-focus frame &optional norecord
This function selects @var{frame}, raises it (should it happen to be
obscured by other frames) and tries to give it the window system's
focus. On a text terminal, the next redisplay displays the new frame
on the entire terminal screen. The optional argument @var{norecord}
has the same meaning as for @code{select-frame} (see below).
The return value of this function is not significant.
@end defun
Ideally, the function described next should focus a frame without also
raising it above other frames. Unfortunately, many window-systems or
window managers may refuse to comply.
@defun x-focus-frame frame &optional noactivate
This function gives @var{frame} the focus of the X server without
necessarily raising it. @var{frame} @code{nil} means use the selected
frame. Under X, the optional argument @var{noactivate}, if
non-@code{nil}, means to avoid making @var{frame}'s window-system window
the ``active'' window which should insist a bit more on avoiding to
raise @var{frame} above other frames.
On MS-Windows the @var{noactivate} argument has no effect. However, if
@var{frame} is a child frame (@pxref{Child Frames}), this function
usually focuses @var{frame} without raising it above other child
frames.
If there is no window system support, this function does nothing.
@end defun
@deffn Command select-frame frame &optional norecord
This function selects frame @var{frame}, temporarily disregarding the
focus of the X server if any. The selection of @var{frame} lasts until
the next time the user does something to select a different frame, or
until the next time this function is called. (If you are using a
window system, the previously selected frame may be restored as the
selected frame after return to the command loop, because it still may
have the window system's input focus.)
The specified @var{frame} becomes the selected frame, and its terminal
becomes the selected terminal. This function then calls
@code{select-window} as a subroutine, passing the window selected
within @var{frame} as its first argument and @var{norecord} as its
second argument (hence, if @var{norecord} is non-@code{nil}, this
avoids changing the order of recently selected windows and the buffer
list). @xref{Selecting Windows}.
This function returns @var{frame}, or @code{nil} if @var{frame} has
been deleted.
In general, you should never use @code{select-frame} in a way that
could switch to a different terminal without switching back when
you're done.
@end deffn
@cindex text-terminal focus notification
Emacs cooperates with the window system by arranging to select frames
as the server and window manager request. When a window system
informs Emacs that one of its frames has been selected, Emacs
internally generates a @dfn{focus-in} event. When an Emacs frame is
displayed on a text-terminal emulator, such as @command{xterm}, which
supports reporting of focus-change notification, the focus-in and
focus-out events are available even for text-mode frames. Focus
events are normally handled by @code{handle-focus-in}.
@deffn Command handle-focus-in event
This function handles focus-in events from window systems and
terminals that support explicit focus notifications. It updates the
per-frame focus flags that @code{frame-focus-state} queries and calls
@code{after-focus-change-function}. In addition, it generates a
@code{switch-frame} event in order to switch the Emacs notion of the
selected frame to the frame most recently focused in some terminal.
It's important to note that this switching of the Emacs selected frame
to the most recently focused frame does not mean that other frames do
not continue to have the focus in their respective terminals. Do not
invoke this function yourself: instead, attach logic to
@code{after-focus-change-function}.
@end deffn
@deffn Command handle-switch-frame frame
This function handles a switch-frame event, which Emacs generates for
itself upon focus notification or under various other circumstances
involving an input event arriving at a different frame from the last
event. Do not invoke this function yourself.
@end deffn
@defun redirect-frame-focus frame &optional focus-frame
This function redirects focus from @var{frame} to @var{focus-frame}.
This means that @var{focus-frame} will receive subsequent keystrokes and
events intended for @var{frame}. After such an event, the value of
@code{last-event-frame} will be @var{focus-frame}. Also, switch-frame
events specifying @var{frame} will instead select @var{focus-frame}.
If @var{focus-frame} is omitted or @code{nil}, that cancels any existing
redirection for @var{frame}, which therefore once again receives its own
events.
One use of focus redirection is for frames that don't have minibuffers.
These frames use minibuffers on other frames. Activating a minibuffer
on another frame redirects focus to that frame. This puts the focus on
the minibuffer's frame, where it belongs, even though the mouse remains
in the frame that activated the minibuffer.
Selecting a frame can also change focus redirections. Selecting frame
@code{bar}, when @code{foo} had been selected, changes any redirections
pointing to @code{foo} so that they point to @code{bar} instead. This
allows focus redirection to work properly when the user switches from
one frame to another using @code{select-window}.
This means that a frame whose focus is redirected to itself is treated
differently from a frame whose focus is not redirected.
@code{select-frame} affects the former but not the latter.
The redirection lasts until @code{redirect-frame-focus} is called to
change it.
@end defun
@defun frame-focus-state frame
This function retrieves the last known focus state of @var{frame}.
It returns @code{nil} if the frame is known not to be focused,
@code{t} if the frame is known to be focused, or @code{unknown} if
Emacs does not know the focus state of the frame. (You may see this
last state in TTY frames running on terminals that do not support
explicit focus notifications.)
@end defun
@defvar after-focus-change-function
This function is called with no arguments when Emacs notices that a
frame may have gotten or lost focus. Focus events are delivered
asynchronously, and may not be delivered in the expected order, so
code that wants to do something depending on the state of focused
frames have go through all the frames and check.
For instance, here's a simple example function that sets the
background color based on whether the frame has focus or not:
@lisp
(add-function :after after-focus-change-function
#'my-change-background)
(defun my-change-background ()
(dolist (frame (frame-list))
(pcase (frame-focus-state frame)
(`t (set-face-background 'default "black" frame))
(`nil (set-face-background 'default "#404040" frame)))))
@end lisp
Multiple frames may appear to have input focus simultaneously due to
focus event delivery differences, the presence of multiple Emacs
terminals, and other factors, and code should be robust in the face of
this situation.
Depending on window system, focus events may also be delivered
repeatedly and with different focus states before settling to the
expected values. Code relying on focus notifications should
``debounce'' any user-visible updates arising from focus changes,
perhaps by deferring work until redisplay.
This function may be called in arbitrary contexts, including from
inside @code{read-event}, so take the same care as you might when
writing a process filter.
@end defvar
@defopt focus-follows-mouse
This option informs Emacs whether and how the window manager transfers
focus when you move the mouse pointer into a frame. It can have three
meaningful values:
@table @asis
@item @code{nil}
The default value @code{nil} should be used when your window manager
follows a ``click-to-focus'' policy where you have to click the mouse
inside of a frame in order for that frame to gain focus.
@item @code{t}
The value @code{t} should be used when your window manager has the focus
automatically follow the position of the mouse pointer but a frame that
gains focus is not raised automatically and may even remain occluded by
other window-system windows.
@item @code{auto-raise}
The value @code{auto-raise} should be used when your window manager has
the focus automatically follow the position of the mouse pointer and a
frame that gains focus is raised automatically.
@end table
If this option is non-@code{nil}, Emacs moves the mouse pointer to the
frame selected by @code{select-frame-set-input-focus}. That function is
used by a number of commands like, for example, @code{other-frame} and
@code{pop-to-buffer}.
The distinction between the values @code{t} and @code{auto-raise} is not
needed for ``normal'' frames because the window manager usually takes
care of raising them. It is useful to automatically raise child frames
via @code{mouse-autoselect-window} (@pxref{Mouse Window
Auto-selection}).
Note that this option does not distinguish ``sloppy'' focus (where the
frame that previously had focus retains focus as long as the mouse
pointer does not move into another window-system window) from ``strict''
focus (where a frame immediately loses focus when it's left by the mouse
pointer). Neither does it recognize whether your window manager
supports delayed focusing or auto-raising where you can explicitly
specify the time until a new frame gets focus or is auto-raised.
You can supply a ``focus follows mouse'' policy for individual Emacs
windows by customizing the variable @code{mouse-autoselect-window}
(@pxref{Mouse Window Auto-selection}).
@end defopt
@node Visibility of Frames
@section Visibility of Frames
@cindex visible frame
@cindex invisible frame
@cindex iconified frame
@cindex minimized frame
@cindex frame visibility
A frame on a graphical display may be @dfn{visible}, @dfn{invisible}, or
@dfn{iconified}. If it is visible, its contents are displayed in the
usual manner. If it is iconified, its contents are not displayed, but
there is a little icon somewhere to bring the frame back into view (some
window managers refer to this state as @dfn{minimized} rather than
@dfn{iconified}, but from Emacs's point of view they are the same thing).
If a frame is invisible, it is not displayed at all.
@cindex mapped frame
@cindex unmapped frame
The concept of visibility is strongly related to that of (un-)mapped
frames. A frame (or, more precisely, its window-system window) is and
becomes @dfn{mapped} when it is displayed for the first time and
whenever it changes its state of visibility from @code{iconified} or
@code{invisible} to @code{visible}. Conversely, a frame is and becomes
@dfn{unmapped} whenever it changes its status from @code{visible} to
@code{iconified} or @code{invisible}.
Visibility is meaningless on text terminals, since only the selected
frame is actually displayed in any case.
@defun frame-visible-p frame
This function returns the visibility status of frame @var{frame}. The
value is @code{t} if @var{frame} is visible, @code{nil} if it is
invisible, and @code{icon} if it is iconified.
On a text terminal, all frames are considered visible for the
purposes of this function, even though only one frame is displayed.
@xref{Raising and Lowering}.
@end defun
@deffn Command iconify-frame &optional frame
This function iconifies frame @var{frame}. If you omit @var{frame}, it
iconifies the selected frame. This usually makes all child frames of
@var{frame} (and their descendants) invisible (@pxref{Child Frames}).
@end deffn
@deffn Command make-frame-visible &optional frame
This function makes frame @var{frame} visible. If you omit @var{frame},
it makes the selected frame visible. This does not raise the frame, but
you can do that with @code{raise-frame} if you wish (@pxref{Raising and
Lowering}).
Making a frame visible usually makes all its child frames (and their
descendants) visible as well (@pxref{Child Frames}).
@end deffn
@deffn Command make-frame-invisible &optional frame force
This function makes frame @var{frame} invisible. If you omit
@var{frame}, it makes the selected frame invisible. Usually, this makes
all child frames of @var{frame} (and their descendants) invisible too
(@pxref{Child Frames}).
Unless @var{force} is non-@code{nil}, this function refuses to make
@var{frame} invisible if all other frames are invisible.
@end deffn
The visibility status of a frame is also available as a frame
parameter. You can read or change it as such. @xref{Management
Parameters}. The user can also iconify and deiconify frames with the
window manager. This happens below the level at which Emacs can exert
any control, but Emacs does provide events that you can use to keep
track of such changes. @xref{Misc Events}.
@defun x-double-buffered-p &optional frame
This function returns non-@code{nil} if @var{frame} is currently
being rendered with double buffering. @var{frame} defaults to the
selected frame.
@end defun
@node Raising and Lowering
@section Raising, Lowering and Restacking Frames
@cindex raising a frame
@cindex lowering a frame
@cindex restacking a frame
@cindex frame stacking order
@cindex frame Z-order
@cindex Z-order
Most window systems use a desktop metaphor. Part of this metaphor is
the idea that system-level windows (representing, e.g., Emacs frames)
are stacked in a notional third dimension perpendicular to the screen
surface. The order induced by stacking is total and usually referred to
as stacking (or Z-) order. Where the areas of two windows overlap, the
one higher up in that order will (partially) cover the one underneath.
You can @dfn{raise} a frame to the top of that order or @dfn{lower} a
frame to its bottom by using the functions @code{raise-frame} and
@code{lower-frame}. You can @dfn{restack} a frame directly above or
below another frame using the function @code{frame-restack}.
Note that all functions described below will respect the adherence of
frames (and all other window-system windows) to their respective z-group
(@pxref{Position Parameters}). For example, you usually cannot lower a
frame below that of the desktop window and you cannot raise a frame
whose @code{z-group} parameter is @code{nil} above the window-system's
taskbar or tooltip window.
@deffn Command raise-frame &optional frame
This function raises frame @var{frame} (default, the selected frame)
above all other frames belonging to the same or a lower z-group as
@var{frame}. If @var{frame} is invisible or iconified, this makes it
visible. If @var{frame} is a child frame (@pxref{Child Frames}), this
raises @var{frame} above all other child frames of its parent.
@end deffn
@deffn Command lower-frame &optional frame
This function lowers frame @var{frame} (default, the selected frame)
below all other frames belonging to the same or a higher z-group as
@var{frame}. If @var{frame} is a child frame (@pxref{Child Frames}),
this lowers @var{frame} below all other child frames of its parent.
@end deffn
@defun frame-restack frame1 frame2 &optional above
This function restacks @var{frame1} below @var{frame2}. This implies
that if both frames are visible and their display areas overlap,
@var{frame2} will (partially) obscure @var{frame1}. If the optional
third argument @var{above} is non-@code{nil}, this function restacks
@var{frame1} above @var{frame2}. This means that if both frames are
visible and their display areas overlap, @var{frame1} will (partially)
obscure @var{frame2}.
Technically, this function may be thought of as an atomic action
performed in two steps: The first step removes @var{frame1}'s
window-system window from the display. The second step reinserts
@var{frame1}'s window into the display below (above if @var{above} is
true) that of @var{frame2}. Hence the position of @var{frame2} in its
display's Z (stacking) order relative to all other frames excluding
@var{frame1} remains unaltered.
Some window managers may refuse to restack windows.
@end defun
Note that the effect of restacking will only hold as long as neither of
the involved frames is iconified or made invisible. You can use the
@code{z-group} (@pxref{Position Parameters}) frame parameter to add a
frame to a group of frames permanently shown above or below other
frames. As long as a frame belongs to one of these groups, restacking
it will only affect its relative stacking position within that group.
The effect of restacking frames belonging to different z-groups is
undefined. You can list frames in their current stacking order with the
function @code{frame-list-z-order} (@pxref{Finding All Frames}).
@defopt minibuffer-auto-raise
If this is non-@code{nil}, activation of the minibuffer raises the frame
that the minibuffer window is in.
@end defopt
On window systems, you can also enable auto-raising (on frame
selection) or auto-lowering (on frame deselection) using frame
parameters. @xref{Management Parameters}.
@cindex top frame
The concept of raising and lowering frames also applies to text
terminal frames. On each text terminal, only the top frame is
displayed at any one time.
@defun tty-top-frame &optional terminal
This function returns the top frame on @var{terminal}. @var{terminal}
should be a terminal object, a frame (meaning that frame's terminal),
or @code{nil} (meaning the selected frame's terminal). If it does not
refer to a text terminal, the return value is @code{nil}.
@end defun
@node Frame Configurations
@section Frame Configurations
@cindex frame configuration
A @dfn{frame configuration} records the current arrangement of frames,
all their properties, and the window configuration of each one.
(@xref{Window Configurations}.)
@defun current-frame-configuration
This function returns a frame configuration list that describes
the current arrangement of frames and their contents.
@end defun
@defun set-frame-configuration configuration &optional nodelete
This function restores the state of frames described in
@var{configuration}. However, this function does not restore deleted
frames.
Ordinarily, this function deletes all existing frames not listed in
@var{configuration}. But if @var{nodelete} is non-@code{nil}, the
unwanted frames are iconified instead.
@end defun
@node Child Frames
@section Child Frames
@cindex child frames
@cindex parent frames
Child frames are objects halfway between windows (@pxref{Windows}) and
``normal'' frames. Like windows, they are attached to an owning frame.
Unlike windows, they may overlap each other---changing the size or
position of one child frame does not change the size or position of any
of its sibling child frames.
By design, operations to make or modify child frames are implemented
with the help of frame parameters (@pxref{Frame Parameters}) without any
specialized functions or customizable variables. Child frames
are meaningful on graphical and text terminals.
To create a new child frame or to convert a normal frame into a child
frame, set that frame's @code{parent-frame} parameter (@pxref{Frame
Interaction Parameters}) to that of an already existing frame. The
frame specified by that parameter will then be the frame's parent frame
as long as the parameter is not changed or reset. Technically, this
makes the child frame's window-system window a child window of the
parent frame's window-system window.
@cindex reparent frame
@cindex nest frame
The @code{parent-frame} parameter can be changed at any time.
Setting it to another frame @dfn{reparents} the child frame. Setting
it to another child frame makes the frame a @dfn{nested} child frame.
Setting it to @code{nil} restores the frame's status as a top-level
frame---a frame whose window-system window is a child of its display's
root window.@footnote{On Haiku, child frames are only visible when a
parent frame is active, owing to a limitation of the Haiku windowing
system. Owing to the same limitation, child frames are only
guaranteed to appear above their top-level parent; that is to say, the
top-most frame in the hierarchy, which does not have a parent frame.}
Since child frames can be arbitrarily nested, a frame can be both a
child and a parent frame. Also, the relative roles of child and parent
frame may be reversed at any time (though it's usually a good idea to
keep the size of a child frame sufficiently smaller than that of its
parent). An error will be signaled for the attempt to make a frame an
ancestor of itself.
Most window-systems clip a child frame at the native edges
(@pxref{Frame Geometry}) of its parent frame---everything outside these
edges is usually invisible. A child frame's @code{left} and @code{top}
parameters specify a position relative to the top-left corner of its
parent's native frame. When the parent frame is resized, this position
remains conceptually unaltered.
NS builds do not clip child frames at the parent frame's edges,
allowing them to be positioned so they do not obscure the parent frame
while still being visible themselves.
Usually, moving a parent frame moves along all its child frames and
their descendants as well, keeping their relative positions unaltered.
Note that the hook @code{move-frame-functions} (@pxref{Frame Position})
is run for a child frame only when the position of the child frame
relative to its parent frame changes.
When a parent frame is resized, its child frames conceptually retain
their previous sizes and their positions relative to the left upper
corner of the parent. This means that a child frame may become
(partially) invisible when its parent frame shrinks. The parameter
@code{keep-ratio} (@pxref{Frame Interaction Parameters}) can be used to
resize and reposition a child frame proportionally whenever its parent
frame is resized. This may avoid obscuring parts of a frame when its
parent frame is shrunk.
A visible child frame always appears on top of its parent frame thus
obscuring parts of it, except on NS builds where it may be positioned
beneath the parent. This is comparable to the window-system window of a
top-level frame which also always appears on top of its parent
window---the desktop's root window. When a parent frame is iconified or
made invisible (@pxref{Visibility of Frames}), its child frames are made
invisible. When a parent frame is deiconified or made visible, its
child frames are made visible.
When a parent frame is about to be deleted (@pxref{Deleting
Frames}), its child frames are recursively deleted before it. There
is one exception to this rule: When the child frame serves as a
surrogate minibuffer frame (@pxref{Minibuffers and Frames}) for
another frame, it is retained until the parent frame has been deleted.
If, at this time, no remaining frame uses the child frame as its
minibuffer frame, Emacs will try to delete the child frame too. If
that deletion fails for whatever reason, the child frame is made a
top-level frame.
Whether a child frame can have a menu or tool bar is window-system or
window manager dependent. Most window-systems explicitly disallow menu
bars for child frames. It seems advisable to disable both, menu and
tool bars, via the frame's initial parameters settings.
Usually, child frames do not exhibit window manager decorations like a
title bar or external borders (@pxref{Frame Geometry}). When the child
frame does not show a menu or tool bar, any other of the frame's borders
(@pxref{Layout Parameters}) can be used instead of the external borders.
In particular, under X (but not when building with GTK+), the frame's
outer border can be used. On MS-Windows, specifying a non-zero outer
border width will show a one-pixel wide external border. Under all
window-systems, the internal border can be used. In either case, it's
advisable to disable a child frame's window manager decorations with the
@code{undecorated} frame parameter (@pxref{Management Parameters}).
To resize or move an undecorated child frame with the mouse, special
frame parameters (@pxref{Mouse Dragging Parameters}) have to be used.
The internal border of a child frame, if present, can be used to resize
the frame with the mouse, provided that frame has a non-@code{nil}
@code{drag-internal-border} parameter. If set, the @code{snap-width}
parameter indicates the number of pixels where the frame @dfn{snaps} at
the respective edge or corner of its parent frame.
There are two ways to drag an entire child frame with the mouse: The
@code{drag-with-mode-line} parameter, if non-@code{nil}, enables
dragging a frame without minibuffer window (@pxref{Minibuffer
Windows}) via the mode line area of its bottommost window. The
@code{drag-with-header-line} parameter, if non-@code{nil}, enables
dragging the frame via the header line area of its topmost window.
In order to give a child frame a draggable header or mode line, the
window parameters @code{mode-line-format} and @code{header-line-format}
are handy (@pxref{Window Parameters}). These allow removing an
unwanted mode line (when @code{drag-with-header-line} is chosen) and to
remove mouse-sensitive areas which might interfere with frame dragging.
When the user drags a frame with a mouse and overshoots, it's easy
to drag a frame out of the screen area of its parent. Retrieving such
a frame can be hairy once the mouse button has been released. To
prevent such a situation, it is advisable to set the frame's
@code{top-visible} or @code{bottom-visible} parameter (@pxref{Mouse
Dragging Parameters}).
Set the @code{top-visible} parameter of a child frame to a number
when you intend to allow the user dragging that frame by its header
line. Setting @code{top-visible} to a number inhibits dragging the
top edge of the child frame above the top edge of its parent. Set the
@code{bottom-visible} parameter to a number when you intend to drag
that frame via its mode line; this inhibits dragging the bottom edge
of the child frame beneath the bottom edge of its parent. In either
case, that number also specifies width and height (in pixels) of the
area of the child frame that remains visible during dragging.
When a child frame is used for displaying a buffer via
@code{display-buffer-in-child-frame} (@pxref{Buffer Display Action
Functions}), the frame's @code{auto-hide-function} parameter
(@pxref{Frame Interaction Parameters}) can be set to a function, in
order to appropriately deal with the frame when the window displaying
the buffer shall be quit.
When a child frame is used during minibuffer interaction, for example,
to display completions in a separate window, the @code{minibuffer-exit}
parameter (@pxref{Frame Interaction Parameters}) is useful in order to
deal with the frame when the minibuffer is exited.
The behavior of child frames deviates from that of top-level frames in
a number of other ways as well. Here we sketch a few of them:
@itemize @bullet
@item
The semantics of maximizing and iconifying child frames is highly
window-system dependent. As a rule, applications should never invoke
these operations on child frames. By default, invoking
@code{iconify-frame} on a child frame will try to iconify the top-level
frame corresponding to that child frame instead. To obtain a different
behavior, users may customize the option @code{iconify-child-frame}
described below.
@item
Raising, lowering and restacking child frames (@pxref{Raising and
Lowering}) or changing the @code{z-group} (@pxref{Position Parameters})
of a child frame changes only the stacking order of child frames with
the same parent.
@item
Many window-systems are not able to change the opacity (@pxref{Font and
Color Parameters}) of child frames.
@item
Transferring focus from a child frame to an ancestor that is not its
parent by clicking with the mouse in a visible part of that ancestor's
window may fail with some window-systems. You may have to click into
the direct parent's window-system window first.
@item
Window managers might not bother to extend their focus follows mouse
policy to child frames. Customizing @code{mouse-autoselect-window} can
help in this regard (@pxref{Mouse Window Auto-selection}).
@item
Dropping (@pxref{Drag and Drop}) on child frames is not guaranteed to
work on all window-systems. Some will drop the object on the parent
frame or on some ancestor instead.
@end itemize
The following two functions can be useful when working with child and
parent frames:
@defun frame-parent &optional frame
This function returns the parent frame of @var{frame}. The parent frame
of @var{frame} is the Emacs frame whose window-system window is the
parent window of @var{frame}'s window-system window. If such a frame
exists, @var{frame} is considered a child frame of that frame.
This function returns @code{nil} if @var{frame} has no parent frame.
@end defun
@defun frame-ancestor-p ancestor descendant
This functions returns non-@code{nil} if @var{ancestor} is an ancestor
of @var{descendant}. @var{ancestor} is an ancestor of @var{descendant}
when it is either @var{descendant}'s parent frame or it is an ancestor
of @var{descendant}'s parent frame. Both, @var{ancestor} and
@var{descendant} must specify live frames.
@end defun
Note also the function @code{window-largest-empty-rectangle}
(@pxref{Coordinates and Windows}) which can be used to inscribe a child
frame in the largest empty area of an existing window. This can be
useful to avoid that a child frame obscures any text shown in that
window.
Customizing the following option can be useful to tweak the behavior of
@code{iconify-frame} for child frames.
@defopt iconify-child-frame
This option tells Emacs how to proceed when it is asked to iconify a
child frame. If it is @code{nil}, @code{iconify-frame} will do nothing
when invoked on a child frame. If it is @code{iconify-top-level}, Emacs
will try to iconify the top-level frame that is the ancestor of this
child frame instead. If it is @code{make-invisible}, Emacs will try to
make this child frame invisible instead of iconifying it.
Any other value means to try iconifying the child frame. Since such an
attempt may not be honored by all window managers and can even lead to
making the child frame unresponsive to user actions, the default is to
iconify the top level frame instead.
@end defopt
@node Mouse Tracking
@section Mouse Tracking
@cindex mouse tracking
@c @cindex tracking the mouse Duplicates track-mouse
Sometimes it is useful to @dfn{track} the mouse, which means to display
something to indicate where the mouse is and move the indicator as the
mouse moves. For efficient mouse tracking, you need a way to wait until
the mouse actually moves.
The convenient way to track the mouse is to ask for events to represent
mouse motion. Then you can wait for motion by waiting for an event. In
addition, you can easily handle any other sorts of events that may
occur. That is useful, because normally you don't want to track the
mouse forever---only until some other event, such as the release of a
button.
@defmac track-mouse body@dots{}
This macro executes @var{body}, with generation of mouse motion events
enabled. Typically, @var{body} would use @code{read-event} to read
the motion events and modify the display accordingly. @xref{Motion
Events}, for the format of mouse motion events.
The value of @code{track-mouse} is that of the last form in
@var{body}. You should design @var{body} to return when it sees the
up-event that indicates the release of the button, or whatever kind of
event means it is time to stop tracking. Its value also controls how
mouse events are reported while a mouse button is held down: if it is
@code{dropping} or @code{drag-source}, the motion events are reported
relative to the frame underneath the pointer. If there is no such
frame, the events will be reported relative to the frame the mouse
buttons were first pressed on. In addition, the @code{posn-window} of
the mouse position list will be @code{nil} if the value is
@code{drag-source}. This is useful to determine if a frame is not
directly visible underneath the mouse pointer.
The @code{track-mouse} macro causes Emacs to generate mouse motion
events by binding the variable @code{track-mouse} to a
non-@code{nil} value. If that variable has the special value
@code{dragging}, it additionally instructs the display engine to
refrain from changing the shape of the mouse pointer. This is
desirable in Lisp programs that require mouse dragging across large
portions of Emacs display, which might otherwise cause the mouse
pointer to change its shape according to the display portion it hovers
on (@pxref{Pointer Shape}). Therefore, Lisp programs that need the
mouse pointer to retain its original shape during dragging should bind
@code{track-mouse} to the value @code{dragging} at the beginning of
their @var{body}.
@end defmac
The usual purpose of tracking mouse motion is to indicate on the screen
the consequences of pushing or releasing a button at the current
position.
In many cases, you can avoid the need to track the mouse by using
the @code{mouse-face} text property (@pxref{Special Properties}).
That works at a much lower level and runs more smoothly than
Lisp-level mouse tracking.
@ignore
@c These are not implemented yet.
These functions change the screen appearance instantaneously. The
effect is transient, only until the next ordinary Emacs redisplay. That
is OK for mouse tracking, since it doesn't make sense for mouse tracking
to change the text, and the body of @code{track-mouse} normally reads
the events itself and does not do redisplay.
@defun x-contour-region window beg end
This function draws lines to make a box around the text from @var{beg}
to @var{end}, in window @var{window}.
@end defun
@defun x-uncontour-region window beg end
This function erases the lines that would make a box around the text
from @var{beg} to @var{end}, in window @var{window}. Use it to remove
a contour that you previously made by calling @code{x-contour-region}.
@end defun
@defun x-draw-rectangle frame left top right bottom
This function draws a hollow rectangle on frame @var{frame} with the
specified edge coordinates, all measured in pixels from the inside top
left corner. It uses the cursor color, the one used for indicating the
location of point.
@end defun
@defun x-erase-rectangle frame left top right bottom
This function erases a hollow rectangle on frame @var{frame} with the
specified edge coordinates, all measured in pixels from the inside top
left corner. Erasure means redrawing the text and background that
normally belong in the specified rectangle.
@end defun
@end ignore
@node Mouse Position
@section Mouse Position
@cindex mouse position
@cindex position of mouse
The functions @code{mouse-position} and @code{set-mouse-position}
give access to the current position of the mouse.
@defun mouse-position
This function returns a description of the position of the mouse. The
value looks like @code{(@var{frame} @var{x} . @var{y})}, where @var{x}
and @var{y} are integers giving the (possibly rounded) position in
multiples of the default character size of @var{frame} (@pxref{Frame
Font}) relative to the native position of @var{frame} (@pxref{Frame
Geometry}).
@end defun
@defvar mouse-position-function
If non-@code{nil}, the value of this variable is a function for
@code{mouse-position} to call. @code{mouse-position} calls this
function just before returning, with its normal return value as the
sole argument, and it returns whatever this function returns to it.
This abnormal hook exists for the benefit of packages like
@file{xt-mouse.el} that need to do mouse handling at the Lisp level.
@end defvar
@defvar tty-menu-calls-mouse-position-function
If non-@code{nil}, TTY menus will call @code{mouse-position-function}
as described above. This exists for cases where
@code{mouse-position-function} is not safe to be called by the TTY
menus, such as if it could trigger redisplay.
@end defvar
@defun set-mouse-position frame x y
This function @dfn{warps the mouse} to position @var{x}, @var{y} in
frame @var{frame}. The arguments @var{x} and @var{y} are integers,
giving the position in multiples of the default character size of
@var{frame} (@pxref{Frame Font}) relative to the native position of
@var{frame} (@pxref{Frame Geometry}).
The resulting mouse position is constrained to the native frame of
@var{frame}. If @var{frame} is not visible, this function does nothing.
The return value is not significant.
@end defun
@defun mouse-pixel-position
This function is like @code{mouse-position} except that it returns
coordinates in units of pixels rather than units of characters.
@end defun
@defun set-mouse-pixel-position frame x y
This function warps the mouse like @code{set-mouse-position} except that
@var{x} and @var{y} are in units of pixels rather than units of
characters.
The resulting mouse position is not constrained to the native frame of
@var{frame}. If @var{frame} is not visible, this function does nothing.
The return value is not significant.
@end defun
On a graphical terminal the following two functions allow the absolute
position of the mouse cursor to be retrieved and set.
@defun mouse-absolute-pixel-position
This function returns a cons cell (@var{x} . @var{y}) of the coordinates
of the mouse cursor position in pixels, relative to a position (0, 0) of
the selected frame's display.
@end defun
@defun set-mouse-absolute-pixel-position x y
This function moves the mouse cursor to the position (@var{x}, @var{y}).
The coordinates @var{x} and @var{y} are interpreted in pixels relative
to a position (0, 0) of the selected frame's display.
@end defun
The following function can tell whether the mouse cursor is currently
visible on a frame:
@defun frame-pointer-visible-p &optional frame
This predicate function returns non-@code{nil} if the mouse pointer
displayed on @var{frame} is visible; otherwise it returns @code{nil}.
@var{frame} omitted or @code{nil} means the selected frame. This is
useful when @code{make-pointer-invisible} is set to @code{t}: it
allows you to know if the pointer has been hidden.
@xref{Mouse Avoidance,,,emacs, The Emacs Manual}.
@end defun
@need 3000
@node Pop-Up Menus
@section Pop-Up Menus
@cindex menus, popup
A Lisp program can pop up a menu so that the user can choose an
alternative with the mouse. On a text terminal, if the mouse is not
available, the user can choose an alternative using the keyboard
motion keys---@kbd{C-n}, @kbd{C-p}, or up- and down-arrow keys.
@defun x-popup-menu position menu
This function displays a pop-up menu and returns an indication of
what selection the user makes.
The argument @var{position} specifies where on the screen to put the
top left corner of the menu. It can be either a mouse button or
@code{touchscreen-begin} event (which says to put the menu where the
user actuated the button) or a list of this form:
@example
((@var{xoffset} @var{yoffset}) @var{window})
@end example
@noindent
where @var{xoffset} and @var{yoffset} are coordinates, measured in
pixels, counting from the top left corner of @var{window}. @var{window}
may be a window or a frame.
If @var{position} is @code{t}, it means to use the current mouse
position (or the top-left corner of the frame if the mouse is not
available on a text terminal). If @var{position} is @code{nil}, it
means to precompute the key binding equivalents for the keymaps
specified in @var{menu}, without actually displaying or popping up the
menu.
The argument @var{menu} says what to display in the menu. It can be a
keymap or a list of keymaps (@pxref{Menu Keymaps}). In this case, the
return value is the list of events corresponding to the user's choice.
This list has more than one element if the choice occurred in a
submenu. (Note that @code{x-popup-menu} does not actually execute the
command bound to that sequence of events.) On text terminals and
toolkits that support menu titles, the title is taken from the prompt
string of @var{menu} if @var{menu} is a keymap, or from the prompt
string of the first keymap in @var{menu} if it is a list of keymaps
(@pxref{Defining Menus}).
Alternatively, @var{menu} can have the following form:
@example
(@var{title} @var{pane1} @var{pane2}...)
@end example
@noindent
where each pane is a list of form
@example
(@var{title} @var{item1} @var{item2}...)
@end example
Each @var{item} should be a cons cell, @code{(@var{line} . @var{value})},
where @var{line} is a string and @var{value} is the value to return if
that @var{line} is chosen. Unlike in a menu keymap, a @code{nil}
@var{value} does not make the menu item non-selectable.
Alternatively, each @var{item} can be a string rather than a cons
cell; this makes a non-selectable menu item.
If the user gets rid of the menu without making a valid choice, for
instance by clicking the mouse away from a valid choice or by typing
@kbd{C-g}, then this normally results in a quit and
@code{x-popup-menu} does not return. But if @var{position} is a mouse
button event (indicating that the user invoked the menu with the
mouse) then no quit occurs and @code{x-popup-menu} returns @code{nil}.
@end defun
@strong{Usage note:} Don't use @code{x-popup-menu} to display a menu
if you could do the job with a prefix key defined with a menu keymap.
If you use a menu keymap to implement a menu, @kbd{C-h c} and @kbd{C-h
a} can see the individual items in that menu and provide help for them.
If instead you implement the menu by defining a command that calls
@code{x-popup-menu}, the help facilities cannot know what happens inside
that command, so they cannot give any help for the menu's items.
The menu bar mechanism, which lets you switch between submenus by
moving the mouse, cannot look within the definition of a command to see
that it calls @code{x-popup-menu}. Therefore, if you try to implement a
submenu using @code{x-popup-menu}, it cannot work with the menu bar in
an integrated fashion. This is why all menu bar submenus are
implemented with menu keymaps within the parent menu, and never with
@code{x-popup-menu}. @xref{Menu Bar}.
If you want a menu bar submenu to have contents that vary, you should
still use a menu keymap to implement it. To make the contents vary, add
a hook function to @code{menu-bar-update-hook} to update the contents of
the menu keymap as necessary.
@defvar x-pre-popup-menu-hook
A normal hook run immediately before a pop-up menu is displayed,
either directly by calling @code{x-popup-menu}, or through a menu
keymap. It won't be called if @code{x-popup-menu} returns for some
other reason without displaying a pop-up menu.
@end defvar
@node On-Screen Keyboards
@section On-Screen Keyboards
An on-screen keyboard is a special kind of pop up provided by the
system, with rows of clickable buttons that act as a real keyboard.
On certain systems (@pxref{On-Screen Keyboards,,,emacs, The Emacs
Manual}), Emacs is supposed to display and hide the on screen keyboard
depending on whether or not the user is about to type something.
@defun frame-toggle-on-screen-keyboard frame hide
This function displays or hides the on-screen keyboard on behalf of
the frame @var{frame}. If @var{hide} is non-@code{nil}, then the
on-screen keyboard is hidden; otherwise, it is displayed.
It returns whether or not the on screen keyboard @strong{may} have
been displayed, which should be used to determine whether or not to
hide the on-screen keyboard later.
This has no effect if the system automatically detects when to display
the on-screen keyboard, or when it does not provide any on-screen
keyboard.
@end defun
@node Dialog Boxes
@section Dialog Boxes
@cindex dialog boxes
A dialog box is a variant of a pop-up menu---it looks a little
different, it always appears in the center of a frame, and it has just
one level and one or more buttons. The main use of dialog boxes is
for asking questions that the user can answer with ``yes'', ``no'',
and a few other alternatives. With a single button, they can also
force the user to acknowledge important information. The functions
@code{y-or-n-p} and @code{yes-or-no-p} use dialog boxes instead of the
keyboard, when called from commands invoked by mouse clicks.
@defun x-popup-dialog position contents &optional header
This function displays a pop-up dialog box and returns an indication of
what selection the user makes. The argument @var{contents} specifies
the alternatives to offer; it has this format:
@example
(@var{title} (@var{string} . @var{value})@dots{})
@end example
@noindent
which looks like the list that specifies a single pane for
@code{x-popup-menu}.
The return value is @var{value} from the chosen alternative.
As for @code{x-popup-menu}, an element of the list may be just a
string instead of a cons cell @code{(@var{string} . @var{value})}.
That makes a box that cannot be selected.
If @code{nil} appears in the list, it separates the left-hand items from
the right-hand items; items that precede the @code{nil} appear on the
left, and items that follow the @code{nil} appear on the right. If you
don't include a @code{nil} in the list, then approximately half the
items appear on each side.
Dialog boxes always appear in the center of a frame; the argument
@var{position} specifies which frame. The possible values are as in
@code{x-popup-menu}, but the precise coordinates or the individual
window don't matter; only the frame matters.
If @var{header} is non-@code{nil}, the frame title for the box is
@samp{Information}, otherwise it is @samp{Question}. The former is used
for @code{message-box} (@pxref{message-box}). (On text terminals, the
box title is not displayed.)
In some configurations, Emacs cannot display a real dialog box; so
instead it displays the same items in a pop-up menu in the center of the
frame.
If the user gets rid of the dialog box without making a valid choice,
for instance using the window manager, then this produces a quit and
@code{x-popup-dialog} does not return.
@end defun
@node Pointer Shape
@section Pointer Shape
@cindex pointer shape
@cindex mouse pointer shape
You can specify the mouse pointer style for particular text or
images using the @code{pointer} text property, and for images with the
@code{:pointer} and @code{:map} image properties. The values you can
use in these properties are in the table below. The actual shapes
may vary between systems; the descriptions are examples.
@table @code
@item text
@itemx nil
The usual mouse pointer style used over text (an ``I''-like shape).
@item arrow
@itemx vdrag
@itemx modeline
An arrow that points north-west.
@item hand
A hand that points upwards.
@item hdrag
A right-left arrow.
@item nhdrag
An up-down arrow.
@item hourglass
A rotating ring.
@end table
Over void parts of the window (parts that do not correspond to any
of the buffer contents), the mouse pointer usually uses the
@code{arrow} style, but you can specify a different style (one of
those above) by setting @code{void-text-area-pointer}.
@defopt void-text-area-pointer
This variable specifies the mouse pointer style for void text areas.
These include the areas after the end of a line or below the last line
in the buffer. The default is to use the @code{arrow} (non-text)
pointer style.
@end defopt
When using some window systems, you can specify what the @code{text}
pointer style really looks like by setting the variable
@code{x-pointer-shape}.
@defvar x-pointer-shape
This variable specifies the pointer shape to use ordinarily in the
Emacs frame, for the @code{text} pointer style.
@end defvar
@defvar x-sensitive-text-pointer-shape
This variable specifies the pointer shape to use when the mouse
is over mouse-sensitive text.
@end defvar
These variables affect newly created frames. They do not normally
affect existing frames; however, if you set the mouse color of a
frame, that also installs the current value of those two variables.
@xref{Font and Color Parameters}.
The values you can use, to specify either of these pointer shapes, are
defined in the file @file{lisp/term/x-win.el}. Use @kbd{M-x apropos
@key{RET} x-pointer @key{RET}} to see a list of them.
@node Window System Selections
@section Window System Selections
@cindex selection (for window systems)
@cindex clipboard
@cindex primary selection
@cindex secondary selection
In window systems, such as X, data can be transferred between
different applications by means of @dfn{selections}. Each window
system defines an arbitrary number of @dfn{selection types}, all
storing their own data; however, only three are commonly used: the
@dfn{clipboard}, @dfn{primary selection}, and @dfn{secondary
selection}. @xref{Cut and Paste,, Cut and Paste, emacs, The GNU Emacs
Manual}, for Emacs commands that make use of these selections. This
section documents the low-level functions for reading and setting
window-system selections; @xref{Accessing Selections}, for
documentation concerning selection types and data formats under
particular window systems.
@deffn Command gui-set-selection type data
This function sets a window-system selection. It takes two arguments:
a selection type @var{type}, and the value to assign to it, @var{data}.
@var{type} should be a symbol; it is usually one of @code{PRIMARY},
@code{SECONDARY} or @code{CLIPBOARD}. These are generally symbols
with upper-case names, in accord with X Window System conventions. If
@var{type} is @code{nil}, that stands for @code{PRIMARY}.
If @var{data} is @code{nil}, it means to clear out the selection.
Otherwise, @var{data} may be a string, a symbol, an integer, an
overlay, or a cons of two markers pointing to the same buffer. An
overlay or a pair of markers stands for text in the overlay or between
the markers. The argument @var{data} may also be a vector of valid
non-vector selection values.
If @var{data} is a string, then its text properties can specify values
used for individual data types. For example, if @var{data} has a
property named @code{text/uri-list}, then a call to
@code{gui-get-selection} with the data type @code{text/uri-list} will
result in the value of that property being used instead of @var{data}
itself.
This function returns @var{data}.
@end deffn
@defun gui-get-selection &optional type data-type
This function accesses selections set up by Emacs or by other
programs. It takes two optional arguments, @var{type} and
@var{data-type}. The default for @var{type}, the selection type, is
@code{PRIMARY}.
The @var{data-type} argument specifies the form of data conversion to
use, to convert the raw data obtained from another program into Lisp
data. @xref{X Selections}, for an enumeration of data types valid under
X, and @pxref{Other Selections} for those elsewhere.
@end defun
@defopt selection-coding-system
This variable provides a coding system (@pxref{Coding Systems}) which
is used to encode selection data, and takes effect on MS-Windows and
X@. It is also used in the MS-DOS port when it runs on MS-Windows and
can access the Windows clipboard text.
On X, the value of this variable provides the coding system which
@code{gui-get-selection} will use to decode selection data for a
subset of text data types, and also forces replies to selection
requests for the polymorphic @code{TEXT} data type to be encoded by
the @code{compound-text-with-extensions} coding system rather than
Unicode.
On MS-Windows, this variable is generally ignored, as the MS-Windows
clipboard provides the information about decoding as part of the
clipboard data, and uses either UTF-16 or locale-specific encoding
automatically as appropriate. We recommend to set the value of this
variable only on the older Windows 9X, as it is otherwise used only in
the very rare cases when the information provided by the clipboard
data is unusable for some reason.
The default value of this variable is the system code page under
MS-Windows 98 or Me, @code{utf-16le-dos} on Windows
NT/W2K/XP/Vista/7/8/10/11, @code{iso-latin-1-dos} on MS-DOS, and
@code{nil} elsewhere.
@end defopt
For backward compatibility, there are obsolete aliases
@code{x-get-selection} and @code{x-set-selection}, which were the
names of @code{gui-get-selection} and @code{gui-set-selection} before
Emacs 25.1.
@node Accessing Selections
@section Accessing Selections
The data types and selections that @code{gui-get-selection} and
@code{gui-set-selection} understand are not precisely specified and
differ subject to the window system on which Emacs is running.
At the same time, @code{gui-set-selection} abstracts over plenty of
complexity: its @var{data} argument is given verbatim to
system-specific code to be rendered suitable for transfer to the
window system or requesting clients.
The most comprehensive implementation of selections exists under the
X Window System. This is both an artifact of history (X was the first
window system supported by Emacs) and one occasioned by technical
considerations: X selections are not merely an expedient for the
transfer of text and multimedia content between clients, but a general
inter-client communication system, a design that has yielded a
proliferation of selection and data types.
Compounding this confusion, there is another inter-client
communication mechanism under X: the Inter-Client Exchange. ICE is
only used by Emacs to communicate with session managers, and is a
separate topic.
@menu
* X Selections:: Selection data types (and more) on X@.
* Other Selections:: How they work on other window systems.
@end menu
@node X Selections
@subsection X Selections
X refrains from defining fixed data types for selection data or a
fixed number of selections. Selections are identified by X ``atoms'',
which are unique 29-bit identifiers issued by the X server for string
names. This complexity is hidden by Emacs: when Lisp provides a
symbol whose name is that of the atom, Emacs will request these
identifiers without further intervention.
When a program ``sets'' a selection under X, it actually makes
itself the ``owner'' of the selection---the X server will then deliver
selection requests to the program, which is obliged to respond to the
requesting client with the selection data.
Similarly, a program does not ``get'' selection data from the X
server. Instead, its selection requests are sent to the client with
the window which last asserted ownership over the selection, which is
expected to respond with the requested data.
Each selection request incorporates three parameters:
@itemize @bullet
@item
The window which requested the selection, which identifies the
@c Not a typo: X spells ``requestor'' with an o.
requesting program, otherwise known as the @dfn{requestor}.
@item
An atom identifying the @dfn{target} to which the owner should convert
the selection. It is easiest to think of the conversion target as the
kind of data that the requestor wants: in selection requests made by
Emacs, the target is determined by the @var{type} argument to
@code{gui-get-selection}.
@item
A 32-bit timestamp representing the X server time at which the
requestor last received input; this parameter is not relevant to Lisp
code, for it's only meant to abet synchronization between the X
server, owner and requestor.
@end itemize
The selection owner responds by transferring to the requestor a
series of bytes, 16 bit words, or 32 bit words, along with another
atom identifying the type of those words. After requesting a
selection, Emacs then applies its own interpretation of the data
format and data type to convert the data transferred by the selection
owner to a Lisp representation, which @code{gui-get-selection}
returns.
Emacs converts selection data consisting of any series of bytes to a
unibyte string holding those bytes, that consisting of a single 16-bit
or 32-bit word as an unsigned number, and that consisting of multiple
such words as a vector of unsigned numbers. The exceptions to this
general pattern are that Emacs applies special treatment for data from
the following conversion targets:
@table @code
@item INTEGER
16-bit or 32-bit words of this type are treated as signed rather than
unsigned integers. If there are multiple words in the selection data,
a vector is returned; otherwise, the integer is returned by itself.
@item ATOM
32-bit words of this type are treated as X atoms, and returned (either
alone or as vectors) as Lisp symbols by the names they identify.
Invalid atoms are replaced by @code{nil}.
@item COMPOUND_TEXT
@item UTF8_STRING
@item STRING
A single @code{foreign-selection} text property set to the type of the
selection data will be placed in unibyte strings derived from a
request for these data types.
@end table
Each selection owner must return at least two selection targets:
@code{TARGETS}, which returns a number of atoms describing the
selection targets that the owner supports, and @code{MULTIPLE}, used
for internal purposes by X clients. A selection owner may support any
number of other targets, some of which may be standardized by the X
Consortium's
@url{http://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html,
Inter-Client Communication Conventions Manual}, while others, such as
@code{UTF8_STRING}, were meant to be standardized by the XFree86
Project, but their standardization was never completed.
Requests for a given selection target may, by convention, return
data in a specific type, or it may return data in one of several
types, whichever is most convenient for the selection owner; the
latter type of selection target is dubbed a @dfn{polymorphic target}.
In response to a request, a selection target may also return no data
at all, whereafter the selection owner executes some action as a side
effect. Targets that are thus replied to are termed @dfn{side-effect
targets}.
Here are some selection targets whose behavior is generally
consistent with a standard when requested from the @code{CLIPBOARD},
@code{PRIMARY}, or @code{SECONDARY} selections.
@table @code
@item ADOBE_PORTABLE_DOCUMENT_FORMAT
This target returns data in Adobe System's ``Portable Document
Format'' format, as a string.
@item APPLE_PICT
This target returns data in the ``PICT'' image format used on
Macintosh computers, as a string.
@item BACKGROUND
@item BITMAP
@item COLORMAP
@item FOREGROUND
Together, these four targets return integer data necessary to make use
of a bitmap image stored on the X server: the pixel value of the
bitmap's background color, the X identifier of the bitmap, the
colormap inside which the background and foreground are allocated, and
the pixel value of the bitmap's foreground color.
@item CHARACTER_POSITION
This target returns two unsigned 32-bit integers of type @code{SPAN}
describing the start and end positions of the selection data in the
text field containing it, in bytes.
@item COMPOUND_TEXT
This target returns a string of type @code{COMPOUND_TEXT} in the X
Consortium's multi-byte text encoding system.
@item DELETE
This target returns nothing, but as a side-effect deletes the
selection contents from any text field containing them.
@item DRAWABLE
@item PIXMAP
This target returns a list of unsigned 32-bit integers, each of which
corresponds to an X server drawable or pixmap.
@item ENCAPSULATED_POSTSCRIPT
@item _ADOBE_EPS
This target returns a string containing encapsulated Postscript code.
@item FILE_NAME
This target returns a string containing one or more file names,
separated by NULL characters.
@item HOST_NAME
This target returns a string containing the fully-qualified domain
name of the machine on which the selection owner is running.
@item USER
This target returns a string containing the user name of the machine
on which the selection owner is running.
@item LENGTH
This target returns an unsigned 32-bit or 16-bit integer containing
the length of the selection data.
@item LINE_NUMBER
This target returns two unsigned 32-bit integers of type @code{SPAN}
describing the line numbers corresponding to the start and end
positions of the selection data in the text field containing it.
@item MODULE
This target returns the name of any function containing the selection
data. It is principally requested by text editors.
@item STRING
This target returns the selection data as a string of type
@code{STRING}, encoded in ISO Latin-1 format, with Unix newline
characters.
@item C_STRING
This target returns the selection data as a ``C string''. This has
been interpreted as meaning the raw selection data in whatever
encoding used by the owner, either terminated with a NULL byte or not
at all, or an ASCII string which may or may not be terminated.
@item UTF8_STRING
This returns the selection data as a string of type
@code{UTF8_STRING}, encoded in UTF-8, with unspecified EOL format.
@item TIMESTAMP
This target returns the X server time at which the selection owner
took ownership over the selection as a 16-bit or 32-bit word of type
@code{CARDINAL}.
@item TEXT
This polymorphic target returns selection data as a string, either
@code{COMPOUND_TEXT}, @code{STRING}, @code{C_STRING}, or
@code{UTF8_STRING}, whichever data type is convenient for the
selection owner.
@end table
When a request for the targets @code{STRING}, @code{COMPOUND_TEXT},
or @code{UTF8_STRING} is made using the function
@code{gui-get-selection}, and neither @code{selection-coding-system}
nor @code{next-selection-coding-system} is set, the resultant strings
are decoded by the proper coding systems for those targets:
@code{iso-8859-1}, @code{compound-text-with-extensions} and
@code{utf-8} respectively.
In addition to the targets specified above (and the many targets
used by various programs for their own purposes), several popular
programs and toolkits have defined selection data types of their own,
without consulting the appropriate X standards bodies. These targets
are generally named after such MIME types as @code{text/html} or
@code{image/jpeg}; they have been witnessed returning the following
forms of data:
@itemize @bullet
@item
Unterminated, newline terminated, or NULL character terminated file
names of an image or text file.
@item
Image or text data in the appropriate format.
@item
@code{file://} URIs (or conceivably newline or NUL terminated lists of
URIs) identifying files in the appropriate format.
@end itemize
These selection targets were first used by Netscape, but are now
proffered by all kinds of programs, especially those based on recent
versions of the GTK+ or Qt toolkits.
Emacs is also capable of serving as a selection owner. When
@code{gui-set-selection} is called, the selection data provided is
recorded internally and Emacs obtains ownership of the selection being
set.
@defvar selection-converter-alist
Alist of selection targets to ``selection converter'' functions. When
a selection request is received, Emacs looks up the selection
converter pertaining to the requested selection target.
Selection converters are called with three arguments: the symbol
corresponding to the atom identifying the selection being requested,
the selection target that is being requested, and the value set with
@code{gui-set-selection}. The values which they must return are
either conses of symbols designating the data type and numbers,
symbols, vectors of numbers or symbols, or the cdrs of such conses by
themselves.
If a selection converter's value is the special symbol @code{NULL},
the data type returned to its requestor is set to @code{NULL}, and no
data is sent in response.
If such a value is a string, it must be a unibyte string; should no
data type be explicitly specified, the data is transferred to its
requestor with the type @code{STRING}.
If it is a symbol, its ``atom'' is retrieved, and it is transferred to
its requestor as a 32-bit value---if no data type is specified, its
type is @code{ATOM}.
If it is a number between @code{-32769} and @code{32768}, it is
transferred to its requestor as a 16 bit value---if no data type is
specified, its type is @code{INTEGER}.
If it is any other number, it is accounted a 32 bit value. Even if
the number returned is unsigned, its requestor will treat words of
type @code{INTEGER} as signed. To return an unsigned value, specify
the type @code{CARDINAL} in its place.
If it is a vector of symbols or numbers, the response to its requestor
will be a list of multiple atoms or numbers. The data type returned
when not expressly set is that of the list's first element.
@end defvar
By default, Emacs is configured with selection converters for the
following selection targets:
@table @code
@item TEXT
This selection converter returns selection data as:
@itemize @bullet
@item
A string of type @code{C_STRING}, if the selection contents contain no
multibyte characters, or contain ``raw 8-bit bytes'' (@pxref{Text
Representations}).
@item
A string of type @code{STRING}, if the selection contents can be
represented as ISO-Latin-1 text.
@item
A string of type @code{COMPOUND_TEXT}, if the selection contents can
be encoded in the X Consortium's Compound Text Encoding, and
@code{selection-coding-system} or @code{next-selection-coding-system}
is set to a coding system whose @code{:mime-charset} property is
@code{x-ctext}.
@item
A string of type @code{UTF8_STRING} otherwise.
@end itemize
@item COMPOUND_TEXT
This selection converter returns selection data as a string of type
@code{COMPOUND_TEXT}.
@item STRING
This selection converter returns selection data as a string of type
@code{STRING}, encoded in ISO-Latin-1 format.
@item UTF8_STRING
This selection converter returns selection data in UTF-8 format.
@item text/plain
@item text/plain;charset=utf-8
@item text/uri-list
@item text/x-xdnd-username
@item XmTRANSFER_SUCCESS
@item XmTRANSFER_FAILURE
@item FILE
@item _DT_NETFILE
These selection converters are used for internal purposes during
drag-and-drop operations and are not available for selections other
than @code{XdndSelection}.
@item TARGETS
This selection converter returns a list of atoms, one for each
selection target understood by Emacs.
@item MULTIPLE
This selection converter is implemented in C code and is used to
implement efficient transfer of selection requests which specify
multiple selection targets at the same time.
@item LENGTH
This selection converter returns the length of the selection data, in
bytes.
@item DELETE
This selection converter is used for internal purposes during
drag-and-drop operations.
@item FILE_NAME
This selection converter returns the file name of the buffer
containing the selection data.
@item CHARACTER_POSITION
This selection converter returns the character positions of each end
of the selection in the buffer containing the selection data.
@item LINE_NUMBER
@item COLUMN_NUMBER
This selection converter returns the line and column numbers of each
end of the selection in the buffer containing the selection data.
@item OWNER_OS
This selection converter returns the name of the operating system on
which Emacs is running.
@item HOST_NAME
This selection converter returns the fully-qualified domain name of
the machine on which Emacs is running.
@item USER
This selection converter returns the username of the user account
under which Emacs is running.
@item CLASS
@item NAME
These selection converters return the resource class and name used by
Emacs.
@item INTEGER
This selection converter returns an integer value verbatim.
@item SAVE_TARGETS
@item _EMACS_INTERNAL
These selection converters are used for internal purposes.
@end table
With the exception of @code{INTEGER}, all selection converters
expect the data provided to @code{gui-set-selection} to be one of the
following:
@itemize @bullet
@item
A string.
@item
A list of the form @w{@code{(@var{beg} @var{end} @var{buf})}}, where
@var{beg} and @var{end} are two markers or overlays describing the
bounds of the selection data in the buffer @var{buf}.
@end itemize
@node Other Selections
@subsection Other Selections
Selections under such window systems as MS-Windows, Nextstep, Haiku
and Android are not aligned with those under X@. Each of these window
system improvises its own selection mechanism without employing the
``selection converter'' mechanism illustrated in the preceding node.
Only the @code{PRIMARY}, @code{CLIPBOARD}, and @code{SECONDARY}
selections are generally supported, with the @code{XdndSelection}
selection that records drag-and-drop data also available under
Nextstep and Haiku.
@cindex PGTK selections
GTK seeks to emulate the X selection system, but its emulations are
not altogether dependable, with the overall quality of each subject to
the GDK backend being used. Therefore, Emacs built with PGTK will
supply the same selection interface as Emacs built with X, but many
selection targets will not be useful.
@cindex MS-Windows selection emulation
@cindex MS-Windows primary and secondary selection
Although a clipboard exists, there is no concept of primary or
secondary selections within the MS-Windows operating system. On this
system, Emacs simulates the presence of a primary and secondary
selection, while saving to and retrieving from the clipboard when so
requested.
The simulation of the primary and secondary selections is conducted
by saving values supplied to @code{gui-set-selection} within the
@code{x-selections} property of the symbol designating the pertinent
selection, namely the @var{type} argument to @code{gui-get-selection}.
Each subsequent call to @code{gui-get-selection} in turn returns its
value, which is not subject to further examination (such as type
checks and the like). Under such circumstances, @var{data-type}
argument is generally disregarded. (But see below for the
qualification regarding @code{TARGETS}.)
@cindex MS-Windows clipboard
Where the clipboard selection is concerned (whenever @var{type} is
@code{CLIPBOARD}), @code{gui-set-selection} verifies that the value
provided is a string and saves it within the system clipboard once it
is encoded by the coding system configured in
@code{selection-coding-system}. Callers of @code{gui-get-selection}
are required to set @var{data-type} to either @code{STRING} or
@code{TARGETS}.
When @var{data-type} is set to @code{TARGETS} in a call to
@code{gui-get-selection}, a vector of symbols is returned when
selection data exists, much as it is under X@. It is impossible to
request clipboard data in any format besides @code{STRING}, for the
prerequisite data conversion routines are absent. Just as strings
saved into the clipboard are encoded by the
@code{selection-coding-system}, so those read from the clipboard are
decoded by that same coding system; this variable and its cousin
@code{next-selection-coding-system} merit particular scrutiny when
difficulties are encountered with saving selection text into the
clipboard.
@cindex Nextstep selections
All three selections standard in X exist in Nextstep as well, but
Emacs is only capable of saving strings to such selections.
Restrictions imposed upon calls to @code{gui-set-selection} there are
much the same as those on MS-Windows, though text is uniformly encoded
as @code{utf-8-unix} without regard to the value of
@code{selection-coding-system}. @code{gui-get-selection} is more
charitable, and accepts requests for the following selection targets:
@c FIXME: how is the text coding system determined, and do image/* or
@c application/* return image data or file names?
@itemize @bullet
@item text/plain
@item image/png
@item text/html
@item application/pdf
@item application/rtf
@item application/rtfd
@item STRING
@item text/plain
@item image/tiff
@end itemize
The @code{XdndSelection} selection is also present under Nextstep,
in the form of a repository that records values supplied to
@code{gui-set-selection}. Its sole purpose is to save such values for
the fundamental drag-and-drop function @code{x-begin-drag}
(@pxref{Drag and Drop}); no guarantees exist concerning its value when
read by anything else.
@cindex Haiku selections
Selections on Haiku systems comprise all three selections customary
under X and the @code{XdndSelection} that records drag-and-drop data.
When @code{gui-set-selection} is called for the former three
selections, the data supplied is converted into a window server
``message'' by a list of @dfn{selection encoder} functions, which is
sent to the window server.
@defvar haiku-normal-selection-encoders
List of selection encoder functions. When @code{gui-set-selection} is
called, each function in this list is successively called with its
@var{selection} and @var{value} arguments. If such a function returns
non-@code{nil}, its return value must be a list of the form
@w{@code{(@var{key} @var{type} @var{value})}}. In this list,
@var{key} must be the name of the data being transferred, generally
that of a MIME type, for example @samp{"text/plain"}, and @var{type}
is a symbol or a number designating the type of the data; thus also
governing the interpretation of @var{value}; following is a list of
valid data types and how each of them will cause @var{value} to be
interpreted.
@table @code
@item string
A unibyte string. The string is NULL-terminated after being placed in
the message.
@item ref
A file name. The file is located and the inode identifying the file
is placed in the message.
@item short
A 16-bit integer value.
@item long
A 32-bit integer value.
@item llong
A 64-bit integer value.
@item byte
@item char
An unsigned byte between 0 and 255.
@item size_t
A number between 0 and 1 minus two to the power of the word size of
the computer Emacs is running on.
@item ssize_t
A number which fits in the C type @code{ssize_t}.
@item point
A cons of two floats, specifying a coordinate on-screen.
@item float
@item double
A single or double-precision floating point number in an unspecified
format.
@item (haiku-numeric-enum MIME)
A unibyte string containing data in a certain MIME type.
@end table
@end defvar
A call to @code{gui-get-selection} generally returns the data
named @var{data-type} within the selection message, albeit with
@var{data-type} replaced by an alternative name should it be one of
the following X selection targets:
@table @code
@item STRING
This represents Latin-1 text under X: ``text/plain;charset=iso-8859-1''
@item UTF8_STRING
This represents UTF-8 text: ``text/plain''
@end table
If @var{data-type} is a text type such as @code{STRING} or a MIME
type matching the pattern @samp{`text/*}, the string data is decoded
with the coding system apposite for it before being returned.
Furthermore, the two data types @var{TIMESTAMP} and @code{TARGETS}
are afforded special treatment; the value returned for the first is
the number of times the selection has been modified since system
startup (@emph{not} a timestamp), and that for the other is a vector
of available selection data types, as elsewhere.
@cindex Android selections
Much like MS-Windows, Android provides a clipboard but no primary or
secondary selection; @code{gui-set-selection} simulates the primary
and secondary selections by saving the value supplied into a variable
subsequent calls to @code{gui-get-selection} return.
From the clipboard, @code{gui-get-selection} is capable of returning
UTF-8 string data of the type @code{STRING}, the @code{TAREGTS} data
type, or image and application data of any MIME type.
@code{gui-set-selection} sets only string data, much as under
MS-Windows, although this data is not affected by the value of
@code{selection-coding-system}. By contrast, only string data can be
saved to and from the primary and secondary selections; but since this
data is not communicated to programs besides Emacs, it is not subject
to encoding or decoding by any coding system.
@node Yanking Media
@section Yanking Media
@cindex yank media from window-system selections
Data saved within window system selections and the MS-Windows
clipboard is not restricted to plain text. It is possible for selection
data to encompass images or other binary data of the like, as well as
rich text content instanced by HTML, and also PostScript. Since the
selection data types incident to this data are at variance with those
for plain text, the insertion of such data is facilitated by a set of
functions dubbed @dfn{yank-media handlers}, which are registered by each
major mode undertaking its insertion and called where warranted upon the
execution of the @code{yank-media} command.
@defun yank-media-handler types handler
Register a yank-media handler which applies to the current buffer.
@var{types} can be a symbol designating a selection data type
(@pxref{Accessing Selections}), a regexp against which such types are
matched, or a list of these symbols and regexps. For instance:
@example
(yank-media-handler 'text/html #'my-html-handler)
(yank-media-handler "image/.*" #'my-image-handler)
@end example
When a selection offers a data type matching @var{types}, the function
@var{handler} is called to insert its data, with the symbol
designating the matching selection data type, and the data returned by
@code{gui-get-selection}.
@end defun
The @code{yank-media-types} command presents a list of selection data
types that are currently available, which is useful when implementing
yank-media handlers; for programs generally offer an eclectic and
seldom consistent medley of data types.
@node Drag and Drop
@section Drag and Drop
@cindex drag and drop
Data transferred by drag and drop is generally either plain text or
a list of URLs designating files or other resources. When text is
dropped, it is inserted at the location of the drop, with recourse to
saving it into the kill ring if that is not possible.
URLs dropped are supplied to pertinent @dfn{DND handler functions}
in the variable @code{dnd-protocol-alist}, or alternatively ``URL
handlers'' as set forth by the variables @code{browse-url-handlers}
and @code{browse-url-default-handlers}; absent matching handlers of
either type, they are treated as plain text and inserted in the
buffer.
@defvar dnd-protocol-alist
This variable is an alist between regexps against which URLs are
matched and DND handler functions called on the dropping of matching
URLs.
@cindex dnd-multiple-handler, a symbol property
If a handler function is a symbol whose @code{dnd-multiple-handler}
property (@pxref{Symbol Properties}) is set, then upon a drop it is
given a list of every URL that matches its regexp; absent this
property, it is called once for each of those URLs. Following this
first argument is one of the symbols @code{copy}, @code{move},
@code{link}, @code{private} or @code{ask} identifying the action to be
taken.
If @var{action} is @code{private}, the program that initiated the drop
does not insist on any particular behavior on the part of its
recipient; a reasonable action to take in that case is to open the URL
or copy its contents into the current buffer. The other values of
@var{action} imply much the same as in the @var{action} argument to
@code{dnd-begin-file-drag}.
Once its work completes, a handler function must return a symbol
designating the action it took: either the action it was provided, or
the symbol @code{private}, which communicates to the source of the
drop that the action it prescribed has not been executed.
When multiple handlers match an overlapping subset of items within a
drop, the handler matched against by the greatest number of items is
called to open that subset. The items it is supplied are subsequently
withheld from other handlers, even those they also match.
@end defvar
@cindex drag and drop, X
@cindex drag and drop, other formats
Emacs does not take measures to accept data besides text and URLs,
for the window system interfaces which enable this are too far removed
from each other to abstract over consistently. Nor are DND handlers
accorded influence over the actions they are meant to take, as
particular drag-and-drop protocols deny recipients such control. The
X11 drag-and-drop implementation rests on several underlying protocols
that make use of selection transfer and share much in common, to which
low level access is provided through the following functions and
variables:
@defvar x-dnd-test-function
This function is called to ascertain whether Emacs should accept a
drop. It is called with three arguments:
@itemize @bullet
@item
The window under the item being dragged, which is to say the window
whose buffer is to receive the drop. If the item is situated over a
non-window component of a frame (such as scroll bars, tool bars and
things to that effect), the frame itself is provided in its place.
@item
One of the symbols @code{move}, @code{copy}, @code{link} or
@code{ask}, representing an action to take on the item data suggested
by the drop source. These symbols carry the same implications as in
@code{x-begin-drag}.
@item
A vector of selection data types (@pxref{X Selections}) the item
provides.
@end itemize
This function must return @code{nil} to reject the drop or a cons of
the action that will be taken (such as through transfer to a DND
handler function) and the selection data type to be requested. The
action returned in that cons may also be the symbol @code{private},
which intimates that the action taken is as yet indeterminate.
@end defvar
@defvar x-dnd-known-types
Modifying @code{x-dnd-test-function} is generally unwarranted, for its
default set of criteria for accepting a drop can be adjusted by
changing this list of selection data types. Each element is a string,
which if found as the symbol name of an element within the list of
data types by the default ``test function'', will induce that function
to accept the drop.
Introducing a new entry into this list is not useful unless a
counterpart handler function is appended to @code{x-dnd-types-alist}.
@end defvar
@defvar x-dnd-types-alist
This variable is an alist between strings designating selection data
types and functions which are called when things of such types are
dropped.
Each such function is supplied three arguments; the first is the
window or frame below the location of the drop, as in
@code{x-dnd-test-function}; the second is the action to be taken,
which may be any of the actions returned by test functions, and third
is the selection data itself (@pxref{Accessing Selections}).
@end defvar
Selection data types as provided by X11 drag-and-drop protocols are
sometimes distinct from those provided by the ICCCM and conforming
clipboard or primary selection owners. Frequently, the name of a MIME
type, such as @code{"text/plain;charset=utf-8"} (with discrepant
capitalization of the ``utf-8''), is substituted for a standard X
selection name such as @code{UTF8_STRING}.
@cindex XDS
@cindex direct save protocol
@vindex x-dnd-direct-save-function
The X Direct Save (@acronym{XDS}) protocol enables programs to
devolve responsibility for naming a dropped file upon the recipient.
When such a drop transpires, DND handlers and the foregoing X-specific
interface are largely circumvented, tasking a different function with
responding to the drop.
@defvar x-dnd-direct-save-function
This variable should be set to a function that registers and names
files dropped using the @acronym{XDS} protocol in a two-step
procedure. It is provided two arguments, @var{need-name} and
@var{filename}.
@enumerate 1
@item
The application from which the file is dragged asks Emacs to provide
the full file name under which to save the file. For this purpose,
the direct-save function is called with its first argument
@var{need-name} non-@code{nil}, and the second argument @var{filename}
set to the basename of the file to be saved. It should return the
fully-expanded absolute file name under which to save the file. For
example, if a file is dragged to a Dired window, the natural directory
for the file is the directory of the file shown at location of the
drop. If saving the file is not possible for some reason, the
function should return @code{nil}, which will cancel the drag-and-drop
operation.
@item
The application from which the file is dragged saves the file under
the name returned by the first call to the direct-save function. If
it succeeds in saving the file, the direct-save function is called
again, this time with the first argument @var{need-name} set to
@code{nil} and the second argument @var{filename} set to the full
absolute name of the saved file. The function is then expected to do
whatever is needed given the fact that file was saved. For example,
Dired should update the directory on display by showing the new file
there.
@end enumerate
Its default @code{x-dnd-direct-save-function} is
@code{x-dnd-save-direct}.
@end defvar
@defun x-dnd-save-direct need-name filename
When called with the @var{need-name} argument non-@code{nil}, this
function prompts the user for the absolute file name under which it
should be saved. If the specified file already exists, it
additionally asks the user whether to overwrite it, and returns the
absolute file name only if the user confirms the overwriting.
When called with the @var{need-name} argument @code{nil}, it reverts
the Dired listing if the current buffer is in Dired mode or one of its
descendants, and otherwise visits the file by calling @code{find-file}
(@pxref{Visiting Functions}).
@end defun
@defun x-dnd-save-direct-immediately need-name filename
This function works like @code{x-dnd-save-direct}, but when called
with its @var{need-name} argument non-@code{nil}, it doesn't prompt
the user for the full name of the file to be saved; instead, it
returns its argument @var{filename} expanded against the current
buffer's default directory (@pxref{File Name Expansion}). (It still
asks for confirmation if a file by that name already exists in the
default directory.)
@end defun
@cindex initiating drag-and-drop
It is also possible to drag content from Emacs to other programs
when this is supported by the current window-system. The functions
which provide for this are as follows:
@cindex drop target, in drag-and-drop operations
@defun dnd-begin-text-drag text &optional frame action allow-same-frame
This function starts a drag-and-drop operation from @var{frame} to
another program (dubbed the @dfn{drop target}), and returns when
@var{text} is dropped or the operation is canceled.
@var{action} must be one of the symbols @code{copy} or @code{move},
where @code{copy} means that @var{text} should be inserted by the drop
target, and @code{move} means the same as @code{copy}, but the caller
must also delete @var{text} from its source as explained in the list
below.
@var{frame} is the frame where the mouse is currently held down, or
@code{nil}, which means to use the selected frame. Since this
function might return promptly if no mouse buttons are held down, it
should be only called in response to a @code{down-mouse-1} or
analogous event (@pxref{Mouse Events}), with @var{frame} set to the
frame where that event was generated (@pxref{Click Events}).
If @var{allow-same-frame} is @code{nil}, drops on top of @var{frame}
will be ignored.
The return value reflects the action that the drop target actually
performed, and thus also what action, if any, the caller should in
turn take. It is one of the following symbols:
@table @code
@item copy
The drop target inserted the dropped text.
@item move
The drop target inserted the dropped text, and the caller should
delete @var{text} from the buffer where it was extracted from, if
applicable.
@item private
The drop target took some other unspecified action.
@item nil
The drag-and-drop operation was canceled.
@end table
@end defun
@defun dnd-begin-file-drag file &optional frame action allow-same-frame
This function starts a drag-and-drop operation from @var{frame} to
another program (dubbed the @dfn{drop target}), and returns when
@var{file} is dropped or the operation is canceled.
If @var{file} is a remote file, then a temporary local copy will be
made.
@var{action} must be one of the symbols @code{copy}, @code{move} or
@code{link}, where @code{copy} means that @var{file} should be opened
or copied by the drop target, @code{move} means the drop target should
move the file to another location, and @code{link} means the drop
target should create a symbolic link to @var{file}. It is an error to
specify @code{link} as the action if @var{file} is a remote file.
@var{frame} and @var{allow-same-frame} mean the same as they do in
calls to @code{dnd-begin-text-drag}.
The return value is the action that the drop target actually
performed, which is one of the following symbols:
@table @code
@item copy
The drop target opened or copied @var{file} to a different location.
@item move
The drop target moved @var{file} to a different location.
@item link
The drop target (usually a file manager) created a symbolic link to
@var{file}.
@item private
The drop target performed some other unspecified action.
@item nil
The drag-and-drop operation was canceled.
@end table
@end defun
@defun dnd-begin-drag-files files &optional frame action allow-same-frame
This function is like @code{dnd-begin-file-drag}, except that
@var{files} is a list of files. If the drop target doesn't support
dropping multiple files, then the first file will be used instead.
@end defun
@defun dnd-direct-save file name &optional frame allow-same-frame
The behavior of this function is akin to that of
@code{dnd-begin-file-drag} (when the default action @code{copy} is
used), except that it accepts a name under which the copy is meant to
be filed.
@end defun
@cindex initiating drag-and-drop, low-level
The high-level interfaces described above are implemented on top of
a lower-level primitive. The low-level interface @code{x-begin-drag}
is also available for dragging content besides text and files. It
demands detailed knowledge of the data types and actions understood by
programs on each platform its callers wish to support.
@defun x-begin-drag targets &optional action frame return-frame allow-current-frame follow-tooltip
This function begins a drag from @var{frame}, and returns when the
drag-and-drop operation ends, either because the drop was successful,
or because the drop was rejected. The drop occurs when all mouse
buttons are released on top of an X window other than @var{frame} (the
@dfn{drop target}), or any X window if @var{allow-current-frame} is
non-@code{nil}. If no mouse buttons are held down when the
drag-and-drop operation begins, this function may immediately return
@code{nil}.
@var{targets} is a list of strings representing selection targets,
much like the @var{data-type} argument to @code{gui-get-selection},
that the drop target can request from Emacs (@pxref{Window System
Selections}).
@var{action} is a symbol designating the action recommended to the
target. It can either be @code{XdndActionCopy} or
@code{XdndActionMove}; both imply copying the contents of the
selection @code{XdndSelection} to the drop target, but the latter
moreover conveys a promise to delete the contents of the selection
after the copying.
@var{action} may also be an alist which associates between symbols
representing available actions, and strings that the drop target
presents to the user for him to select between those actions.
If @var{return-frame} is non-@code{nil} and the mouse moves over an
Emacs frame after first moving out of @var{frame}, then the frame to
which the mouse moves will be returned immediately. If
@var{return-frame} is the symbol @code{now}, then any frame beneath
the mouse pointer will be returned without waiting for the mouse to
first move out of @var{frame}. @var{return-frame} is useful when you
want to treat dragging content from one frame to another specially,
while also dragging content to other programs, but it is not
guaranteed to function on all systems and with all window managers.
If @var{follow-tooltip} is non-@code{nil}, the position of any tooltip
(such as one displayed by @code{tooltip-show}) will follow the
location of the mouse pointer as it moves during the drag-and-drop
operation. The tooltip will be hidden once all mouse buttons are
released.
If the drop was rejected or no drop target was found, this function
returns @code{nil}. Otherwise, it returns a symbol representing the
action the target opted to take, which can differ from @var{action} if
that isn't supported by the drop target. @code{XdndActionPrivate} is
also a valid return value in addition to @code{XdndActionCopy} and
@code{XdndActionMove}; it suggests that the drop target opted for an
indeterminate action, and no further action is required of the caller.
The caller must cooperate with the target to complete the action
selected by the target. For example, callers should delete any buffer
text that was dragged if this function returns @code{XdndActionMove},
and likewise for other drag data where comparable criteria apply.
@end defun
@cindex drag and drop protocols, X
The function @code{x-begin-drag} leverages several drag-and-drop
protocols ``behind the scenes''. When dragging content that is known
to not be supported by a specific drag-and-drop protocol, that
protocol can be disabled by changing the values of the following
variables:
@defvar x-dnd-disable-motif-protocol
When this is non-@code{nil}, the Motif drag and drop protocols are
disabled, and dropping onto programs that only understand them will
not work.
@end defvar
@defvar x-dnd-use-offix-drop
When this is @code{nil}, the OffiX (old KDE) drag and drop protocol is
disabled. When this is the symbol @code{files}, the OffiX protocol
will only be used if @code{"FILE_NAME"} is one of the targets given to
@code{x-begin-drag}. Any other value means to use the OffiX protocol
to drop all supported content.
@end defvar
@defvar x-dnd-use-unsupported-drop
When one of the @code{"STRING"}, @code{"UTF8_STRING"},
@code{"COMPOUND_TEXT"} or @code{"TEXT"} targets is present in the list
given to @code{x-begin-drag}, Emacs will try to use synthesized mouse
events and the primary selection to insert the text if the drop target
doesn't support any drag-and-drop protocol at all.
A side effect is that Emacs will become the owner of the primary
selection upon such a drop. Such emulation can be disabled by setting
this variable to @code{nil}.
@end defvar
@node Color Names
@section Color Names
@cindex color names
@cindex specify color
@cindex numerical RGB color specification
A color name is text (usually in a string) that specifies a color.
Symbolic names such as @samp{black}, @samp{white}, @samp{red}, etc.,
are allowed; use @kbd{M-x list-colors-display} to see a list of
defined names. You can also specify colors numerically in forms such
as @samp{#@var{rgb}} and @samp{RGB:@var{r}/@var{g}/@var{b}}, where
@var{r} specifies the red level, @var{g} specifies the green level,
and @var{b} specifies the blue level. You can use either one, two,
three, or four hex digits for @var{r}; then you must use the same
number of hex digits for all @var{g} and @var{b} as well, making
either 3, 6, 9 or 12 hex digits in all. (See the documentation of the
X Window System for more details about numerical RGB specification of
colors.)
These functions provide a way to determine which color names are
valid, and what they look like. In some cases, the value depends on the
@dfn{selected frame}, as described below; see @ref{Input Focus}, for the
meaning of the term ``selected frame''.
To read user input of color names with completion, use
@code{read-color} (@pxref{High-Level Completion, read-color}).
@defun color-defined-p color &optional frame
This function reports whether a color name is meaningful. It returns
@code{t} if so; otherwise, @code{nil}. The argument @var{frame} says
which frame's display to ask about; if @var{frame} is omitted or
@code{nil}, the selected frame is used.
Note that this does not tell you whether the display you are using
really supports that color. When using X, you can ask for any defined
color on any kind of display, and you will get some result---typically,
the closest it can do. To determine whether a frame can really display
a certain color, use @code{color-supported-p} (see below).
@end defun
@defun defined-colors &optional frame
This function returns a list of the color names that are defined
and supported on frame @var{frame} (default, the selected frame).
If @var{frame} does not support colors, the value is @code{nil}.
@end defun
@defun color-supported-p color &optional frame background-p
This returns @code{t} if @var{frame} can really display the color
@var{color} (or at least something close to it). If @var{frame} is
omitted or @code{nil}, the question applies to the selected frame.
Some terminals support a different set of colors for foreground and
background. If @var{background-p} is non-@code{nil}, that means you are
asking whether @var{color} can be used as a background; otherwise you
are asking whether it can be used as a foreground.
The argument @var{color} must be a valid color name.
@end defun
@defun color-gray-p color &optional frame
This returns @code{t} if @var{color} is a shade of gray, as defined on
@var{frame}'s display. If @var{frame} is omitted or @code{nil}, the
question applies to the selected frame. If @var{color} is not a valid
color name, this function returns @code{nil}.
@end defun
@defun color-values color &optional frame
@cindex rgb value
This function returns a value that describes what @var{color} should
ideally look like on @var{frame}. If @var{color} is defined, the
value is a list of three integers, which give the amount of red, the
amount of green, and the amount of blue. Each integer ranges in
principle from 0 to 65535, but some displays may not use the full
range. This three-element list is called the @dfn{rgb values} of the
color.
If @var{color} is not defined, the value is @code{nil}.
@example
(color-values "black")
@result{} (0 0 0)
(color-values "white")
@result{} (65535 65535 65535)
(color-values "red")
@result{} (65535 0 0)
(color-values "pink")
@result{} (65535 49344 52171)
(color-values "hungry")
@result{} nil
@end example
The color values are returned for @var{frame}'s display. If
@var{frame} is omitted or @code{nil}, the information is returned for
the selected frame's display. If the frame cannot display colors, the
value is @code{nil}.
@end defun
@defun color-name-to-rgb color &optional frame
This function does the same as @code{color-values}, but it returns
color values as floating-point numbers between 0.0 and 1.0 inclusive.
@end defun
@defun color-dark-p rgb
This function returns non-@code{nil} if the color described by its RGB
triplet @var{rgb} is more readable against white background than
against dark background. The argument @var{rgb} should be a list of
the form @w{@code{(@var{r} @var{g} @var{b})}}, with each component a
floating-point number in the range 0.0 to 1.0 inclusive. You can use
@code{color-name-to-rgb} to convert a color's name to such a list.
@end defun
@node Text Terminal Colors
@section Text Terminal Colors
@cindex colors on text terminals
Text terminals usually support only a small number of colors, and
the computer uses small integers to select colors on the terminal.
This means that the computer cannot reliably tell what the selected
color looks like; instead, you have to inform your application which
small integers correspond to which colors. However, Emacs does know
the standard set of colors and will try to use them automatically.
The functions described in this section control how terminal colors
are used by Emacs.
Several of these functions use or return @dfn{rgb values}, described
in @ref{Color Names}.
These functions accept a display (either a frame or the name of a
terminal) as an optional argument. We hope in the future to make
Emacs support different colors on different text terminals; then this
argument will specify which terminal to operate on (the default being
the selected frame's terminal; @pxref{Input Focus}). At present,
though, the @var{frame} argument has no effect.
@defun tty-color-define name number &optional rgb frame
This function associates the color name @var{name} with
color number @var{number} on the terminal.
The optional argument @var{rgb}, if specified, is an rgb value, a list
of three numbers that specify what the color actually looks like.
If you do not specify @var{rgb}, then this color cannot be used by
@code{tty-color-approximate} to approximate other colors, because
Emacs will not know what it looks like.
@end defun
@defun tty-color-clear &optional frame
This function clears the table of defined colors for a text terminal.
@end defun
@defun tty-color-alist &optional frame
This function returns an alist recording the known colors supported by
a text terminal.
Each element has the form @code{(@var{name} @var{number} . @var{rgb})}
or @code{(@var{name} @var{number})}. Here, @var{name} is the color
name, @var{number} is the number used to specify it to the terminal.
If present, @var{rgb} is a list of three color values (for red, green,
and blue) that says what the color actually looks like.
@end defun
@defun tty-color-approximate rgb &optional frame
This function finds the closest color, among the known colors
supported for @var{display}, to that described by the rgb value
@var{rgb} (a list of color values). The return value is an element of
@code{tty-color-alist}.
@end defun
@defun tty-color-translate color &optional frame
This function finds the closest color to @var{color} among the known
colors supported for @var{display} and returns its index (an integer).
If the name @var{color} is not defined, the value is @code{nil}.
@end defun
@node Resources
@section X Resources
This section describes some of the functions and variables for
querying and using X resources, or their equivalent on your operating
system. @xref{X Resources,, X Resources, emacs, The GNU Emacs
Manual}, for more information about X resources.
@defun x-get-resource attribute class &optional component subclass
The function @code{x-get-resource} retrieves a resource value from the X
Window defaults database.
Resources are indexed by a combination of a @dfn{key} and a @dfn{class}.
This function searches using a key of the form
@samp{@var{instance}.@var{attribute}} (where @var{instance} is the name
under which Emacs was invoked), and using @samp{Emacs.@var{class}} as
the class.
The optional arguments @var{component} and @var{subclass} add to the key
and the class, respectively. You must specify both of them or neither.
If you specify them, the key is
@samp{@var{instance}.@var{component}.@var{attribute}}, and the class is
@samp{Emacs.@var{class}.@var{subclass}}.
@end defun
@defvar x-resource-class
This variable specifies the application name that @code{x-get-resource}
should look up. The default value is @code{"Emacs"}. You can examine X
resources for other application names by binding this
variable to some other string, around a call to @code{x-get-resource}.
@end defvar
@defvar x-resource-name
This variable specifies the instance name that @code{x-get-resource}
should look up. The default value is the name Emacs was invoked with,
or the value specified with the @samp{-name} or @samp{-rn} switches.
@end defvar
To illustrate some of the above, suppose that you have the line:
@example
xterm.vt100.background: yellow
@end example
@noindent
in your X resources file (whose name is usually @file{~/.Xdefaults}
or @file{~/.Xresources}). Then:
@example
@group
(let ((x-resource-class "XTerm") (x-resource-name "xterm"))
(x-get-resource "vt100.background" "VT100.Background"))
@result{} "yellow"
@end group
@group
(let ((x-resource-class "XTerm") (x-resource-name "xterm"))
(x-get-resource "background" "VT100" "vt100" "Background"))
@result{} "yellow"
@end group
@end example
@defvar inhibit-x-resources
If this variable is non-@code{nil}, Emacs does not look up X
resources, and X resources do not have any effect when creating new
frames.
@end defvar
@node Display Feature Testing
@section Display Feature Testing
@cindex display feature testing
The functions in this section describe the basic capabilities of a
particular display. Lisp programs can use them to adapt their behavior
to what the display can do. For example, a program that ordinarily uses
a popup menu could use the minibuffer if popup menus are not supported.
The optional argument @var{display} in these functions specifies which
display to ask the question about. It can be a display name, a frame
(which designates the display that frame is on), or @code{nil} (which
refers to the selected frame's display, @pxref{Input Focus}).
@xref{Color Names}, @ref{Text Terminal Colors}, for other functions to
obtain information about displays.
@defun display-popup-menus-p &optional display
This function returns @code{t} if popup menus are supported on
@var{display}, @code{nil} if not. Support for popup menus requires
that the mouse be available, since the menu is popped up by clicking
the mouse on some portion of the Emacs display.
@end defun
@defun display-graphic-p &optional display
This function returns @code{t} if @var{display} is a graphic display
capable of displaying several frames and several different fonts at
once. This is true for displays that use a window system such as X,
and false for text terminals.
@end defun
@defun display-mouse-p &optional display
@cindex mouse, availability
This function returns @code{t} if @var{display} has a mouse available,
@code{nil} if not.
@end defun
@defun display-color-p &optional display
This function returns @code{t} if the screen is a color screen.
@end defun
@defun display-grayscale-p &optional display
This function returns @code{t} if the screen can display shades of gray.
(All color displays can do this.)
@end defun
@defun display-supports-face-attributes-p attributes &optional display
@anchor{Display Face Attribute Testing}
This function returns non-@code{nil} if all the face attributes in
@var{attributes} are supported (@pxref{Face Attributes}).
The definition of ``supported'' is somewhat heuristic, but basically
means that a face containing all the attributes in @var{attributes},
when merged with the default face for display, can be represented in a
way that's
@enumerate
@item
different in appearance than the default face, and
@item
close in spirit to what the attributes specify, if not exact.
@end enumerate
Point (2) implies that a @code{:weight black} attribute will be
satisfied by any display that can display bold, as will
@code{:foreground "yellow"} as long as some yellowish color can be
displayed, but @code{:slant italic} will @emph{not} be satisfied by
the tty display code's automatic substitution of a dim face for
italic.
@end defun
@defun display-selections-p &optional display
This function returns @code{t} if @var{display} supports selections.
Windowed displays normally support selections, but they may also be
supported in some other cases.
@end defun
@defun display-images-p &optional display
This function returns @code{t} if @var{display} can display images.
Windowed displays ought in principle to handle images, but some
systems lack the support for that. On a display that does not support
images, Emacs cannot display a tool bar.
@end defun
@defun display-screens &optional display
This function returns the number of screens associated with the display.
@end defun
@defun display-pixel-height &optional display
This function returns the height of the screen in pixels.
On a character terminal, it gives the height in characters.
For graphical terminals, note that on multi-monitor setups this
refers to the pixel height for all physical monitors associated with
@var{display}. @xref{Multiple Terminals}.
@end defun
@defun display-pixel-width &optional display
This function returns the width of the screen in pixels.
On a character terminal, it gives the width in characters.
For graphical terminals, note that on multi-monitor setups this
refers to the pixel width for all physical monitors associated with
@var{display}. @xref{Multiple Terminals}.
@end defun
@defun display-mm-height &optional display
This function returns the height of the screen in millimeters,
or @code{nil} if Emacs cannot get that information.
For graphical terminals, note that on multi-monitor setups this
refers to the height for all physical monitors associated with
@var{display}. @xref{Multiple Terminals}.
@end defun
@defun display-mm-width &optional display
This function returns the width of the screen in millimeters,
or @code{nil} if Emacs cannot get that information.
For graphical terminals, note that on multi-monitor setups this
refers to the width for all physical monitors associated with
@var{display}. @xref{Multiple Terminals}.
@end defun
@defopt display-mm-dimensions-alist
This variable allows the user to specify the dimensions of graphical
displays returned by @code{display-mm-height} and
@code{display-mm-width} in case the system provides incorrect values.
@end defopt
@cindex backing store
@defun display-backing-store &optional display
This function returns the backing store capability of the display.
Backing store means recording the pixels of windows (and parts of
windows) that are not exposed, so that when exposed they can be
displayed very quickly.
Values can be the symbols @code{always}, @code{when-mapped}, or
@code{not-useful}. The function can also return @code{nil}
when the question is inapplicable to a certain kind of display.
@end defun
@cindex SaveUnder feature
@defun display-save-under &optional display
This function returns non-@code{nil} if the display supports the
SaveUnder feature. That feature is used by pop-up windows
to save the pixels they obscure, so that they can pop down
quickly.
@end defun
@defun display-planes &optional display
This function returns the number of planes the display supports.
This is typically the number of bits per pixel.
For a tty display, it is log to base two of the number of colors supported.
@end defun
@defun display-visual-class &optional display
This function returns the visual class for the screen. The value is
one of the symbols @code{static-gray} (a limited, unchangeable number
of grays), @code{gray-scale} (a full range of grays),
@code{static-color} (a limited, unchangeable number of colors),
@code{pseudo-color} (a limited number of colors), @code{true-color} (a
full range of colors), and @code{direct-color} (a full range of
colors).
@end defun
@defun display-color-cells &optional display
This function returns the number of color cells the screen supports.
@end defun
These functions obtain additional information about the window
system in use where Emacs shows the specified @var{display}. (Their
names begin with @code{x-} for historical reasons.)
@defun x-server-version &optional display
This function returns the list of version numbers of the GUI window
system running on @var{display}, such as the X server on GNU and Unix
systems. The value is a list of three integers: the major and minor
version numbers of the protocol, and the distributor-specific release
number of the window system software itself. On GNU and Unix systems,
these are normally the version of the X protocol and the
distributor-specific release number of the X server software. On
MS-Windows, this is the version of the Windows OS.
@end defun
@defun x-server-vendor &optional display
This function returns the vendor that provided the window system
software (as a string). On GNU and Unix systems this really means
whoever distributes the X server. On MS-Windows this is the vendor ID
string of the Windows OS (Microsoft).
When the developers of X labeled software distributors as
``vendors'', they showed their false assumption that no system could
ever be developed and distributed noncommercially.
@end defun
@ignore
@defvar x-no-window-manager
This variable's value is @code{t} if no X window manager is in use.
@end defvar
@end ignore
|