ahk 0.3.2

The ahk language: a lexer, an AST, a parser and an interpreter for AutoHotkey-style scripts
Documentation
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
//! The machine the script drives.
//!
//! The runtime does no I/O of its own: everything that touches the
//! machine goes through one of the traits here. The traits are the
//! capabilities a machine may have, so a desktop with a keyboard and no
//! pointer says so about the pointer alone, and the script that asks
//! for the pointer is told why it cannot have it.
//!
//! [`Desktop`] is the sum of the capabilities. A desktop implements the
//! ones it has, and the sum, and the sum has no methods of its own.
//!
//! Every method that a capability does not have to answer says so:
//! "this desktop cannot ...". A question the machine cannot answer
//! fails with the reason, and never answers `false`.

use crate::dll::{NativeCall, NativeFailure, NativeResult};
use alloc::string::{String, ToString};
use alloc::vec::Vec;

/// The answer to a question about a window.
#[derive(Debug, Clone, PartialEq)]
pub enum WindowAnswer {
    /// The window is there and is the active one.
    Active,
    /// The window exists and is not the active one.
    NotActive,
    /// The window is not there.
    ///
    /// This is an answer and not a failure: `WinExist` says that a window
    /// that is not there is not there, and `WinActive` says that a window
    /// that is not there is not the active one.
    Absent,
    /// The desktop cannot tell; the reason says why.
    Unknown(String),
}

/// The keyboard of the desktop.
pub trait Keyboard {
    /// Type text exactly, and say how it was typed.
    fn type_text(&mut self, text: &str) -> Result<String, String>;

    /// Press one key, and say how it was pressed.
    fn press_key(&mut self, name: &str, modifiers: &[String]) -> Result<String, String>;

    /// Put a key down, and leave it down.
    fn key_down(&mut self, _name: &str) -> Result<String, String> {
        Err("this desktop cannot hold a key down".to_string())
    }

    /// Let a key come up.
    fn key_up(&mut self, _name: &str) -> Result<String, String> {
        Err("this desktop cannot hold a key down".to_string())
    }

    /// Whether a key is down right now.
    fn key_is_down(&mut self, _name: &str) -> Result<bool, String> {
        Err("this desktop cannot tell which keys are down".to_string())
    }

    /// The keys that are down right now.
    fn keys_down(&mut self) -> Result<Vec<String>, String> {
        Err("this desktop cannot tell which keys are down".to_string())
    }

    /// The state of a lock light of the keyboard.
    ///
    /// The three locks of a keyboard are CapsLock, NumLock and ScrollLock.
    /// `None` is a name that is not a lock of a keyboard.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `SetCapsLockState
    /// ("On")` makes `GetKeyState("CapsLock", "T")` answer 1, and "Off"
    /// makes it answer 0 -- the state a program sets is the state it reads
    /// back.
    fn lock_light(&mut self, _name: &str) -> Result<Option<bool>, String> {
        Err("this desktop cannot tell the state of a lock light".to_string())
    }

    /// Set a lock light of the keyboard, and say whether it is on now.
    fn set_lock_light(&mut self, _name: &str, _on: bool) -> Result<bool, String> {
        Err("this desktop cannot set a lock light".to_string())
    }

    /// Turn a lock key on or off.
    ///
    /// The desktop that can read the state of a lock key but not change it
    /// says so, and the state of the key is not touched.
    fn set_lock(&mut self, _lock: &str, _on: bool) -> Result<(), String> {
        Err("this desktop cannot change the state of the lock keys".to_string())
    }

    /// Whether a lock key is on: "CapsLock", "NumLock" or "ScrollLock".
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: a lock key is a key
    /// whose state is a switch, and not a key that is held: `SetCapsLockState`
    /// turns the switch, and the state of it is what `GetKeyState` answers for
    /// the mode "T".
    fn lock_is_on(&mut self, _lock: &str) -> Result<bool, String> {
        Err("this desktop cannot read the state of the lock keys".to_string())
    }

    /// The name of the keyboard layout of the machine.
    ///
    /// The name is the one the platform gives it -- the KLID of Windows,
    /// the keymap of the session -- and the empty text when the platform
    /// has no name to give, the way KeySharp answers it. A machine that
    /// cannot say at all is a failure with the reason.
    fn keyboard_layout_name(&mut self) -> Result<String, String> {
        Err("this desktop cannot say the keyboard layout".to_string())
    }
}

/// The pointer of the desktop.
pub trait Pointer {
    /// The name of the shape of the cursor of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `A_Cursor` answers
    /// the name of the shape -- "IBeam" for the shape of a field of text.
    fn cursor_shape(&mut self) -> Result<String, String> {
        Err("this desktop cannot tell the shape of the cursor".to_string())
    }

    /// Click at a screen position.
    fn click(&mut self, x: i64, y: i64, button: &str, count: u32) -> Result<String, String>;

    /// Put a mouse button down, and leave it down.
    fn mouse_down(
        &mut self,
        _x: Option<i64>,
        _y: Option<i64>,
        _button: &str,
    ) -> Result<String, String> {
        Err("this desktop cannot hold a mouse button down".to_string())
    }

    /// Let a mouse button come up.
    fn mouse_up(
        &mut self,
        _x: Option<i64>,
        _y: Option<i64>,
        _button: &str,
    ) -> Result<String, String> {
        Err("this desktop cannot hold a mouse button down".to_string())
    }

    /// Move the pointer to a screen position.
    ///
    /// A desktop that cannot move the pointer says so; the default is an
    /// error, because a script that believes it moved the pointer and did
    /// not is a script that types into the wrong window.
    fn move_pointer(&mut self, _x: i64, _y: i64) -> Result<String, String> {
        Err("this desktop cannot move the pointer".to_string())
    }

    /// Where the pointer is, in screen pixels.
    fn mouse_position(&mut self) -> Result<(i64, i64), String> {
        Err("this desktop cannot tell where the pointer is".to_string())
    }

    /// The speed of the pointer, from 0 to 100.
    ///
    /// The number is the number of steps of a movement, and the speed of
    /// v2 is 0 to 100 with a default of 2: the 1 to 20 of the mouse of
    /// Windows is not the setting of v2.
    fn set_mouse_speed(&mut self, _speed: i64) -> Result<String, String> {
        Err("this desktop cannot change the speed of the pointer".to_string())
    }

    /// The delay between two movements of the pointer, in milliseconds.
    fn set_mouse_delay(&mut self, _delay: i64) -> Result<String, String> {
        Err("this desktop cannot change the delay of the pointer".to_string())
    }

    /// Confine the pointer to a rectangle of the screen, or release it.
    ///
    /// The rectangle is `(left, top, right, bottom)`, the far edges
    /// exclusive, and `None` releases the confinement. A desktop that
    /// does not own the pointer cannot confine it, and says so.
    fn clip_cursor(&mut self, _rect: Option<(i64, i64, i64, i64)>) -> Result<(), String> {
        Err("this desktop cannot confine the pointer".to_string())
    }
}

/// The screen of the desktop.
pub trait Screen {
    /// Capture a region of the screen into a file; return the path.
    fn capture(
        &mut self,
        x: i64,
        y: i64,
        width: i64,
        height: i64,
        filename: &str,
    ) -> Result<String, String>;

    /// The colour of one pixel, as `#rrggbb`.
    fn pixel(&mut self, x: i64, y: i64) -> Result<String, String>;

    /// The size of the screen, in pixels.
    ///
    /// The width comes first and the height second, the way the two
    /// variables of v2 ask for them.
    /// The `ClassNN` of every control of the script's window, one per line.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `WinGetControls` answers the
    /// three of a window with a label, an edit and a button, as `Static1`, `Edit1` and
    /// `Button1`.
    fn gui_controls(&mut self) -> Result<String, String> {
        Err("this desktop cannot list the controls of the window of the script".to_string())
    }

    /// The text of every control of the script's window, each followed by a line break.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `WinGetText` of a window with a
    /// label and an edit answers the two texts, one after the other, each with a break.
    fn gui_all_text(&mut self) -> Result<String, String> {
        Err("this desktop cannot read the text of the window of the script".to_string())
    }

    /// The opacity of the window of the script, or set it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `WinSetTransparent` counts
    /// from nought to 255, and `WinGetTransparent` answers the number that was set.
    fn gui_opacity(&mut self, _setting: Option<i64>) -> Result<i64, String> {
        Err("this desktop cannot read the opacity of the window of the script".to_string())
    }

    /// Put a text into a control of the script at its cursor.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `EditPaste` takes the text
    /// **first** and the handle second, as the whole family does.
    fn gui_paste(&mut self, _number: u64, _text: &str) -> Result<(), String> {
        Err("this desktop cannot put a text into a control of the script".to_string())
    }

    /// Whether a check box of the script is ticked, and ticking it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: the `Value` of a check box
    /// is a **number**, nought or one, and its `Text` is its label.
    fn gui_checked(&mut self, _number: u64, _setting: Option<bool>) -> Result<i64, String> {
        Err("this desktop cannot read the tick of a check box of the script".to_string())
    }

    /// The scale factor of the output, as the session reports it.
    ///
    /// `A_ScreenDPI` is 96 times this, the number v2 gives with the scale of the
    /// session applied.
    fn screen_scale(&mut self) -> Result<i64, String> {
        Err("this desktop does not know the scale of the output".to_string())
    }

    fn screen_size(&mut self) -> Result<(i64, i64), String> {
        Err("this desktop cannot tell how big the screen is".to_string())
    }

    /// Show a small window of text, and answer the number that names it. An empty
    /// text takes it away. Measured on the binary of v2.0.19 on 2026-11-10:
    /// showing one answers an Integer and `ToolTip()` clears it.
    fn tooltip_show(&mut self, _text: &str, _x: i64, _y: i64) -> Result<i64, String> {
        Err("this desktop cannot show a tooltip".to_string())
    }

    /// Move and size the window of the script. Measured on the binary of v2.0.19
    /// on 2026-11-10: `WinMove` of the window the script made works and answers
    /// nothing. A Wayland compositor places windows itself, so the call is the
    /// one the toolkit offers and need not be honoured on the screen.
    fn window_move(&mut self, _x: i64, _y: i64, _width: i64, _height: i64) -> Result<(), String> {
        Err("this desktop cannot move the window of the script".to_string())
    }

    /// The monitors of the desktop, in the order it lists them.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `MonitorGetCount`
    /// answers a whole number, `MonitorGetName(1)` answers the name of the
    /// first output, and a monitor that is not there is refused with
    /// "Parameter #1 of MonitorGetName is invalid.".
    fn monitors(&mut self) -> Result<Vec<Monitor>, String> {
        Err("this desktop cannot list the monitors".to_string())
    }

