Newer
Older
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
(type timestamp time)))
(defun input-focus (display)
(declare (type display display)
(clx-values focus revert-to)))
(defun query-keymap (display)
(declare (type display display)
(clx-values (bit-vector 256))))
(defun open-font (display name)
;; Font objects may be cached and reference counted locally within the display
;; object. This function might not execute a with-display if the font is cached.
;; The protocol QueryFont request happens on-demand under the covers.
(declare (type display display)
(type stringable name)
(clx-values font)))
;; We probably want a per-font bit to indicate whether caching on
;; text-extents/width calls is desirable. But what to name it?
(defun discard-font-info (font)
;; Discards any state that can be re-obtained with QueryFont. This is simply
;; a performance hint for memory-limited systems.
(declare (type font font)))
;; This can be signalled anywhere a pseudo font access fails.
(define-condition invalid-font error
font)
;; Note: font-font-info removed.
(defun font-name (font)
;; Returns nil for a pseudo font returned by gcontext-font.
(declare (type font font)
(clx-values (or null string))))
(defun font-direction (font)
(declare (type font font)
(clx-values draw-direction)))
(defun font-min-char (font)
(declare (type font font)
(clx-values card16)))
(defun font-max-char (font)
(declare (type font font)
(clx-values card16)))
(defun font-min-byte1 (font)
(declare (type font font)
(clx-values card8)))
(defun font-max-byte1 (font)
(declare (type font font)
(clx-values card8)))
(defun font-min-byte2 (font)
(declare (type font font)
(clx-values card8)))
(defun font-max-byte2 (font)
(declare (type font font)
(clx-values card8)))
(defun font-all-chars-exist-p (font)
(declare (type font font)
(clx-values boolean)))
(defun font-default-char (font)
(declare (type font font)
(clx-values card16)))
(defun font-ascent (font)
(declare (type font font)
(clx-values int16)))
(defun font-descent (font)
(declare (type font font)
(clx-values int16)))
;; The list contains alternating keywords and int32s.
(deftype font-props () 'list)
(defun font-properties (font)
(declare (type font font)
(clx-values font-props)))
(defun font-property (font name)
(declare (type font font)
(type keyword name)
(clx-values (or null int32))))
;; For each of left-bearing, right-bearing, width, ascent, descent, attributes:
(defun char-<metric> (font index)
;; Note: I have tentatively chosen to return nil for an out-of-bounds index
;; (or an in-bounds index on a pseudo font), although returning zero or
;; signalling might be better.
(declare (type font font)
(type card16 index)
(clx-values (or null int16))))
(defun max-char-<metric> (font)
;; Note: I have tentatively chosen separate accessors over allowing :min and
;; :max as an index above.
(declare (type font font)
(clx-values int16)))
(defun min-char-<metric> (font)
(declare (type font font)
(clx-values int16)))
;; Note: char16-<metric> accessors could be defined to accept two-byte indexes.
(defun close-font (font)
;; This might not generate a protocol request if the font is reference
;; counted locally or if it is a pseudo font.
(declare (type font font)))
(defun list-font-names (display pattern &key (max-fonts 65535) (result-type 'list))
(declare (type display display)
(type string pattern)
(type card16 max-fonts)
(type type result-type)
(clx-values (clx-sequence string))))
(defun list-fonts (display pattern &key (max-fonts 65535) (result-type 'list))
;; Returns "pseudo" fonts that contain basic font metrics and properties, but
;; no per-character metrics and no resource-ids. These pseudo fonts will be
;; converted (internally) to real fonts dynamically as needed, by issuing an
;; OpenFont request. However, the OpenFont might fail, in which case the
;; invalid-font error can arise.
(declare (type display display)
(type string pattern)
(type card16 max-fonts)
(type type result-type)
(clx-values (clx-sequence font))))
(defun font-path (display &key (result-type 'list))
(declare (type display display)
(type type result-type)
(clx-values (clx-sequence (or string pathname)))))
(defsetf font-path (display) (paths)
(declare (type display display)
(type (clx-sequence (or string pathname)) paths)))
(defun create-pixmap (&key width height depth drawable)
(declare (type card16 width height)
(type card8 depth)
(type drawable drawable)
(clx-values pixmap)))
(defun free-pixmap (pixmap)
(declare (type pixmap pixmap)))
(defun create-gcontext (&key drawable function plane-mask foreground background
line-width line-style cap-style join-style fill-style fill-rule
arc-mode tile stipple ts-x ts-y font subwindow-mode
exposures clip-x clip-y clip-mask clip-ordering
dash-offset dashes
(cache-p t))
;; Only non-nil components are passed on in the request, but for effective caching
;; assumptions have to be made about what the actual protocol defaults are. For
;; all gcontext components, a value of nil causes the default gcontext value to be
;; used. For clip-mask, this implies that an empty rect-seq cannot be represented
;; as a list. Note: use of stringable as font will cause an implicit open-font.
;; Note: papers over protocol SetClipRectangles and SetDashes special cases. If
;; cache-p is true, then gcontext state is cached locally, and changing a gcontext
;; component will have no effect unless the new value differs from the cached
;; value. Component changes (setfs and with-gcontext) are always deferred
;; regardless of the cache mode, and sent over the protocol only when required by a
;; local operation or by an explicit call to force-gcontext-changes.
(declare (type drawable drawable)
(type (or null boole-constant) function)
(type (or null pixel) plane-mask foreground background)
(type (or null card16) line-width dash-offset)
(type (or null int16) ts-x ts-y clip-x clip-y)
(type (or null (member :solid :dash :double-dash)) line-style)
(type (or null (member :not-last :butt :round :projecting)) cap-style)
(type (or null (member :miter :round :bevel)) join-style)
(type (or null (member :solid :tiled :opaque-stippled :stippled)) fill-style)
(type (or null (member :even-odd :winding)) fill-rule)
(type (or null (member :chord :pie-slice)) arc-mode)
(type (or null pixmap) tile stipple)
(type (or null fontable) font)
(type (or null (member :clip-by-children :include-inferiors)) subwindow-mode)
(type (or null (member :on :off)) exposures)
(type (or null (member :none) pixmap rect-seq) clip-mask)
(type (or null (member :unsorted :y-sorted :yx-sorted :yx-banded)) clip-ordering)
(type (or null (or card8 (clx-sequence card8))) dashes)
(type boolean cache)
(clx-values gcontext)))
;; For each argument to create-gcontext (except font, clip-mask and
;; clip-ordering) declared as (type <type> <name>), there is an accessor:
(defun gcontext-<name> (gcontext)
;; The value will be nil if the last value stored is unknown (e.g., the cache was
;; off, or the component was copied from a gcontext with unknown state).
(declare (type gcontext gcontext)
(clx-values <type>)))
;; For each argument to create-gcontext (except clip-mask and clip-ordering) declared
;; as (type (or null <type>) <name>), there is a setf for the corresponding accessor:
(defsetf gcontext-<name> (gcontext) (value)
(declare (type gcontext gcontext)
(type <type> value)))
(defun gcontext-font (gcontext &optional metrics-p)
;; If the stored font is known, it is returned. If it is not known and
;; metrics-p is false, then nil is returned. If it is not known and
;; metrics-p is true, then a pseudo font is returned. Full metric and
;; property information can be obtained, but the font does not have a name or
;; a resource-id, and attempts to use it where a resource-id is required will
;; result in an invalid-font error.
(declare (type gcontext gcontext)
(type boolean metrics-p)
(clx-values (or null font))))
(defun gcontext-clip-mask (gcontext)
(declare (type gcontext gcontext)
(clx-values (or null (member :none) pixmap rect-seq)
(or null (member :unsorted :y-sorted :yx-sorted :yx-banded)))))
(defsetf gcontext-clip-mask (gcontext &optional ordering) (clip-mask)
;; Is nil illegal here, or is it transformed to a vector?
;; A bit strange, but retains setf form.
(declare (type gcontext gcontext)
(type (or null (member :unsorted :y-sorted :yx-sorted :yx-banded)) clip-ordering)
(type (or (member :none) pixmap rect-seq) clip-mask)))
(defun force-gcontext-changes (gcontext)
;; Force any delayed changes.
(declare (type gcontext gcontext)))
(defmacro with-gcontext ((gcontext &key
function plane-mask foreground background
line-width line-style cap-style join-style fill-style fill-rule
arc-mode tile stipple ts-x ts-y font subwindow-mode
exposures clip-x clip-y clip-mask clip-ordering
dashes dash-offset)
&body body)
;; Changes gcontext components within the dynamic scope of the body (i.e.,
;; indefinite scope and dynamic extent), on a per-process basis in a multi-process
;; environment. The values are all evaluated before bindings are performed. The
;; body is not surrounded by a with-display. If cache-p is nil or the some
;; component states are unknown, this will implement save/restore by creating a
;; temporary gcontext and doing gcontext-components to and from it.
)
(defun copy-gcontext-components (src dst &rest keys)
(declare (type gcontext src dst)
(type (clx-list gcontext-key) keys)))
(defun copy-gcontext (src dst)
(declare (type gcontext src dst))
;; Copies all components.
)
(defun free-gcontext (gcontext)
(declare (type gcontext gcontext)))
(defun clear-area (window &key (x 0) (y 0) width height exposures-p)
;; Passing in a zero width or height is a no-op. A null width or height translates
;; into a zero value in the protocol request.
(declare (type window window)
(type int16 x y)
(type (or null card16) width height)
(type boolean exposures-p)))
(defun copy-area (src gcontext src-x src-y width height dst dst-x dst-y)
(declare (type drawable src dst)
(type gcontext gcontext)
(type int16 src-x src-y dst-x dst-y)
(type card16 width height)))
(defun copy-plane (src gcontext plane src-x src-y width height dst dst-x dst-y)
(declare (type drawable src dst)
(type gcontext gcontext)
(type pixel plane)
(type int16 src-x src-y dst-x dst-y)
(type card16 width height)))
(defun draw-point (drawable gcontext x y)
;; Should be clever about appending to existing buffered protocol request, provided
;; gcontext has not been modified.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)))
(defun draw-points (drawable gcontext points &optional relative-p)
(declare (type drawable drawable)
(type gcontext gcontext)
(type point-seq points)
(type boolean relative-p)))
(defun draw-line (drawable gcontext x1 y1 x2 y2 &optional relative-p)
;; Should be clever about appending to existing buffered protocol request, provided
;; gcontext has not been modified.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x1 y1 x2 y2)
(type boolean relative-p)))
(defun draw-lines (drawable gcontext points &key relative-p fill-p (shape :complex))
(declare (type drawable drawable)
(type gcontext gcontext)
(type point-seq points)
(type boolean relative-p fill-p)
(type (member :complex :non-convex :convex) shape)))
(defun draw-segments (drawable gcontext segments)
(declare (type drawable drawable)
(type gcontext gcontext)
(type seg-seq segments)))
(defun draw-rectangle (drawable gcontext x y width height &optional fill-p)
;; Should be clever about appending to existing buffered protocol request, provided
;; gcontext has not been modified.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)
(type card16 width height)
(type boolean fill-p)))
(defun draw-rectangles (drawable gcontext rectangles &optional fill-p)
(declare (type drawable drawable)
(type gcontext gcontext)
(type rect-seq rectangles)
(type boolean fill-p)))
(defun draw-arc (drawable gcontext x y width height angle1 angle2 &optional fill-p)
;; Should be clever about appending to existing buffered protocol request, provided
;; gcontext has not been modified.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)
(type card16 width height)
(type angle angle1 angle2)
(type boolean fill-p)))
(defun draw-arcs (drawable gcontext arcs &optional fill-p)
(declare (type drawable drawable)
(type gcontext gcontext)
(type arc-seq arcs)
(type boolean fill-p)))
;; The following image routines are bare minimum. It may be useful to define some
;; form of "image" object to hide representation details and format conversions. It
;; also may be useful to provide stream-oriented interfaces for reading and writing
;; the data.
(defun put-raw-image (drawable gcontext data
&key (start 0) depth x y width height (left-pad 0) format)
;; Data must be a sequence of 8-bit quantities, already in the appropriate format
;; for transmission; the caller is responsible for all byte and bit swapping and
;; compaction. Start is the starting index in data; the end is computed from the
;; other arguments.
(declare (type drawable drawable)
(type gcontext gcontext)
(type (clx-sequence card8) data)
(type array-index start)
(type card8 depth left-pad)
(type int16 x y)
(type card16 width height)
(type (member :bitmap :xy-pixmap :z-pixmap) format)))
(defun get-raw-image (drawable &key data (start 0) x y width height
(plane-mask 0xffffffff) format
(result-type '(vector (unsigned-byte 8))))
;; If data is given, it is modified in place (and returned), otherwise a new
;; sequence is created and returned, with a size computed from the other arguments
;; and the returned depth. The sequence is filled with 8-bit quantities, in
;; transmission format; the caller is responsible for any byte and bit swapping and
;; compaction required for further local use.
(declare (type drawable drawable)
(type (or null (clx-sequence card8)) data)
(type array-index start)
(type int16 x y)
(type card16 width height)
(type pixel plane-mask)
(type (member :xy-pixmap :z-pixmap) format)
(clx-values (clx-sequence card8) depth visual-info)))
(defun translate-default (src src-start src-end font dst dst-start)
;; dst is guaranteed to have room for (- src-end src-start) integer elements,
;; starting at dst-start; whether dst holds 8-bit or 16-bit elements depends
;; on context. font is the current font, if known. The function should
;; translate as many elements of src as possible into indexes in the current
;; font, and store them into dst. The first return value should be the src
;; index of the first untranslated element. If no further elements need to
;; be translated, the second return value should be nil. If a horizontal
;; motion is required before further translation, the second return value
;; should be the delta in x coordinate. If a font change is required for
;; further translation, the second return value should be the new font. If
;; known, the pixel width of the translated text can be returned as the third
;; value; this can allow for appending of subsequent output to the same
;; protocol request, if no overall width has been specified at the higher
;; level.
(declare (type sequence src)
(type array-index src-start src-end dst-start)
(type (or null font) font)
(type vector dst)
(clx-values array-index (or null int16 font) (or null int32))))
;; There is a question below of whether translate should always be required, or
;; if not, what the default should be or where it should come from. For
;; example, the default could be something that expected a string as src and
;; translated the CL standard character set to ASCII indexes, and ignored fonts
;; and bits. Or the default could expect a string but otherwise be "system
;; dependent". Or the default could be something that expected a vector of
;; integers and did no translation. Or the default could come from the
;; gcontext (but what about text-extents and text-width?).
(defun text-extents (font sequence &key (start 0) end translate)
;; If multiple fonts are involved, font-ascent and font-descent will be the
;; maximums. If multiple directions are involved, the direction will be nil.
;; Translate will always be called with a 16-bit dst buffer.
(declare (type sequence sequence)
(type (or font gcontext) font)
(type translate translate)
(clx-values width ascent descent left right font-ascent font-descent direction
(or null array-index))))
(defun text-width (font sequence &key (start 0) end translate)
;; Translate will always be called with a 16-bit dst buffer.
(declare (type sequence sequence)
(type (or font gcontext) font)
(type translate translate)
(clx-values int32 (or null array-index))))
;; This controls the element size of the dst buffer given to translate. If
;; :default is specified, the size will be based on the current font, if known,
;; and otherwise 16 will be used. [An alternative would be to pass the buffer
;; size to translate, and allow it to return the desired size if it doesn't
;; like the current size. The problem is that the protocol doesn't allow
;; switching within a single request, so to allow switching would require
;; knowing the width of text, which isn't necessarily known. We could call
;; text-width to compute it, but perhaps that is doing too many favors?] [An
;; additional possibility is to allow an index-size of :two-byte, in which case
;; translate would be given a double-length 8-bit array, and translate would be
;; expected to store first-byte/second-byte instead of 16-bit integers.]
(deftype index-size () '(member :default 8 16))
;; In the glyph functions below, if width is specified, it is assumed to be the
;; total pixel width of whatever string of glyphs is actually drawn.
;; Specifying width will allow for appending the output of subsequent calls to
;; the same protocol request, provided gcontext has not been modified in the
;; interim. If width is not specified, appending of subsequent output might
;; not occur (unless translate returns the width). Specifying width is simply
;; a hint, for performance.
(defun draw-glyph (drawable gcontext x y elt
&key translate width (size :default))
;; Returns true if elt is output, nil if translate refuses to output it.
;; Second result is width, if known.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)
(type translate translate)
(type (or null int32) width)
(type index-size size)
(clx-values boolean (or null int32))))
(defun draw-glyphs (drawable gcontext x y sequence
&key (start 0) end translate width (size :default))
;; First result is new start, if end was not reached. Second result is
;; overall width, if known.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)
(type sequence sequence)
(type array-index start)
(type (or null array-index) end)
(type (or null int32) width)
(type translate translate)
(type index-size size)
(clx-values (or null array-index) (or null int32))))
(defun draw-image-glyph (drawable gcontext x y elt
&key translate width (size :default))
;; Returns true if elt is output, nil if translate refuses to output it.
;; Second result is overall width, if known. An initial font change is
;; allowed from translate.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)
(type translate translate)
(type (or null int32) width)
(type index-size size)
(clx-values boolean (or null int32))))
(defun draw-image-glyphs (drawable gcontext x y sequence
&key (start 0) end width translate (size :default))
;; An initial font change is allowed from translate, but any subsequent font
;; change or horizontal motion will cause termination (because the protocol
;; doesn't support chaining). [Alternatively, font changes could be accepted
;; as long as they are accompanied with a width return value, or always
;; accept font changes and call text-width as required. However, horizontal
;; motion can't really be accepted, due to semantics.] First result is new
;; start, if end was not reached. Second result is overall width, if known.
(declare (type drawable drawable)
(type gcontext gcontext)
(type int16 x y)
(type sequence sequence)
(type array-index start)
(type (or null array-index) end)
(type (or null int32) width)
(type translate translate)
(type index-size size)
(clx-values (or null array-index) (or null int32))))
(defun create-colormap (visual window &optional alloc-p)
(declare (type visual-info visual)
(type window window)
(type boolean alloc-p)
(clx-values colormap)))
(defun free-colormap (colormap)
(declare (type colormap colormap)))
(defun copy-colormap-and-free (colormap)
(declare (type colormap colormap)
(clx-values colormap)))
(defun install-colormap (colormap)
(declare (type colormap colormap)))
(defun uninstall-colormap (colormap)
(declare (type colormap colormap)))
(defun installed-colormaps (window &key (result-type 'list))
(declare (type window window)
(type type result-type)
(clx-values (clx-sequence colormap))))
(defun alloc-color (colormap color)
(declare (type colormap colormap)
(type (or stringable color) color)
(clx-values pixel screen-color exact-color)))
(defun alloc-color-cells (colormap colors &key (planes 0) contiguous-p (result-type 'list))
(declare (type colormap colormap)
(type card16 colors planes)
(type boolean contiguous-p)
(type type result-type)
(clx-values (clx-sequence pixel) (clx-sequence mask))))
(defun alloc-color-planes (colormap colors
&key (reds 0) (greens 0) (blues 0)
contiguous-p (result-type 'list))
(declare (type colormap colormap)
(type card16 colors reds greens blues)
(type boolean contiguous-p)
(type type result-type)
(clx-values (clx-sequence pixel) red-mask green-mask blue-mask)))
(defun free-colors (colormap pixels &optional (plane-mask 0))
(declare (type colormap colormap)
(type (clx-sequence pixel) pixels)
(type pixel plane-mask)))
(defun store-color (colormap pixel spec &key (red-p t) (green-p t) (blue-p t))
(declare (type colormap colormap)
(type pixel pixel)
(type (or stringable color) spec)
(type boolean red-p green-p blue-p)))
(defun store-colors (colormap specs &key (red-p t) (green-p t) (blue-p t))
;; If stringables are specified for colors, it is unspecified whether all
;; stringables are first resolved and then a single StoreColors protocol request is
;; issued, or whether multiple StoreColors protocol requests are issued.
(declare (type colormap colormap)
(type (repeat-seq (pixel pixel) ((or stringable color) color)) specs)
(type boolean red-p green-p blue-p)))
(defun query-colors (colormap pixels &key (result-type 'list))
(declare (type colormap colormap)
(type (clx-sequence pixel) pixels)
(type type result-type)
(clx-values (clx-sequence color))))
(defun lookup-color (colormap name)
(declare (type colormap colormap)
(type stringable name)
(clx-values screen-color true-color)))
(defun create-cursor (&key source mask x y foreground background)
(declare (type pixmap source)
(type (or null pixmap) mask)
(type card16 x y)
(type color foreground background)
(clx-values cursor)))
(defun create-glyph-cursor (&key source-font source-char mask-font mask-char
foreground background)
(declare (type font source-font)
(type card16 source-char)
(type (or null font) mask-font)
(type (or null card16) mask-char)
(type color foreground background)
(clx-values cursor)))
(defun free-cursor (cursor)
(declare (type cursor cursor)))
(defun recolor-cursor (cursor foreground background)
(declare (type cursor cursor)
(type color foreground background)))
(defun query-best-cursor (width height drawable)
(declare (type card16 width height)
(type drawable display)
(clx-values width height)))
(defun query-best-tile (width height drawable)
(declare (type card16 width height)
(type drawable drawable)
(clx-values width height)))
(defun query-best-stipple (width height drawable)
(declare (type card16 width height)
(type drawable drawable)
(clx-values width height)))
(defun query-extension (display name)
(declare (type display display)
(type stringable name)
(clx-values major-opcode first-event first-error)))
(defun list-extensions (display &key (result-type 'list))
(declare (type display display)
(type type result-type)
(clx-values (clx-sequence string))))
;; Should pointer-mapping setf be changed to set-pointer-mapping?
(defun set-modifier-mapping (display &key shift lock control mod1 mod2 mod3 mod4 mod5)
;; Can signal device-busy.
;; Setf ought to allow multiple values.
;; Returns true for success, nil for failure
(declare (type display display)
(type (clx-sequence card8) shift lock control mod1 mod2 mod3 mod4 mod5)
(clx-values (member :success :busy :failed))))
(defun modifier-mapping (display)
;; each value is a list of card8s
(declare (type display display)
(clx-values shift lock control mod1 mod2 mod3 mod4 mod5)))
;; Either we will want lots of defconstants for well-known values, or perhaps
;; an integer-to-keyword translation function for well-known values.
(defun change-keyboard-mapping (display keysyms
&key (start 0) end (first-keycode start))
;; start/end give subrange of keysyms
;; first-keycode is the first-keycode to store at
(declare (type display display)
(type (array * (* *)) keysyms)
(type array-index start)
(type (or null array-index) end)
(type card8 first-keycode)))
(defun keyboard-mapping (display &key first-keycode start end data)
;; First-keycode specifies which keycode to start at (defaults to
;; min-keycode). Start specifies where (in result) to put first-keycode
;; (defaults to first-keycode). (- end start) is the number of keycodes to
;; get (end defaults to (1+ max-keycode)). If data is specified, the results
;; are put there.
(declare (type display display)
(type (or null card8) first-keycode)
(type (or null array-index) start end)
(type (or null (array * (* *))) data)
(clx-values (array * (* *)))))
(defun change-keyboard-control (display &key key-click-percent
bell-percent bell-pitch bell-duration
led led-mode key auto-repeat-mode)
(declare (type display display)
(type (or null (member :default) int16) key-click-percent
bell-percent bell-pitch bell-duration)
(type (or null card8) led key)
(type (or null (member :on :off)) led-mode)
(type (or null (member :on :off :default)) auto-repeat-mode)))
(defun keyboard-control (display)
(declare (type display display)
(clx-values key-click-percent bell-percent bell-pitch bell-duration
led-mask global-auto-repeat auto-repeats)))
(defun bell (display &optional (percent-from-normal 0))
;; It is assumed that an eventual audio extension to X will provide more complete
;; control.
(declare (type display display)
(type int8 percent-from-normal)))
(defun pointer-mapping (display &key (result-type 'list))
(declare (type display display)
(type type result-type)
(clx-values (clx-sequence card8))))
(defsetf pointer-mapping (display) (map)
;; Can signal device-busy.
(declare (type display display)
(type (clx-sequence card8) map)))
(defun change-pointer-control (display &key acceleration threshold)
;; Acceleration is rationalized if necessary.
(declare (type display display)
(type (or null (member :default) number) acceleration)
(type (or null (member :default) integer) threshold)))
(defun pointer-control (display)
(declare (type display display)
(clx-values acceleration threshold)))
(defun set-screen-saver (display timeout interval blanking exposures)
;; Setf ought to allow multiple values.
;; Timeout and interval are in seconds, will be rounded to minutes.
(declare (type display display)
(type (or (member :default) int16) timeout interval)
(type (member :on :off :default) blanking exposures)))
(defun screen-saver (display)
;; Returns timeout and interval in seconds.
(declare (type display display)
(clx-values timeout interval blanking exposures)))
(defun activate-screen-saver (display)
(declare (type display display)))
(defun reset-screen-saver (display)
(declare (type display display)))
(defun add-access-host (display host)
;; A string must be acceptable as a host, but otherwise the possible types for host
;; are not constrained, and will likely be very system dependent.
(declare (type display display)))
(defun remove-access-host (display host)
;; A string must be acceptable as a host, but otherwise the possible types for host
;; are not constrained, and will likely be very system dependent.
(declare (type display display)))
(defun access-hosts (display &key (result-type 'list))
;; The type of host objects returned is not constrained, except that the hosts must
;; be acceptable to add-access-host and remove-access-host.
(declare (type display display)
(type type result-type)
(clx-values (clx-sequence host) enabled-p)))
(defun access-control (display)
;; setf'able
(declare (type display display)
(clx-values boolean)))
(defun close-down-mode (display)
;; setf'able
;; Cached locally in display object.
(declare (type display display)
(clx-values (member :destroy :retain-permanent :retain-temporary))))
(defun kill-client (display resource-id)
(declare (type display display)
(type resource-id resource-id)))
(defun kill-temporary-clients (display)
(declare (type display display)))
(defun make-event-mask (&rest keys)
;; This is only defined for core events.
;; Useful for constructing event-mask, pointer-event-mask, device-event-mask.
(declare (type (clx-list event-mask-class) keys)
(clx-values mask32)))
(defun make-event-keys (event-mask)
;; This is only defined for core events.
(declare (type mask32 event-mask)
(clx-values (clx-list event-mask-class))))
(defun make-state-mask (&rest keys)
;; Useful for constructing modifier-mask, state-mask.
(declare (type (clx-list state-mask-key) keys)
(clx-values mask16)))
(defun make-state-keys (state-mask)
(declare (type mask16 mask)
(clx-values (clx-list state-mask-key))))
(defmacro with-event-queue ((display) &body body)
;; Grants exclusive access to event queue.
)
(defun event-listen (display &optional (timeout 0))
(declare (type display display)
(type (or null number) timeout)
(clx-values (or null number) (or null (member :timeout) (not null))))
;; Returns the number of events queued locally, if any, else nil. Hangs
;; waiting for events, forever if timeout is nil, else for the specified
;; number of seconds. The second value returned is :timeout if the
;; operation timed out, and some other non-nil value if an EOF has been
;; detected.
)
(defun process-event (display &key handler timeout peek-p discard-p (force-output-p t))
;; If force-output-p is true, first invokes display-force-output. Invokes
;; handler on each queued event until handler returns non-nil, and that
;; returned object is then returned by process-event. If peek-p is true,
;; then the event is not removed from the queue. If discard-p is true, then
;; events for which handler returns nil are removed from the queue,
;; otherwise they are left in place. Hangs until non-nil is generated for
;; some event, or for the specified timeout (in seconds, if given); however,
;; it is acceptable for an implementation to wait only once on network data,
;; and therefore timeout prematurely. Returns nil on timeout or EOF, with a
;; second return value being :timeout for a timeout and some other non-nil
;; value for EOF. If handler is a sequence, it is expected to contain
;; handler functions specific to each event class; the event code is used to
;; index the sequence, fetching the appropriate handler. The arguments to
;; the handler are described further below using declare-event. If
;; process-event is invoked recursively, the nested invocation begins with
;; the event after the one currently being processed.
(declare (type display display)
(type (or (clx-sequence (function (&key &allow-other-keys) t))
(function (&key &allow-other-keys) t))
handler)
(type (or null number) timeout)
(type boolean peek-p)))
(defun make-event-handlers (&key (type 'array) default)
(declare (type t type) ;Sequence type specifier
(type function default)
(clx-values sequence)) ;Default handler for initial content
;; Makes a handler sequence suitable for process-event
)
(defun event-handler (handlers event-key)
(declare (type sequence handlers)
(type event-key event-key)
(clx-values function))
;; Accessor for a handler sequence
)
(defsetf event-handler (handlers event-key) (handler)
(declare (type sequence handlers)
(type event-key event-key)
(type function handler)
(clx-values function))
;; Setf accessor for a handler sequence
)
(defmacro event-case ((display &key timeout peek-p discard-p (force-output-p t))
&body clauses)
(declare (arglist (display &key timeout peek-p discard-p force-output-p)
(event-or-events ((&rest args) |...|) &body body) |...|))
;; If force-output-p is true, first invokes display-force-output. Executes
;; the matching clause for each queued event until a clause returns non-nil,
;; and that returned object is then returned by event-case. If peek-p is
;; true, then the event is not removed from the queue. If discard-p is
;; true, then events for which the clause returns nil are removed from the
;; queue, otherwise they are left in place. Hangs until non-nil is
;; generated for some event, or for the specified timeout (in seconds, if
;; given); however, it is acceptable for an implementation to wait only once
;; on network data, and therefore timeout prematurely. Returns nil on
;; timeout or EOF with a second return value being :timeout for a timeout
;; and some other non-nil value for EOF. In each clause, event-or-events is
;; an event-key or a list of event-keys (but they need not be typed as
;; keywords) or the symbol t or otherwise (but only in the last clause).
;; The keys are not evaluated, and it is an error for the same key to appear
;; in more than one clause. Args is the list of event components of
;; interest; corresponding values (if any) are bound to variables with these
;; names (i.e., the args are variable names, not keywords, the keywords are
;; derived from the variable names). An arg can also be a (keyword var)
;; form, as for keyword args in a lambda lists. If no t/otherwise clause
;; appears, it is equivalent to having one that returns nil. If
;; process-event is invoked recursively, the nested invocation begins with
;; the event after the one currently being processed.
)
(defmacro event-cond ((display &key timeout peek-p discard-p (force-output-p t))
&body clauses)
;; The clauses of event-cond are of the form:
;; (event-or-events binding-list test-form . body-forms)
;;
;; EVENT-OR-EVENTS event-key or a list of event-keys (but they
;; need not be typed as keywords) or the symbol t
;; or otherwise (but only in the last clause). If
;; no t/otherwise clause appears, it is equivalent
;; to having one that returns nil. The keys are
;; not evaluated, and it is an error for the same
;; key to appear in more than one clause.
;;
;; BINDING-LIST The list of event components of interest.
;; corresponding values (if any) are bound to
;; variables with these names (i.e., the binding-list
;; has variable names, not keywords, the keywords are
;; derived from the variable names). An arg can also
;; be a (keyword var) form, as for keyword args in a
;; lambda list.
;;
;; The matching TEST-FORM for each queued event is executed until a
;; clause's test-form returns non-nil. Then the BODY-FORMS are
;; evaluated, returning the (possibly multiple) values of the last
;; form from event-cond. If there are no body-forms then, if the
;; test-form is non-nil, the value of the test-form is returned as a
;; single value.
;;
;; Options:
;; FORCE-OUTPUT-P When true, first invoke display-force-output if no
;; input is pending.
;;
;; PEEK-P When true, then the event is not removed from the queue.
;;
;; DISCARD-P When true, then events for which the clause returns nil
;; are removed from the queue, otherwise they are left in place.
;;
;; TIMEOUT If NIL, hang until non-nil is generated for some event's
;; test-form. Otherwise return NIL after TIMEOUT seconds have
;; elapsed. NIL is also returned whenever EOF is read.
;; Whenever NIL is returned a second value is returned which
;; is either :TIMEOUT if a timeout occurred or some other
;; non-NIL value if an EOF is detected.
;;
(declare (arglist (display &key timeout peek-p discard-p force-output-p)
(event-or-events (&rest args) test-form &body body) |...|))
)
(defun discard-current-event (display)
(declare (type display display)
(clx-values boolean))
;; Discard the current event for DISPLAY.
;; Returns NIL when the event queue is empty, else T.
;; To ensure events aren't ignored, application code should only call
;; this when throwing out of event-case or process-next-event, or from
;; inside even-case, event-cond or process-event when :peek-p is T and
;; :discard-p is NIL.
)
(defmacro declare-event (event-codes &rest declares)
;; Used to indicate the keyword arguments for handler functions in process-event
;; and event-case. In the declares, an argument listed as (name1 name2) indicates
;; synonyms for the same argument. All process-event handlers can have
;; (display display), (event-key event-key), and (boolean send-event-p) as keyword
;; arguments, and an event-case clause can also have event-key and send-event-p as
;; arguments.
(declare (arglist event-key-or-keys &rest (type &rest keywords))))
(declare-event (:key-press :key-release :button-press :button-release)
(card16 sequence)
(window (window event-window) root)
((or null window) child)
(boolean same-screen-p)
(int16 x y root-x root-y)
(card16 state)
((or null card32) time)
;; for key-press and key-release, code is the keycode
;; for button-press and button-release, code is the button number
(card8 code))
(declare-event :motion-notify
(card16 sequence)
(window (window event-window) root)
((or null window) child)
(boolean same-screen-p)
(int16 x y root-x root-y)
(card16 state)
((or null card32) time)
(boolean hint-p))
(declare-event (:enter-notify :leave-notify)
(card16 sequence)
(window (window event-window) root)
((or null window) child)
(boolean same-screen-p)
(int16 x y root-x root-y)
(card16 state)
((or null card32) time)
((member :normal :grab :ungrab) mode)
((member :ancestor :virtual :inferior :nonlinear :nonlinear-virtual) kind)
(boolean focus-p))
(declare-event (:focus-in :focus-out)
(card16 sequence)
(window (window event-window))
((member :normal :while-grabbed :grab :ungrab) mode)
((member :ancestor :virtual :inferior :nonlinear :nonlinear-virtual
:pointer :pointer-root :none)
kind))
(declare-event :keymap-notify
((bit-vector 256) keymap))
(declare-event :exposure
(card16 sequence)
(window (window event-window))