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
|
/************************************************************
Copyright 1987, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
********************************************************/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include "misc.h"
#include "resource.h"
#define NEED_EVENTS
#define NEED_REPLIES
#include <X11/Xproto.h>
#include "windowstr.h"
#include "inputstr.h"
#include "scrnintstr.h"
#include "cursorstr.h"
#include "dixstruct.h"
#include "site.h"
#ifndef XKB_IN_SERVER
#define XKB_IN_SERVER
#endif
#ifdef XKB
#include <xkbsrv.h>
#endif
#include "xace.h"
#include "dispatch.h"
#include "swaprep.h"
#include "dixevents.h"
#include <X11/extensions/XI.h>
#include <X11/extensions/XIproto.h>
#include "exglobals.h"
#include "exevents.h"
int CoreDevicePrivatesIndex = 0;
static int CoreDevicePrivatesGeneration = -1;
/* The client that is allowed to change pointer-keyboard pairings. */
static ClientPtr pairingClient = NULL;
/**
* Alloc memory for new sprite, reset to default values
*/
DeviceIntPtr
AddInputDevice(DeviceProc deviceProc, Bool autoStart)
{
DeviceIntPtr dev, *prev; /* not a typo */
DeviceIntPtr devtmp;
int devid;
char devind[MAX_DEVICES];
/* Find next available id */
memset(devind, 0, sizeof(char)*MAX_DEVICES);
if (inputInfo.keyboard)
devind[inputInfo.keyboard->id]++;
if (inputInfo.pointer)
devind[inputInfo.pointer->id]++;
for (devtmp = inputInfo.devices; devtmp; devtmp = devtmp->next)
devind[devtmp->id]++;
for (devtmp = inputInfo.off_devices; devtmp; devtmp = devtmp->next)
devind[devtmp->id]++;
for (devid = 0; devid < MAX_DEVICES && devind[devid]; devid++)
;
if (devid >= MAX_DEVICES)
return (DeviceIntPtr)NULL;
dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
if (!dev)
return (DeviceIntPtr)NULL;
dev->name = (char *)NULL;
dev->type = 0;
dev->id = devid;
inputInfo.numDevices++;
dev->public.on = FALSE;
dev->public.processInputProc = (ProcessInputProc)NoopDDA;
dev->public.realInputProc = (ProcessInputProc)NoopDDA;
dev->public.enqueueInputProc = EnqueueEvent;
dev->deviceProc = deviceProc;
dev->startup = autoStart;
/* device grab defaults */
dev->deviceGrab.sync.frozen = FALSE;
dev->deviceGrab.sync.other = NullGrab;
dev->deviceGrab.sync.state = NOT_GRABBED;
dev->deviceGrab.sync.event = (xEvent *) NULL;
dev->deviceGrab.sync.evcount = 0;
dev->deviceGrab.grab = NullGrab;
dev->deviceGrab.grabTime = currentTime;
dev->deviceGrab.fromPassiveGrab = FALSE;
dev->key = (KeyClassPtr)NULL;
dev->valuator = (ValuatorClassPtr)NULL;
dev->button = (ButtonClassPtr)NULL;
dev->focus = (FocusClassPtr)NULL;
dev->proximity = (ProximityClassPtr)NULL;
dev->absolute = (AbsoluteClassPtr)NULL;
dev->kbdfeed = (KbdFeedbackPtr)NULL;
dev->ptrfeed = (PtrFeedbackPtr)NULL;
dev->intfeed = (IntegerFeedbackPtr)NULL;
dev->stringfeed = (StringFeedbackPtr)NULL;
dev->bell = (BellFeedbackPtr)NULL;
dev->leds = (LedFeedbackPtr)NULL;
#ifdef XKB
dev->xkb_interest = NULL;
#endif
dev->nPrivates = 0;
dev->devPrivates = NULL;
dev->unwrapProc = NULL;
dev->coreEvents = TRUE;
dev->inited = FALSE;
dev->enabled = FALSE;
/* sprite defaults */
dev->spriteInfo = (SpriteInfoPtr)xcalloc(sizeof(SpriteInfoRec), 1);
if (!dev->spriteInfo)
return (DeviceIntPtr)NULL;
dev->spriteInfo->sprite = NULL;
dev->spriteInfo->spriteOwner = FALSE;
for (prev = &inputInfo.off_devices; *prev; prev = &(*prev)->next)
;
*prev = dev;
dev->next = NULL;
return dev;
}
/**
* Enable the device through the driver, initialize the DIX sprite or pair the
* device, add the device to the device list.
*
* After calling EnableDevice(), a device can and will send events.
*/
Bool
EnableDevice(DeviceIntPtr dev)
{
DeviceIntPtr *prev;
int ret;
DeviceIntRec dummyDev;
devicePresenceNotify ev;
for (prev = &inputInfo.off_devices;
*prev && (*prev != dev);
prev = &(*prev)->next)
;
/* Sprites pop up on the first root window, so we can supply it directly
* here.
*/
if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner)
InitializeSprite(dev, WindowTable[0]);
else
PairDevices(NULL, inputInfo.pointer, dev);
if ((*prev != dev) || !dev->inited ||
((ret = (*dev->deviceProc)(dev, DEVICE_ON)) != Success)) {
ErrorF("couldn't enable device %d\n", dev->id);
return FALSE;
}
dev->enabled = TRUE;
*prev = dev->next;
for (prev = &inputInfo.devices; *prev; prev = &(*prev)->next)
;
*prev = dev;
dev->next = NULL;
ev.type = DevicePresenceNotify;
ev.time = currentTime.milliseconds;
ev.devchange = DeviceEnabled;
ev.deviceid = dev->id;
dummyDev.id = 0;
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
(xEvent *) &ev, 1);
return TRUE;
}
/**
* Shut device down through drivers, remove from device list.
*/
Bool
DisableDevice(DeviceIntPtr dev)
{
DeviceIntPtr *prev;
DeviceIntRec dummyDev;
devicePresenceNotify ev;
for (prev = &inputInfo.devices;
*prev && (*prev != dev);
prev = &(*prev)->next)
;
if (*prev != dev)
return FALSE;
(void)(*dev->deviceProc)(dev, DEVICE_OFF);
dev->enabled = FALSE;
*prev = dev->next;
dev->next = inputInfo.off_devices;
inputInfo.off_devices = dev;
ev.type = DevicePresenceNotify;
ev.time = currentTime.milliseconds;
ev.devchange = DeviceDisabled;
ev.deviceid = dev->id;
dummyDev.id = 0;
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
(xEvent *) &ev, 1);
return TRUE;
}
/**
* Initialize device through driver, allocate memory for cursor sprite (if
* applicable) and send a PresenceNotify event to all clients.
*
* Must be called before EnableDevice.
*/
int
ActivateDevice(DeviceIntPtr dev)
{
int ret = Success;
devicePresenceNotify ev;
DeviceIntRec dummyDev;
ScreenPtr pScreen = screenInfo.screens[0];
if (!dev || !dev->deviceProc)
return BadImplementation;
ret = (*dev->deviceProc) (dev, DEVICE_INIT);
dev->inited = (ret == Success);
/* Initialize memory for sprites. */
if (IsPointerDevice(dev))
pScreen->DeviceCursorInitialize(dev, pScreen);
ev.type = DevicePresenceNotify;
ev.time = currentTime.milliseconds;
ev.devchange = DeviceAdded;
ev.deviceid = dev->id;
dummyDev.id = 0;
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
(xEvent *) &ev, 1);
return ret;
}
static void
CoreKeyboardBell(int volume, DeviceIntPtr pDev, pointer arg, int something)
{
KeybdCtrl *ctrl = arg;
DDXRingBell(volume, ctrl->bell_pitch, ctrl->bell_duration);
}
static void
CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
{
return;
}
static int
CoreKeyboardProc(DeviceIntPtr pDev, int what)
{
CARD8 *modMap;
KeySymsRec keySyms;
#ifdef XKB
XkbComponentNamesRec names;
#endif
switch (what) {
case DEVICE_INIT:
keySyms.minKeyCode = 8;
keySyms.maxKeyCode = 255;
keySyms.mapWidth = 4;
keySyms.map = (KeySym *)xcalloc(sizeof(KeySym),
(keySyms.maxKeyCode -
keySyms.minKeyCode + 1) *
keySyms.mapWidth);
if (!keySyms.map) {
ErrorF("Couldn't allocate core keymap\n");
return BadAlloc;
}
modMap = (CARD8 *)xalloc(MAP_LENGTH);
if (!modMap) {
ErrorF("Couldn't allocate core modifier map\n");
return BadAlloc;
}
bzero((char *)modMap, MAP_LENGTH);
#ifdef XKB
if (!noXkbExtension) {
bzero(&names, sizeof(names));
XkbSetRulesDflts("base", "pc105", "us", NULL, NULL);
XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, modMap,
CoreKeyboardBell, CoreKeyboardCtl);
}
else
#endif
{
/* FIXME Our keymap here isn't exactly useful. */
InitKeyboardDeviceStruct((DevicePtr)pDev, &keySyms, modMap,
CoreKeyboardBell, CoreKeyboardCtl);
}
xfree(keySyms.map);
xfree(modMap);
break;
case DEVICE_CLOSE:
pDev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
break;
default:
break;
}
return Success;
}
static int
CorePointerProc(DeviceIntPtr pDev, int what)
{
BYTE map[33];
int i = 0;
switch (what) {
case DEVICE_INIT:
for (i = 1; i <= 32; i++)
map[i] = i;
InitPointerDeviceStruct((DevicePtr)pDev, map, 32,
GetMotionHistory, (PtrCtrlProcPtr)NoopDDA,
GetMotionHistorySize(), 2);
pDev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
pDev->valuator->lastx = pDev->valuator->axisVal[0];
pDev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
pDev->valuator->lasty = pDev->valuator->axisVal[1];
break;
case DEVICE_CLOSE:
pDev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
break;
default:
break;
}
return Success;
}
/**
* Initialize a virtual core keyboard and a virtual core pointer.
*
* Both devices are not tied to physical devices, but guarantee that there is
* always a keyboard and a pointer present and keep the protocol semantics.
* Both core devices are NOT part of the device list and act only as a
* fallback if no physical device is available.
*/
void
InitCoreDevices(void)
{
DeviceIntPtr dev;
if (CoreDevicePrivatesGeneration != serverGeneration) {
CoreDevicePrivatesIndex = AllocateDevicePrivateIndex();
CoreDevicePrivatesGeneration = serverGeneration;
}
if (!inputInfo.keyboard) {
dev = AddInputDevice(CoreKeyboardProc, TRUE);
if (!dev)
FatalError("Failed to allocate core keyboard");
dev->name = strdup("Virtual core keyboard");
#ifdef XKB
dev->public.processInputProc = CoreProcessKeyboardEvent;
dev->public.realInputProc = CoreProcessKeyboardEvent;
if (!noXkbExtension)
XkbSetExtension(dev, ProcessKeyboardEvent);
#else
dev->public.processInputProc = ProcessKeyboardEvent;
dev->public.realInputProc = ProcessKeyboardEvent;
#endif
dev->deviceGrab.ActivateGrab = ActivateKeyboardGrab;
dev->deviceGrab.DeactivateGrab = DeactivateKeyboardGrab;
dev->coreEvents = FALSE;
dev->spriteInfo->spriteOwner = FALSE;
if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
FatalError("Couldn't allocate keyboard devPrivates\n");
dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
(void)ActivateDevice(dev);
inputInfo.keyboard = dev;
}
if (!inputInfo.pointer) {
dev = AddInputDevice(CorePointerProc, TRUE);
if (!dev)
FatalError("Failed to allocate core pointer");
dev->name = strdup("Virtual core pointer");
#ifdef XKB
dev->public.processInputProc = CoreProcessPointerEvent;
dev->public.realInputProc = CoreProcessPointerEvent;
if (!noXkbExtension)
XkbSetExtension(dev, ProcessPointerEvent);
#else
dev->public.processInputProc = ProcessPointerEvent;
dev->public.realInputProc = ProcessPointerEvent;
#endif
dev->deviceGrab.ActivateGrab = ActivatePointerGrab;
dev->deviceGrab.DeactivateGrab = DeactivatePointerGrab;
dev->coreEvents = FALSE;
dev->spriteInfo->spriteOwner = TRUE;
if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
FatalError("Couldn't allocate pointer devPrivates\n");
dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
(void)ActivateDevice(dev);
inputInfo.pointer = dev;
}
}
/**
* Activate and enable all devices.
*
* InitAndStartDevices needs to be called AFTER the windows are initialized.
* Devices will start sending events after InitAndStartDevices() has
* completed.
*/
int
InitAndStartDevices(WindowPtr root)
{
DeviceIntPtr dev, next;
for (dev = inputInfo.off_devices; dev; dev = dev->next) {
DebugF("(dix) initialising device %d\n", dev->id);
ActivateDevice(dev);
}
if (!inputInfo.keyboard) {
ErrorF("No core keyboard\n");
return BadImplementation;
}
if (!inputInfo.pointer) {
ErrorF("No core pointer\n");
return BadImplementation;
}
/* Now enable all devices */
if (inputInfo.keyboard->inited && inputInfo.keyboard->startup)
EnableDevice(inputInfo.keyboard);
if (inputInfo.pointer->inited && inputInfo.pointer->startup)
EnableDevice(inputInfo.pointer);
/* Remove VCP and VCK from device list */
inputInfo.devices = NULL;
inputInfo.keyboard->next = inputInfo.pointer->next = NULL;
/* enable real devices */
for (dev = inputInfo.off_devices; dev; dev = next)
{
DebugF("(dix) enabling device %d\n", dev->id);
next = dev->next;
if (dev->inited && dev->startup)
(void)EnableDevice(dev);
}
/* All of the devices are started up now. Pair VCK with VCP, then
* pair each real keyboard with a real pointer.
*/
PairDevices(NULL, inputInfo.pointer, inputInfo.keyboard);
for (dev = inputInfo.devices; dev; dev = dev->next)
{
if (!DevHasCursor(dev))
PairDevices(NULL, GuessFreePointerDevice(), dev);
else
/* enter/leave counter on root window */
((FocusSemaphoresPtr)root->devPrivates[FocusPrivatesIndex].ptr)->enterleave++;
}
return Success;
}
/**
* Shut down device and free memory.
*/
static void
CloseDevice(DeviceIntPtr dev)
{
KbdFeedbackPtr k, knext;
PtrFeedbackPtr p, pnext;
IntegerFeedbackPtr i, inext;
StringFeedbackPtr s, snext;
BellFeedbackPtr b, bnext;
LedFeedbackPtr l, lnext;
ScreenPtr screen = screenInfo.screens[0];
int j;
if (!dev)
return;
if (dev->inited)
(void)(*dev->deviceProc)(dev, DEVICE_CLOSE);
/* free sprite memory */
if (IsPointerDevice(dev))
screen->DeviceCursorCleanup(dev, screen);
xfree(dev->name);
if (dev->key) {
#ifdef XKB
if (dev->key->xkbInfo)
XkbFreeInfo(dev->key->xkbInfo);
#endif
xfree(dev->key->curKeySyms.map);
xfree(dev->key->modifierKeyMap);
xfree(dev->key);
}
if (dev->valuator) {
/* Counterpart to 'biggest hack ever' in init. */
if (dev->valuator->motion &&
dev->valuator->GetMotionProc == GetMotionHistory)
xfree(dev->valuator->motion);
xfree(dev->valuator);
}
if (dev->button) {
#ifdef XKB
if (dev->button->xkb_acts)
xfree(dev->button->xkb_acts);
#endif
xfree(dev->button);
}
if (dev->focus) {
xfree(dev->focus->trace);
xfree(dev->focus);
}
if (dev->proximity)
xfree(dev->proximity);
for (k = dev->kbdfeed; k; k = knext) {
knext = k->next;
#ifdef XKB
if (k->xkb_sli)
XkbFreeSrvLedInfo(k->xkb_sli);
#endif
xfree(k);
}
for (p = dev->ptrfeed; p; p = pnext) {
pnext = p->next;
xfree(p);
}
for (i = dev->intfeed; i; i = inext) {
inext = i->next;
xfree(i);
}
for (s = dev->stringfeed; s; s = snext) {
snext = s->next;
xfree(s->ctrl.symbols_supported);
xfree(s->ctrl.symbols_displayed);
xfree(s);
}
for (b = dev->bell; b; b = bnext) {
bnext = b->next;
xfree(b);
}
for (l = dev->leds; l; l = lnext) {
lnext = l->next;
#ifdef XKB
if (l->xkb_sli)
XkbFreeSrvLedInfo(l->xkb_sli);
#endif
xfree(l);
}
#ifdef XKB
while (dev->xkb_interest)
XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
#endif
if (DevHasCursor(dev)) {
xfree(dev->spriteInfo->sprite->spriteTrace);
xfree(dev->spriteInfo->sprite);
}
/* a client may have the device set as client pointer */
for (j = 0; j < currentMaxClients; j++)
{
if (clients[j] && clients[j]->clientPtr == dev)
{
clients[j]->clientPtr = NULL;
clients[j]->clientPtr = PickPointer(clients[j]);
}
}
if (dev->devPrivates)
xfree(dev->devPrivates);
xfree(dev->deviceGrab.sync.event);
xfree(dev->spriteInfo);
xfree(dev);
}
void
CloseDownDevices(void)
{
DeviceIntPtr dev, next;
CloseDevice(inputInfo.keyboard);
CloseDevice(inputInfo.pointer);
for (dev = inputInfo.devices; dev; dev = next)
{
next = dev->next;
CloseDevice(dev);
}
for (dev = inputInfo.off_devices; dev; dev = next)
{
next = dev->next;
CloseDevice(dev);
}
inputInfo.devices = NULL;
inputInfo.off_devices = NULL;
inputInfo.keyboard = NULL;
inputInfo.pointer = NULL;
}
/**
* Remove the cursor sprite for all devices. This needs to be done before any
* resources are freed or any device is deleted.
*/
void
UndisplayDevices()
{
DeviceIntPtr dev;
ScreenPtr screen = screenInfo.screens[0];
for (dev = inputInfo.devices; dev; dev = dev->next)
{
screen->UndisplayCursor(dev, screen);
}
}
int
RemoveDevice(DeviceIntPtr dev)
{
DeviceIntPtr prev,tmp,next;
int ret = BadMatch;
devicePresenceNotify ev;
DeviceIntRec dummyDev;
ScreenPtr screen = screenInfo.screens[0];
int deviceid;
DebugF("(dix) removing device %d\n", dev->id);
if (!dev || dev == inputInfo.keyboard || dev == inputInfo.pointer)
return BadImplementation;
screen->UndisplayCursor(dev, screen);
deviceid = dev->id;
DisableDevice(dev);
prev = NULL;
for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) {
next = tmp->next;
if (tmp == dev) {
if (prev==NULL)
inputInfo.devices = next;
else
prev->next = next;
CloseDevice(tmp);
ret = Success;
}
}
prev = NULL;
for (tmp = inputInfo.off_devices; tmp; (prev = tmp), (tmp = next)) {
next = tmp->next;
if (tmp == dev) {
CloseDevice(tmp);
if (prev == NULL)
inputInfo.off_devices = next;
else
prev->next = next;
ret = Success;
}
}
if (ret == Success) {
inputInfo.numDevices--;
ev.type = DevicePresenceNotify;
ev.time = currentTime.milliseconds;
ev.devchange = DeviceRemoved;
ev.deviceid = deviceid;
dummyDev.id = 0;
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
(xEvent *) &ev, 1);
}
return ret;
}
int
NumMotionEvents(void)
{
/* only called to fill data in initial connection reply.
* VCP is ok here, it is the only fixed device we have. */
return inputInfo.pointer->valuator->numMotionEvents;
}
void
RegisterPointerDevice(DeviceIntPtr device)
{
RegisterOtherDevice(device);
}
void
RegisterKeyboardDevice(DeviceIntPtr device)
{
RegisterOtherDevice(device);
}
_X_EXPORT DevicePtr
LookupKeyboardDevice(void)
{
return inputInfo.keyboard ? &inputInfo.keyboard->public : NULL;
}
_X_EXPORT DevicePtr
LookupPointerDevice(void)
{
return inputInfo.pointer ? &inputInfo.pointer->public : NULL;
}
DevicePtr
LookupDevice(int id)
{
DeviceIntPtr dev;
for (dev=inputInfo.devices; dev; dev=dev->next) {
if (dev->id == (CARD8)id)
return (DevicePtr)dev;
}
for (dev=inputInfo.off_devices; dev; dev=dev->next) {
if (dev->id == (CARD8)id)
return (DevicePtr)dev;
}
return NULL;
}
void
QueryMinMaxKeyCodes(KeyCode *minCode, KeyCode *maxCode)
{
if (inputInfo.keyboard) {
*minCode = inputInfo.keyboard->key->curKeySyms.minKeyCode;
*maxCode = inputInfo.keyboard->key->curKeySyms.maxKeyCode;
}
}
Bool
SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src)
{
int i, j;
int rowDif = src->minKeyCode - dst->minKeyCode;
/* if keysym map size changes, grow map first */
if (src->mapWidth < dst->mapWidth)
{
for (i = src->minKeyCode; i <= src->maxKeyCode; i++)
{
#define SI(r, c) (((r-src->minKeyCode)*src->mapWidth) + (c))
#define DI(r, c) (((r - dst->minKeyCode)*dst->mapWidth) + (c))
for (j = 0; j < src->mapWidth; j++)
dst->map[DI(i, j)] = src->map[SI(i, j)];
for (j = src->mapWidth; j < dst->mapWidth; j++)
dst->map[DI(i, j)] = NoSymbol;
#undef SI
#undef DI
}
return TRUE;
}
else if (src->mapWidth > dst->mapWidth)
{
KeySym *map;
int bytes = sizeof(KeySym) * src->mapWidth *
(dst->maxKeyCode - dst->minKeyCode + 1);
map = (KeySym *)xalloc(bytes);
if (!map)
return FALSE;
bzero((char *)map, bytes);
if (dst->map)
{
for (i = 0; i <= dst->maxKeyCode-dst->minKeyCode; i++)
memmove((char *)&map[i*src->mapWidth],
(char *)&dst->map[i*dst->mapWidth],
dst->mapWidth * sizeof(KeySym));
xfree(dst->map);
}
dst->mapWidth = src->mapWidth;
dst->map = map;
}
memmove((char *)&dst->map[rowDif * dst->mapWidth],
(char *)src->map,
(int)(src->maxKeyCode - src->minKeyCode + 1) *
dst->mapWidth * sizeof(KeySym));
return TRUE;
}
static Bool
InitModMap(KeyClassPtr keyc)
{
int i, j;
CARD8 keysPerModifier[8];
CARD8 mask;
keyc->maxKeysPerModifier = 0;
for (i = 0; i < 8; i++)
keysPerModifier[i] = 0;
for (i = 8; i < MAP_LENGTH; i++)
{
for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
{
if (mask & keyc->modifierMap[i])
{
if (++keysPerModifier[j] > keyc->maxKeysPerModifier)
keyc->maxKeysPerModifier = keysPerModifier[j];
}
}
}
keyc->modifierKeyMap = (KeyCode *)xalloc(8*keyc->maxKeysPerModifier);
if (!keyc->modifierKeyMap && keyc->maxKeysPerModifier)
return (FALSE);
bzero((char *)keyc->modifierKeyMap, 8*(int)keyc->maxKeysPerModifier);
for (i = 0; i < 8; i++)
keysPerModifier[i] = 0;
for (i = 8; i < MAP_LENGTH; i++)
{
for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
{
if (mask & keyc->modifierMap[i])
{
keyc->modifierKeyMap[(j*keyc->maxKeysPerModifier) +
keysPerModifier[j]] = i;
keysPerModifier[j]++;
}
}
}
return TRUE;
}
_X_EXPORT Bool
InitKeyClassDeviceStruct(DeviceIntPtr dev, KeySymsPtr pKeySyms, CARD8 pModifiers[])
{
int i;
KeyClassPtr keyc;
keyc = (KeyClassPtr)xalloc(sizeof(KeyClassRec));
if (!keyc)
return FALSE;
keyc->curKeySyms.map = (KeySym *)NULL;
keyc->curKeySyms.mapWidth = 0;
keyc->curKeySyms.minKeyCode = pKeySyms->minKeyCode;
keyc->curKeySyms.maxKeyCode = pKeySyms->maxKeyCode;
keyc->modifierKeyMap = (KeyCode *)NULL;
keyc->state = 0;
keyc->prev_state = 0;
if (pModifiers)
memmove((char *)keyc->modifierMap, (char *)pModifiers, MAP_LENGTH);
else
bzero((char *)keyc->modifierMap, MAP_LENGTH);
bzero((char *)keyc->down, DOWN_LENGTH);
for (i = 0; i < 8; i++)
keyc->modifierKeyCount[i] = 0;
if (!SetKeySymsMap(&keyc->curKeySyms, pKeySyms) || !InitModMap(keyc))
{
xfree(keyc->curKeySyms.map);
xfree(keyc->modifierKeyMap);
xfree(keyc);
return FALSE;
}
dev->key = keyc;
#ifdef XKB
dev->key->xkbInfo= NULL;
if (!noXkbExtension) XkbInitDevice(dev);
#endif
return TRUE;
}
_X_EXPORT Bool
InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
CARD8 *map)
{
ButtonClassPtr butc;
int i;
butc = (ButtonClassPtr)xalloc(sizeof(ButtonClassRec));
if (!butc)
return FALSE;
butc->numButtons = numButtons;
for (i = 1; i <= numButtons; i++)
butc->map[i] = map[i];
butc->buttonsDown = 0;
butc->state = 0;
butc->motionMask = 0;
bzero((char *)butc->down, DOWN_LENGTH);
#ifdef XKB
butc->xkb_acts= NULL;
#endif
dev->button = butc;
return TRUE;
}
_X_EXPORT Bool
InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
ValuatorMotionProcPtr motionProc,
int numMotionEvents, int mode)
{
int i;
ValuatorClassPtr valc;
if (!dev)
return FALSE;
valc = (ValuatorClassPtr)xalloc(sizeof(ValuatorClassRec) +
numAxes * sizeof(AxisInfo) +
numAxes * sizeof(unsigned int));
if (!valc)
return FALSE;
valc->motion = NULL;
valc->first_motion = 0;
valc->last_motion = 0;
valc->GetMotionProc = motionProc;
valc->numMotionEvents = numMotionEvents;
valc->motionHintWindow = NullWindow;
valc->numAxes = numAxes;
valc->mode = mode;
valc->axes = (AxisInfoPtr)(valc + 1);
valc->axisVal = (int *)(valc->axes + numAxes);
valc->lastx = 0;
valc->lasty = 0;
valc->dxremaind = 0;
valc->dyremaind = 0;
dev->valuator = valc;
/* biggest hack ever. */
if (motionProc == GetMotionHistory)
AllocateMotionHistory(dev);
for (i=0; i<numAxes; i++) {
InitValuatorAxisStruct(dev, i, -1, -1, 0, 0, 0);
valc->axisVal[i]=0;
}
return TRUE;
}
_X_EXPORT Bool
InitAbsoluteClassDeviceStruct(DeviceIntPtr dev)
{
AbsoluteClassPtr abs;
abs = (AbsoluteClassPtr)xalloc(sizeof(AbsoluteClassRec));
if (!abs)
return FALSE;
/* we don't do anything sensible with these, but should */
abs->min_x = -1;
abs->min_y = -1;
abs->max_x = -1;
abs->max_y = -1;
abs->flip_x = 0;
abs->flip_y = 0;
abs->rotation = 0;
abs->button_threshold = 0;
abs->offset_x = 0;
abs->offset_y = 0;
abs->width = -1;
abs->height = -1;
abs->following = 0;
dev->absolute = abs;
return TRUE;
}
_X_EXPORT Bool
InitFocusClassDeviceStruct(DeviceIntPtr dev)
{
FocusClassPtr focc;
focc = (FocusClassPtr)xalloc(sizeof(FocusClassRec));
if (!focc)
return FALSE;
focc->win = PointerRootWin;
focc->revert = None;
focc->time = currentTime;
focc->trace = (WindowPtr *)NULL;
focc->traceSize = 0;
focc->traceGood = 0;
dev->focus = focc;
return TRUE;
}
_X_EXPORT Bool
InitKbdFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc,
KbdCtrlProcPtr controlProc)
{
KbdFeedbackPtr feedc;
feedc = (KbdFeedbackPtr)xalloc(sizeof(KbdFeedbackClassRec));
if (!feedc)
return FALSE;
feedc->BellProc = bellProc;
feedc->CtrlProc = controlProc;
#ifdef XKB
defaultKeyboardControl.autoRepeat = TRUE;
#endif
feedc->ctrl = defaultKeyboardControl;
feedc->ctrl.id = 0;
if ((feedc->next = dev->kbdfeed) != 0)
feedc->ctrl.id = dev->kbdfeed->ctrl.id + 1;
dev->kbdfeed = feedc;
#ifdef XKB
feedc->xkb_sli= NULL;
if (!noXkbExtension)
XkbFinishDeviceInit(dev);
#endif
(*dev->kbdfeed->CtrlProc)(dev,&dev->kbdfeed->ctrl);
return TRUE;
}
_X_EXPORT Bool
InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc)
{
PtrFeedbackPtr feedc;
feedc = (PtrFeedbackPtr)xalloc(sizeof(PtrFeedbackClassRec));
if (!feedc)
return FALSE;
feedc->CtrlProc = controlProc;
feedc->ctrl = defaultPointerControl;
feedc->ctrl.id = 0;
if ( (feedc->next = dev->ptrfeed) )
feedc->ctrl.id = dev->ptrfeed->ctrl.id + 1;
dev->ptrfeed = feedc;
(*controlProc)(dev, &feedc->ctrl);
return TRUE;
}
static LedCtrl defaultLedControl = {
DEFAULT_LEDS, DEFAULT_LEDS_MASK, 0};
static BellCtrl defaultBellControl = {
DEFAULT_BELL,
DEFAULT_BELL_PITCH,
DEFAULT_BELL_DURATION,
0};
static IntegerCtrl defaultIntegerControl = {
DEFAULT_INT_RESOLUTION,
DEFAULT_INT_MIN_VALUE,
DEFAULT_INT_MAX_VALUE,
DEFAULT_INT_DISPLAYED,
0};
_X_EXPORT Bool
InitStringFeedbackClassDeviceStruct (
DeviceIntPtr dev, StringCtrlProcPtr controlProc,
int max_symbols, int num_symbols_supported, KeySym *symbols)
{
int i;
StringFeedbackPtr feedc;
feedc = (StringFeedbackPtr)xalloc(sizeof(StringFeedbackClassRec));
if (!feedc)
return FALSE;
feedc->CtrlProc = controlProc;
feedc->ctrl.num_symbols_supported = num_symbols_supported;
feedc->ctrl.num_symbols_displayed = 0;
feedc->ctrl.max_symbols = max_symbols;
feedc->ctrl.symbols_supported = (KeySym *)
xalloc (sizeof (KeySym) * num_symbols_supported);
feedc->ctrl.symbols_displayed = (KeySym *)
xalloc (sizeof (KeySym) * max_symbols);
if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed)
{
if (feedc->ctrl.symbols_supported)
xfree(feedc->ctrl.symbols_supported);
if (feedc->ctrl.symbols_displayed)
xfree(feedc->ctrl.symbols_displayed);
xfree(feedc);
return FALSE;
}
for (i=0; i<num_symbols_supported; i++)
*(feedc->ctrl.symbols_supported+i) = *symbols++;
for (i=0; i<max_symbols; i++)
*(feedc->ctrl.symbols_displayed+i) = (KeySym) NULL;
feedc->ctrl.id = 0;
if ( (feedc->next = dev->stringfeed) )
feedc->ctrl.id = dev->stringfeed->ctrl.id + 1;
dev->stringfeed = feedc;
(*controlProc)(dev, &feedc->ctrl);
return TRUE;
}
_X_EXPORT Bool
InitBellFeedbackClassDeviceStruct (DeviceIntPtr dev, BellProcPtr bellProc,
BellCtrlProcPtr controlProc)
{
BellFeedbackPtr feedc;
feedc = (BellFeedbackPtr)xalloc(sizeof(BellFeedbackClassRec));
if (!feedc)
return FALSE;
feedc->CtrlProc = controlProc;
feedc->BellProc = bellProc;
feedc->ctrl = defaultBellControl;
feedc->ctrl.id = 0;
if ( (feedc->next = dev->bell) )
feedc->ctrl.id = dev->bell->ctrl.id + 1;
dev->bell = feedc;
(*controlProc)(dev, &feedc->ctrl);
return TRUE;
}
_X_EXPORT Bool
InitLedFeedbackClassDeviceStruct (DeviceIntPtr dev, LedCtrlProcPtr controlProc)
{
LedFeedbackPtr feedc;
feedc = (LedFeedbackPtr)xalloc(sizeof(LedFeedbackClassRec));
if (!feedc)
return FALSE;
feedc->CtrlProc = controlProc;
feedc->ctrl = defaultLedControl;
feedc->ctrl.id = 0;
if ( (feedc->next = dev->leds) )
feedc->ctrl.id = dev->leds->ctrl.id + 1;
#ifdef XKB
feedc->xkb_sli= NULL;
#endif
dev->leds = feedc;
(*controlProc)(dev, &feedc->ctrl);
return TRUE;
}
_X_EXPORT Bool
InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr controlProc)
{
IntegerFeedbackPtr feedc;
feedc = (IntegerFeedbackPtr)xalloc(sizeof(IntegerFeedbackClassRec));
if (!feedc)
return FALSE;
feedc->CtrlProc = controlProc;
feedc->ctrl = defaultIntegerControl;
feedc->ctrl.id = 0;
if ( (feedc->next = dev->intfeed) )
feedc->ctrl.id = dev->intfeed->ctrl.id + 1;
dev->intfeed = feedc;
(*controlProc)(dev, &feedc->ctrl);
return TRUE;
}
_X_EXPORT Bool
InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons,
ValuatorMotionProcPtr motionProc,
PtrCtrlProcPtr controlProc, int numMotionEvents,
int numAxes)
{
DeviceIntPtr dev = (DeviceIntPtr)device;
return(InitButtonClassDeviceStruct(dev, numButtons, map) &&
InitValuatorClassDeviceStruct(dev, numAxes, motionProc,
numMotionEvents, 0) &&
InitPtrFeedbackClassDeviceStruct(dev, controlProc));
}
_X_EXPORT Bool
InitKeyboardDeviceStruct(DevicePtr device, KeySymsPtr pKeySyms,
CARD8 pModifiers[], BellProcPtr bellProc,
KbdCtrlProcPtr controlProc)
{
DeviceIntPtr dev = (DeviceIntPtr)device;
return(InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers) &&
InitFocusClassDeviceStruct(dev) &&
InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc));
}
_X_EXPORT void
SendMappingNotify(DeviceIntPtr pDev, unsigned request, unsigned firstKeyCode,
unsigned count, ClientPtr client)
{
int i;
xEvent event;
event.u.u.type = MappingNotify;
event.u.mappingNotify.request = request;
if (request == MappingKeyboard)
{
event.u.mappingNotify.firstKeyCode = firstKeyCode;
event.u.mappingNotify.count = count;
}
#ifdef XKB
if (!noXkbExtension &&
((request == MappingKeyboard) || (request == MappingModifier))) {
XkbApplyMappingChange(pDev,request,firstKeyCode,count, client);
}
#endif
/* 0 is the server client */
for (i=1; i<currentMaxClients; i++)
{
if (clients[i] && clients[i]->clientState == ClientStateRunning)
{
#ifdef XKB
if (!noXkbExtension &&
(request == MappingKeyboard) &&
(clients[i]->xkbClientFlags != 0) &&
(clients[i]->mapNotifyMask&XkbKeySymsMask))
continue;
#endif
event.u.u.sequenceNumber = clients[i]->sequence;
WriteEventsToClient(clients[i], 1, &event);
}
}
}
/*
* n-squared algorithm. n < 255 and don't want to copy the whole thing and
* sort it to do the checking. How often is it called? Just being lazy?
*/
Bool
BadDeviceMap(BYTE *buff, int length, unsigned low, unsigned high, XID *errval)
{
int i, j;
for (i = 0; i < length; i++)
if (buff[i]) /* only check non-zero elements */
{
if ((low > buff[i]) || (high < buff[i]))
{
*errval = buff[i];
return TRUE;
}
for (j = i + 1; j < length; j++)
if (buff[i] == buff[j])
{
*errval = buff[i];
return TRUE;
}
}
return FALSE;
}
Bool
AllModifierKeysAreUp(dev, map1, per1, map2, per2)
DeviceIntPtr dev;
CARD8 *map1, *map2;
int per1, per2;
{
int i, j, k;
CARD8 *down = dev->key->down;
for (i = 8; --i >= 0; map2 += per2)
{
for (j = per1; --j >= 0; map1++)
{
if (*map1 && BitIsOn(down, *map1))
{
for (k = per2; (--k >= 0) && (*map1 != map2[k]);)
;
if (k < 0)
return FALSE;
}
}
}
return TRUE;
}
static int
DoSetModifierMapping(ClientPtr client, KeyCode *inputMap,
int numKeyPerModifier)
{
DeviceIntPtr pDev = NULL;
int i = 0, inputMapLen = numKeyPerModifier * 8;
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
for (i = 0; i < inputMapLen; i++) {
/* Check that all the new modifiers fall within the advertised
* keycode range, and are okay with the DDX. */
if (inputMap[i] && ((inputMap[i] < pDev->key->curKeySyms.minKeyCode ||
inputMap[i] > pDev->key->curKeySyms.maxKeyCode) ||
!LegalModifier(inputMap[i], pDev))) {
client->errorValue = inputMap[i];
return BadValue;
}
}
if (!XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE))
return BadAccess;
/* None of the modifiers (old or new) may be down while we change
* the map. */
if (!AllModifierKeysAreUp(pDev, pDev->key->modifierKeyMap,
pDev->key->maxKeysPerModifier,
inputMap, numKeyPerModifier) ||
!AllModifierKeysAreUp(pDev, inputMap, numKeyPerModifier,
pDev->key->modifierKeyMap,
pDev->key->maxKeysPerModifier)) {
return MappingBusy;
}
}
}
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
bzero(pDev->key->modifierMap, MAP_LENGTH);
/* Annoyingly, we lack a modifierKeyMap size, so we have to just free
* and re-alloc it every time. */
if (pDev->key->modifierKeyMap)
xfree(pDev->key->modifierKeyMap);
if (inputMapLen) {
pDev->key->modifierKeyMap = (KeyCode *) xalloc(inputMapLen);
if (!pDev->key->modifierKeyMap)
return BadAlloc;
memcpy(pDev->key->modifierKeyMap, inputMap, inputMapLen);
pDev->key->maxKeysPerModifier = numKeyPerModifier;
for (i = 0; i < inputMapLen; i++) {
if (inputMap[i]) {
pDev->key->modifierMap[inputMap[i]] |=
(1 << (((unsigned int)i) / numKeyPerModifier));
}
}
}
else {
pDev->key->modifierKeyMap = NULL;
pDev->key->maxKeysPerModifier = 0;
}
}
}
return Success;
}
int
ProcSetModifierMapping(ClientPtr client)
{
xSetModifierMappingReply rep;
REQUEST(xSetModifierMappingReq);
REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
if (client->req_len != ((stuff->numKeyPerModifier << 1) +
(sizeof (xSetModifierMappingReq) >> 2)))
return BadLength;
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.success = DoSetModifierMapping(client, (KeyCode *)&stuff[1],
stuff->numKeyPerModifier);
/* FIXME: Send mapping notifies for all the extended devices as well. */
SendMappingNotify(inputInfo.keyboard, MappingModifier, 0, 0, client);
WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
return client->noClientException;
}
int
ProcGetModifierMapping(ClientPtr client)
{
xGetModifierMappingReply rep;
KeyClassPtr keyc = inputInfo.keyboard->key;
REQUEST_SIZE_MATCH(xReq);
rep.type = X_Reply;
rep.numKeyPerModifier = keyc->maxKeysPerModifier;
rep.sequenceNumber = client->sequence;
/* length counts 4 byte quantities - there are 8 modifiers 1 byte big */
rep.length = keyc->maxKeysPerModifier << 1;
WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep);
/* Use the (modified by DDX) map that SetModifierMapping passed in */
(void)WriteToClient(client, (int)(keyc->maxKeysPerModifier << 3),
(char *)keyc->modifierKeyMap);
return client->noClientException;
}
int
ProcChangeKeyboardMapping(ClientPtr client)
{
REQUEST(xChangeKeyboardMappingReq);
unsigned len;
KeySymsRec keysyms;
KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
DeviceIntPtr pDev = NULL;
REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2);
if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode))
return BadLength;
if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
(stuff->firstKeyCode > curKeySyms->maxKeyCode)) {
client->errorValue = stuff->firstKeyCode;
return BadValue;
}
if (((unsigned)(stuff->firstKeyCode + stuff->keyCodes - 1) >
curKeySyms->maxKeyCode) || (stuff->keySymsPerKeyCode == 0)) {
client->errorValue = stuff->keySymsPerKeyCode;
return BadValue;
}
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
if (!XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE))
return BadAccess;
}
}
keysyms.minKeyCode = stuff->firstKeyCode;
keysyms.maxKeyCode = stuff->firstKeyCode + stuff->keyCodes - 1;
keysyms.mapWidth = stuff->keySymsPerKeyCode;
keysyms.map = (KeySym *)&stuff[1];
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
if (!SetKeySymsMap(&pDev->key->curKeySyms, &keysyms))
return BadAlloc;
}
}
/* FIXME: Send mapping notifies for all the extended devices as well. */
SendMappingNotify(inputInfo.keyboard, MappingKeyboard,
stuff->firstKeyCode, stuff->keyCodes, client);
return client->noClientException;
}
static int
DoSetPointerMapping(DeviceIntPtr device, BYTE *map, int n)
{
int i = 0;
DeviceIntPtr dev = NULL;
if (!device || !device->button)
return BadDevice;
for (dev = inputInfo.devices; dev; dev = dev->next) {
if ((dev->coreEvents || dev == inputInfo.pointer) && dev->button) {
for (i = 0; i < n; i++) {
if ((device->button->map[i + 1] != map[i]) &&
BitIsOn(device->button->down, i + 1)) {
return MappingBusy;
}
}
}
}
for (dev = inputInfo.devices; dev; dev = dev->next) {
if ((dev->coreEvents || dev == inputInfo.pointer) && dev->button) {
for (i = 0; i < n; i++)
dev->button->map[i + 1] = map[i];
}
}
return Success;
}
int
ProcSetPointerMapping(ClientPtr client)
{
REQUEST(xSetPointerMappingReq);
BYTE *map;
int ret;
DeviceIntPtr ptr = PickPointer(client);
xSetPointerMappingReply rep;
REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
if (client->req_len != (sizeof(xSetPointerMappingReq)+stuff->nElts+3) >> 2)
return BadLength;
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.success = MappingSuccess;
map = (BYTE *)&stuff[1];
/* So we're bounded here by the number of core buttons. This check
* probably wants disabling through XFixes. */
/* MPX: With ClientPointer, we can return the right number of buttons.
* Let's just hope nobody changed ClientPointer between GetPointerMapping
* and SetPointerMapping
*/
if (stuff->nElts != ptr->button->numButtons) {
client->errorValue = stuff->nElts;
return BadValue;
}
if (BadDeviceMap(&map[0], (int)stuff->nElts, 1, 255, &client->errorValue))
return BadValue;
ret = DoSetPointerMapping(ptr, map, stuff->nElts);
if (ret != Success) {
rep.success = ret;
WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
return Success;
}
/* FIXME: Send mapping notifies for all the extended devices as well. */
SendMappingNotify(ptr, MappingPointer, 0, 0, client);
WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
return Success;
}
int
ProcGetKeyboardMapping(ClientPtr client)
{
xGetKeyboardMappingReply rep;
REQUEST(xGetKeyboardMappingReq);
DeviceIntPtr kbd = PickKeyboard(client);
KeySymsPtr curKeySyms = &kbd->key->curKeySyms;
REQUEST_SIZE_MATCH(xGetKeyboardMappingReq);
if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
(stuff->firstKeyCode > curKeySyms->maxKeyCode)) {
client->errorValue = stuff->firstKeyCode;
return BadValue;
}
if (stuff->firstKeyCode + stuff->count >
(unsigned)(curKeySyms->maxKeyCode + 1)) {
client->errorValue = stuff->count;
return BadValue;
}
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.keySymsPerKeyCode = curKeySyms->mapWidth;
/* length is a count of 4 byte quantities and KeySyms are 4 bytes */
rep.length = (curKeySyms->mapWidth * stuff->count);
WriteReplyToClient(client, sizeof(xGetKeyboardMappingReply), &rep);
client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
WriteSwappedDataToClient(
client,
curKeySyms->mapWidth * stuff->count * sizeof(KeySym),
&curKeySyms->map[(stuff->firstKeyCode - curKeySyms->minKeyCode) *
curKeySyms->mapWidth]);
return client->noClientException;
}
int
ProcGetPointerMapping(ClientPtr client)
{
xGetPointerMappingReply rep;
/* Apps may get different values each time they call GetPointerMapping as
* the ClientPointer could change. */
ButtonClassPtr butc = PickPointer(client)->button;
REQUEST_SIZE_MATCH(xReq);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.nElts = butc->numButtons;
rep.length = ((unsigned)rep.nElts + (4-1))/4;
WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
(void)WriteToClient(client, (int)rep.nElts, (char *)&butc->map[1]);
return Success;
}
void
NoteLedState(DeviceIntPtr keybd, int led, Bool on)
{
KeybdCtrl *ctrl = &keybd->kbdfeed->ctrl;
if (on)
ctrl->leds |= ((Leds)1 << (led - 1));
else
ctrl->leds &= ~((Leds)1 << (led - 1));
}
_X_EXPORT int
Ones(unsigned long mask) /* HACKMEM 169 */
{
unsigned long y;
y = (mask >> 1) &033333333333;
y = mask - y - ((y >>1) & 033333333333);
return (((y + (y >> 3)) & 030707070707) % 077);
}
static int
DoChangeKeyboardControl (ClientPtr client, DeviceIntPtr keybd, XID *vlist,
BITS32 vmask)
{
#define DO_ALL (-1)
KeybdCtrl ctrl;
int t;
int led = DO_ALL;
int key = DO_ALL;
BITS32 index2;
int mask = vmask, i;
ctrl = keybd->kbdfeed->ctrl;
while (vmask) {
index2 = (BITS32) lowbit (vmask);
vmask &= ~index2;
switch (index2) {
case KBKeyClickPercent:
t = (INT8)*vlist;
vlist++;
if (t == -1) {
t = defaultKeyboardControl.click;
}
else if (t < 0 || t > 100) {
client->errorValue = t;
return BadValue;
}
ctrl.click = t;
break;
case KBBellPercent:
t = (INT8)*vlist;
vlist++;
if (t == -1) {
t = defaultKeyboardControl.bell;
}
else if (t < 0 || t > 100) {
client->errorValue = t;
return BadValue;
}
ctrl.bell = t;
break;
case KBBellPitch:
t = (INT16)*vlist;
vlist++;
if (t == -1) {
t = defaultKeyboardControl.bell_pitch;
}
else if (t < 0) {
client->errorValue = t;
return BadValue;
}
ctrl.bell_pitch = t;
break;
case KBBellDuration:
t = (INT16)*vlist;
vlist++;
if (t == -1)
t = defaultKeyboardControl.bell_duration;
else if (t < 0) {
client->errorValue = t;
return BadValue;
}
ctrl.bell_duration = t;
break;
case KBLed:
led = (CARD8)*vlist;
vlist++;
if (led < 1 || led > 32) {
client->errorValue = led;
return BadValue;
}
if (!(mask & KBLedMode))
return BadMatch;
break;
case KBLedMode:
t = (CARD8)*vlist;
vlist++;
if (t == LedModeOff) {
if (led == DO_ALL)
ctrl.leds = 0x0;
else
ctrl.leds &= ~(((Leds)(1)) << (led - 1));
}
else if (t == LedModeOn) {
if (led == DO_ALL)
ctrl.leds = ~0L;
else
ctrl.leds |= (((Leds)(1)) << (led - 1));
}
else {
client->errorValue = t;
return BadValue;
}
#ifdef XKB
if (!noXkbExtension) {
XkbEventCauseRec cause;
XkbSetCauseCoreReq(&cause,X_ChangeKeyboardControl,client);
XkbSetIndicators(keybd,((led == DO_ALL) ? ~0L : (1L<<(led-1))),
ctrl.leds, &cause);
ctrl.leds = keybd->kbdfeed->ctrl.leds;
}
#endif
break;
case KBKey:
key = (KeyCode)*vlist;
vlist++;
if ((KeyCode)key < inputInfo.keyboard->key->curKeySyms.minKeyCode ||
(KeyCode)key > inputInfo.keyboard->key->curKeySyms.maxKeyCode) {
client->errorValue = key;
return BadValue;
}
if (!(mask & KBAutoRepeatMode))
return BadMatch;
break;
case KBAutoRepeatMode:
i = (key >> 3);
mask = (1 << (key & 7));
t = (CARD8)*vlist;
vlist++;
#ifdef XKB
if (!noXkbExtension && key != DO_ALL)
XkbDisableComputedAutoRepeats(keybd,key);
#endif
if (t == AutoRepeatModeOff) {
if (key == DO_ALL)
ctrl.autoRepeat = FALSE;
else
ctrl.autoRepeats[i] &= ~mask;
}
else if (t == AutoRepeatModeOn) {
if (key == DO_ALL)
ctrl.autoRepeat = TRUE;
else
ctrl.autoRepeats[i] |= mask;
}
else if (t == AutoRepeatModeDefault) {
if (key == DO_ALL)
ctrl.autoRepeat = defaultKeyboardControl.autoRepeat;
else
ctrl.autoRepeats[i] =
(ctrl.autoRepeats[i] & ~mask) |
(defaultKeyboardControl.autoRepeats[i] & mask);
}
else {
client->errorValue = t;
return BadValue;
}
break;
default:
client->errorValue = mask;
return BadValue;
}
}
keybd->kbdfeed->ctrl = ctrl;
#ifdef XKB
/* The XKB RepeatKeys control and core protocol global autorepeat */
/* value are linked */
if (!noXkbExtension)
XkbSetRepeatKeys(keybd, key, keybd->kbdfeed->ctrl.autoRepeat);
else
#endif
(*keybd->kbdfeed->CtrlProc)(keybd, &keybd->kbdfeed->ctrl);
return Success;
#undef DO_ALL
}
int
ProcChangeKeyboardControl (ClientPtr client)
{
XID *vlist;
BITS32 vmask;
int ret = Success, error = Success;
DeviceIntPtr pDev = NULL;
REQUEST(xChangeKeyboardControlReq);
REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq);
vmask = stuff->mask;
vlist = (XID *)&stuff[1];
if (client->req_len != (sizeof(xChangeKeyboardControlReq)>>2)+Ones(vmask))
return BadLength;
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
if ((pDev->coreEvents || pDev == inputInfo.keyboard) &&
pDev->kbdfeed && pDev->kbdfeed->CtrlProc) {
if (!XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE))
return BadAccess;
}
}
for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
if ((pDev->coreEvents || pDev == inputInfo.keyboard) &&
pDev->kbdfeed && pDev->kbdfeed->CtrlProc) {
ret = DoChangeKeyboardControl(client, pDev, vlist, vmask);
if (ret != Success)
error = ret;
}
}
return error;
}
int
ProcGetKeyboardControl (ClientPtr client)
{
int i;
KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl;
xGetKeyboardControlReply rep;
REQUEST_SIZE_MATCH(xReq);
rep.type = X_Reply;
rep.length = 5;
rep.sequenceNumber = client->sequence;
rep.globalAutoRepeat = ctrl->autoRepeat;
rep.keyClickPercent = ctrl->click;
rep.bellPercent = ctrl->bell;
rep.bellPitch = ctrl->bell_pitch;
rep.bellDuration = ctrl->bell_duration;
rep.ledMask = ctrl->leds;
for (i = 0; i < 32; i++)
rep.map[i] = ctrl->autoRepeats[i];
WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep);
return Success;
}
int
ProcBell(ClientPtr client)
{
DeviceIntPtr keybd = inputInfo.keyboard;
int base = keybd->kbdfeed->ctrl.bell;
int newpercent;
REQUEST(xBellReq);
REQUEST_SIZE_MATCH(xBellReq);
if (!keybd->kbdfeed->BellProc)
return BadDevice;
if (stuff->percent < -100 || stuff->percent > 100) {
client->errorValue = stuff->percent;
return BadValue;
}
newpercent = (base * stuff->percent) / 100;
if (stuff->percent < 0)
newpercent = base + newpercent;
else
newpercent = base - newpercent + stuff->percent;
for (keybd = inputInfo.devices; keybd; keybd = keybd->next) {
if ((keybd->coreEvents || keybd == inputInfo.keyboard) &&
keybd->kbdfeed && keybd->kbdfeed->BellProc) {
#ifdef XKB
if (!noXkbExtension)
XkbHandleBell(FALSE, FALSE, keybd, newpercent,
&keybd->kbdfeed->ctrl, 0, None, NULL, client);
else
#endif
(*keybd->kbdfeed->BellProc)(newpercent, keybd,
&keybd->kbdfeed->ctrl, 0);
}
}
return Success;
}
int
ProcChangePointerControl(ClientPtr client)
{
DeviceIntPtr mouse = PickPointer(client);
PtrCtrl ctrl; /* might get BadValue part way through */
REQUEST(xChangePointerControlReq);
REQUEST_SIZE_MATCH(xChangePointerControlReq);
if (!mouse->ptrfeed->CtrlProc)
return BadDevice;
ctrl = mouse->ptrfeed->ctrl;
if ((stuff->doAccel != xTrue) && (stuff->doAccel != xFalse)) {
client->errorValue = stuff->doAccel;
return(BadValue);
}
if ((stuff->doThresh != xTrue) && (stuff->doThresh != xFalse)) {
client->errorValue = stuff->doThresh;
return(BadValue);
}
if (stuff->doAccel) {
if (stuff->accelNum == -1) {
ctrl.num = defaultPointerControl.num;
}
else if (stuff->accelNum < 0) {
client->errorValue = stuff->accelNum;
return BadValue;
}
else {
ctrl.num = stuff->accelNum;
}
if (stuff->accelDenum == -1) {
ctrl.den = defaultPointerControl.den;
}
else if (stuff->accelDenum <= 0) {
client->errorValue = stuff->accelDenum;
return BadValue;
}
else {
ctrl.den = stuff->accelDenum;
}
}
if (stuff->doThresh) {
if (stuff->threshold == -1) {
ctrl.threshold = defaultPointerControl.threshold;
}
else if (stuff->threshold < 0) {
client->errorValue = stuff->threshold;
return BadValue;
}
else {
ctrl.threshold = stuff->threshold;
}
}
for (mouse = inputInfo.devices; mouse; mouse = mouse->next) {
if ((mouse->coreEvents || mouse == PickPointer(client)) &&
mouse->ptrfeed && mouse->ptrfeed->CtrlProc) {
mouse->ptrfeed->ctrl = ctrl;
(*mouse->ptrfeed->CtrlProc)(mouse, &mouse->ptrfeed->ctrl);
}
}
return Success;
}
int
ProcGetPointerControl(ClientPtr client)
{
DeviceIntPtr ptr = PickPointer(client);
PtrCtrl *ctrl = &ptr->ptrfeed->ctrl;
xGetPointerControlReply rep;
REQUEST_SIZE_MATCH(xReq);
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.threshold = ctrl->threshold;
rep.accelNumerator = ctrl->num;
rep.accelDenominator = ctrl->den;
WriteReplyToClient(client, sizeof(xGenericReply), &rep);
return Success;
}
void
MaybeStopHint(DeviceIntPtr dev, ClientPtr client)
{
GrabPtr grab = dev->deviceGrab.grab;
if ((grab && SameClient(grab, client) &&
((grab->eventMask & PointerMotionHintMask) ||
(grab->ownerEvents &&
(EventMaskForClient(dev->valuator->motionHintWindow, client) &
PointerMotionHintMask)))) ||
(!grab &&
(EventMaskForClient(dev->valuator->motionHintWindow, client) &
PointerMotionHintMask)))
dev->valuator->motionHintWindow = NullWindow;
}
int
ProcGetMotionEvents(ClientPtr client)
{
WindowPtr pWin;
xTimecoord * coords = (xTimecoord *) NULL;
xGetMotionEventsReply rep;
int i, count, xmin, xmax, ymin, ymax, rc;
unsigned long nEvents;
DeviceIntPtr mouse = PickPointer(client);
TimeStamp start, stop;
REQUEST(xGetMotionEventsReq);
REQUEST_SIZE_MATCH(xGetMotionEventsReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
if (rc != Success)
return rc;
if (mouse->valuator->motionHintWindow)
MaybeStopHint(mouse, client);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
nEvents = 0;
start = ClientTimeToServerTime(stuff->start);
stop = ClientTimeToServerTime(stuff->stop);
if ((CompareTimeStamps(start, stop) != LATER) &&
(CompareTimeStamps(start, currentTime) != LATER) &&
mouse->valuator->numMotionEvents)
{
if (CompareTimeStamps(stop, currentTime) == LATER)
stop = currentTime;
coords = (xTimecoord *)ALLOCATE_LOCAL(mouse->valuator->numMotionEvents
* sizeof(xTimecoord));
if (!coords)
return BadAlloc;
count = (*mouse->valuator->GetMotionProc) (mouse, coords,
start.milliseconds,
stop.milliseconds,
pWin->drawable.pScreen);
xmin = pWin->drawable.x - wBorderWidth (pWin);
xmax = pWin->drawable.x + (int)pWin->drawable.width +
wBorderWidth (pWin);
ymin = pWin->drawable.y - wBorderWidth (pWin);
ymax = pWin->drawable.y + (int)pWin->drawable.height +
wBorderWidth (pWin);
for (i = 0; i < count; i++)
if ((xmin <= coords[i].x) && (coords[i].x < xmax) &&
(ymin <= coords[i].y) && (coords[i].y < ymax))
{
coords[nEvents].time = coords[i].time;
coords[nEvents].x = coords[i].x - pWin->drawable.x;
coords[nEvents].y = coords[i].y - pWin->drawable.y;
nEvents++;
}
}
rep.length = nEvents * (sizeof(xTimecoord) >> 2);
rep.nEvents = nEvents;
WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep);
if (nEvents)
{
client->pSwapReplyFunc = (ReplySwapPtr) SwapTimeCoordWrite;
WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord),
(char *)coords);
}
if (coords)
DEALLOCATE_LOCAL(coords);
return Success;
}
int
ProcQueryKeymap(ClientPtr client)
{
xQueryKeymapReply rep;
int i;
CARD8 *down = inputInfo.keyboard->key->down;
REQUEST_SIZE_MATCH(xReq);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 2;
if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
for (i = 0; i<32; i++)
rep.map[i] = down[i];
else
bzero((char *)&rep.map[0], 32);
WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
return Success;
}
/* Pair the keyboard to the pointer device. Keyboard events will follow the
* pointer sprite.
*/
int
PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd)
{
if (!ptr)
return BadDevice;
if (!pairingClient)
RegisterPairingClient(client);
else if (pairingClient != client)
return BadAccess;
if (kbd->spriteInfo->spriteOwner)
{
xfree(kbd->spriteInfo->sprite);
kbd->spriteInfo->sprite = NULL;
kbd->spriteInfo->spriteOwner = FALSE;
}
kbd->spriteInfo->sprite = ptr->spriteInfo->sprite;
kbd->spriteInfo->paired = ptr;
return Success;
}
/* Return the pointer that is paired with the given keyboard. If no pointer is
* paired, return the virtual core pointer
*/
DeviceIntPtr
GetPairedPointer(DeviceIntPtr kbd)
{
DeviceIntPtr ptr = inputInfo.devices;
while(ptr)
{
if (ptr->spriteInfo->sprite == kbd->spriteInfo->sprite &&
ptr->spriteInfo->spriteOwner)
{
return ptr;
}
ptr = ptr->next;
}
return inputInfo.pointer;
}
/* Find the keyboard device that is paired with the given pointer. If none is
* found, return NULL.
* We also check if the paired device is a keyboard. If not (e.g. evdev brain)
* we don't return it. This probably needs to be fixed.
*/
_X_EXPORT DeviceIntPtr
GetPairedKeyboard(DeviceIntPtr ptr)
{
DeviceIntPtr dev = inputInfo.devices;
while(dev)
{
if (ptr != dev &&
IsKeyboardDevice(dev) &&
ptr->spriteInfo->sprite == dev->spriteInfo->sprite)
return dev;
dev = dev->next;
}
return dev;
}
/*
* Register a client to be able to pair devices.
*/
Bool
RegisterPairingClient(ClientPtr client)
{
if (!pairingClient)
{
pairingClient = client;
} else if (pairingClient != client)
{
return False;
}
return True;
}
/*
* Unregister pairing client;
*/
Bool
UnregisterPairingClient(ClientPtr client)
{
if (pairingClient)
{
if ( pairingClient == client)
{
pairingClient = NULL;
} else
return False;
}
return True;
}
/* Guess a pointer that could be a good one for pairing. Any pointer that is
* not yet paired with keyboard is considered a good one.
* If no pointer is found, the last real pointer is chosen. If that doesn't
* work either, we take the core pointer.
*/
DeviceIntPtr
GuessFreePointerDevice()
{
DeviceIntPtr it, it2;
DeviceIntPtr lastRealPtr = NULL;
it = inputInfo.devices;
while(it)
{
/* found device with a sprite? */
if (it->spriteInfo->spriteOwner)
{
lastRealPtr = it;
it2 = inputInfo.devices;
while(it2)
{
/* something paired with it? */
if (it != it2 &&
it2->spriteInfo->sprite == it->spriteInfo->sprite)
break;
it2 = it2->next;
}
/* woohoo! no pairing set up for 'it' yet */
if (!it2)
return it;
}
it = it->next;
}
return (lastRealPtr) ? lastRealPtr : inputInfo.pointer;
}
|