    /// The first pixel of a colour inside a region, if there is one.
    fn pixel_search(
        &mut self,
        _x1: i64,
        _y1: i64,
        _x2: i64,
        _y2: i64,
        _colour: &str,
    ) -> Result<Option<(i64, i64)>, String> {
        Err("this desktop cannot search the screen for a colour".to_string())
    }

    /// The work area of a monitor: left, top, right and bottom.
    ///
    /// The work area is the part of the monitor that the panels and the
    /// taskbars leave. `None` is a monitor that is not there.
    fn monitor_work_area(
        &mut self,
        _monitor: usize,
    ) -> Result<Option<(i64, i64, i64, i64)>, String> {
        Err("this desktop cannot say the work area of its monitors".to_string())
    }

    /// The place of the primary monitor, counted from one, among the
    /// monitors of the desktop.
    fn primary_monitor(&mut self) -> Result<usize, String> {
        Err("this desktop cannot say which monitor is the primary one".to_string())
    }
}

/// The way the title of a window is matched with the text that is wanted.
///
/// Measured on the binary of v2.0.19 on 2026-10-31 and read in the
/// documentation of v2.0.19: the mode 1 wants the title of the window to
/// start with the text, the mode 2 wants it to have the text in it, the
/// mode 3 wants it to be the text, and the pattern wants the text to be a
/// regular expression.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TitleMatch {
    /// The title of the window starts with the text that is wanted.
    Starts,
    /// The title of the window has the text that is wanted in it.
    Contains,
    /// The title of the window is the text that is wanted.
    Exact,
    /// The text that is wanted is a pattern of a regular expression.
    Pattern,
}

impl TitleMatch {
    /// Whether the title of a window matches the text that is wanted.
    ///
    /// The case matters, as it matters in v2: "the window titles and text
    /// are case-sensitive". The only exception is the case-insensitive
    /// option of the pattern, which v2 spells with an `i)` at the front of
    /// the title.
    ///
    /// The pattern is the one of the engine of the tree, and a pattern that
    /// the engine does not carry is a failure with the reason of the engine.
    pub fn matches(self, title: &str, wanted: &str) -> Result<bool, String> {
        match self {
            TitleMatch::Starts => Ok(title.starts_with(wanted)),
            TitleMatch::Contains => Ok(title.contains(wanted)),
            TitleMatch::Exact => Ok(title == wanted),
            TitleMatch::Pattern => {
                // v2 spells the case-insensitive option of a title with an
                // `i)` at the front of it, and the engine of the tree spells
                // it with `(?i)`.
                let (pattern, ignore_case) = match wanted.strip_prefix("i)") {
                    Some(rest) => (rest, true),
                    None => (wanted, false),
                };
                let pattern = if ignore_case {
                    alloc::format!("(?i){pattern}")
                } else {
                    pattern.to_string()
                };
                let regex = crate::regex::Regex::new(&pattern)?;
                Ok(regex.find(title)?.is_some())
            }
        }
    }
}

/// A window of the desktop, as the listing of the windows describes it.
///
/// The two things that v2 reads of a window are the ones here: the identifier,
/// which is what `WinGetID` answers and what the entries of `WinGetList` are,
/// and the class, which is what `WinGetClass` answers.
///
/// The identifier of a Wayland window is a token that the compositor gives it,
/// and not a number, so it is text here. Measured on the binary of v2.0.19 on
/// 2026-11-09: the id of a window of Windows is a whole number, and a script
/// that does arithmetic on it would not have the same thing on Wayland.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct WindowRef {
    /// The identifier the compositor gives the window, or the empty text when
    /// it did not give one.
    pub id: String,
    /// The class of the window: the application id of it on Wayland, and the
    /// class of the window on X11.
    pub class: String,
}

/// Where a window is and how big it is.
///
/// The x and the y are the upper-left corner of the window, and not its
/// center; the width and the height are of the window that the user sees.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct WindowGeometry {
    /// The left of the window.
    pub x: i64,
    /// The top of the window.
    pub y: i64,
    /// How wide the window is.
    pub width: i64,
    /// How tall the window is.
    pub height: i64,
}

/// What a command of the `WinWait` family waits for.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WaitFor {
    /// A window that matches exists.
    Present,
    /// A window that matches exists and has the focus.
    Active,
    /// No window that matches has the focus.
    NotActive,
    /// No window that matches exists.
    Close,
}

/// The space of the drive that a path is on, in megabytes.
///
/// v2 answers the two numbers of a drive in megabytes, measured on the binary
/// of v2.0.19 on 2026-11-09: `DriveGetSpaceFree("C:\")` answered `836675` and
/// `DriveGetCapacity("C:\")` answered `3905969`, both whole numbers.
///
/// A drive of this tree is the filesystem that a path is on, because a Linux
/// box has mount points and not the letters of a drive.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DriveSpace {
    /// The space that is free, in megabytes.
    pub free: i64,
    /// The capacity of the drive, in megabytes.
    pub capacity: i64,
    /// The filesystem of the drive, as the machine names it: "ext4", "zfs".
    pub filesystem: String,
    /// The kind of the drive, in the word of v2: "Fixed", "Network",
    /// "Removable", "CDROM", "RAMDisk" or "Unknown".
    pub kind: String,
}

/// A monitor: an output of the desktop, and the rectangle of it.
///
/// The rectangle is in the space of the desktop, which is the space the windows
/// are placed in. It is what `MonitorGet` answers.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Monitor {
    /// The name of the output, when the desktop gives one.
    pub name: String,
    /// The left of the monitor.
    pub left: i64,
    /// The top of the monitor.
    pub top: i64,
    /// The right of the monitor.
    pub right: i64,
    /// The bottom of the monitor.
    pub bottom: i64,
    /// The scale of the monitor: 1 is the ordinary one.
    pub scale: i64,
}

/// What became of a question about a control of a window.
///
/// The two failures are different facts and v2 tells them apart. Measured on the
/// binary of v2.0.19 on 2026-11-09: `ControlGetText("x", "zzz-no-such-window-zzz")`
/// fails with **"Target window not found."** and the title in the `Extra`, and
/// `ControlGetText("x", "A")` -- a window that is there -- fails with **"Target
/// control not found."**. Neither of them answers an empty text, which is what
/// this tree answered before the measurement.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ControlAnswer {
    /// The control is there, and this is its text.
    Found(String),
    /// No window of the session has this title.
    NoSuchWindow,
    /// The window is there and the control is not in it.
    NoSuchControl,
}

/// What became of a question about a property of a control.
///
/// Measured on the binary of v2.0.19 on 2026-11-09 with a window of its own
/// making: `ControlGetVisible` and `ControlGetEnabled` answer **1** for a control
/// that is there and visible or enabled, so the answer is a number and not a
/// truth of the host; and the two failures are the two of `ControlGetText`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControlFlag {
    /// The control is there and the flag is set.
    Yes,
    /// The control is there and the flag is not set.
    No,
    /// No window of the session has this title.
    NoSuchWindow,
    /// The window is there and the control is not in it.
    NoSuchControl,
}

/// What became of a question that writes to a control.
///
/// Measured on the binary of v2.0.19 on 2026-11-09: `ControlSetText` answers the
/// **empty text** when it worked, and the two failures are the two of
/// `ControlGetText`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControlEdit {
    /// The text was written.
    Done,
    /// No window of the session has this title.
    NoSuchWindow,
    /// The window is there and the control is not in it.
    NoSuchControl,
}

/// The windows of the desktop.
pub trait Windows {
    /// Whether the window with this title is the active one.
    ///
    /// The mode is the way the title is matched with the text that is
    /// wanted: it is the setting of the script, and the runtime hands it
    /// with the question.
    fn window_active(&mut self, _title: &str, _mode: TitleMatch) -> Result<WindowAnswer, String> {
        Err("this desktop cannot tell which window is active".to_string())
    }

    /// Whether a window with this title exists.
    ///
    /// The mode is the way the title is matched with the text that is
    /// wanted: it is the setting of the script, and the runtime hands it
    /// with the question.
    fn window_exists(&mut self, _title: &str, _mode: TitleMatch) -> Result<WindowAnswer, String> {
        Err("this desktop cannot list the windows".to_string())
    }

    /// The title of the active window.
    fn active_window_title(&mut self) -> Result<Option<String>, String> {
        Err("this desktop cannot tell which window is active".to_string())
    }

    /// The windows whose title matches, in the order the desktop lists them.
    ///
    /// The empty title matches every window. Measured on the binary of
    /// v2.0.19 on 2026-11-09: `WinGetList()` and `WinGetList("")` both
    /// answered every window of the desktop, and `WinGetCount()` with no
    /// argument answered the number of them -- so an empty title is not "no
    /// window", and it is not "the last found window" either, because this
    /// runtime keeps none.
    fn matching_windows(
        &mut self,
        _title: &str,
        _mode: TitleMatch,
    ) -> Result<Vec<WindowRef>, String> {
        Err("this desktop cannot list the windows".to_string())
    }

    /// Where the window is and how big it is.
    ///
    /// `None` is a window that is not there. A window that **is** there but
    /// whose geometry the compositor did not describe is a failure with the
    /// reason, and not a geometry of zeros: a script must be told that the
    /// place is not known, and not be given a window at the origin.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `WinGetPos` writes
    /// its four answers into four variables given by reference, and it
    /// answers the empty text. A window that is not there is a failure --
    /// "Target window not found." -- and a call with no window at all is the
    /// same failure, because there is no last found window to fall back to.
    fn window_geometry(
        &mut self,
        _title: &str,
        _mode: TitleMatch,
    ) -> Result<Option<WindowGeometry>, String> {
        Err("this desktop cannot tell where a window is".to_string())
    }

    /// Whether a window is maximized, minimized, or neither.
    ///
    /// The answer is the number of v2: `1` for maximized, `-1` for minimized
    /// and `0` for neither. `None` is a window that is not there.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09, on a window of its
    /// own: `0` before, `1` after `WinMaximize`, `0` after `WinRestore`, and
    /// `-1` after `WinMinimize`.
    fn window_min_max(&mut self, _title: &str, _mode: TitleMatch) -> Result<Option<i64>, String> {
        Err("this desktop cannot tell whether a window is maximized".to_string())
    }

    /// Wait until a condition about a window holds.
    ///
    /// `Some` is the condition met, and the empty text is the answer of the
    /// conditions that are about the absence of a window -- `NotActive` and
    /// `Close` -- because there is no window to identify. `None` is the
    /// timeout.
    ///
    /// The empty title is no window at all: v2 falls back to the last found
    /// window, and this runtime keeps none, so the conditions that talk about
    /// the absence of a window hold at once and the ones that talk about its
    /// presence never do. Measured on the binary of v2.0.19 on 2026-11-09:
    /// `WinWaitNotActive("no-such")` and `WinWaitClose("no-such")` answered
    /// `1` at once, and `WinWait`/`WinWaitActive` answered `0` when the
    /// timeout ran out.
    fn window_wait(
        &mut self,
        _title: &str,
        _mode: TitleMatch,
        _what: WaitFor,
        _timeout_ms: u64,
    ) -> Result<Option<String>, String> {
        Err("this desktop cannot wait for a window".to_string())
    }

    /// The text of a named control of the window with this title.
    ///
    /// This is the **accessibility** layer: AT-SPI is a D-Bus protocol, and
    /// D-Bus is what a Wayland session keeps, so it is the one way to reach the
    /// controls of a window on the box. The AHK_X11 reaches the same layer
    /// through `at-spi.cr`, and it is the most valuable piece it has.
    ///
    /// A control is named, and the name is what a script writes: the text of a
    /// label, the caption of a button. The window is found by its title, which
    /// is the `Name` of a window in the tree.
    ///
    /// It is a method here and not a capability trait of its own, because the
    /// controls are the windows' and every fake desktop of the suite already
    /// answers `Windows`. A trait of its own is the rule of this tree, and it
    /// would have cost an empty `impl` in eighteen test files for no gain the
    /// suite can see.
    ///
    /// `None` is a window or a control that is not there, and not a failure: a
    /// script asks about a control that may be absent.
    fn control_text(&mut self, _control: &str, _title: &str) -> Result<ControlAnswer, String> {
        Err("this desktop cannot read the controls of a window".to_string())
    }

    /// Whether a named control of the window with this title is visible.
    fn control_visible(&mut self, _control: &str, _title: &str) -> Result<ControlFlag, String> {
        Err("this desktop cannot read the controls of a window".to_string())
    }

    /// Whether a named control of the window with this title is enabled.
    fn control_enabled(&mut self, _control: &str, _title: &str) -> Result<ControlFlag, String> {
        Err("this desktop cannot read the controls of a window".to_string())
    }

    /// Write a text into a named control of the window with this title.
    fn control_set_text(
        &mut self,
        _control: &str,
        _title: &str,
        _text: &str,
    ) -> Result<ControlEdit, String> {
        Err("this desktop cannot write to the controls of a window".to_string())
    }

    /// Click a named control of the window with this title.
    fn control_click(&mut self, _control: &str, _title: &str) -> Result<ControlEdit, String> {
        Err("this desktop cannot click the controls of a window".to_string())
    }

    /// Put the focus on a named control of the window with this title.
    fn control_focus(&mut self, _control: &str, _title: &str) -> Result<ControlEdit, String> {
        Err("this desktop cannot focus the controls of a window".to_string())
    }

    /// Type a text into a named control of the window with this title.
    ///
    /// The way in is two capabilities together: the focus goes on the control
    /// through the accessibility layer, and the keys go through the keyboard.
    fn control_send_text(
        &mut self,
        _control: &str,
        _title: &str,
        _text: &str,
    ) -> Result<ControlEdit, String> {
        Err("this desktop cannot type into the controls of a window".to_string())
    }

    /// The process of the window with this title.
    ///
    /// `None` is a window that is not there. Measured on the binary of v2.0.19 on
    /// 2026-11-09: `WinGetPID` answers the number of the process, and a title that
    /// no window has is "Target window not found.".
    fn window_pid(&mut self, _title: &str) -> Result<Option<i64>, String> {
        Err("this desktop cannot say the process of a window".to_string())
    }

    /// Whether a window of the script is open.
    ///
    /// It is what makes the lazy open composable: `gui_open` refuses a second
    /// window, so a member that needs one has to ask first whether there is one
    /// already. Without it, the second `Show` of a script would be refused by
    /// its own desktop.
    fn gui_is_open(&mut self) -> bool {
        false
    }

    /// Open a window of the script's own, and answer the handle of it.
    ///
    /// This is the `Gui` of v2. The window is **not shown**: measured on the
    /// binary of v2.0.19 on 2026-11-09, `Gui()` makes it and `Show()` puts it on
    /// the screen, and a script may add to it in between.
    fn gui_open(&mut self, _title: &str) -> Result<u64, String> {
        Err("this desktop cannot make a window of the script".to_string())
    }

    /// Add a control to a window of the script.
    ///
    /// The answer is the number that names the control and its `ClassNN`, which
    /// is the file name of the kind and the count of that kind -- `Edit1` for the
    /// first edit, whatever else was added before it. Measured on the binary of
    /// v2.0.19 on 2026-11-09.
    fn gui_add(&mut self, _handle: u64, _kind: &str, _text: &str) -> Result<(u64, String), String> {
        Err("this desktop cannot add a control to a window of the script".to_string())
    }

    /// The items of a list-shaped control of the script's window, one per line.
    /// Measured on the binary of v2.0.19 on 2026-11-10: `ControlGetItems`
    /// answers an array of them.
    fn gui_combo_items(&mut self, _number: u64) -> Result<String, String> {
        Err("this desktop cannot read the items of a list-shaped control".to_string())
    }

    /// Append an item to a list-shaped control. Measured on the same day:
    /// `ControlAddItem("gamma", ...)` makes the array one longer.
    fn gui_combo_add(&mut self, _number: u64, _text: &str) -> Result<(), String> {
        Err("this desktop cannot add an item to a list-shaped control".to_string())
    }

    /// Choose an item by its 1-based index or by its text. Returns the index.
    /// Measured on the same day: `ControlChooseIndex(2, ...)` leaves the
    /// control's `Value` at 2.
    fn gui_combo_select(
        &mut self,
        _number: u64,
        _wanted: &str,
        _by_text: bool,
    ) -> Result<i64, String> {
        Err("this desktop cannot choose an item of a list-shaped control".to_string())
    }

    /// The chosen item as (index, text). Measured on the same day: nothing
    /// chosen is (0, ""), and `ControlGetChoice` reads the text alone.
    fn gui_combo_choice(&mut self, _number: u64) -> Result<(i64, String), String> {
        Err("this desktop cannot read the choice of a list-shaped control".to_string())
    }

    /// Remove an item by its 1-based index. Measured on the binary of v2.0.19
    /// on 2026-11-10: `ControlDeleteItem(1, ...)` leaves the array one shorter.
    fn gui_combo_delete(&mut self, _number: u64, _index: &str) -> Result<(), String> {
        Err("this desktop cannot remove an item of a list-shaped control".to_string())
    }

    /// The 1-based index of the first item that is this text, or zero.
    fn gui_combo_find(&mut self, _number: u64, _text: &str) -> Result<i64, String> {
        Err("this desktop cannot find an item of a list-shaped control".to_string())
    }

    /// Open or close the pop-up of a list-shaped control. Measured on the
    /// binary of v2.0.19 on 2026-11-10: `ControlShowDropDown` and
    /// `ControlHideDropDown` both answer the empty text.
    fn gui_combo_dropdown(&mut self, _number: u64, _show: bool) -> Result<(), String> {
        Err("this desktop cannot open the pop-up of a list-shaped control".to_string())
    }

    /// The text of the status bar of the script's window. Measured on the
    /// binary of v2.0.19 on 2026-11-10: `StatusBarGetText(1, WinTitle)`
    /// answers it.
    fn gui_status_text(&mut self) -> Result<String, String> {
        Err("this desktop cannot read the text of a status bar".to_string())
    }

    // -- the list view ------------------------------------------------------------
    //
    // Measured on the binary of v2.0.19 on 2026-11-10: a ListView is
    // `SysListView321`, `lv.Add("", "a", "b")` answers a 1-based row number,
    // `lv.GetCount()` counts them, `lv.GetText(row, col)` reads a cell,
    // `lv.Modify(row, ...)` changes and selects one, `lv.GetNext()` gives the
    // next row, and `ListViewGetContent` answers the cells separated by tabs
    // and the rows by line breaks.

    /// Append a row of cells; answers its 1-based number.
    fn gui_list_add(&mut self, _number: u64, _cells: &[String]) -> Result<i64, String> {
        Err("this desktop cannot add a row to a list view".to_string())
    }

    /// The number of rows.
    fn gui_list_count(&mut self, _number: u64) -> Result<i64, String> {
        Err("this desktop cannot count the rows of a list view".to_string())
    }

    /// The text of one cell, by 1-based row and column.
    fn gui_list_text(&mut self, _number: u64, _row: i64, _col: i64) -> Result<String, String> {
        Err("this desktop cannot read a cell of a list view".to_string())
    }

    /// Every row, cells by tabs and rows by line breaks; `selected` limits it
    /// to the row that is chosen.
    fn gui_list_content(&mut self, _number: u64, _selected: bool) -> Result<String, String> {
        Err("this desktop cannot read the content of a list view".to_string())
    }

    /// Change the cells of a row and select it; answers 1.
    fn gui_list_modify(
        &mut self,
        _number: u64,
        _row: i64,
        _cells: &[String],
    ) -> Result<i64, String> {
        Err("this desktop cannot change a row of a list view".to_string())
    }

    /// The row after this one, or zero when there is none.
    fn gui_list_next(&mut self, _number: u64, _start: i64) -> Result<i64, String> {
        Err("this desktop cannot read the next row of a list view".to_string())
    }

    // -- the tree view ------------------------------------------------------------
    //
    // Measured on the binary of v2.0.19 on 2026-11-10: a TreeView is
    // `SysTreeView321`, `tv.Add(text, parent)` answers an item id, and the
    // Get* family walks the tree by those ids. This runtime numbers its items
    // sequentially from one, which is an identity a script can hold and compare.

    /// Add an item under a parent (0 = a root); answers its id.
    fn gui_tree_add(
        &mut self,
        _number: u64,
        _text: &str,
        _parent: i64,
        _options: &str,
    ) -> Result<i64, String> {
        Err("this desktop cannot add an item to a tree view".to_string())
    }

    /// The number of items.
    fn gui_tree_count(&mut self, _number: u64) -> Result<i64, String> {
        Err("this desktop cannot count the items of a tree view".to_string())
    }

    /// The text of an item.
    fn gui_tree_text(&mut self, _number: u64, _item: i64) -> Result<String, String> {
        Err("this desktop cannot read the text of an item of a tree view".to_string())
    }

    /// A related item's id: "parent", "child", "next" or "prev".
    fn gui_tree_relation(
        &mut self,
        _number: u64,
        _item: i64,
        _relation: &str,
    ) -> Result<i64, String> {
        Err("this desktop cannot walk a tree view".to_string())
    }

    /// The id of the selected item, or zero.
    fn gui_tree_selection(&mut self, _number: u64) -> Result<i64, String> {
        Err("this desktop cannot read the selection of a tree view".to_string())
    }

    /// Select or expand an item; answers its id.
    fn gui_tree_modify(&mut self, _number: u64, _item: i64, _options: &str) -> Result<i64, String> {
        Err("this desktop cannot change an item of a tree view".to_string())
    }

    /// Remove an item.
    fn gui_tree_delete(&mut self, _number: u64, _item: i64) -> Result<i64, String> {
        Err("this desktop cannot delete an item of a tree view".to_string())
    }

    /// A second, independent text slot on a control.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-10: on an Edit or a Text
    /// control `Value` and `Text` are the SAME text, but a Hotkey keeps them
    /// apart -- writing `hk.Text` does not change `hk.Value` and the other way
    /// round. A Link is the other shape: its `Value` is always empty and
    /// writing it is refused with "Invalid usage.", while `Text` is its
    /// caption. This slot is the second string for those two kinds.
    fn gui_second_value(&mut self, _number: u64, _setting: Option<&str>) -> Result<String, String> {
        Err("this desktop has no second text slot for a control".to_string())
    }

    /// The place and size of a control of the script's window, relative to its
    /// client area: (x, y, width, height).
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-10: `ControlGetPos` with
    /// four VarRef outputs answers the four numbers. The reference does NOT
    /// hang on this name -- the earlier note was a call with plain strings.
    fn gui_control_pos(&mut self, _number: u64) -> Result<(i64, i64, i64, i64), String> {
        Err("this desktop cannot say where a control of the window is".to_string())
    }

    /// Show a menu bar on the window of the script.
    ///
    /// The JSON is an array of `[name, callback]` entries. Measured on the
    /// binary of v2.0.19 on 2026-11-10: a `MenuBar` attached with
    /// `Gui.Menu :=` shows at the top of the window.
    fn gui_menu_bar(&mut self, _json: &str) -> Result<(), String> {
        Err("this desktop cannot show a menu bar on the window of the script".to_string())
    }

    /// Where the caret of the text is, in the client coordinates of the
    /// window of the script.
    ///
    /// `None` is no caret: no window, or nothing focused that holds one.
    /// Measured on the binary of v2.0.19 on 2026-11-10: with no window
    /// `CaretGetPos` answers 0 and the variables of the caller are left
    /// untouched; with a focused Edit it answers 1 and the place of the
    /// caret in the client area.
    fn gui_caret(&mut self) -> Result<Option<(i64, i64)>, String> {
        Err("this desktop cannot find the caret of the window".to_string())
    }

    /// Put a window of the script on the screen.
    fn gui_show(&mut self, _handle: u64) -> Result<(), String> {
        Err("this desktop cannot show a window of the script".to_string())
    }

    /// Take a window of the script away.
    fn gui_destroy(&mut self, _handle: u64) -> Result<(), String> {
        Err("this desktop cannot take away a window of the script".to_string())
    }

    /// Read the text of a control of a window of the script, or write it.
    ///
    /// The number is the one `gui_add` answered, which is the `Hwnd` of the
    /// control. Measured on the binary of v2.0.19 on 2026-11-09: `Value` of a
    /// control is read and written as text.
    fn gui_value(&mut self, _number: u64, _setting: Option<&str>) -> Result<String, String> {
        Err("this desktop cannot read the text of a control of the script".to_string())
    }

    /// Read a flag of a control of a window of the script, or write it.
    ///
    /// The flag is `"enabled"` or `"visible"`. Measured on the binary of v2.0.19
    /// on 2026-11-09: both are integers of nought and one, read and written.
    fn gui_flag(
        &mut self,
        _number: u64,
        _name: &str,
        _setting: Option<bool>,
    ) -> Result<i64, String> {
        Err("this desktop cannot read a flag of a control of the script".to_string())
    }

    /// Set a state of a control of the script's window, named by its `ClassNN`.
    ///
    /// The states are `"visible"` and `"enabled"`.
    fn gui_control_state(&mut self, _classnn: &str, _what: &str, _on: bool) -> Result<(), String> {
        Err("this desktop cannot set a state of a control of the script".to_string())
    }

    /// Show or hide a control of the script's window, named by its `ClassNN`.
    fn gui_visibility(&mut self, _classnn: &str, _on: bool) -> Result<(), String> {
        Err("this desktop cannot show or hide a control of the script".to_string())
    }

    /// The number that names a control of the script's window, from its `ClassNN`.
    fn gui_number_named(&mut self, _classnn: &str) -> Result<i64, String> {
        Err("this desktop cannot find a control of the script by its name".to_string())
    }

    /// Which control of the script's window has the focus, as its `ClassNN`.
    fn gui_focused(&mut self) -> Result<String, String> {
        Err("this desktop cannot read the focus of a control of the script".to_string())
    }

    /// The text a control of the script has selected.
    fn gui_selection(&mut self, _number: u64) -> Result<String, String> {
        Err("this desktop cannot read the selection of a control of the script".to_string())
    }

    /// Where the cursor of a control of the script is, as a place in its text.
    fn gui_cursor(&mut self, _number: u64) -> Result<i64, String> {
        Err("this desktop cannot read the cursor of a control of the script".to_string())
    }

    /// How many lines the text of a control of the script holds.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `EditGetLineCount` of a
    /// control added with three lines answers 3.
    fn gui_line_count(&mut self, _number: u64) -> Result<i64, String> {
        Err("this desktop cannot count the lines of a control of the script".to_string())
    }

    /// Apply one option to a window of the script, with the sign the script wrote.
    ///
    /// The options a program controls under this compositor are `AlwaysOnTop`,
    /// `Resize`, `Caption` and `Disabled`; the rest are refused with the reason.
    fn gui_option(&mut self, _name: &str, _on: bool) -> Result<(), String> {
        Err("this desktop cannot set an option of the window of the script".to_string())
    }

    /// Take a window of the script off the screen.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `Hide` answers the empty
    /// text and takes no parameters.
    fn gui_hide(&mut self) -> Result<(), String> {
        Err("this desktop cannot hide the window of the script".to_string())
    }

    /// Put the focus on a control of a window of the script.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `Focus` answers the empty
    /// text and takes no parameters.
    fn gui_focus(&mut self, _number: u64) -> Result<(), String> {
        Err("this desktop cannot put the focus on a control of the script".to_string())
    }

    /// Set the size of a control of a window of the script.
    ///
    /// The **size** and not the place: measured on 2026-11-09, the window this
    /// tree makes lays its controls out in order, and GTK gives a child of a
    /// layout no place of its own.
    fn gui_size(&mut self, _number: u64, _width: i64, _height: i64) -> Result<(), String> {
        Err("this desktop cannot size a control of the script".to_string())
    }

    /// Read the events of the windows of the script that have happened.
    ///
    /// The answer is the events **since the last time it was asked**, one name
    /// each, and an empty answer is the common case and must cost almost
    /// nothing. Measured on the binary of v2.0.19 on 2026-11-09: the events a
    /// window of a script has are `close`, `escape`, and a click on a control.
    fn gui_events(&mut self) -> Result<Vec<String>, String> {
        Ok(Vec::new())
    }

    /// Read the title of a window of the script, or write it.
    fn gui_title(&mut self, _handle: u64, _setting: Option<&str>) -> Result<String, String> {
        Err("this desktop cannot say the title of a window of the script".to_string())
    }

    /// The capabilities of the windows of this desktop.
    ///
    /// The names are the ones of `WinGetCapability`: `AlwaysOnTopGet`,
    /// `AlwaysOnTopSet`, `WindowEnabledGet`, `ControlEnabledGet`,
    /// `WindowList`, `WindowActivate`, `WindowMinimize` and `WindowClose`.
    /// Only a capability the machine can really answer is here.
    fn window_capabilities(&mut self) -> Vec<String> {
        Vec::new()
    }

    /// Whether a window is enabled, when the machine knows.
    ///
    /// This is the state of the window itself. On a session of X11 it is
    /// the state of the window of the machine; on a native Wayland session
    /// it is mapped and not minimized, because the compositor publishes no
    /// more than that.
    fn window_enabled(&mut self, _window: &WindowInfo) -> Result<Option<bool>, String> {
        Err("this desktop cannot say whether a window is enabled".to_string())
    }

    /// Put a window above the others, or take it from there.
    ///
    /// The answer is a failure with the reason when the machine cannot do
    /// it: a change that did not happen is never reported as a change that
    /// did.
    fn set_always_on_top(&mut self, _window: &WindowInfo, _on: bool) -> Result<(), String> {
        Err("this desktop cannot put a window above the others".to_string())
    }

    /// Whether a window is above the others, when the machine knows.
    ///
    /// `Ok(None)` is the answer of a machine that cannot say: it is not
    /// `false`, and the caller refuses with the reason. A question that
    /// cannot be answered does not answer `false` in this tree.
    fn always_on_top(&mut self, _window: &WindowInfo) -> Result<Option<bool>, String> {
        Err("this desktop cannot say whether a window is above the others".to_string())
    }

    /// The windows of the session, in the order the desktop lists them.
    ///
    /// The id of a window is the identifier of this runtime, and not a handle
    /// of Windows: a script hands it back to this runtime, and a number that
    /// no window has is a window that is not there -- it is not a failure.
    /// The class of a window is the name the desktop gives it: the
    /// application id on Wayland, and the class of the window on X11.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `WinGetList` answers
    /// the ids of the windows as an array, `WinGetCount` their number, and
    /// the class of a window is the class name the system gives it.
    fn windows(&mut self) -> Result<Vec<WindowInfo>, String> {
        Err("this desktop cannot list the windows".to_string())
    }

    /// The window at a point of the screen.
    ///
    /// The answer is `None` when no window is at the point, and a failure
    /// with the reason when the machine cannot say: zero means "no
    /// window", and a desktop that does not publish what is under a point
    /// does not answer zero for it.
    fn the_window_at(&mut self, _x: i64, _y: i64) -> Result<Option<i64>, String> {
        Err("this desktop cannot say which window is at a point".to_string())
    }
}

/// The processes of the desktop.
pub trait Processes {
    /// Run a command; return its exit code, stdout and stderr.
    fn run(&mut self, command: &str, window: &str) -> Result<(i32, String, String), String>;

    /// Launch a program without waiting for it; return the pid of it.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `Run` of the
    /// v1 does not wait for the program, and it writes the pid of it into a
    /// variable of the script. The desktop that cannot launch a program says
    /// so, and not `false`.
    fn launch(&mut self, _command: &str, _working_dir: &str) -> Result<u32, String> {
        Err("this desktop cannot launch a program".to_string())
    }

    /// Launch a program and wait for it; return the pid of it, the code and
    /// what it wrote.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `RunWait` of
    /// the v1 waits for the program and writes the pid of it into a variable
    /// of the script. The desktop that cannot launch a program says so, and
    /// not `false`.
    fn run_and_wait(
        &mut self,
        _command: &str,
        _working_dir: &str,
    ) -> Result<(u32, i32, String, String), String> {
        Err("this desktop cannot launch a program".to_string())
    }

    /// The value of an environment variable.
    ///
    /// The value is `None` when the environment does not have the variable,
    /// and the value of a variable that is there may be the empty text.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// warning of the environment is given when the variable is there, and the
    /// name that the environment does not have is a name that has no value.
    fn env_get(&mut self, _name: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot read the environment".to_string())
    }

    /// Set an environment variable; answer what it was set to.
    fn env_set(&mut self, _name: &str, _value: &str) -> Result<String, String> {
        Err("this desktop cannot write the environment".to_string())
    }

    // -- the processes -----------------------------------------------------------
    //
    // The process family of v2.0.19 asks about a process by the pid of it or
    // by the name of it, and `None` means the process of the script itself.
    //
    // Measured on the binary of v2.0.19 on 2026-11-09: the name of a call is
    // the text of it, and a text that is a number is a pid -- a pid that is
    // not there answers zero, and it is not a failure. The methods below are
    // the ones of the capability: a desktop that has no processes says so
    // with the reason, and never answers zero for a question it cannot ask.
    //
    // The shape of each answer is the one of the binary of v2.0.19, measured
    // on the same day; the Linux reading behind them is in `ahk-box`, over
    // `/proc`.

    /// The pid of a process, and zero when there is no such process.
    fn process_exist(&mut self, _which: Option<&str>) -> Result<u32, String> {
        Err("this desktop cannot read the processes of the machine".to_string())
    }

    /// The name of the executable of a process.
    ///
    /// The name is the file name of the executable, and not the whole path
    /// of it. `None` is a process that is not there, which the caller says
    /// with the words of the dialect: "Target process not found.", of the
    /// class `TargetError`.
    fn process_name(&mut self, _which: Option<&str>) -> Result<Option<String>, String> {
        Err("this desktop cannot read the processes of the machine".to_string())
    }

    /// The full path of the executable of a process.
    ///
    /// `None` is a process that is not there, which the caller says with the
    /// words of the dialect.
    fn process_path(&mut self, _which: Option<&str>) -> Result<Option<String>, String> {
        Err("this desktop cannot read the processes of the machine".to_string())
    }

    /// The pid of the parent of a process, and zero when there is no such
    /// process.
    fn process_parent(&mut self, _which: Option<&str>) -> Result<u32, String> {
        Err("this desktop cannot read the processes of the machine".to_string())
    }

    /// Close a process: answer the pid that was closed, and zero when the
    /// process was not there or could not be closed.
    fn process_close(&mut self, _which: &str) -> Result<u32, String> {
        Err("this desktop cannot close a process of the machine".to_string())
    }

    /// Wait for a process to exist: answer the pid of it, and zero at the
    /// timeout.
    ///
    /// A timeout of `None` waits forever, which is what the omitted timeout
    /// of the binary does.
    fn process_wait(&mut self, _which: &str, _timeout: Option<f64>) -> Result<u32, String> {
        Err("this desktop cannot wait for a process of the machine".to_string())
    }

    /// Wait for a process that is there to close.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: the answer is zero
    /// when the process is not there any more -- a process that never existed
    /// included -- and the pid of the process that is still there at the
    /// timeout.
    fn process_wait_close(&mut self, _which: &str, _timeout: Option<f64>) -> Result<u32, String> {
        Err("this desktop cannot wait for a process of the machine".to_string())
    }

    /// Set the priority of a process: answer the pid of it.
    ///
    /// The priority is the word of v2 -- "Low", "BelowNormal", "Normal",
    /// "AboveNormal", "High" or "Realtime", and the binary reads the first
    /// letter of it -- and `None` is a process that is not there, which the
    /// caller says with the words of the dialect.
    fn process_set_priority(
        &mut self,
        _priority: &str,
        _which: Option<&str>,
    ) -> Result<Option<u32>, String> {
        Err("this desktop cannot set the priority of a process".to_string())
    }

    /// Kill a process.
    ///
    /// The answer is a failure with the reason when the machine cannot do
    /// it: a process that is not killed is never reported as killed.
    fn kill_a_process(&mut self, _pid: u32) -> Result<(), String> {
        Err("this desktop cannot kill a process".to_string())
    }

    fn the_state_of_a_process(&mut self, _pid: u32) -> Result<Option<ProcessState>, String> {
        Err("this desktop cannot say the state of a process".to_string())
    }

    /// Start a program with a text on its standard input and wait for
    /// it; return the pid, the code of the exit and what it wrote.
    fn run_with_stdin(
        &mut self,
        _program: &str,
        _arguments: &[String],
        _standard_input: &str,
        _working_dir: &str,
    ) -> Result<(u32, i32, String, String), String> {
        Err("this desktop cannot launch a program".to_string())
    }

    /// Start a program with a text on its standard input, and do not
    /// wait for it; return the pid of it.
    ///
    /// The runner of the tree reads its script on the standard input, so
    /// a program that is started this way receives what the script gives
    /// it there. A desktop that cannot start a program says so.
    fn launch_with_stdin(
        &mut self,
        _program: &str,
        _arguments: &[String],
        _standard_input: &str,
        _working_dir: &str,
    ) -> Result<u32, String> {
        Err("this desktop cannot launch a program".to_string())
    }
}

/// The files of the desktop.
pub trait Files {
    /// Create a shortcut to a program, the way this platform makes one.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `FileCreateShortcut` answers the
    /// empty text and makes the file, and it makes it even for a target that is not
    /// there.
    fn create_shortcut(
        &mut self,
        _target: &str,
        _shortcut: &str,
        _working_directory: &str,
        _arguments: &str,
        _description: &str,
        _icon: &str,
    ) -> Result<(), String> {
        Err("this desktop cannot create a shortcut".to_string())
    }

    /// Empty the trash of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `FileRecycleEmpty` answers the
    /// empty text.
    fn empty_the_trash(&mut self) -> Result<(), String> {
        Err("this desktop cannot empty the trash".to_string())
    }

    /// Put one file in the trash of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-10: `FileRecycle(path)`
    /// answers the empty text and the file is gone. An earlier note said the
    /// reference answers "Failed" for a file that exists -- that was a path
    /// that was not there, not the name.
    fn recycle_a_file(&mut self, _path: &str) -> Result<(), String> {
        Err("this desktop cannot put a file in the trash".to_string())
    }

    /// Read a shortcut back: (target, dir, args, description, icon).
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-10: `FileGetShortcut` of a
    /// shortcut answers all eight of its fields. The icon NUMBER and the run
    /// state have no counterpart in a `.desktop` file, so those two answers
    /// are the empty text here.
    fn read_shortcut(
        &mut self,
        _shortcut: &str,
    ) -> Result<(String, String, String, String, String), String> {
        Err("this desktop cannot read a shortcut".to_string())
    }

    /// The directory the script is in.
    ///
    /// The name of the directory is a subfolder of the working directory
    /// when it is not an absolute path.
    fn set_working_directory(&mut self, _directory: &str) -> Result<String, String> {
        Err("this desktop cannot change the working directory".to_string())
    }

    /// The files of a directory that match a pattern.
    ///
    /// The mode is v2's: "R" walks into the subfolders as well, and "D"
    /// gives the directories instead of the files. The "A" gives the files
    /// and the directories together, and it is the mode of the v1 that has
    /// the number one.
    fn list_files(
        &mut self,
        _folder: &str,
        _pattern: &str,
        _mode: &str,
    ) -> Result<Vec<String>, String> {
        Err("this desktop cannot list the files of a directory".to_string())
    }

    /// The directory where the run started.
    ///
    /// It is the directory the run began in, and not the one that the run
    /// is in now: a script that changes the working directory does not
    /// change this one.
    fn initial_working_directory(&mut self) -> Result<String, String> {
        Err("this desktop cannot say where the run started".to_string())
    }

    /// The directory the script runs in.
    fn working_directory(&mut self) -> Result<String, String> {
        Err("this desktop cannot tell where the script runs".to_string())
    }

    /// The lines of a file.
    fn read_file(&mut self, _path: &str) -> Result<Vec<String>, String> {
        Err("this desktop cannot read a file".to_string())
    }

    /// The bytes of a file.
    ///
    /// The read of a file is the bytes of it: the dialect reads them in the
    /// encoding that it asks for, and the machine keeps them as they are.
    fn read_the_bytes_of_a_file(&mut self, _path: &str) -> Result<Vec<u8>, String> {
        Err("this desktop cannot read a file".to_string())
    }

    /// The path of a file, in the form the machine writes it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `TraySetIcon` puts
    /// the icon of the script, and `A_IconFile` answers the path of it in
    /// the canonical form of the machine -- "C:\WINDOWS\System32\SHELL32.dll"
    /// for the shell32.dll that the script wrote in another case.
    fn canonical_path(&mut self, _path: &str) -> Result<String, String> {
        Err("this desktop cannot write the canonical form of a path".to_string())
    }

    /// Write a file, replacing what was in it; return what was written.
    fn write_file(&mut self, _path: &str, _text: &str) -> Result<String, String> {
        Err("this desktop cannot write a file".to_string())
    }

    /// Add to the end of a file; return what was added.
    ///
    /// The bytes are the ones the dialect wrote, and the mark is the mark of
    /// the encoding of the file: the machine writes it when the file is
    /// made, and not when the file is already there.
    fn append_file(&mut self, _path: &str, _bytes: &[u8], _mark: &[u8]) -> Result<String, String> {
        Err("this desktop cannot write a file".to_string())
    }

    /// The attributes of the first entry that matches the pattern.
    ///
    /// The pattern is v2's: the last part of it may carry the wildcards
    /// `*` and `?`, and the answer is the attributes of the first entry
    /// that matches, a folder among them. The empty list is the answer
    /// when there is none. A folder is asked for with the mode "D", and
    /// any entry with the empty mode.
    fn attributes_of_the_pattern(
        &mut self,
        _pattern: &str,
        _mode: &str,
    ) -> Result<Vec<String>, String> {
        Err("this desktop cannot look for a file".to_string())
    }

    /// Take a file away.
    fn delete_file(&mut self, _path: &str) -> Result<String, String> {
        Err("this desktop cannot delete a file".to_string())
    }

    /// Make a directory.
    fn create_dir(&mut self, _path: &str) -> Result<String, String> {
        Err("this desktop cannot make a directory".to_string())
    }

    /// Take a directory away.
    ///
    /// The flag asks for the folder with the contents of it: v2 has the
    /// option, and without it a folder that is not empty stays.
    fn dir_delete(&mut self, _path: &str, _recurse: bool) -> Result<String, String> {
        Err("this desktop cannot delete a directory".to_string())
    }

    /// Open a file and answer the handle of it.
    ///
    /// The mode is the way AutoHotkey spells it: `r`, `w`, `a` or `rw`.
    fn open_file(&mut self, _path: &str, _mode: &str) -> Result<i64, String> {
        Err("this desktop cannot open a file".to_string())
    }

    /// The bytes of an open file, at a place in it.
    fn read_file_at(&mut self, _handle: i64, _pos: i64, _count: i64) -> Result<Vec<u8>, String> {
        Err("this desktop cannot read a file".to_string())
    }

    /// Write bytes to an open file, at a place in it; answer how many
    /// were written.
    fn write_file_at(&mut self, _handle: i64, _pos: i64, _bytes: &[u8]) -> Result<usize, String> {
        Err("this desktop cannot write a file".to_string())
    }

    /// How big an open file is.
    fn file_size(&mut self, _handle: i64) -> Result<i64, String> {
        Err("this desktop cannot tell how big a file is".to_string())
    }

    /// How big a file is, in the bytes of it.
    ///
    /// The answer is the size of the file and not the size of a folder: the
    /// machine gives the size of a folder as zero.
    fn the_size_of_a_file(&mut self, _path: &str) -> Result<i64, String> {
        Err("this desktop cannot tell how big a file is".to_string())
    }

    /// Close an open file.
    fn close_file(&mut self, _handle: i64) -> Result<(), String> {
        Err("this desktop cannot close a file".to_string())
    }

    /// Take a copy of a file.
    fn copy_file(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
        Err("this desktop cannot copy a file".to_string())
    }

    /// Move a file.
    fn move_file(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
        Err("this desktop cannot move a file".to_string())
    }

    /// Take a copy of a folder and of everything in it.
    fn copy_dir(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
        Err("this desktop cannot copy a folder".to_string())
    }

    /// Move a folder.
    fn move_dir(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
        Err("this desktop cannot move a folder".to_string())
    }

    /// The attributes of a file.
    fn file_attributes(&mut self, _path: &str) -> Result<Vec<String>, String> {
        Err("this desktop cannot read the attributes of a file".to_string())
    }

    /// Change the attributes of a file.
    fn set_file_attributes(
        &mut self,
        _path: &str,
        _attributes: &[String],
    ) -> Result<String, String> {
        Err("this desktop cannot change the attributes of a file".to_string())
    }

    /// The times of a file: when it was made, when it was changed, when it
    /// was read.
    fn file_times(&mut self, _path: &str) -> Result<(i64, i64, i64), String> {
        Err("this desktop cannot read the times of a file".to_string())
    }

    /// Change the times of a file.
    ///
    /// A time of nothing is a time that does not change.
    fn set_file_times(
        &mut self,
        _path: &str,
        _created: Option<i64>,
        _modified: Option<i64>,
        _accessed: Option<i64>,
    ) -> Result<String, String> {
        Err("this desktop cannot change the times of a file".to_string())
    }

    /// The value of a key of an ini file.
    fn ini_read(
        &mut self,
        _path: &str,
        _section: &str,
        _key: &str,
        _default: &str,
    ) -> Result<String, String> {
        Err("this desktop cannot read an ini file".to_string())
    }

    /// Write a key of an ini file.
    fn ini_write(
        &mut self,
        _path: &str,
        _section: &str,
        _key: &str,
        _value: &str,
    ) -> Result<String, String> {
        Err("this desktop cannot write an ini file".to_string())
    }

    /// Take a key of an ini file away.
    fn ini_delete(&mut self, _path: &str, _section: &str, _key: &str) -> Result<String, String> {
        Err("this desktop cannot write an ini file".to_string())
    }

    /// Empty the trash of the machine.
    ///
    /// The answer is nothing. A `drive` that is given names the trash to
    /// empty, and the deskop that has one trash for the whole machine
    /// empties it for any drive.
    fn empty_trash(&mut self, _drive: Option<&str>) -> Result<(), String> {
        Err("this desktop has no trash to empty".to_string())
    }

    /// Recycle a file or a folder, or the files that a pattern matches.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: a file that is there
    /// is recycled and the answer is nothing; a plain path that is not there
    /// is the failure "Failed"; and a pattern that matches nothing is not a
    /// failure. A desktop with no trash says so.
    fn recycle(&mut self, _pattern: &str) -> Result<(), String> {
        Err("this desktop has no trash to recycle a file into".to_string())
    }

    /// Make an empty temporary file, and answer its full path.
    ///
    /// Measured on the documentation of KeySharp on 2026-11-11:
    /// `FileCreateTemp()` makes the file and answers where it is.
    fn create_temp_file(&mut self) -> Result<String, String> {
        Err("this desktop cannot make a temporary file".to_string())
    }

    /// The directory the script is in.
    ///
    /// The name of the directory is a subfolder of the working directory
    /// when it is not an absolute path.
    /// Create a shortcut to a program, the way this platform makes one.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `FileCreateShortcut`
    /// answers the empty text and makes the file, and it makes it even for a
    /// target that is not there.
    /// The full path to a file, the way the platform writes one.
    ///
    /// Measured on the documentation of KeySharp on 2026-11-11:
    /// `FileFullPath(Filename)` answers the full path to the file.
    fn full_path(&mut self, _path: &str) -> Result<String, String> {
        Err("this desktop cannot say the full path of a file".to_string())
    }
}

/// The clipboard of the desktop.
pub trait Clipboard {
    /// What is on the clipboard.
    fn clipboard_read(&mut self) -> Result<String, String> {
        Err("this desktop cannot read the clipboard".to_string())
    }

    /// Put something on the clipboard.
    fn clipboard_write(&mut self, _text: &str) -> Result<String, String> {
        Err("this desktop cannot write the clipboard".to_string())
    }
}

/// The timers of the desktop.
///
/// The runtime runs the timer of a script between the statements of the
/// script, so the budget of a timer is the budget of the script. This is
/// asked only of a desktop that wants the timers of its own.
pub trait Timers {
    /// Whether the desktop takes the timers of the script over.
    fn takes_over_timers(&mut self) -> bool {
        false
    }
}

/// The hotkeys of the desktop.
pub trait Hotkeys {
    /// Register a hotkey, spelled the way the script spells it.
    fn register_hotkey(&mut self, _name: &str) -> Result<String, String> {
        Err("this desktop cannot register a hotkey".to_string())
    }

    /// Take a hotkey away.
    fn unregister_hotkey(&mut self, _name: &str) -> Result<String, String> {
        Err("this desktop cannot register a hotkey".to_string())
    }

    /// The hotkeys that are registered.
    fn hotkeys(&mut self) -> Result<Vec<String>, String> {
        Err("this desktop cannot list the hotkeys".to_string())
    }

    /// The hotkey that was pressed since the last question.
    ///
    /// The desktop watches the keyboard and says which of the hotkeys it
    /// registered was pressed; the runtime owns the function that the
    /// hotkey runs, and asks this between the statements of the script.
    fn fired_hotkey(&mut self) -> Result<Option<String>, String> {
        Err("this desktop cannot watch the keyboard".to_string())
    }
}

/// The native calls of the desktop.
///
/// A call into a library of the machine is not something the language
/// can do: the crate does no I/O of its own, and the desktop is the way
/// out. The call carries the blocks the callee may write into, and the
/// answer comes back with them.
pub trait Native {
    /// The call of a function of a library.
    fn call_native(&mut self, _call: &mut NativeCall) -> Result<NativeResult, NativeFailure> {
        Err(NativeFailure::invalid(
            "this desktop cannot make a native call.",
        ))
    }
}

/// The pictures of the desktop.
///
/// A picture is an image of the machine, and the machine is the one
/// that reads it: a desktop that does not read the images says so.
pub trait Pictures {
    /// Load a picture of a file, and answer the number that identifies
    /// it.
    ///
    /// `None` is the answer when the picture is not there: v2 answers
    /// zero in that case, and not a failure.
    fn load_picture(
        &mut self,
        _filename: &str,
        _options: &PictureOptions,
    ) -> Result<Option<u32>, String> {
        Err("the picture is read by the desktop, and this desktop does not read the images of the machine.".to_string())
    }

    /// Look for a picture on the screen.
    fn image_search(
        &mut self,
        _x1: i64,
        _y1: i64,
        _x2: i64,
        _y2: i64,
        _image: &Image,
        _options: &ImageOptions,
    ) -> Result<ImageSearch, String> {
        Err("the search of a picture is made by the desktop, and this desktop does not read the images of the machine.".to_string())
    }
}

/// The network of the desktop.
///
/// A download is a file that comes from the network, and the network is
/// the machine's: a desktop that does not reach it says so.
pub trait Network {
    /// Fetch a file of the network and write it on the disk.
    ///
    /// The answer is the path of the file that was written.
    fn download(&mut self, _url: &str, _file: &str) -> Result<String, String> {
        Err(
            "the download is made by the desktop, and this desktop does not reach the network."
                .to_string(),
        )
    }

    /// The IPv4 addresses of the interfaces of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `SysGetIPAddresses`
    /// answers an **array** of the addresses as text, in the order the machine
    /// lists them.
    fn ip_addresses(&mut self) -> Result<Vec<String>, String> {
        Err("this desktop cannot list the addresses of its interfaces.".to_string())
    }

    /// Send a mail message through the network of the machine.
    ///
    /// A desktop that cannot send a mail says so with the reason: a
    /// message that was not sent is never reported as sent.
    fn send_mail(&mut self, _message: &MailMessage) -> Result<(), String> {
        Err("this desktop cannot send mail".to_string())
    }
}

/// The options of a picture.
///
/// The options are the ones of v2: the size the picture is loaded at,
/// and the icon of a file that has many. The runtime reads them, and
/// the desktop keeps the ones that are about the machine.
#[derive(Clone, Debug, Default)]
pub struct PictureOptions {
    /// The width of the picture, in pixels.
    pub width: Option<i64>,
    /// The height of the picture, in pixels.
    pub height: Option<i64>,
    /// The icon of a file that has many.
    pub icon: Option<i64>,
}

/// The options of a search of the screen for a picture.
#[derive(Clone, Debug, Default)]
pub struct ImageOptions {
    /// How much the colours of the screen may differ from the picture.
    pub variation: i64,
    /// The size the picture is looked for at.
    pub width: Option<i64>,
    /// The size the picture is looked for at.
    pub height: Option<i64>,
    /// The colour of the picture that matches any colour of the screen.
    pub transparent: Option<String>,
}

/// The picture of a search.
///
/// v2 writes the picture as the name of a file, and it writes the
/// handle of a picture that was loaded before in the spelling of
/// Windows: "HBITMAP:*123". The runtime reads both.
#[derive(Clone, Debug)]
pub enum Image {
    /// A picture of a file.
    File(String),
    /// A picture that was loaded before.
    Loaded(u32),
}

/// The answer of a search of the screen for a picture.
#[derive(Clone, Debug)]
pub enum ImageSearch {
    /// The picture is not on the screen.
    NotFound,
    /// The picture is on the screen, at this place.
    Found(i64, i64),
    /// The picture could not be loaded.
    NotLoadable,
}

/// The sound of the machine.
///
/// The names are the ones of v2: the volume of a device, whether it is
/// muted, and the playing of a sound. The device is named by the script
/// with the name of the device, or with `#` and its number -- `#1` is
/// the first device -- and the empty name is the device of the system.
pub trait Sound {
    /// The names of the sound devices of the machine: the one that plays
    /// and the one that records.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `SoundGetName` with
    /// no component answers the name of the device that plays -- "Speakers
    /// (Fosi Audio K5 Pro)" on the machine of that day -- and with the
    /// component one the name of the one that records -- "Microphone".
    fn sound_device_names(&mut self) -> Result<(String, String), String> {
        Err("this desktop cannot tell the names of the sound devices".to_string())
    }

    /// The name of the sound device of this name, if the machine has one.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `SoundGetName` with
    /// a device that the machine does not have throws "Component not
    /// found.".
    fn sound_device_named(&mut self, _device: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot tell the names of the sound devices".to_string())
    }
    /// The volume of a device, as a number between 0 and 100.
    fn sound_volume(&mut self, _device: &str) -> Result<f64, String> {
        Err("this desktop cannot say the volume of a device".to_string())
    }

    /// Set the volume of a device, as a number between 0 and 100.
    fn sound_set_volume(&mut self, _device: &str, _volume: f64) -> Result<(), String> {
        Err("this desktop cannot set the volume of a device".to_string())
    }

    /// Whether a device is muted.
    fn sound_muted(&mut self, _device: &str) -> Result<bool, String> {
        Err("this desktop cannot say whether a device is muted".to_string())
    }

    /// Mute a device, or unmute it.
    fn sound_set_muted(&mut self, _device: &str, _muted: bool) -> Result<(), String> {
        Err("this desktop cannot mute a device".to_string())
    }

    /// Play a sound file.
    fn sound_play(&mut self, _path: &str) -> Result<String, String> {
        Err("this desktop cannot play a sound".to_string())
    }

    /// Play a tone of a frequency, for a number of milliseconds.
    fn sound_beep(&mut self, _frequency: f64, _duration_ms: u64) -> Result<String, String> {
        Err("this desktop cannot play a tone".to_string())
    }
}

/// The machine, the session and the user.
///
/// The names are the ones of v2: the name of the user, the name of the
/// computer, the shell of the session, the folders of the machine, the
/// version of the operating system, the language of the session, whether
/// the script is elevated, and how long the session has been idle.
///
/// The folders are the ones the machine has. A folder that the machine
/// does not have is not in the answer: the name that asks for it says
/// so.
pub trait Machine {
    /// The name of the user that launched the session.
    fn user_name(&mut self) -> Result<String, String> {
        Err("this desktop cannot say the name of the user".to_string())
    }

    /// The name of the computer, as the network sees it.
    fn computer_name(&mut self) -> Result<String, String> {
        Err("this desktop cannot say the name of the computer".to_string())
    }

    /// The program that runs a command of the session.
    ///
    /// v2 calls it `A_ComSpec`, and on the machine of the box it is the
    /// shell of the session.
    fn shell(&mut self) -> Result<String, String> {
        Err("this desktop cannot say the shell of the session".to_string())
    }

    /// The folders of the machine.
    fn folders(&mut self) -> Result<Folders, String> {
        Err("this desktop cannot say the folders of the machine".to_string())
    }

    /// The version of the operating system.
    fn os_version(&mut self) -> Result<String, String> {
        Err("this desktop cannot say the version of the operating system".to_string())
    }

    /// The language of the session.
    fn language(&mut self) -> Result<String, String> {
        Err("this desktop cannot say the language of the session".to_string())
    }

    /// Whether the script runs with the rights of an administrator.
    fn is_admin(&mut self) -> Result<bool, String> {
        Err("this desktop cannot say whether the script is elevated".to_string())
    }

    /// How long the session has been idle, in milliseconds.
    /// The path of the executable that is running the script.
    ///
    /// It is what `A_AhkPath` answers. A desktop that cannot tell says so, and
    /// the variable is then a refusal and not an empty text: a script that
    /// reads the path of the interpreter must be told that it is not known.
    fn executable(&mut self) -> Result<String, String> {
        Err("this desktop cannot tell the path of the interpreter".to_string())
    }

    /// The space of the drive that a path is on.
    ///
    /// `None` is a path whose drive is not there. A path that is there and a
    /// drive whose space cannot be read is a failure with the reason.
    fn drive_space(&mut self, _path: &str) -> Result<Option<DriveSpace>, String> {
        Err("this desktop cannot tell the space of a drive".to_string())
    }

    /// The value of the registry of the machine, and its kind.
    ///
    /// `None` is a value that is not there; a key that is not there is a
    /// failure with the reason of the machine. Measured on the binary of
    /// v2.0.19 on 2026-11-11: `RegRead` of a value that is not there
    /// throws "(2) The system cannot find the file specified.".
    fn registry_value(
        &mut self,
        _key: &str,
        _name: &str,
    ) -> Result<Option<(String, String)>, String> {
        Err("this desktop cannot read the registry of the machine".to_string())
    }

    /// Write a value into the registry of the machine.
    ///
    /// The key is made when it is not there, with its ancestors: measured
    /// on the binary of v2.0.19 on 2026-11-11.
    fn registry_write(
        &mut self,
        _key: &str,
        _name: &str,
        _kind: &str,
        _value: &str,
    ) -> Result<(), String> {
        Err("this desktop cannot write the registry of the machine".to_string())
    }

    /// Remove a value of the registry of the machine.
    fn registry_delete(&mut self, _key: &str, _name: &str) -> Result<(), String> {
        Err("this desktop cannot remove a value of the registry".to_string())
    }

    /// Remove a key of the registry of the machine.
    fn registry_delete_key(&mut self, _key: &str) -> Result<(), String> {
        Err("this desktop cannot remove a key of the registry".to_string())
    }

    /// Make a key of the registry of the machine.
    fn registry_create_key(&mut self, _key: &str) -> Result<(), String> {
        Err("this desktop cannot make a key of the registry".to_string())
    }

    /// The directory of the Windows of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `A_WinDir` answers
    /// "C:\WINDOWS" on a machine of Windows.
    fn windows_directory(&mut self) -> Result<String, String> {
        Err("this desktop cannot tell the directory of the Windows of the machine".to_string())
    }

    /// The directory of the programs of the user, in the Windows of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `A_ProgramFiles`
    /// answers "C:\Program Files" on a machine of Windows.
    fn program_files(&mut self) -> Result<String, String> {
        Err("this desktop cannot tell the directory of the programs of the machine".to_string())
    }

    /// Put the icon of the script in the tray of the session.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-11: `TraySetIcon` puts
    /// the icon of the script in the tray, and the built-in variables carry
    /// it afterwards.
    fn tray_set_icon(&mut self, _name: &str) -> Result<(), String> {
        Err("this desktop has no tray to put the icon of the script in".to_string())
    }

    /// The label of the drive that a path is on.
    ///
    /// `None` is a drive that is not there. Measured on the binary of
    /// v2.0.19 on 2026-11-10: `DriveGetLabel` of a drive that is not there
    /// throws "(3) The system cannot find the path specified.".
    fn drive_label(&mut self, _path: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot tell the label of a drive".to_string())
    }

    /// The serial of the drive that a path is on, as the machine writes it.
    ///
    /// Measured on the binary of the same day: `DriveGetSerial` of a drive
    /// that is not there throws the same "(3) ..." as the label, and of a
    /// drive that is there answers a whole number -- the volume serial of
    /// Windows. The serial of a Linux drive is the string of the hardware,
    /// so the shape is the machine's.
    fn drive_serial(&mut self, _path: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot tell the serial of a drive".to_string())
    }

    /// The drives of the machine, one name per line.
    ///
    /// Measured on the binary of the same day: `DriveGetList` answers the
    /// drive letters run together -- a letter is one character, so no
    /// separator is needed. A drive of this platform is a device name, which
    /// is more than one character, so the names ride apart on newlines.
    fn drive_list(&mut self) -> Result<Vec<String>, String> {
        Err("this desktop cannot list the drives".to_string())
    }

    /// The status of the drive a path is on, when that drive is a CD or DVD
    /// reader. `None` is a drive that is not a reader.
    ///
    /// Measured on the binary of the same day: `DriveGetStatusCD` of a drive
    /// that is not a reader throws "Failed".
    fn drive_status_cd(&mut self, _path: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot tell the status of a CD drive".to_string())
    }

    /// Eject the drive of a path.
    fn drive_eject(&mut self, _path: &str) -> Result<(), String> {
        Err("this desktop cannot eject a drive".to_string())
    }

    /// Lock the drive of a path against removal.
    fn drive_lock(&mut self, _path: &str) -> Result<(), String> {
        Err("this desktop cannot lock a drive".to_string())
    }

    /// Unlock the drive of a path.
    fn drive_unlock(&mut self, _path: &str) -> Result<(), String> {
        Err("this desktop cannot unlock a drive".to_string())
    }

    /// Spin the drive of a path down.
    fn drive_retract(&mut self, _path: &str) -> Result<(), String> {
        Err("this desktop cannot spin a drive down".to_string())
    }

    /// Write a new label on the drive of a path.
    fn drive_set_label(&mut self, _path: &str, _label: &str) -> Result<(), String> {
        Err("this desktop cannot write the label of a drive".to_string())
    }

    fn idle_times(&mut self) -> Result<Idle, String> {
        Err("this desktop cannot say how long the session has been idle".to_string())
    }

    /// The state of the drive that a path is on.
    ///
    /// `None` is a path that is not a drive of this machine: the binary
    /// answers "Invalid" for it.
    fn drive_status(&mut self, _path: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot say what state a drive is in".to_string())
    }

    /// The kind of the drive that a path is on.
    ///
    /// `None` is a path that is not a drive of this machine: the binary
    /// answers the empty text for it.
    fn drive_type(&mut self, _path: &str) -> Result<Option<String>, String> {
        Err("this desktop cannot say what kind a drive is".to_string())
    }

    /// The drive that a path is on, when the path is one.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `DriveGetType` of a
    /// drive that is not there answers the empty text, and `DriveGetStatus`
    /// of one answers "Invalid"; the other readings of a drive that is not
    /// there are the failure of the machine.
    fn drive(&mut self, _path: &str) -> Result<Option<Drive>, String> {
        Err("this desktop cannot say what a drive is".to_string())
    }

    /// Write a text to the debugger of the machine.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-09: `OutputDebug` writes
    /// the text to the debugger and answers nothing. A machine whose debugger
    /// is the standard error of the process writes it there.
    fn output_debug(&mut self, _text: &str) -> Result<(), String> {
        Err("this desktop has no debugger to write to".to_string())
    }

    /// The identity of the thread the run is on.
    ///
    /// The identity of a thread is the machine's, and a machine that
    /// cannot say is a failure with the reason: the number of a thread
    /// is not guessed.
    fn the_current_thread_id(&mut self) -> Result<i64, String> {
        Err("this desktop cannot say the thread it runs on".to_string())
    }
}

/// The dialogs of the desktop.
///
/// A dialog asks the user a question and waits for the answer. The
/// answer of an input box is the text the user typed and the way the
/// dialog was closed; the answer of a file selection is the path, or
/// the paths, of what the user chose.
///
/// The options of a dialog are read by the runtime before the question
/// is asked: an option that v2 does not know is refused there, and the
/// desktop is never asked about it.
pub trait Dialogs {
    /// Ask the user for a text.
    ///
    /// The answer carries the text the user typed and the way the
    /// dialog was closed: "OK", "Cancel" or "Timeout".
    fn input_box(
        &mut self,
        _prompt: &str,
        _title: &str,
        _options: &InputOptions,
        _default: &str,
    ) -> Result<InputAnswer, String> {
        Err("this desktop cannot ask the user for a text".to_string())
    }

    /// Ask the user for a file, or for a folder.
    ///
    /// The answer is one path, or many of them when the user may choose
    /// more than one.
    fn file_select(
        &mut self,
        _options: &FileOptions,
        _root: &str,
        _title: &str,
        _filter: &str,
    ) -> Result<FileAnswer, String> {
        Err("this desktop cannot ask the user for a file".to_string())
    }

    /// Ask the user for a folder.
    ///
    /// The options are the number of v2: 1 is the button that makes a
    /// new folder, 2 is the field where the name is written, and 4 is
    /// the old style of the dialog.
    fn dir_select(
        &mut self,
        _starting: &str,
        _options: i64,
        _prompt: &str,
    ) -> Result<String, String> {
        Err("this desktop cannot ask the user for a folder".to_string())
    }

    /// Tell the user something, without asking anything back.
    ///
    /// The title is the first line of it and the text is the body. A desktop
    /// that has no way to tell the user anything says so, and not `false`.
    ///
    /// The `TrayTip` of v2 is the name of this: on Windows it is a balloon in
    /// the tray, and on a Linux desktop it is a notification of the session,
    /// which is the same thing said to the same person. The refusal of the
    /// tree used to call it a name of Windows, which was false: the box has
    /// `notify-send` on it.
    fn notify(&mut self, _title: &str, _text: &str) -> Result<(), String> {
        Err("this desktop cannot show a notification".to_string())
    }
}

/// The answer of an input box.
#[derive(Clone, Debug, Default)]
pub struct InputAnswer {
    /// The text the user typed.
    pub value: String,
    /// The way the dialog was closed: "OK", "Cancel" or "Timeout".
    pub result: String,
}

/// The answer of a file selection.
#[derive(Clone, Debug)]
pub enum FileAnswer {
    /// One file, or one folder.
    One(String),
    /// Many files, or many folders.
    Many(Vec<String>),
}

/// The options of an input box.
///
/// The options are the ones of v2: where the window is, how big it is,
/// how long it waits, and whether the text is hidden. The runtime
/// reads them, and gives the desktop the ones that are about the
/// machine.
#[derive(Clone, Debug, Default)]
pub struct InputOptions {
    /// The seconds the window waits for the user before it closes itself.
    pub timeout: Option<f64>,
    /// Whether the text the user types is hidden.
    pub password: bool,
    /// The width of the window, in pixels.
    pub width: Option<i64>,
    /// The height of the window, in pixels.
    pub height: Option<i64>,
    /// Where the window is, in pixels, from the left of the screen.
    pub x: Option<i64>,
    /// Where the window is, in pixels, from the top of the screen.
    pub y: Option<i64>,
}

/// The options of a file selection.
#[derive(Clone, Debug, Default)]
pub struct FileOptions {
    /// The number of the flags of v2, when the options were a number.
    ///
    /// The flags are the ones of the documentation: 1 is a file that
    /// must be there, 2 is a path that must be there, 8 asks to make a
    /// new file, 16 asks to overwrite one and 32 keeps the shortcuts as
    /// they are.
    pub flags: i64,
    /// Whether the user may choose a folder instead of a file.
    pub directory: bool,
    /// Whether the user may choose more than one file.
    pub multiple: bool,
    /// Whether the dialog is a save dialog.
    pub save: bool,
}

/// The folders of the machine, as the names of v2 ask for them.
///
/// A folder that is not there is a folder the machine does not have.
#[derive(Clone, Debug, Default)]
pub struct Folders {
    /// `A_AppData`: the application data of the user.
    pub app_data: Option<String>,
    /// `A_AppDataCommon`: the application data of everybody.
    pub app_data_common: Option<String>,
    /// `A_Desktop`: the desktop of the user.
    pub desktop: Option<String>,
    /// `A_DesktopCommon`: the desktop of everybody.
    pub desktop_common: Option<String>,
    /// `A_StartMenu`: the start menu of the user.
    pub start_menu: Option<String>,
    /// `A_StartMenuCommon`: the start menu of everybody.
    pub start_menu_common: Option<String>,
    /// `A_Programs`: the programs of the user.
    pub programs: Option<String>,
    /// `A_ProgramsCommon`: the programs of everybody.
    pub programs_common: Option<String>,
    /// `A_Startup`: the startup folder of the user.
    pub startup: Option<String>,
    /// `A_StartupCommon`: the startup folder of everybody.
    pub startup_common: Option<String>,
    /// `A_MyDocuments`: the documents of the user.
    pub my_documents: Option<String>,
    /// `A_Temp`: the folder of the temporary files.
    pub temp: Option<String>,
}

/// The idle times of the session, in milliseconds.
#[derive(Clone, Copy, Debug, Default)]
pub struct Idle {
    /// `A_TimeIdle`: since the last input of any kind.
    pub any: u64,
    /// `A_TimeIdlePhysical`: since the last input of the user.
    pub physical: u64,
    /// `A_TimeIdleKeyboard`: since the last key of the user.
    pub keyboard: u64,
    /// `A_TimeIdleMouse`: since the last move of the mouse.
    pub mouse: u64,
}

/// The sum of the capabilities: what the runtime drives.
///
/// The trait has no methods of its own. It is the sum, so that the
/// runtime can hold one thing and ask it for everything.
pub trait Desktop:
    Keyboard
    + Pointer
    + Screen
    + Windows
    + Processes
    + Files
    + Clipboard
    + Timers
    + Hotkeys
    + Native
    + Sound
    + Machine
    + Dialogs
    + Network
    + Pictures
{
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct WindowInfo {
    /// The identifier of the window, as this runtime names it.
    pub id: i64,
    /// The title of the window.
    pub title: String,
    /// The class of the window.
    pub class: String,
    /// Whether the window is the active one.
    pub active: bool,
}

#[derive(Debug, Clone)]
pub struct ProcessState {
    /// Whether the process has exited.
    pub has_exited: bool,
    /// The code it exited with, when it has exited.
    pub exit_code: Option<i32>,
    /// The moment it exited, as the text of the date and the time.
    pub exit_time: Option<String>,
}

/// The network of the desktop.
///
/// A download is a file that comes from the network, and the network is
/// the machine's: a desktop that does not reach it says so.
/// One mail message, validated by the dialect.
///
/// The shape is the one the `Mail` of KeySharp accepts: the recipients,
/// the subject, the body, the sender and the optional copies, replies,
/// attachments and headers of it, beside the server and the port to
/// send it through. The validation of all of it is the dialect's, and
/// the sending is the machine's.
pub struct MailMessage {
    /// The recipients of the message.
    pub to: Vec<String>,
    /// The copies.
    pub cc: Vec<String>,
    /// The blind copies.
    pub bcc: Vec<String>,
    /// The subject of the message.
    pub subject: String,
    /// The body of the message.
    pub body: String,
    /// The sender.
    pub from: String,
    /// The address the replies go to, when it is not the sender.
    pub reply_to: Option<String>,
    /// The paths of the attachments.
    pub attachments: Vec<String>,
    /// The headers beside the ones the message carries.
    pub headers: Vec<(String, String)>,
    /// The SMTP server.
    pub host: String,
    /// The port of the server, 25 when the host named none.
    pub port: u16,
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Drive {
    /// The kind of the drive: "Fixed", "Removable", "Network", "CDROM",
    /// "RAMDisk" or "Unknown".
    pub drive_type: String,
    /// The name of the format of the volume.
    pub filesystem: String,
    /// The label of the volume, and the empty text when it has none.
    pub label: String,
    /// The number that identifies the volume.
    pub serial: i64,
    /// The free space, in megabytes.
    pub free_megabytes: i64,
    /// The capacity, in megabytes.
    pub capacity_megabytes: i64,
    /// The state of the drive: "Ready" and the like.
    pub status: String,
}

impl Monitor {
    /// The number of the columns of the monitor.
    pub fn width(&self) -> i64 {
        self.right - self.left
    }

    /// The number of the rows of the monitor.
    pub fn height(&self) -> i64 {
        self.bottom - self.top
    }
}