1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330
|
/* xkeycaps, Copyright (c) 1991, 1992, 1993, 1994, 1997, 1998
* by Jamie Zawinski <jwz@jwz.org>
*
* 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. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
#if defined(__STDC__) && defined(__unix)
#include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef NO_UNAME
# include <sys/utsname.h>
#endif
#include <X11/X.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xmu/WinUtil.h>
#include <X11/Xmu/Error.h>
#include <X11/Xaw/Simple.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/List.h>
#include <X11/Xaw/Viewport.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Toggle.h>
#include <X11/Xaw/SimpleMenu.h>
#include <X11/Xaw/SmeBSB.h>
#include <X11/Xaw/MenuButton.h>
#include <X11/Xaw/Scrollbar.h>
#ifdef XAWBUG
/* At some point it seemed like the Toggle widget (really, the Command widget)
didn't provide a GetValues-hook to access the "state" property, so we had
to access that slot directly. Well, this isn't the case with MIT R5 pl25,
or with OpenWindows 3.0, so let's try living without it now.
*/
# include <X11/IntrinsicP.h>
# include <X11/CoreP.h>
# include <X11/Xaw/SimpleP.h>
# include <X11/Xaw/CommandP.h>
#endif /* XAWBUG */
#include "KbdWidgetP.h"
#include "KeyWidgetP.h"
#include "xkeycaps.h"
#include "kbddef.h"
#include "vroot.h" /* This is standard in R5 but not R4 */
#ifndef NO_PWD
#include <pwd.h>
#endif
/* We can only do Vendor keysyms in X11r5, because earlier versions
didn't provide any way to map over the contents of an xrm database.
*/
#ifdef XtSpecificationRelease
# if XtSpecificationRelease >= 5
# define DO_VENDOR_KEYSYMS
# endif
#endif
static int y_or_n_p P((KeyboardWidget widget,
char *name, char *name0, char *name1, char *name2));
static int y_or_n_p_with_args P((KeyboardWidget,
char *name,
char *name0, char *name1, char *name2,
char *arg0, char *arg1, char *arg2,
char *arg3, char *arg4, char *arg5));
static Widget make_button P((Widget parent, char *name, char *string,
Widget left, Widget top, XtCallbackProc callback,
XtPointer data, char *menu_name));
struct key_menus {
Widget popup;
Widget popup_kids [10];
struct edit_key_box *edit_key_box;
struct select_kbd_box *select_kbd_box;
};
#ifndef isupper
# define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#endif
#ifndef _tolower
# define _tolower(c) ((c) - 'A' + 'a')
#endif
int
#ifdef __STDC__
string_equal (const char *s1, const char *s2)
#else /* ! __STDC__ */
string_equal (s1, s2)
const char *s1, *s2;
#endif /* ! __STDC__ */
{
if (s1 == s2) return 1;
if (!s1 || !s2) return 0;
while (*s1 && *s2)
{
if ((isupper (*s1) ? _tolower (*s1) : *s1) !=
(isupper (*s2) ? _tolower (*s2) : *s2))
return 0;
s1++, s2++;
}
return ((*s1 || *s2) ? 0 : 1);
}
static Widget
#ifdef __STDC__
make_button (Widget parent,
char *name, char *string,
Widget left, Widget top,
XtCallbackProc callback,
XtPointer data,
char *menu_name)
#else /* ! __STDC__ */
make_button (parent, name, string, left, top, callback, data, menu_name)
Widget parent;
char *name, *string;
Widget left, top;
XtCallbackProc callback;
XtPointer data;
char *menu_name;
#endif /* ! __STDC__ */
{
Widget w = make_label_1 (parent, name, string, left, top,
(menu_name
? menuButtonWidgetClass
: commandWidgetClass),
callback, data);
if (menu_name)
{
Arg av [10];
int ac = 0;
XtSetArg (av [ac], XtNmenuName, menu_name); ac++;
XtSetValues (w, av, ac);
}
return w;
}
static Widget
#ifdef __STDC__
make_toggle (Widget parent, char *name, Widget left, Widget top, int state,
XtCallbackProc callback,
XtPointer data, char *label, Widget radio_group,
XtPointer radio_data)
#else /* ! __STDC__ */
make_toggle (parent, name, left, top, state, callback, data, label,
radio_group, radio_data)
Widget parent;
char *name;
Widget left, top;
int state;
void (*callback) ();
XtPointer data;
char *label;
Widget radio_group;
XtPointer radio_data;
#endif /* ! __STDC__ */
{
Arg av [20];
int ac = 0;
Widget w;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainLeft); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainTop); ac++;
XtSetArg (av[ac], XtNjustify, XtJustifyLeft); ac++;
XtSetArg (av[ac], XtNstate, (state ? True : False)); ac++;
if (left) XtSetArg (av[ac], XtNfromHoriz, left), ac++;
if (top) XtSetArg (av[ac], XtNfromVert, top), ac++;
if (label) XtSetArg (av[ac], XtNlabel, label), ac++;
if (radio_group) XtSetArg (av[ac], XtNradioGroup, radio_group), ac++;
if (radio_data) XtSetArg (av[ac], XtNradioData, radio_data), ac++;
w = XtCreateManagedWidget (name, toggleWidgetClass, parent, av, ac);
if (callback) XtAddCallback (w, XtNcallback, callback, data);
return w;
}
static void
#ifdef __STDC__
button_quit (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
button_quit (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
exit (0);
}
static int modify_keyboard_modifiers P((KeyboardWidget, XModifierKeymap *));
static int modify_keyboard P((KeyboardWidget, int first_keycode,
int keysyms_per_keycode, KeySym *keysyms,
int num_codes, XModifierKeymap *modmap));
static void
#ifdef __STDC__
button_restore (Widget button, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
button_restore (button, client_data, call_data)
Widget button;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = *((KeyboardWidget *) client_data);
KeySym *keysyms;
KeyCode lowest = 255, highest = 0;
XModifierKeymap *modmap;
int per_code = widget->keyboard.default_keysyms_per_code;
int i, j, k;
if (0 != y_or_n_p (widget, "restoreQuery", "yes", "no", 0))
{
message (widget, "Aborted.");
return;
}
keysyms = (KeySym *) calloc (sizeof (KeySym), per_code * 256);
modmap = XNewModifiermap (2); /* It'll grow */
memset (modmap->modifiermap, 0, modmap->max_keypermod * 8);
for (i = 0; i < widget->keyboard.nrows; i++)
{
struct KeyWidget_row *row = &widget->keyboard.rows [i];
for (j = 0; j < row->nkeys; j++)
{
KeyWidget key = row->keys [j];
if (key->key.keycode)
{
if (key->key.keycode < lowest)
lowest = key->key.keycode;
if (key->key.keycode > highest)
highest = key->key.keycode;
for (k = 0; k < per_code; k++)
keysyms [key->key.keycode * per_code + k] =
key->key.default_keysyms [k];
if (key->key.default_mods)
for (k = 0; k < 8; k++)
if (key->key.default_mods & (1<<k))
modmap = XInsertModifiermapEntry (modmap,
key->key.keycode,
k);
}
}
}
if (highest <= lowest) exit (-69); /* can't happen */
if (! modify_keyboard (widget, lowest, per_code,
keysyms + (lowest * per_code),
highest - lowest, modmap))
message (widget, "Keyboard restored to default state.");
XFreeModifiermap (modmap);
free (keysyms);
}
static FILE *
#ifdef __STDC__
open_output_file(KeyboardWidget widget, char **name)
#else /* ! __STDC__ */
open_output_file(widget, name)
KeyboardWidget widget;
char **name;
#endif /* ! __STDC__ */
{
const char *home = getenv("HOME");
const char *base = ".xmodmap";
int L = strlen(home) + strlen(base) + 2;
char *target = 0;
struct stat st;
FILE *out = 0;
#ifndef NO_UNAME
struct utsname uts;
if (uname (&uts) >= 0)
L += strlen(uts.nodename) + 1;
else
uts.nodename[0] = 0;
#endif
target = (char *) malloc(L+1);
strcpy(target, home);
if (target[strlen(target)-1] != '/')
strcat(target, "/");
strcat(target, base);
#ifndef NO_UNAME
if (uts.nodename)
{
strcat(target, "-");
strcat(target, uts.nodename);
}
#endif
if (!stat(target, &st))
{
char *t2;
if (y_or_n_p_with_args(widget,
"overwriteQuery",
"ok", "cancel", 0,
target, 0, 0, 0, 0, 0))
goto DONE;
t2 = (char *) malloc (strlen(target) + 10);
strcpy (t2, target);
strcat (t2, ".BAK");
rename (target, t2);
free (t2);
}
out = fopen(target, "w");
DONE:
*name = 0;
if (out)
*name = target;
else
free (target);
return out;
}
void
#ifdef __STDC__
make_long_kbd_name (const char *vendor, const char *kbd_style, char *buf)
#else /* ! __STDC__ */
make_long_kbd_name (vendor, kbd_style, buf)
const char *vendor;
const char *kbd_style;
char *buf;
#endif /* ! __STDC__ */
{
strcpy(buf, (vendor ? vendor : ""));
if (kbd_style && *kbd_style)
{
strcat(buf, " ");
strcat(buf, kbd_style);
}
}
static char *bit_names[] = { "Shift", "Lock", "Control", "Mod1",
"Mod2", "Mod3", "Mod4", "Mod5" };
static void
#ifdef __STDC__
button_write (Widget button, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
button_write (button, client_data, call_data)
Widget button;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
char *filename = 0;
FILE *out;
KeyboardWidget widget = *((KeyboardWidget *) client_data);
XModifierKeymap *current_modmap, *default_modmap;
int per_code = widget->keyboard.default_keysyms_per_code;
struct { KeyWidget key; int count; char *names[8]; }
all [256], differences [256];
int all_count = 0, diff_count = 0;
KeySym *keysyms;
int count, i, j, k;
int partial = y_or_n_p (widget, "writeQuery", "full", "partial", "abort");
time_t now = time ((time_t *) 0);
#ifdef NO_PWD
char *userid = 0;
#else
struct passwd *pw = (struct passwd *) getpwuid (getuid ());
char *userid = (pw ? pw->pw_name : 0);
#endif
KeyCode added [8][255];
KeyCode subtracted [8][255];
int added_count, subtracted_count;
int cmkpm, dmkpm;
int any_mod_changes = 0;
if (partial >= 2)
{
message (widget, "Aborted.");
return;
}
current_modmap = XGetModifierMapping (XtDisplay (widget));
default_modmap = XNewModifiermap (2); /* It'll grow */
memset (default_modmap->modifiermap, 0, default_modmap->max_keypermod * 8);
out = open_output_file(widget, &filename);
if (!out) return;
for (i = 0; i < widget->keyboard.nrows; i++)
{
struct KeyWidget_row *row = &widget->keyboard.rows [i];
for (j = 0; j < row->nkeys; j++)
{
KeyWidget key = row->keys [j];
if (key->key.keycode)
{
unsigned long bits = key->key.modifier_bits;
keysyms = XGetKeyboardMapping (XtDisplay (widget),
key->key.keycode,
1, &count);
if (! keysyms) count = 0;
all [all_count].key = key;
for (; count > 0; count--)
if (keysyms [count-1]) break;
if (count == 0)
{
all [all_count].names [0] = "NoSymbol";
count = 1;
}
else
for (k = 0; k < count; k++)
{
char *str = "NoSymbol";
if (keysyms [k])
{
str = XKeysymToString (keysyms [k]);
if (! str)
{
/* core leak, but this shouldn't ever happen
unless there's a bug in libX11.a, or the
user did something stupid with xmodmap.
*/
str = (char *) malloc (255);
sprintf (str, "0x%02X", (int) keysyms [k]);
}
}
all [all_count].names [k] = str;
}
all [all_count].count = count;
if (! keysyms) count = 0;
if (count > per_code ||
((!partial) && (bits != key->key.default_mods)) ||
(count > 0 && keysyms[0] != key->key.default_keysyms[0]) ||
(count > 1 && keysyms[1] != key->key.default_keysyms[1]) ||
(count > 2 && keysyms[2] != key->key.default_keysyms[2]) ||
(count > 3 && keysyms[3] != key->key.default_keysyms[3]) ||
(count > 4 && keysyms[4] != key->key.default_keysyms[4]) ||
(count > 5 && keysyms[5] != key->key.default_keysyms[5]) ||
(count > 6 && keysyms[6] != key->key.default_keysyms[6]) ||
(count > 7 && keysyms[7] != key->key.default_keysyms[7]))
differences [diff_count++] = all [all_count];
all_count++;
for (k = 0; k < 8; k++)
{
if (key->key.default_mods & (1<<k))
default_modmap =
XInsertModifiermapEntry (default_modmap,
key->key.keycode, k);
if (bits & (1<<k))
current_modmap =
XInsertModifiermapEntry (current_modmap,
key->key.keycode, k);
}
if (keysyms) XFree ((char *) keysyms);
}
}
}
/* I'd just like to take this moment to point out that C has all
the expressive power of two dixie cups and a string.
*/
cmkpm = current_modmap->max_keypermod;
dmkpm = default_modmap->max_keypermod;
memset (added, 0, sizeof (added));
memset (subtracted, 0, sizeof (subtracted));
for (i = 0; i < 8; i++)
{
KeyCode kc1, kc2 = 0;
added_count = subtracted_count = 0;
if (partial)
{
for (j = 0; j < cmkpm; j++)
{
kc1 = current_modmap->modifiermap [i * cmkpm + j];
if (!kc1) continue;
for (k = 0; k < dmkpm; k++)
{
kc2 = default_modmap->modifiermap [i * dmkpm + k];
if (kc1 == kc2) break;
}
if (kc1 != kc2) added [i][added_count++] = kc1;
}
for (j = 0; j < dmkpm; j++)
{
kc1 = default_modmap->modifiermap [i * dmkpm + j];
if (!kc1) continue;
for (k = 0; k < cmkpm; k++)
{
kc2 = current_modmap->modifiermap [i * cmkpm + k];
if (kc1 == kc2) break;
}
if (kc1 != kc2) subtracted [i][subtracted_count++] = kc1;
}
if (added_count || subtracted_count) any_mod_changes = 1;
}
else
{
for (j = 0; j < cmkpm; j++)
{
kc1 = current_modmap->modifiermap [i * cmkpm + j];
if (kc1)
added [i][added_count++] = kc1;
}
}
}
{
char *t;
char s[1024];
make_long_kbd_name(widget->keyboard.vendor, widget->keyboard.kbd_style, s);
fprintf (out, "!\n! This is an `xmodmap' input file for %s%s keyboards.\n",
((strlen(s) > 40) ? "\n! " : ""), s);
t = ctime (&now);
t [strlen (t) - 1] = 0; /* bastards */
fprintf (out, "! Automatically generated on %s", t);
}
if (userid)
fprintf (out, " by %s", userid);
fprintf (out, " with\n! %s.\n", short_version);
fprintf (out, "! http://www.jwz.org/xkeycaps/\n");
fprintf (out, "!\n");
if (partial && any_mod_changes)
{
fprintf (out, "! This file presupposes that the keyboard is in the ");
fprintf (out,
"default state, and\n! may malfunction if it is not.\n!\n");
}
else if (! partial)
{
if (diff_count)
fprintf (out, "! This file makes the following changes:\n!\n");
else
fprintf (out, "! This file encodes the default state.\n!\n");
}
/* If we're going to write out "remove" commands, do it before writing
out any "keycode" statements, since xmodmap is so lame. We only
generate "remove" statements in "partial" mode.
http://catalog.com/hopkins/images/smegmas.gif
*/
any_mod_changes = 0;
if (partial)
for (i = 0; i < 8; i++)
{
char *str;
KeySym ks;
if (subtracted [i][0])
{
fprintf (out, "remove %-8s=", bit_names [i]);
for (j = 0; j < sizeof (subtracted [0]); j++)
{
KeyWidget kw;
if (! subtracted [i][j]) break;
any_mod_changes = 1;
/* note: we don't use the *current* keysym corresponding to the
keycode being removed here, but the *default* one...
*/
kw = keycode_to_key (widget, subtracted [i][j]);
ks = kw->key.default_keysyms [0];
str = XKeysymToString (ks);
if (str)
fprintf (out, " %s", str);
else
fprintf (out, " 0x%04X", subtracted [i][j]);
}
fprintf (out, "\n");
}
}
if (any_mod_changes) fprintf (out, "\n");
/* Write out the differences. This happens in both "partial" and "full"
modes, but in "full" mode it's in the form of a descriptive comment
instead of xmodmap commands.
*/
for (i = 0; i < diff_count; i++)
{
if (partial)
fprintf (out, "keycode 0x%02X =\t", differences[i].key->key.keycode);
else
fprintf (out, "! The \"%s\" key generates ",
differences[i].key->key.key_name);
for (j = 0; j < differences[i].count; j++)
{
fprintf (out, "%s", differences[i].names[j]);
if (j+1 == differences[i].count) continue;
if (partial)
{
fprintf (out, "\t");
if (strlen (differences[i].names[j]) < 8) putchar ('\t');
}
else
{
if (j+1 == differences[i].count-1)
fprintf (out, "%s", (j == 0) ? " and " : ", and ");
else
fprintf (out, ", ");
}
}
/* write the diffs of the modifier bits in the full-mode comment. */
if (!partial &&
differences[i].key->key.default_mods !=
differences[i].key->key.modifier_bits)
{
unsigned long bits = differences[i].key->key.modifier_bits;
int this_mod_count = 0;
if (! bits)
fprintf (out, ", and has no modifiers\n");
else
{
fprintf (out, ", and the ");
for (k = 0; k < 8; k++)
{
if (bits & (1<<k))
{
if (this_mod_count++) fprintf (out, "/");
fprintf (out, "%s", bit_names [k]);
}
}
fprintf (out, " modifier%s\n", (this_mod_count>1 ? "s" : ""));
}
}
else
fprintf (out, "\n");
}
/* In "full" mode, write out all the "keycode" commands. This is the
first actual xmodmap command text in full mode.
*/
if (!partial)
{
fprintf (out, "\n");
for (i = 0; i < all_count; i++)
{
fprintf (out, "keycode 0x%02X =\t", all [i].key->key.keycode);
for (j = 0; j < all[i].count; j++)
{
fprintf (out, "%s", all[i].names[j]);
if (j == all[i].count - 1) continue;
fprintf (out, "\t");
if (strlen (all[i].names[j]) < 8) fprintf (out, "\t");
}
fprintf (out, "\n");
}
fprintf (out, "\n");
fprintf (out, "clear Shift\nclear Lock\nclear Control\nclear Mod1\n");
fprintf (out, "clear Mod2\nclear Mod3\nclear Mod4\nclear Mod5\n");
}
/* In partial mode, write out any "add" commands. This is after any
"keycode" commands have already been output (and any "remove" commands
before them.) In full mode, the "add" commands are the whole story.
*/
fprintf (out, "\n");
for (i = 0; i < 8; i++)
{
char *str;
KeySym ks;
if (added [i][0])
{
fprintf (out, "add %-8s=", bit_names [i]);
for (j = 0; j < sizeof (added [0]); j++)
{
if (! added [i][j]) break;
ks = XKeycodeToKeysym (XtDisplay (widget), added [i][j], 0);
str = XKeysymToString (ks);
if (str)
fprintf (out, " %s", str);
else
fprintf (out, " 0x%04X", added [i][j]);
}
fprintf (out, "\n");
}
}
fclose (out);
y_or_n_p_with_args (widget, "wroteFileMessage",
"ok", 0, 0,
(filename ? filename : "???"), 0, 0, 0, 0, 0);
if (filename) free (filename);
}
static Window
#ifdef __STDC__
lowest_window (Display *dpy, Window window, Window limit, int x, int y)
#else /* ! __STDC__ */
lowest_window (dpy, window, limit, x, y)
Display *dpy;
Window window, limit;
int x, y;
#endif /* ! __STDC__ */
{
XWindowAttributes xgwa;
XGetWindowAttributes (dpy, window, &xgwa);
/* Ignore all windows which are not at or below `limit'. This prevents
us from assigning focus to windows which are part of the WM decoration,
since `limit' is the result of XmuClientWindow() -- it limits us to
descending the tree of the client proper.
*/
if (window == limit) limit = 0;
if (xgwa.x <= x &&
xgwa.y <= y &&
xgwa.x + xgwa.width > x &&
xgwa.y + xgwa.height > y)
{
Window root, parent, *kids;
unsigned int nkids;
if (!XQueryTree (dpy, window, &root, &parent, &kids, &nkids))
abort ();
if (kids)
{
unsigned int i;
Window kid = 0;
for (i = 0; i < nkids; i++)
{
kid = lowest_window (dpy, kids[i], limit,
x - xgwa.x, y - xgwa.y);
if (kid) break;
}
XFree ((char *)kids);
if (kid) return kid;
}
/* Don't accept windows outside of the client tree. */
if (limit) return 0;
/* Don't accept windows which don't take KeyPress. */
if (! (xgwa.all_event_masks & KeyPressMask)) return 0;
return window;
}
else
return 0;
}
static void
#ifdef __STDC__
button_pick_window (Widget button, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
button_pick_window (button, client_data, call_data)
Widget button;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget keyboard = *((KeyboardWidget *) client_data);
Widget topmost, target;
Display *dpy = XtDisplay (keyboard);
Window root = RootWindowOfScreen (keyboard->core.screen);
Window window = 0;
Window wm_window;
int click_x = 0, click_y = 0;
int buttons = 0;
int once = 0;
XEvent event;
message (keyboard, "Please select the window to type at:");
if (XGrabPointer (dpy, root, False, ButtonPressMask | ButtonReleaseMask,
GrabModeSync, GrabModeAsync, root,
keyboard->keyboard.select_cursor, CurrentTime))
{
XBell (dpy, 0);
message (keyboard, "Grab failed.");
return;
}
while (window == 0 || buttons != 0)
{
/* allow one more event */
XAllowEvents (dpy, SyncPointer, CurrentTime);
XWindowEvent (dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
switch (event.type)
{
case ButtonPress:
once = 1;
if (window == 0 && event.xbutton.subwindow)
{
window = event.xbutton.subwindow; /* window selected */
click_x = event.xbutton.x;
click_y = event.xbutton.y;
}
buttons++;
break;
case ButtonRelease:
if (buttons > 0) buttons--;
break;
}
}
XUngrabPointer(dpy, CurrentTime);
XSync (dpy, 0);
wm_window = window;
if (window && window != root) window = XmuClientWindow (dpy, window);
topmost = (Widget) keyboard;
while (XtParent (topmost)) topmost = XtParent (topmost);
target = XtWindowToWidget (XtDisplay (topmost), window);
if (window == XtWindow (topmost)) target = topmost;
if (target || window == root) window = 0;
if (window)
{
char buf [255];
char buf2 [100];
char *string1 = 0, *string2 = 0, *string3 = 0;
char *name;
XClassHint classhint;
Window lowest = lowest_window (dpy, wm_window, window, click_x, click_y);
if (! lowest)
{
/* Maybe they clicked in the wrong place in the app. Let's try
again by picking the exact center of the frame and looking
there for something that accepts keyboard input.
*/
XWindowAttributes xgwa;
XGetWindowAttributes (dpy, wm_window, &xgwa);
lowest = lowest_window (dpy, wm_window, window,
xgwa.x + (xgwa.width / 2),
xgwa.y + (xgwa.height / 2));
if (! lowest)
{
/* Still couldn't find one; give up. */
XBell (dpy, 0);
message (keyboard,
"No window there that accepts keyboard input!");
goto done;
}
}
classhint.res_name = classhint.res_class = 0;
if (! XGetClassHint (dpy, window, &classhint))
classhint.res_name = classhint.res_class = 0;
string1 = classhint.res_name;
string2 = classhint.res_class;
XFetchName (dpy, window, &string3);
name = string3;
if (string2 && string3 && string_equal (string2, string3)) string3 = 0;
if (string1 && string3 && string_equal (string1, string3)) string3 = 0;
if (string1 && string2 && string_equal (string1, string2)) string2 = 0;
if (!string2) string2 = string3, string3 = 0;
if (!string1) string1 = string2, string2 = 0;
if (string1 && string2 && string3)
sprintf (buf2, "%s / %s / %s", string1, string2, string3);
else if (string1 && string2)
sprintf (buf2, "%s / %s", string1, string2);
else if (string1)
sprintf (buf2, "%s", string1);
else
sprintf (buf2, "unnamed");
if (window == lowest)
sprintf (buf, "Keyboard focus locked on window 0x%X (%s)",
(int) window, buf2);
else
sprintf (buf, "Keyboard focus locked on window 0x%X <- 0x%X (%s)",
(int) lowest, (int) window, buf2);
message (keyboard, buf);
if (!classhint.res_class)
;
else if (string_equal (classhint.res_class, "xterm"))
message2 (keyboard,
"Remember to select \"Allow SendEvents\" from the XTerm menu.");
else if (string_equal (classhint.res_class, "cmdtool") ||
string_equal (classhint.res_class, "shelltool") ||
string_equal (classhint.res_class, "textedit"))
message2 (keyboard,
"Did you remember to use the -defeateventsecurity option when launching it?");
if (classhint.res_name) XFree (classhint.res_name);
if (classhint.res_class) XFree (classhint.res_class);
if (name) XFree (name);
window = lowest;
}
else
message (keyboard, "Keyboard-focus cleared.");
done:
keyboard->keyboard.target_window = window;
}
static int
#ifdef __STDC__
modify_keyboard_modifiers (KeyboardWidget widget, XModifierKeymap *modmap)
#else /* ! __STDC__ */
modify_keyboard_modifiers (widget, modmap)
KeyboardWidget widget;
XModifierKeymap *modmap;
#endif /* ! __STDC__ */
{
Display *display = XtDisplay ((Widget) widget);
int retries, timeout;
char buf [255];
for (retries = 4, timeout = 2; retries > 0; retries--, timeout *= 2)
{
int result;
result = XSetModifierMapping (display, modmap);
switch (result)
{
case MappingSuccess:
mappingNotify_event_expected = 1;
return 0;
case MappingBusy:
sprintf (buf, "please release all keys withing %d seconds", timeout);
/* Calling message() doesn't work because exposes don't get
processed while we're sleeping.
*/
message (widget, buf);
fprintf (stderr, "%s: %s\n", progname, buf);
XSync (display, 0);
sleep (timeout);
continue;
case MappingFailed:
message (widget, "XSetModifierMapping() failed");
XBell (display, 0);
return -1;
default:
sprintf (buf, "unknown return code %d from XSetModifierMapping()",
result);
message (widget, buf);
XBell (display, 0);
return -1;
}
}
sprintf (buf, "XSetModifierMapping() failed");
message (widget, buf);
XBell (display, 0);
return -1;
}
/* We install this as an error handler around the call to
XChangeKeyboardMapping(), so that we can trap errors that that
operation generates. Gotta love this 1960's condition system...
*/
static int XChangeKeyboardMapping_error = 0;
static int
#ifdef __STDC__
modify_keyboard_error_handler (Display *dpy, XErrorEvent *error)
#else /* ! __STDC__ */
modify_keyboard_error_handler (dpy, error)
Display *dpy;
XErrorEvent *error;
#endif /* ! __STDC__ */
{
switch (error->request_code)
{
case X_ChangeKeyboardMapping:
XChangeKeyboardMapping_error = 1;
return 0;
default:
XmuPrintDefaultErrorMessage (dpy, error, stderr);
exit (-1);
}
}
static int
#ifdef __STDC__
modify_keyboard (KeyboardWidget widget, int first_keycode,
int keysyms_per_keycode, KeySym *keysyms,
int num_codes, XModifierKeymap *modmap)
#else /* ! __STDC__ */
modify_keyboard (widget, first_keycode, keysyms_per_keycode, keysyms,
num_codes, modmap)
KeyboardWidget widget;
int first_keycode;
int keysyms_per_keycode;
KeySym *keysyms;
int num_codes;
XModifierKeymap *modmap;
#endif /* ! __STDC__ */
{
Display *display = XtDisplay ((Widget) widget);
XErrorHandler old_handler;
if (keysyms_per_keycode == 0) keysyms_per_keycode = 1;
XSync (display, 0);
mappingNotify_event_expected = 1;
XChangeKeyboardMapping_error = 0;
old_handler = XSetErrorHandler (modify_keyboard_error_handler);
XChangeKeyboardMapping (display, first_keycode, keysyms_per_keycode,
keysyms, num_codes);
/* Is there a race condition here? Are we guarenteed that by calling
XSync() we will get back an error generated by the previously-sent
request?
*/
XSync (XtDisplay ((Widget) widget), 0);
XSetErrorHandler (old_handler);
if (XChangeKeyboardMapping_error)
{
mappingNotify_event_expected = 0;
message (widget, "XChangeKeyboardMapping() failed.");
XBell (display, 0);
return -1;
}
if (modmap)
return modify_keyboard_modifiers (widget, modmap);
return 0;
}
static void
#ifdef __STDC__
restore_key_default (Widget parent, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
restore_key_default (parent, client_data, call_data)
Widget parent;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = (KeyboardWidget) client_data;
KeyWidget key = widget->keyboard.key_under_mouse;
KeySym *keysyms = key->key.default_keysyms;
int per_code = widget->keyboard.default_keysyms_per_code;
KeyCode code = key->key.keycode;
unsigned long bits = key->key.default_mods;
XModifierKeymap *modmap;
int i, error;
if (! code)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
modmap = XGetModifierMapping (XtDisplay (widget));
for (i = 0; i < 8; i++)
if (bits & (1<<i))
modmap = XInsertModifiermapEntry (modmap, code, i);
else
modmap = XDeleteModifiermapEntry (modmap, code, i);
XSync (XtDisplay (widget), 0);
error = modify_keyboard (widget, code, per_code, keysyms, 1, modmap);
XFreeModifiermap (modmap);
if (! error)
{
char *k, buf [255], buf2 [255], *b = buf;
for (i = 0; i < per_code; i++)
{
if (i) *b++ = ',', *b++ = ' ';
k = XKeysymToString (keysyms [i]);
if (keysyms [i] && !k)
{
sprintf (b, "0x%04X", (int) keysyms [i]);
k = b;
}
else
{
if (! k) k = "NoSymbol";
strcpy (b, k);
}
b += strlen (k);
}
sprintf (buf2, "KeyCode 0x%02X restored to default state (%s)",
key->key.keycode, buf);
message (widget, buf2);
}
XSync (XtDisplay (widget), 0);
}
static void
#ifdef __STDC__
swap_key (Widget parent, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
swap_key (parent, client_data, call_data)
Widget parent;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = (KeyboardWidget) client_data;
XModifierKeymap *modmap = XGetModifierMapping (XtDisplay (widget));
KeyWidget source_key = widget->keyboard.key_under_mouse;
KeyWidget target_key;
KeySym *source_keysyms;
KeySym *target_keysyms;
int source_count, target_count;
unsigned long source_bits = source_key->key.modifier_bits;
unsigned long target_bits;
KeyCode source_code = source_key->key.keycode;
KeyCode target_code;
char buf [255];
int i, error;
if (source_key->key.keycode == 0)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
sprintf (buf, "Click on the key to swap with 0x%02X (%s)",
source_key->key.keycode,
source_key->key.key_name);
target_key = prompt_for_key (widget, buf);
if (! target_key) return;
target_bits = target_key->key.modifier_bits;
target_code = target_key->key.keycode;
if (target_code == 0)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
if (source_code == target_code)
{
XBell (XtDisplay (widget), 0);
message (widget, "Those keys are the same!");
return;
}
for (i = 0; i < 8; i++)
{
if (source_bits & (1<<i))
modmap = XInsertModifiermapEntry (modmap, target_code, i);
else
modmap = XDeleteModifiermapEntry (modmap, target_code, i);
if (target_bits & (1<<i))
modmap = XInsertModifiermapEntry (modmap, source_code, i);
else
modmap = XDeleteModifiermapEntry (modmap, source_code, i);
}
source_keysyms = XGetKeyboardMapping (XtDisplay (widget), source_code,
1, &source_count);
target_keysyms = XGetKeyboardMapping (XtDisplay (widget), target_code,
1, &target_count);
error = modify_keyboard (widget, target_code,
source_count, source_keysyms, 1, modmap);
if (error) return;
error = modify_keyboard (widget, source_code,
target_count, target_keysyms, 1, 0);
if (error) return;
sprintf (buf, "Keys 0x%02x (%s) and 0x%02x (%s) swapped.",
source_key->key.keycode, source_key->key.key_name,
target_key->key.keycode, target_key->key.key_name);
message (widget, buf);
if (source_keysyms) XFree ((char *) source_keysyms);
if (target_keysyms) XFree ((char *) target_keysyms);
if (modmap) XFreeModifiermap (modmap);
}
static void
#ifdef __STDC__
clone_key (Widget parent, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
clone_key (parent, client_data, call_data)
Widget parent;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = (KeyboardWidget) client_data;
XModifierKeymap *modmap = XGetModifierMapping (XtDisplay (widget));
KeyWidget source_key = widget->keyboard.key_under_mouse;
KeyWidget target_key;
KeySym *source_keysyms;
int source_count;
unsigned long source_bits = source_key->key.modifier_bits;
KeyCode source_code = source_key->key.keycode;
KeyCode target_code;
char buf [255];
int i, error;
if (source_key->key.keycode == 0)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
sprintf (buf, "Click on the key to turn into a copy of 0x%02X (%s)",
source_key->key.keycode,
source_key->key.key_name);
target_key = prompt_for_key (widget, buf);
if (! target_key) return;
target_code = target_key->key.keycode;
if (target_code == 0)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
if (source_code == target_code)
{
XBell (XtDisplay (widget), 0);
message (widget, "Those keys are the same!");
return;
}
for (i = 0; i < 8; i++)
{
if (source_bits & (1<<i))
modmap = XInsertModifiermapEntry (modmap, target_code, i);
else
modmap = XDeleteModifiermapEntry (modmap, target_code, i);
}
source_keysyms = XGetKeyboardMapping (XtDisplay (widget), source_code,
1, &source_count);
error = modify_keyboard (widget, target_code,
source_count, source_keysyms, 1, modmap);
if (source_keysyms) XFree ((char *) source_keysyms);
if (modmap) XFreeModifiermap (modmap);
if (error) return;
sprintf (buf, "Keys 0x%02x (%s) and 0x%02x (%s) are now the same.",
source_key->key.keycode, source_key->key.key_name,
target_key->key.keycode, target_key->key.key_name);
message (widget, buf);
}
static void
#ifdef __STDC__
disable_key (Widget parent, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
disable_key (parent, client_data, call_data)
Widget parent;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = (KeyboardWidget) client_data;
KeyWidget key = widget->keyboard.key_under_mouse;
KeyCode code = key->key.keycode;
KeySym keysym = 0;
int i, error;
char buf [255];
XModifierKeymap *modmap = XGetModifierMapping (XtDisplay (widget));
if (code == 0)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
for (i = 0; i < 8; i++)
modmap = XDeleteModifiermapEntry (modmap, code, i);
error = modify_keyboard (widget, code, 1, &keysym, 1, modmap);
XFreeModifiermap (modmap);
if (! error)
{
sprintf (buf, "KeyCode 0x%02X (%s) disabled.", key->key.keycode,
key->key.key_name);
message (widget, buf);
}
XSync (XtDisplay (widget), 0);
}
static struct edit_key_box * make_edit_key_dbox P((KeyboardWidget));
static struct select_kbd_box * make_select_kbd_dbox P((KeyboardWidget));
static void pop_up_key_dbox P((Widget, XtPointer, XtPointer));
struct key_menus *
#ifdef __STDC__
make_key_menus (KeyboardWidget *kbd)
#else /* ! __STDC__ */
make_key_menus (kbd)
KeyboardWidget *kbd;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = *kbd;
Arg av [20];
int ac = 0, i = 0;
Widget menu, item;
struct key_menus *key_menus = (struct key_menus *)
malloc (sizeof (struct key_menus));
memset (key_menus->popup_kids, 0, sizeof (key_menus->popup_kids));
XawSimpleMenuAddGlobalActions (XtWidgetToApplicationContext((Widget)widget));
XtSetArg (av[ac], XtNlabel, "keyMenu"); ac++;
menu = XtCreatePopupShell ("keyMenu", simpleMenuWidgetClass,
(Widget) widget, av, ac);
XtAddCallback (menu, XtNpopupCallback, key_menu_pre_popup_hook,
(XtPointer) widget);
key_menus->popup = menu;
ac = 0;
item = XtCreateManagedWidget ("editKeysyms", smeBSBObjectClass, menu, av,ac);
XtAddCallback (item, XtNcallback, pop_up_key_dbox, (XtPointer) widget);
key_menus->popup_kids [i++] = item;
item = XtCreateManagedWidget ("swapKey", smeBSBObjectClass, menu, av, ac);
XtAddCallback (item, XtNcallback, swap_key, (XtPointer) widget);
key_menus->popup_kids [i++] = item;
item = XtCreateManagedWidget ("cloneKey", smeBSBObjectClass, menu, av, ac);
XtAddCallback (item, XtNcallback, clone_key, (XtPointer) widget);
key_menus->popup_kids [i++] = item;
item = XtCreateManagedWidget ("disableKey", smeBSBObjectClass, menu, av, ac);
XtAddCallback (item, XtNcallback, disable_key, (XtPointer) widget);
key_menus->popup_kids [i++] = item;
item = XtCreateManagedWidget ("restoreKey", smeBSBObjectClass, menu, av, ac);
XtAddCallback (item, XtNcallback, restore_key_default, (XtPointer) widget);
key_menus->popup_kids [i++] = item;
key_menus->edit_key_box = make_edit_key_dbox (widget);
key_menus->select_kbd_box = make_select_kbd_dbox (widget);
return key_menus;
}
void
#ifdef __STDC__
sensitize_menu (KeyboardWidget widget, Widget menu, Bool sensitive)
#else /* ! __STDC__ */
sensitize_menu (widget, menu, sensitive)
KeyboardWidget widget;
Widget menu;
Bool sensitive;
#endif /* ! __STDC__ */
{
Arg av [10];
int ac = 0, i = 0;
struct key_menus *key_menus = widget->keyboard.key_menus;
if (menu != key_menus->popup) return;
XtSetArg (av [ac], XtNsensitive, sensitive); ac++;
for (i = 0; i < sizeof (key_menus->popup_kids); i++)
if (! key_menus->popup_kids [i]) return;
else XtSetValues (key_menus->popup_kids [i], av, ac);
}
Widget
#ifdef __STDC__
make_command_widgets (Widget parent, Widget *kbd)
#else /* ! __STDC__ */
make_command_widgets (parent, kbd)
Widget parent;
Widget *kbd;
#endif /* ! __STDC__ */
{
Widget box, top;
Arg av [20];
int ac = 0;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainLeft); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainTop); ac++;
box = XtCreateManagedWidget ("buttons", formWidgetClass, parent, av, ac);
top = 0;
top = make_button (box, "quit", NULL, 0, top, button_quit, kbd, 0);
top = make_button (box, "keyboard", NULL, 0, top, pop_up_kbd_dbox, kbd, 0);
top = make_button (box, "focus", NULL, 0, top, button_pick_window, kbd, 0);
top = make_button (box, "restore", NULL, 0, top, button_restore, kbd, 0);
top = make_button (box, "write", NULL, 0, top, button_write, kbd, 0);
return box;
}
/* These are used to compute the default sizes of the windows. Hack hack.
*/
#define LONGEST_KEYSYM_NAME "Greek_upsilonaccentdieresis"
#define MEDIUM_LENGTH_KEYSYM_NAME "Greek_IOTAdiaresis"
struct keyset_names {
const char *name; /* The name of this keyset (for the dialog box) */
unsigned int number; /* The top two bytes of corresponding keysym values */
}
static all_keyset_names[] = {
{ "Latin1", 0x00 },
{ "Latin2", 0x01 },
{ "Latin3", 0x02 },
{ "Latin4", 0x03 },
{ "Katakana", 0x04 },
{ "Arabic", 0x05 },
{ "Cyrillic", 0x06 },
{ "Greek", 0x07 },
{ "Technical", 0x08 },
{ "Special", 0x09 },
{ "Publishing", 0x0A },
{ "APL", 0x0B },
{ "Hebrew", 0x0C },
{ "Thai", 0x0D },
{ "Korean", 0x0E },
{ "ISO", 0xFE }, /* "ISO 9995 Function and Modifier Keys" */
{ "Keyboard", 0xFF },
#ifdef DO_VENDOR_KEYSYMS
{ "Vendor", 0xFFFF }, /* special-case hack */
#endif
{ 0, 0 }
};
static char **keysym_name_buffer = 0;
static int keysym_name_buffer_size = 0;
static void
#ifdef __STDC__
ensure_keysym_name_buffer (int size)
#else /* ! __STDC__ */
ensure_keysym_name_buffer (size)
int size;
#endif /* ! __STDC__ */
{
if (keysym_name_buffer_size >= size)
return;
if (keysym_name_buffer) free ((char *) keysym_name_buffer);
keysym_name_buffer_size = size;
keysym_name_buffer = (char **) malloc (sizeof (char *) * size);
}
#ifdef DO_VENDOR_KEYSYMS
struct vendor_keysym {
char *name;
KeySym keysym;
int index;
};
static struct vendor_keysym *vendor_keysyms = 0;
static int n_vendor_keysyms = 0;
static XrmDatabase vendor_keysym_db = 0;
static Bool
#ifdef __STDC__
init_vendor_keysyms_mapper (XrmDatabase *db,
XrmBindingList bindings,
XrmQuarkList quarks,
XrmRepresentation *type,
XrmValue *value,
XPointer closure)
#else /* ! __STDC__ */
init_vendor_keysyms_mapper (db, bindings, quarks, type, value, closure)
XrmDatabase *db;
XrmBindingList bindings;
XrmQuarkList quarks;
XrmRepresentation *type;
XrmValue *value;
XPointer closure;
#endif /* ! __STDC__ */
{
KeySym keysym;
char c;
int i;
int *count = (int *) closure;
if (quarks [1]) /* should only be one level deep. */
abort ();
if (! value->addr || value->size <= 1)
return False;
keysym = 0;
for (i = 0; i < value->size - 1; i++)
{
c = ((char *) value->addr) [i];
if ('0' <= c && c <= '9') keysym = (keysym<<4)+c-'0';
else if ('a' <= c && c <= 'z') keysym = (keysym<<4)+c-'a'+10;
else if ('A' <= c && c <= 'Z') keysym = (keysym<<4)+c-'A'+10;
else
{
fprintf (stderr, "%s: unparsable entry in XKeysymDB: \"%s: %s\"\n",
progname, XrmQuarkToString (quarks [0]),
(char *) value->addr);
return False;
}
}
if (n_vendor_keysyms <= *count)
{
n_vendor_keysyms *= 2;
vendor_keysyms = (struct vendor_keysym *)
realloc (vendor_keysyms, sizeof (struct vendor_keysym) *
n_vendor_keysyms);
}
vendor_keysyms [*count].index = -1; /* we fill this in later */
vendor_keysyms [*count].keysym = keysym;
vendor_keysyms [*count].name = (char *) XrmQuarkToString (quarks [0]);
(*count)++;
return False;
}
static int
#ifdef __STDC__
sort_vendor_keysyms_1 (int left, int right)
#else /* ! __STDC__ */
sort_vendor_keysyms_1 (left, right)
int left, right;
#endif /* ! __STDC__ */
{
int L = left, R = right, middle;
struct vendor_keysym swap;
KeySym pivot = vendor_keysyms [left].keysym;
while (L < R)
{
while (vendor_keysyms [L].keysym <= pivot && L <= right)
L++;
while (vendor_keysyms [R].keysym > pivot && R >= left)
R--;
if (L < R)
{
swap = vendor_keysyms [L];
vendor_keysyms [L] = vendor_keysyms [R];
vendor_keysyms [R] = swap;
}
}
middle = R;
swap = vendor_keysyms [left];
vendor_keysyms [left] = vendor_keysyms [middle];
vendor_keysyms [middle] = swap;
if (left < middle - 1)
middle = sort_vendor_keysyms_1 (left, middle - 1);
if (middle + 1 < right)
middle = sort_vendor_keysyms_1 (middle + 1, right);
return middle;
}
static void
sort_vendor_keysyms P((void))
{
int i;
sort_vendor_keysyms_1 (0, n_vendor_keysyms - 1);
for (i = 0; i < n_vendor_keysyms; i++)
{
if (i > 0 && vendor_keysyms [i].keysym < vendor_keysyms [i-1].keysym)
abort ();
vendor_keysyms [i].index = i;
}
}
#ifndef NO_XInitKeysymDB
extern XrmDatabase _XInitKeysymDB P((void));
#endif
static void
#ifdef __STDC__
init_vendor_keysyms (KeyboardWidget widget)
#else /* ! __STDC__ */
init_vendor_keysyms (widget)
KeyboardWidget widget;
#endif /* ! __STDC__ */
{
static int done = 0;
int count = 0;
XrmName name = { 0 };
XrmClass class = { 0 };
if (done) return;
done = 1;
if (! vendor_keysym_db)
{
char *dbname = (char *) getenv ("XKEYSYMDB");
#ifdef KEYSYMDB
if (! dbname) dbname = KEYSYMDB;
#endif /* KEYSYMDB */
#ifdef NO_XInitKeysymDB
if (dbname)
vendor_keysym_db = XrmGetFileDatabase (dbname);
#else /* we have _XInitKeysymDB(), so let Xlib be clever for us. */
vendor_keysym_db = _XInitKeysymDB ();
#endif /* _XInitKeysymDB */
if (! vendor_keysym_db) /* still don't have it... */
{
if (dbname)
y_or_n_p_with_args (widget, "noKeysymDBError", "ok", 0, 0,
dbname, 0, 0, 0, 0, 0);
else
y_or_n_p (widget, "unknownKeysymDBError", "ok", 0, 0);
return;
}
}
n_vendor_keysyms = 255; /* probably not more than this; it's realloc'd. */
vendor_keysyms = (struct vendor_keysym *)
malloc (n_vendor_keysyms * sizeof (struct vendor_keysym));
XrmEnumerateDatabase (vendor_keysym_db, &name, &class,
XrmEnumOneLevel, init_vendor_keysyms_mapper,
(XtPointer) &count);
if (count < n_vendor_keysyms) /* might as well shrink it */
{
n_vendor_keysyms = count;
vendor_keysyms = (struct vendor_keysym *)
realloc (vendor_keysyms, count * sizeof (struct vendor_keysym));
}
else if (! count)
{
free ((char *) vendor_keysyms);
n_vendor_keysyms = 0;
vendor_keysyms = 0;
return;
}
/* Hash order isn't very pretty; sort them by keysym numeric value. */
sort_vendor_keysyms ();
}
static void
#ifdef __STDC__
fill_keysym_name_buffer_with_vendor_keysyms (KeyboardWidget keyboard)
#else /* ! __STDC__ */
fill_keysym_name_buffer_with_vendor_keysyms (keyboard)
KeyboardWidget keyboard;
#endif /* ! __STDC__ */
{
int i;
if (! vendor_keysyms) init_vendor_keysyms (keyboard);
ensure_keysym_name_buffer (n_vendor_keysyms + 1);
for (i = 0; i < n_vendor_keysyms; i++)
keysym_name_buffer [i] = vendor_keysyms [i].name;
keysym_name_buffer [i] = 0;
}
static int
#ifdef __STDC__
vendor_keysym_to_small_index (KeyboardWidget keyboard, KeySym keysym)
#else /* ! __STDC__ */
vendor_keysym_to_small_index (keyboard, keysym)
KeyboardWidget keyboard;
KeySym keysym;
#endif /* ! __STDC__ */
{
int i;
char buf [255];
if (! vendor_keysyms) init_vendor_keysyms (keyboard);
for (i = 0; i < n_vendor_keysyms; i++)
if (keysym == vendor_keysyms [i].keysym)
return vendor_keysyms [i].index;
sprintf (buf, "Unrecognised vendor keysym 0x%08X.", (int) keysym);
XBell (XtDisplay ((Widget) keyboard), 0);
message (keyboard, buf);
fprintf (stderr, "%s: %s\n", progname, buf);
return 0;
}
#endif /* DO_VENDOR_KEYSYMS */
struct edit_key_box {
KeyboardWidget keyboard;
Widget shell;
Widget label;
Widget keysym_buttons [8];
Widget mod_buttons [8];
Widget keyset_list, keysym_list;
Widget autorepeat_widget;
int autorepeat;
};
static void
#ifdef __STDC__
keyset_list_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
keyset_list_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
XawListReturnStruct *lr = (XawListReturnStruct *) call_data;
struct edit_key_box *box = (struct edit_key_box *) client_data;
int set = 0;
int i, j = 0;
int set_start = 0;
set = -1;
for (i = 0; i < sizeof(all_keyset_names)/sizeof(*all_keyset_names); i++)
if (lr->list_index == i)
{
set = all_keyset_names[i].number;
break;
}
if (set != 0) set_start = 1; /* Latin1 is the only set that has NoSymbol */
#ifdef DO_VENDOR_KEYSYMS
if (set == 0xFFFF) /* FFFF means "vendor keysym" */
fill_keysym_name_buffer_with_vendor_keysyms (box->keyboard);
else
#endif
if (set == -1)
{
ensure_keysym_name_buffer (256);
keysym_name_buffer [0] = 0;
}
else
{
ensure_keysym_name_buffer (256);
for (i = set_start; i < 256; i++)
{
char *name = XKeysymToString ((set << 8) | i);
if (! name && i == 0) name = "NoSymbol";
if (name)
keysym_name_buffer [j++] = name;
}
keysym_name_buffer [j++] = 0;
}
XawListChange (box->keysym_list, keysym_name_buffer, 0, 0, True);
}
static void
#ifdef __STDC__
keysym_list_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
keysym_list_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
XawListReturnStruct *lr = (XawListReturnStruct *) call_data;
struct edit_key_box *box = (struct edit_key_box *) client_data;
int i = (int) XawToggleGetCurrent (box->keysym_buttons [0]);
if (i > 0)
{
Widget button = box->keysym_buttons [i-1];
/* If the string is wider than the parent of the button, setting the
label will leave it at the size it was before. So, first stretch
it to the max width, and then let SetValues (maybe) resize it
smaller. What a piece of junk. */
XtResizeWidget (button,
XtParent (button)->core.width,
button->core.height,
button->core.border_width);
XtVaSetValues (button, XtNlabel, lr->string, 0);
}
}
static void
#ifdef __STDC__
autorepeat_button_cb (Widget widget, XtPointer client_data,
XtPointer call_data)
#else /* ! __STDC__ */
autorepeat_button_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct edit_key_box *box = (struct edit_key_box *) client_data;
Arg av [10];
int ac = 0;
box->autorepeat = !box->autorepeat;
XtSetArg (av [ac], XtNlabel, (box->autorepeat ? "Yes" : "No")); ac++;
XtSetValues (widget, av, ac);
}
static void
#ifdef __STDC__
abort_button_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
abort_button_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct edit_key_box *box = (struct edit_key_box *) client_data;
XtPopdown (box->shell);
message (box->keyboard, "Aborted.");
}
static int stop_the_insanity P((KeyboardWidget,
int keycode, KeySym *keysyms, int count,
unsigned long modbits,
XModifierKeymap *modmap));
static void
#ifdef __STDC__
ok_button_cb (Widget button, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
ok_button_cb (button, client_data, call_data)
Widget button;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct edit_key_box *box = (struct edit_key_box *) client_data;
KeyboardWidget widget = box->keyboard;
KeyWidget key = widget->keyboard.key_under_mouse;
KeyCode code = key->key.keycode;
KeySym keysyms [8];
int keysym_count;
unsigned long modbits = 0;
XModifierKeymap *modmap = XGetModifierMapping (XtDisplay (widget));
int i, error;
Arg av [10];
int ac = 0;
char *str;
ac = 0;
XtSetArg (av [ac], XtNlabel, &str); ac++;
for (i = 0; i < 8; i++)
{
XtGetValues (box->keysym_buttons [i], av, ac);
if (str && !strcmp (str, "NoSymbol")) str = 0;
if (! str)
keysyms [i] = 0;
else
{
keysyms [i] = XStringToKeysym (str);
if (! keysyms [i])
fprintf (stderr,
"%s: ERROR: XStringToKeysym(\"%s\") returned 0\n",
progname, str);
}
}
for (keysym_count = 8; keysym_count > 0; keysym_count--)
if (keysyms [keysym_count-1]) break;
for (i = 0; i < 8; i++)
{
#ifndef XAWBUG
Boolean state = 0;
XtVaGetValues (box->mod_buttons[i], XtNstate, &state, NULL);
#else /* XAWBUG */
int state = ((CommandWidget) (box->mod_buttons [i]))->command.set;
#endif
modbits |= ((!!state) << i);
if (state)
modmap = XInsertModifiermapEntry (modmap, code, i);
else
modmap = XDeleteModifiermapEntry (modmap, code, i);
}
if (stop_the_insanity (widget, code, keysyms, keysym_count, modbits, modmap))
return;
XSync (XtDisplay (widget), 0);
error = modify_keyboard (widget, code, keysym_count,
keysyms, 1, modmap);
XFreeModifiermap (modmap);
if (!error && box->autorepeat != key->key.auto_repeat_p)
{
XKeyboardControl values;
values.key = key->key.keycode;
values.auto_repeat_mode =
(box->autorepeat ? AutoRepeatModeOn : AutoRepeatModeOff);
XChangeKeyboardControl (XtDisplay (widget), KBKey | KBAutoRepeatMode,
&values);
}
XtPopdown (box->shell);
if (! error) message (box->keyboard, "Modified.");
}
static void
#ifdef __STDC__
move_scrollbar (Widget list, float percent)
#else /* ! __STDC__ */
move_scrollbar (list, percent)
Widget list;
float percent;
#endif /* ! __STDC__ */
{
Widget vp = XtParent (list);
Widget scrollbar = XtNameToWidget (vp, "vertical");
float visible_fraction = (((float) vp->core.height) /
((float) list->core.height));
if (visible_fraction < 1.0)
percent -= (visible_fraction / 2.0);
XawScrollbarSetThumb (scrollbar, 0.0, -1.0);
XtCallCallbacks (scrollbar, XtNjumpProc, (XtPointer) &percent);
}
static void
#ifdef __STDC__
keysym_button_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
keysym_button_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct edit_key_box *box = (struct edit_key_box *) client_data;
KeyboardWidget keyboard = box->keyboard;
char *keysym_name = 0;
KeySym real_keysym;
int list_index = 0;
int keyset = 0, keysym = 0, index = 0, list_size = 0;
Arg av[10];
int ac = 0;
int i;
if (call_data == 0) /* we're being toggled off */
return;
XtSetArg (av[ac], XtNlabel, &keysym_name); ac++;
XtGetValues (widget, av, ac);
real_keysym = XStringToKeysym (keysym_name);
/* Get the one that's in the list */
keysym_name = XKeysymToString (real_keysym);
if (real_keysym > 0xFFFF)
{
#ifdef DO_VENDOR_KEYSYMS
int i;
keysym = 0;
for (i = 0; i < sizeof(all_keyset_names)/sizeof(*all_keyset_names); i++)
if (!strcmp(all_keyset_names[i].name, "Vendor"))
{
keysym = i;
break;
}
if (keysym == 0) abort();
keysym = vendor_keysym_to_small_index (keyboard, real_keysym);
#else
XBell (XtDisplay (keyboard), 0);
message (keyboard,
"XKeyCaps was compiled without support for Vendor keysyms.");
message2 (keyboard, "Consider upgrading to X11r5...");
keyset = 0;
keysym = 0;
#endif
}
else
{
keyset = (real_keysym >> 8);
keysym = (real_keysym & 0xff);
}
list_size = (sizeof (all_keyset_names) / sizeof (all_keyset_names[0]));
list_index = -1;
for (i = 0; i < sizeof(all_keyset_names)/sizeof(*all_keyset_names); i++)
if (all_keyset_names[i].number == keyset)
{
list_index = i;
break;
}
if (list_index < 0)
{
XawListUnhighlight(box->keyset_list);
move_scrollbar (box->keyset_list, 0.0);
}
else
{
XawListHighlight (box->keyset_list, list_index);
move_scrollbar (box->keyset_list,
(((float) list_index) / ((float) list_size)));
}
keyset_list_cb (box->keyset_list, box,
XawListShowCurrent (box->keyset_list));
index = 256;
for (list_size = 0; list_size < 256; list_size++)
if (keysym_name_buffer [list_size] == keysym_name)
index = list_size;
else if (! keysym_name_buffer [list_size])
break;
if (! keysym_name) index = 0;
if (index < 256)
{
XawListHighlight (box->keysym_list, index);
move_scrollbar (box->keysym_list,
(((float) index) / ((float) list_size)));
}
else
{
XawListUnhighlight (box->keysym_list);
}
}
static void
#ifdef __STDC__
undo_button_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
undo_button_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct edit_key_box *box = (struct edit_key_box *) client_data;
KeyboardWidget keyboard = box->keyboard;
KeyWidget key = keyboard->keyboard.key_under_mouse;
KeySym *keysyms;
int syms_per_code = 0;
char buf [255];
Arg av[20];
int ac = 0;
int i;
keysyms = XGetKeyboardMapping (XtDisplay (widget), key->key.keycode,
1, &syms_per_code);
sprintf (buf, "Definition of key 0x%02X (%s)", key->key.keycode,
key->key.key_name);
XtSetArg (av[ac], XtNlabel, buf); ac++;
XtSetValues (box->label, av, ac);
ac = 0;
for (i = 0; i < syms_per_code; i++)
{
char *sym;
char buf [255];
if (!keysyms || !keysyms[i])
sym = "NoSymbol";
else
sym = XKeysymToString (keysyms [i]);
if (! sym)
{
sprintf (buf, "0x%04X", (int) keysyms [i]);
sym = buf;
}
ac = 0;
XtSetArg (av[ac], XtNlabel, sym); ac++;
XtSetValues (box->keysym_buttons [i], av, ac);
}
if (keysyms) XFree ((char *) keysyms);
ac = 0;
XtSetArg (av[ac], XtNlabel, "NoSymbol"); ac++;
for (; i < 8; i++)
XtSetValues (box->keysym_buttons [i], av, ac);
for (i = 0; i < 8; i++)
{
ac = 0;
XtSetArg (av[ac], XtNstate,
((key->key.modifier_bits & 1<<i) ? True : False)); ac++;
XtSetValues (box->mod_buttons [i], av, ac);
}
XawToggleSetCurrent (box->keysym_buttons [0], (XtPointer) 1);
keysym_button_cb (box->keysym_buttons [0], box, (void *) 1);
box->autorepeat = !key->key.auto_repeat_p;
autorepeat_button_cb (box->autorepeat_widget, box, 0);
}
static struct edit_key_box *
#ifdef __STDC__
make_edit_key_dbox (KeyboardWidget widget)
#else /* ! __STDC__ */
make_edit_key_dbox (widget)
KeyboardWidget widget;
#endif /* ! __STDC__ */
{
struct edit_key_box *box = (struct edit_key_box *)
malloc (sizeof (struct edit_key_box));
Arg av [20];
int ac = 0;
Widget toplevel, box1, box2;
Widget keysym_box, button_box, keyset_box, keyset_syms_box, mod_box;
Widget line_box, prev, prev_tog;
Widget set_list, sym_list;
Widget set_vp, sym_vp;
toplevel = XtCreatePopupShell ("editKey", transientShellWidgetClass,
(Widget) widget, av, ac);
box1 = XtCreateManagedWidget ("vertical", panedWidgetClass, toplevel, av,ac);
box->label = make_label (box1, "label", 0, 0, 0);
ac = 0;
XtSetArg (av[ac], XtNorientation, "horizontal"); ac++;
box2 = XtCreateManagedWidget ("horizontal", panedWidgetClass, box1, av, ac);
ac = 0;
keysym_box = XtCreateManagedWidget ("keysymBox", formWidgetClass, box2,
av, ac);
prev = make_label (keysym_box, "symsOfCode", 0, 0, 0);
prev = make_label (keysym_box, "spacer", "", 0, prev);
ac = 0;
prev_tog = 0;
line_box = prev;
#define TOG(var, name, index) \
{ ac = 0; \
XtSetArg (av[ac], XtNorientation, "horizontal"); ac++; \
XtSetArg (av [ac], XtNfromVert, line_box); ac++; \
XtSetArg (av[ac], XtNtop, XtChainTop); ac++; \
XtSetArg (av[ac], XtNbottom, XtChainTop); ac++; \
line_box = XtCreateManagedWidget ("keysymLine", boxWidgetClass, \
keysym_box, av, ac); \
var = make_label (line_box, name, 0, 0, prev); \
if (index) \
var = make_toggle (line_box, "keysymValue" ,var, prev, 0, \
keysym_button_cb, box, MEDIUM_LENGTH_KEYSYM_NAME, \
prev_tog, (XtPointer) index); \
else \
var = make_button (line_box, "autoRepeatValue", "Yes", var, prev, \
autorepeat_button_cb, box, 0); \
prev_tog = prev = var; }
TOG (box->keysym_buttons [0], "keysym1", 1);
TOG (box->keysym_buttons [1], "keysym2", 2);
TOG (box->keysym_buttons [2], "keysym3", 3);
TOG (box->keysym_buttons [3], "keysym4", 4);
TOG (box->keysym_buttons [4], "keysym5", 5);
TOG (box->keysym_buttons [5], "keysym6", 6);
TOG (box->keysym_buttons [6], "keysym7", 7);
TOG (box->keysym_buttons [7], "keysym8", 8);
prev = prev_tog = 0;
line_box = make_label (keysym_box, "spacer2", "", 0, line_box);
TOG (box->autorepeat_widget, "autoRepeat", 0);
#undef TOG
ac = 0;
mod_box = XtCreateManagedWidget ("modifierBox", formWidgetClass,
box2, av, ac);
prev = make_label (mod_box, "modifiers", 0, 0, 0);
prev = make_label (mod_box, "spacer", "", 0, prev);
#define TOG(var, name) \
{ var = make_toggle (mod_box, name, 0, prev, 0, 0, 0, 0, 0, 0); \
prev = var; }
TOG (box->mod_buttons [0], "modShift");
TOG (box->mod_buttons [1], "modLock");
TOG (box->mod_buttons [2], "modControl");
TOG (box->mod_buttons [3], "mod1");
TOG (box->mod_buttons [4], "mod2");
TOG (box->mod_buttons [5], "mod3");
TOG (box->mod_buttons [6], "mod4");
TOG (box->mod_buttons [7], "mod5");
#undef TOG
ac = 0;
keyset_box = XtCreateManagedWidget("keysetBox", formWidgetClass,
box2, av, ac);
prev = make_label (keyset_box, "allKeySets", 0, 0, 0);
ac = 0;
XtSetArg (av[ac], XtNfromVert, prev); ac++;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainRight); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainBottom); ac++;
set_vp = XtCreateManagedWidget ("keysetsVp", viewportWidgetClass,
keyset_box, av, ac);
ac = 0;
{
static const char *list[sizeof(all_keyset_names) /
sizeof(*all_keyset_names)];
int i = 0;
for (i = 0; i < sizeof(list)/sizeof(*list); i++)
list[i] = all_keyset_names[i].name;
XtSetArg (av[ac], XtNlist, list); ac++;
}
set_list = XtCreateManagedWidget ("keysets", listWidgetClass, set_vp,av,ac);
XtAddCallback (set_list, XtNcallback, keyset_list_cb, (XtPointer) box);
/* Gag! These lists won't size themselves correctly. */
XtVaSetValues (set_list, XtNwidth, set_list->core.width + 20, 0);
ac = 0;
keyset_syms_box = XtCreateManagedWidget ("keysetSymsBox", formWidgetClass,
box2, av, ac);
prev = make_label (keyset_syms_box, "keySymsOfSet", 0, 0, 0);
ac = 0;
XtSetArg (av[ac], XtNfromVert, prev); ac++;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainRight); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainBottom); ac++;
sym_vp = XtCreateManagedWidget ("keysymsVp", viewportWidgetClass,
keyset_syms_box, av, ac);
ensure_keysym_name_buffer (256);
#if 0
memcpy (keysym_name_buffer, all_keyset_names, sizeof (all_keyset_names));
#endif
keysym_name_buffer [0] = LONGEST_KEYSYM_NAME;
keysym_name_buffer [1] = 0;
ac = 0;
XtSetArg (av[ac], XtNlist, keysym_name_buffer); ac++;
sym_list = XtCreateManagedWidget ("keysyms", listWidgetClass, sym_vp,av,ac);
XtAddCallback (sym_list, XtNcallback, keysym_list_cb, (XtPointer) box);
/* Gag! These lists won't size themselves correctly. */
XtVaSetValues (sym_list, XtNwidth, sym_list->core.width + 20, 0);
ac = 0;
XtSetArg (av[ac], XtNskipAdjust, True); ac++;
button_box = XtCreateManagedWidget ("buttons", boxWidgetClass, box1, av, ac);
prev = make_button (button_box, "undo", 0, 0, 0, undo_button_cb, box, 0);
prev = make_button (button_box, "abort", 0, prev, 0, abort_button_cb, box,0);
prev = make_button (button_box, "ok", 0, prev, 0, ok_button_cb, box, 0);
box->keyboard = widget;
box->shell = toplevel;
box->keyset_list = set_list;
box->keysym_list = sym_list;
return box;
}
static void
#ifdef __STDC__
pop_up_key_dbox (Widget parent, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
pop_up_key_dbox (parent, client_data, call_data)
Widget parent;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = (KeyboardWidget) client_data;
struct edit_key_box *edit_key_box =
widget->keyboard.key_menus->edit_key_box;
if (widget->keyboard.key_under_mouse->key.keycode == 0)
{
y_or_n_p (widget, "magicKeyError", "ok", 0, 0);
return;
}
{
Widget topmost = parent;
int x, y, w, h;
XtRealizeWidget (edit_key_box->shell);
w = edit_key_box->shell->core.width;
h = edit_key_box->shell->core.height;
while (topmost->core.parent)
topmost = topmost->core.parent;
if (topmost->core.width < w) x = topmost->core.x;
else x = topmost->core.x + ((topmost->core.width - w) / 2);
if (topmost->core.height < h) y = topmost->core.y;
else y = topmost->core.y + ((topmost->core.height - h) / 2);
XtMoveWidget (edit_key_box->shell, x, y);
}
XtPopup (edit_key_box->shell, XtGrabNonexclusive);
undo_button_cb (edit_key_box->shell, edit_key_box, 0);
}
static struct keyboard_set {
int kbd_index;
const char *vendor;
char *type;
char **maps; /* short names of maps */
char **full_maps; /* long names (vendor+kbd+map) */
int map_count;
} *keyboard_sets;
int keyboard_set_count;
int vendor_count;
static char const **vendors;
static char **keyboard_types; /* compared to keyboard_sets[i].type[j] */
static char *longest_type; /* longest of all keyboard_sets[i].type */
static char *longest_map; /* longest of all keyboard_sets[i].maps[j] */
struct select_kbd_box {
KeyboardWidget keyboard;
Widget shell;
Widget label;
Widget label2;
Widget icon;
Widget vendor_list, keyboard_list, keymap_list;
struct keyboard_set *set;
const char *map;
};
static char *default_maps[] = { "default", 0 };
static void
make_kbd_lists P((void))
{
int kbd_count = 0;
int i, j;
i = 0;
vendor_count = 0;
while (all_kbds[i].vendor)
{
const char *v = all_kbds[i].vendor;
vendor_count++;
i++;
while (all_kbds[i].vendor &&
!strcmp(v, all_kbds[i].vendor))
i++;
}
vendors = (const char **) malloc (sizeof(*vendors) * (vendor_count+1));
i = 0;
j = 0;
while (all_kbds[i].vendor)
{
const char *v = all_kbds[i].vendor;
vendors[j++] = v;
i++;
while (all_kbds[i].vendor &&
!strcmp(v, all_kbds[i].vendor))
i++;
}
vendors[j] = 0;
for (kbd_count = 0; all_kbds [kbd_count].short_name; kbd_count++)
;
keyboard_sets = (struct keyboard_set *)
malloc (sizeof (struct keyboard_set) * kbd_count);
longest_type = 0;
longest_map = 0;
i = 0;
j = 0;
while (i < kbd_count)
{
char last_style [255];
char full [255];
char *tail;
strcpy (last_style, all_kbds[i].kbd_style);
make_long_kbd_name (all_kbds[i].vendor, last_style, full);
tail = (char *) strchr (last_style, '(');
if (tail) *tail = 0;
tail = (char *) strchr (full, '(');
keyboard_sets [j].kbd_index = i;
keyboard_sets [j].map_count = 0;
keyboard_sets [j].vendor = all_kbds[i].vendor;
if (tail)
{
int L;
int count = 0;
int k;
/* Edit out the parens (but not the trailing space) */
*tail = 0;
tail++;
tail [strlen (tail) - 1] = 0;
L = strlen (full);
count = 0;
while (1)
{
char name[255];
make_long_kbd_name(all_kbds[i+count].vendor,
all_kbds[i+count].kbd_style,
name);
if (strlen (name) < L ||
!!strncmp (full, name, L))
break;
count++;
}
keyboard_sets [j].maps = (char **)
malloc (sizeof (char *) * (count+1));
keyboard_sets [j].full_maps = (char **)
malloc (sizeof (char *) * (count+1));
for (k = 0; k < count; k++)
{
char full[255];
const char *map;
char *map_name = 0;
int ML;
make_long_kbd_name(all_kbds [i+k].vendor,
all_kbds [i+k].kbd_style,
full);
map = strchr(full, '(');
if (!map) abort();
map++;
ML = strlen (map);
map_name = (char *) malloc (ML);
memcpy (map_name, map, ML);
map_name [--ML] = 0;
keyboard_sets [j].maps[k] = map_name;
keyboard_sets [j].full_maps[k] = strdup(full);
if (!longest_map || strlen (longest_map) < ML)
longest_map = keyboard_sets [j].maps[k];
}
keyboard_sets [j].maps[k] = 0;
i += count;
keyboard_sets [j].map_count = count;
}
else
{
keyboard_sets [j].maps = default_maps;
keyboard_sets [j].full_maps = (char **) malloc (sizeof (char *) * 2);
keyboard_sets [j].full_maps [0] = strdup(full);
keyboard_sets [j].full_maps [1] = 0;
keyboard_sets [j].map_count = 1;
i++;
}
keyboard_sets [j].type = (char *) malloc (strlen (last_style) + 1);
memcpy (keyboard_sets [j].type, last_style, strlen (last_style) + 1);
if (!longest_type ||
strlen (longest_type) < strlen(keyboard_sets [j].type))
longest_type = keyboard_sets [j].type;
j++;
}
keyboard_set_count = j;
{
int max = 0;
keyboard_types = (char **) malloc (sizeof (char *) * (j + 1));
for (i = 0; i < j; i++)
{
keyboard_types [i] = keyboard_sets [i].type;
if (keyboard_sets [i].map_count > max)
max = keyboard_sets [i].map_count;
}
keyboard_types[i] = 0;
}
}
static void
#ifdef __STDC__
kbd_abort_button_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
kbd_abort_button_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct select_kbd_box *box = (struct select_kbd_box *) client_data;
Widget shell = box->shell;
XtPopdown (shell);
}
static void
#ifdef __STDC__
kbd_ok_button_cb (Widget button, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
kbd_ok_button_cb (button, client_data, call_data)
Widget button;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
struct select_kbd_box *box = (struct select_kbd_box *) client_data;
KeyboardWidget kbd = box->keyboard;
const char *map = box->map;
kbd_abort_button_cb (button, client_data, call_data);
replace_keyboard (kbd, map);
}
static void
#ifdef __STDC__
keymap_list_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
keymap_list_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
XawListReturnStruct *lr = (XawListReturnStruct *) call_data;
struct select_kbd_box *box = (struct select_kbd_box *) client_data;
struct keyboard_set *set = box->set;
box->map = set->full_maps [lr->list_index];
}
static int current_vendor_offset = 0;
static void
#ifdef __STDC__
keyboard_list_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
keyboard_list_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
XawListReturnStruct *lr = (XawListReturnStruct *) call_data;
struct select_kbd_box *box = (struct select_kbd_box *) client_data;
int kbd = lr->list_index + current_vendor_offset;
int map = 0;
int i = 0;
while (strcmp (keyboard_sets [i].type, keyboard_types [kbd]))
i++;
box->set = &keyboard_sets [i];
XawListChange (box->keymap_list, (char **) box->set->maps, 0, 0, True);
for (i = 0; i < box->set->map_count; i++)
{
char buf[255];
make_long_kbd_name(box->keyboard->keyboard.vendor,
box->keyboard->keyboard.kbd_style,
buf);
if (!strcmp (box->set->full_maps[i], buf))
{
map = i;
break;
}
}
XawListHighlight (box->keymap_list, map);
lr->list_index = map;
keymap_list_cb (widget, client_data, call_data);
move_scrollbar (box->keymap_list,
(((float) map) / ((float) box->set->map_count)));
{
int w, h;
Pixmap p = get_keyboard_icon (XtDisplay (widget),
&all_kbds [box->set->kbd_index], &w, &h);
XtVaSetValues (box->icon, XtNbitmap, p, XtNheight, h, 0);
}
}
static void
#ifdef __STDC__
vendor_list_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
vendor_list_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
XawListReturnStruct *lr = (XawListReturnStruct *) call_data;
struct select_kbd_box *box = (struct select_kbd_box *) client_data;
int vendor = lr->list_index;
const char *v = vendors[vendor];
static char *list[255];
int kbd;
int i, j;
for (i = 0; i < keyboard_set_count; i++)
if (!strcmp(v, keyboard_sets[i].vendor))
break;
current_vendor_offset = i;
j = 0;
while (keyboard_sets[i].type &&
!strcmp(v, keyboard_sets[i].vendor))
list[j++] = keyboard_sets[i++].type;
list [j] = 0;
kbd = 0;
if (box->set)
{
char *s1 = strdup (box->keyboard->keyboard.kbd_style);
char *s2 = strchr (s1, '(');
if (s2) *s2 = 0;
for (i = 0; list[i]; i++)
if (!strcmp (s1, list[i]))
{
kbd = i;
break;
}
free (s1);
}
XawListChange (box->keyboard_list, list, 0, 0, True);
XawListHighlight (box->keyboard_list, kbd);
lr->list_index = kbd;
keyboard_list_cb (widget, client_data, call_data);
}
static struct select_kbd_box *
#ifdef __STDC__
make_select_kbd_dbox (KeyboardWidget widget)
#else /* ! __STDC__ */
make_select_kbd_dbox (widget)
KeyboardWidget widget;
#endif /* ! __STDC__ */
{
struct select_kbd_box *box = (struct select_kbd_box *)
malloc (sizeof (struct select_kbd_box));
Arg av [20];
int ac = 0;
Widget toplevel, box1, box2;
Widget button_box, vendor_box, keyboard_box, keymap_box;
Widget prev;
Widget vendor_list, kbd_list, map_list;
Widget vendor_vp, kbd_vp, map_vp;
make_kbd_lists ();
toplevel = XtCreatePopupShell ("selectKbd", transientShellWidgetClass,
XtParent ((Widget) widget), av, ac);
box1 = XtCreateManagedWidget ("vertical", panedWidgetClass, toplevel, av,ac);
box->label = make_label (box1, "label", 0, 0, 0);
box->label2 = make_label (box1, "label2", "", 0, 0);
ac = 0;
XtSetArg (av[ac], XtNorientation, "horizontal"); ac++;
box2 = XtCreateManagedWidget ("horizontal", panedWidgetClass, box1, av, ac);
ac = 0;
vendor_box = XtCreateManagedWidget ("vendorBox", formWidgetClass,
box2, av, ac);
prev = make_label (vendor_box, "vendors", 0, 0, 0);
ac = 0;
XtSetArg (av[ac], XtNfromVert, prev); ac++;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainRight); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainBottom); ac++;
vendor_vp = XtCreateManagedWidget ("vendorsVp", viewportWidgetClass,
vendor_box, av, ac);
ac = 0;
XtSetArg (av[ac], XtNlist, vendors); ac++;
vendor_list = XtCreateManagedWidget ("vendorsList", listWidgetClass,
vendor_vp, av, ac);
XtAddCallback (vendor_list, XtNcallback, vendor_list_cb, (XtPointer) box);
/* Gag! These lists won't size themselves correctly. */
XtVaSetValues (vendor_list, XtNwidth, vendor_list->core.width + 20, 0);
ac = 0;
keyboard_box = XtCreateManagedWidget ("keyboardBox", formWidgetClass,
box2, av, ac);
prev = make_label (keyboard_box, "keyboards", 0, 0, 0);
ac = 0;
XtSetArg (av[ac], XtNfromVert, prev); ac++;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainRight); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainBottom); ac++;
kbd_vp = XtCreateManagedWidget ("keyboardsVp", viewportWidgetClass,
keyboard_box, av, ac);
ac = 0;
{
static char *dummy[2];
dummy[0] = longest_type;
dummy[1] = 0;
ac = 0;
XtSetArg (av[ac], XtNlist, dummy); ac++;
kbd_list = XtCreateManagedWidget ("keyboardsList", listWidgetClass, kbd_vp,
av, ac);
XtAddCallback (kbd_list, XtNcallback, keyboard_list_cb, (XtPointer) box);
/* Gag! These lists won't size themselves correctly. */
XtVaSetValues (kbd_list, XtNwidth, kbd_list->core.width + 20, 0);
}
ac = 0;
keymap_box = XtCreateManagedWidget ("keymapBox", formWidgetClass,
box2, av, ac);
prev = make_label (keymap_box, "keymaps", 0, 0, 0);
ac = 0;
XtSetArg (av[ac], XtNfromVert, prev); ac++;
XtSetArg (av[ac], XtNleft, XtChainLeft); ac++;
XtSetArg (av[ac], XtNright, XtChainRight); ac++;
XtSetArg (av[ac], XtNtop, XtChainTop); ac++;
XtSetArg (av[ac], XtNbottom, XtChainBottom); ac++;
map_vp = XtCreateManagedWidget ("keymapsVp", viewportWidgetClass,
keymap_box, av, ac);
{
static char *dummy[2];
dummy[0] = longest_map;
dummy[1] = 0;
ac = 0;
XtSetArg (av[ac], XtNlist, dummy); ac++;
map_list = XtCreateManagedWidget ("keymapsList", listWidgetClass, map_vp,
av, ac);
XtAddCallback (map_list, XtNcallback, keymap_list_cb, (XtPointer) box);
/* Gag! These lists won't size themselves correctly. */
XtVaSetValues (map_list, XtNwidth, map_list->core.width + 20, 0);
}
ac = 0;
XtSetArg (av[ac], XtNskipAdjust, True); ac++;
button_box = XtCreateManagedWidget ("buttons", boxWidgetClass, box1, av, ac);
prev = make_button (button_box, "abort", 0, prev, 0, kbd_abort_button_cb,
box, 0);
prev = make_button (button_box, "ok", 0, prev, 0, kbd_ok_button_cb,
box, 0);
prev = make_label (button_box, "spacer", "", 0, prev);
box->icon = make_label (button_box, "kbd_icon", 0, prev, 0);
box->keyboard = 0;
box->shell = toplevel;
box->vendor_list = vendor_list;
box->keyboard_list = kbd_list;
box->keymap_list = map_list;
box->set = 0;
box->map = 0;
return box;
}
void
#ifdef __STDC__
pop_up_kbd_dbox (Widget parent, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
pop_up_kbd_dbox (parent, client_data, call_data)
Widget parent;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
KeyboardWidget widget = *((KeyboardWidget *) client_data);
struct select_kbd_box *select_kbd_box =
widget->keyboard.key_menus->select_kbd_box;
select_kbd_box->keyboard = widget;
XtVaSetValues (select_kbd_box->label2, XtNlabel, choose_kbd_message, 0);
choose_kbd_dubious_p = 0;
choose_kbd_message [0] = 0;
{
Widget topmost = parent;
int x, y, w, h;
XtRealizeWidget (select_kbd_box->shell);
/* #### It'd be nice to wait here until it was mapped... */
w = select_kbd_box->shell->core.width;
h = select_kbd_box->shell->core.height;
while (topmost->core.parent)
topmost = topmost->core.parent;
if (topmost->core.width < w) x = topmost->core.x;
else x = topmost->core.x + ((topmost->core.width - w) / 2);
if (topmost->core.height < h) y = topmost->core.y;
else y = topmost->core.y + ((topmost->core.height - h) / 2);
XtMoveWidget (select_kbd_box->shell, x, y);
}
{
XawListReturnStruct lr;
int this_vendor = 0;
int this_kbd = 0;
int this_vendor_start = 0;
int i, j;
char buf[255];
const char *last_vendor = 0;
make_long_kbd_name(widget->keyboard.vendor,
widget->keyboard.kbd_style,
buf);
for (i = 0; i <= keyboard_set_count; i++)
{
if (last_vendor && !!strcmp(last_vendor, keyboard_sets[i].vendor))
{
this_vendor_start = i;
this_vendor++;
this_kbd = 0;
}
last_vendor = keyboard_sets[i].vendor;
for (j = 0; j < keyboard_sets[i].map_count; j++)
if (!strcmp (keyboard_sets[i].full_maps[j], buf))
{
this_kbd = i - this_vendor_start;
goto out;
}
}
out:
lr.list_index = this_vendor;
XawListHighlight (select_kbd_box->vendor_list, this_vendor);
move_scrollbar (select_kbd_box->vendor_list,
(((float) this_vendor) / ((float) vendor_count)));
vendor_list_cb ((Widget) widget,
(void *) select_kbd_box,
(void *) &lr);
lr.list_index = this_kbd;
XawListHighlight (select_kbd_box->keyboard_list, this_kbd);
/* move_scrollbar (select_kbd_box->keyboard_list,
(((float) this_kbd) / ((float) keyboard_set_count)));
*/
keyboard_list_cb ((Widget) widget,
(void *) select_kbd_box,
(void *) &lr);
}
XtPopup (select_kbd_box->shell, XtGrabNonexclusive);
}
static void
#ifdef __STDC__
yorn_button_cb (Widget widget, XtPointer client_data, XtPointer call_data)
#else /* ! __STDC__ */
yorn_button_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data, call_data;
#endif /* ! __STDC__ */
{
*((int *) client_data) = 1;
}
static int
#ifdef __STDC__
y_or_n_p_with_args (KeyboardWidget widget,
char *name,
char *name0, char *name1, char *name2,
char *arg0, char *arg1, char *arg2, char *arg3,
char *arg4, char *arg5)
#else /* ! __STDC__ */
y_or_n_p_with_args (widget, name,
name0, name1, name2,
arg0, arg1, arg2, arg3, arg4, arg5)
KeyboardWidget widget;
char *name;
char *name0, *name1, *name2;
char *arg0, *arg1, *arg2, *arg3, *arg4, *arg5;
#endif /* ! __STDC__ */
{
XtAppContext app = XtWidgetToApplicationContext ((Widget) widget);
Widget topmost = (Widget) widget;
Widget label;
XEvent event;
int x, y, w, h;
Arg av [10];
int ac = 0;
Widget shell, box1, box2, prev;
int ans [3];
shell = XtCreatePopupShell (name, transientShellWidgetClass,
(Widget) widget, av, ac);
box1 = XtCreateManagedWidget ("paned", panedWidgetClass, shell, av, ac);
label = make_label (box1, "label", 0, 0, 0);
if (arg0) /* format into the label if desired. */
{
char *old_string;
char new_string [4000];
ac = 0;
XtSetArg (av [ac], XtNlabel, &old_string); ac++;
XtGetValues (label, av, ac);
if (!strcmp (old_string, XtName (label)))
strcpy (new_string, "ERROR: RESOURCES ARE NOT INSTALLED CORRECTLY");
else
sprintf (new_string, old_string, arg0, arg1, arg2, arg3, arg4, arg5);
ac = 0;
XtSetArg (av [ac], XtNlabel, new_string); ac++;
XtSetValues (label, av, ac);
}
ac = 0;
XtSetArg (av[ac], XtNorientation, "horizontal"); ac++;
box2 = XtCreateManagedWidget ("buttons", boxWidgetClass, box1, av, ac);
prev = 0;
if (name0) prev = make_button (box2,name0,0,prev,0,yorn_button_cb,&ans[0],0);
if (name1) prev = make_button (box2,name1,0,prev,0,yorn_button_cb,&ans[1],0);
if (name2) prev = make_button (box2,name2,0,prev,0,yorn_button_cb,&ans[2],0);
XtRealizeWidget (shell);
w = shell->core.width;
h = shell->core.height;
while (topmost->core.parent)
topmost = topmost->core.parent;
if (topmost->core.width < w) x = topmost->core.x;
else x = topmost->core.x + ((topmost->core.width - w) / 2);
if (topmost->core.height < h) y = topmost->core.y;
else y = topmost->core.y + ((topmost->core.height - h) / 2);
XtMoveWidget (shell, x, y);
XtPopup (shell, XtGrabNonexclusive);
memset (ans, 0, sizeof (ans));
while (! (ans[0] || ans[1] || ans[2]))
{
XtAppNextEvent (app, &event);
if (event.xany.type == KeymapNotify)
keyboard_handle_keymap_notify ((Widget) widget, 0, &event, 0);
else if (event.xany.type == MappingNotify)
keyboard_handle_mapping_notify ((Widget) widget, 0, &event, 0);
XtDispatchEvent (&event);
}
XtPopdown (shell);
XtDestroyWidget (shell);
if (ans[0]) return 0;
if (ans[1]) return 1;
if (ans[2]) return 2;
exit (-69);
}
static int
#ifdef __STDC__
y_or_n_p (KeyboardWidget widget,
char *name, char *name0, char *name1, char *name2)
#else /* ! __STDC__ */
y_or_n_p (widget, name, name0, name1, name2)
KeyboardWidget widget;
char *name, *name0, *name1, *name2;
#endif /* ! __STDC__ */
{
return y_or_n_p_with_args (widget, name, name0, name1, name2, 0,0,0,0,0,0);
}
KeyWidget
#ifdef __STDC__
prompt_for_key (KeyboardWidget keyboard, char *msg)
#else /* ! __STDC__ */
prompt_for_key (keyboard, msg)
KeyboardWidget keyboard;
char *msg;
#endif /* ! __STDC__ */
{
XtAppContext app = XtWidgetToApplicationContext ((Widget) keyboard);
KeyWidget key;
XEvent event;
message (keyboard, msg);
if (XGrabPointer (XtDisplay (keyboard), XtWindow (keyboard), True,
ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, 0,
keyboard->keyboard.select_cursor,
CurrentTime))
{
XBell (XtDisplay (keyboard), 0);
message (keyboard, "Grab failed.");
return 0;
}
while (1)
{
XtAppNextEvent (app, &event);
if (event.xany.type == ButtonPress)
{
XUngrabPointer (XtDisplay (keyboard), CurrentTime);
if ((key = keyboard->keyboard.key_under_mouse))
return key;
XBell (XtDisplay (keyboard), 0);
message (keyboard, "You must click on a key.");
return 0;
}
else if (event.xany.type == ButtonRelease ||
event.xany.type == KeyPress ||
event.xany.type == KeyRelease)
{
XUngrabPointer (XtDisplay (keyboard), CurrentTime);
XBell (XtDisplay (keyboard), 0);
XPutBackEvent (XtDisplay (keyboard), &event);
message (keyboard, "Aborted.");
return 0;
}
else
{
if (event.xany.type == KeymapNotify)
keyboard_handle_keymap_notify ((Widget) keyboard, 0, &event, 0);
else if (event.xany.type == MappingNotify)
keyboard_handle_mapping_notify ((Widget) keyboard, 0, &event, 0);
XtDispatchEvent (&event);
}
}
}
/* What a mess the X keyboard model is... */
#include <X11/keysym.h>
static char *
#ifdef __STDC__
index_to_name (int index)
#else /* ! __STDC__ */
index_to_name (index)
int index;
#endif /* ! __STDC__ */
{
return (index == ShiftMapIndex ? "Shift" :
index == LockMapIndex ? "Lock" :
index == ControlMapIndex ? "Control" :
index == Mod1MapIndex ? "1" :
index == Mod2MapIndex ? "2" :
index == Mod3MapIndex ? "3" :
index == Mod4MapIndex ? "4" :
index == Mod5MapIndex ? "5" :
"???");
}
static char *
#ifdef __STDC__
keysym_to_name (KeySym keysym)
#else /* ! __STDC__ */
keysym_to_name (keysym)
KeySym keysym;
#endif /* ! __STDC__ */
{
char *n = XKeysymToString (keysym);
if (! n) /* ought not happen, but does if XKeysymDB isn't installed right */
{
n = (char *) malloc (20); /* leaks! */
sprintf (n, "Unknown-KeySym-0x%X", (int) keysym);
}
return n;
}
static int
#ifdef __STDC__
stop_the_insanity (KeyboardWidget widget,
int keycode,
KeySym *keysyms,
int count,
unsigned long modbits,
XModifierKeymap *modmap)
#else /* ! __STDC__ */
stop_the_insanity (widget, keycode, keysyms, count, modbits, modmap)
KeyboardWidget widget;
int keycode;
KeySym *keysyms;
int count;
unsigned long modbits;
XModifierKeymap *modmap;
#endif /* ! __STDC__ */
{
int i;
KeySym type = 0; /* The canonical modifier keysym on this key */
KeySym basic_keysym = 0; /* The non-canonical version */
KeySym companion = 0; /* The "other" version of this key */
/* Check that the keysyms that are attached to this key are compatible:
It is incorrect to put Control_[LR] and Meta_[LR] on the same key.
*/
{
KeySym conflict = 0;
KeySym nonmod = 0;
for (i = 0; i < count && !conflict; i++)
switch ((int) keysyms [i])
{
#define check(k) \
case k: \
if (type && type != k) \
conflict = keysyms [i]; \
else \
type = k, \
basic_keysym = keysyms[i]; \
break
case XK_Meta_R: check (XK_Meta_L);
case XK_Super_R: check (XK_Super_L);
case XK_Hyper_R: check (XK_Hyper_L);
case XK_Alt_R: check (XK_Alt_L);
case XK_Control_R: check (XK_Control_L);
case XK_Shift_R: check (XK_Shift_L);
check (XK_Shift_Lock);
check (XK_Caps_Lock);
check (XK_Mode_switch);
#undef check
default:
nonmod = keysyms [i];
break;
}
switch ((int) basic_keysym)
{
case XK_Meta_L: companion = XK_Meta_R; break;
case XK_Super_L: companion = XK_Super_R; break;
case XK_Hyper_L: companion = XK_Hyper_R; break;
case XK_Alt_L: companion = XK_Alt_R; break;
case XK_Control_L: companion = XK_Control_R; break;
case XK_Shift_L: companion = XK_Shift_R; break;
case XK_Meta_R: companion = XK_Meta_L; break;
case XK_Super_R: companion = XK_Super_L; break;
case XK_Hyper_R: companion = XK_Hyper_L; break;
case XK_Alt_R: companion = XK_Alt_L; break;
case XK_Control_R: companion = XK_Control_L; break;
case XK_Shift_R: companion = XK_Shift_L; break;
}
if (nonmod && type) /* all modifier syms and non-mod syms conflict. */
{
conflict = type;
type = nonmod;
}
if (conflict)
return (y_or_n_p_with_args (widget, "keysymConflictWarning",
"ok", "cancel", 0,
keysym_to_name (type),
keysym_to_name (conflict),
0, 0, 0, 0));
}
/* Check that the modifier bits are compatible with the keysyms:
It is incorrect to put ModControl on a key with any keysym other
than Control_L or Control_R.
*/
{
int losing = 0;
int bad_index = 0;
if (modbits & ControlMask && type != XK_Control_L)
losing = 1, bad_index = ControlMapIndex;
else if (modbits & ShiftMask && type != XK_Shift_L)
losing = 1, bad_index = ShiftMapIndex;
else if (modbits & LockMask && type != XK_Caps_Lock &&
type != XK_Shift_Lock)
losing = 1, bad_index = LockMapIndex;
if (losing)
return (y_or_n_p_with_args (widget, "badModifiersWarning",
"ok", "cancel", 0,
index_to_name (bad_index),
(bad_index == ShiftMapIndex ? "Shift_L" :
bad_index == LockMapIndex ? "Caps_Lock" :
bad_index == ControlMapIndex ? "Control_L" :
"<<INTERNAL ERROR>>"),
(bad_index == ShiftMapIndex ? "Shift_R" :
bad_index == LockMapIndex ? "Shift_Lock" :
bad_index == ControlMapIndex ? "Control_R" :
"<<INTERNAL ERROR>>"),
index_to_name (bad_index),
0, 0));
}
/* Do the opposite check - the previous code checked for the case of
attaching ModControl to Meta_L, but this checks for attaching Mod1
to Control_L. */
if ((type == XK_Shift_L || type == XK_Control_L ||
type == XK_Shift_Lock || type == XK_Caps_Lock) &&
(modbits & (~ (ShiftMask | LockMask | ControlMask))))
return (y_or_n_p_with_args (widget, "badModifiersWarning2",
"ok", "cancel", 0,
keysym_to_name (basic_keysym),
(type == XK_Shift_L ? "Shift" :
type == XK_Control_L ? "Control" :
type == XK_Shift_Lock ? "Lock" :
type == XK_Caps_Lock ? "Lock" :
"<<INTERNAL ERROR>>"),
(type == XK_Shift_L ? "Shift" :
type == XK_Control_L ? "Control" :
type == XK_Shift_Lock ? "Shift_Lock" :
type == XK_Caps_Lock ? "Caps_Lock" :
"<<INTERNAL ERROR>>"),
0, 0, 0));
/* Check that the key is generating at most one modifier bit.
The behavior of more than one modifier bit is undefined.
If this is a modifier keysym, warn if it has no modifier bits
at all (which has defined behavior, and may be what is desired,
but which novices are likely to do by accident.)
*/
{
int bitcount = 0;
int i;
for (i = 0; i < 8; i++)
if (modbits & (1<<i)) bitcount++;
if (bitcount > 1)
return (y_or_n_p (widget, "multipleModifiersWarning",
"ok", "cancel", 0));
else if (bitcount == 0 && type != 0)
return (y_or_n_p_with_args (widget, "noModifiersWarning",
"ok", "cancel", 0,
keysym_to_name (type), 0, 0, 0, 0, 0));
}
/* Check that some other (incompatible) key is not generating the same
modifiers as this key. */
{
Display *dpy = XtDisplay ((Widget) widget);
unsigned long conflict_code = 0;
KeySym conflict_sym = 0;
int conflict_bit = 0;
int this_bit = 0;
int modifier_index, modifier_key;
int mkpm = modmap->max_keypermod;
for (modifier_index = 0; modifier_index < 8; modifier_index++)
/* Ignore modifier bits which this key does not generate. */
if ((1 << modifier_index) & modbits)
for (modifier_key = 0; modifier_key < mkpm; modifier_key++)
{
int column;
KeySym last_sym = 0;
for (column = 0; column < 4; column += 2)
{
KeyCode code2 = modmap->modifiermap [modifier_index * mkpm
+ modifier_key];
KeySym sym = (code2
? XKeycodeToKeysym (dpy, code2, column)
: 0);
KeySym this = 0;
if (!sym) continue;
if (sym == last_sym) continue;
last_sym = sym;
switch ((int) sym)
{
case XK_Meta_R: this = XK_Meta_L; break;
case XK_Super_R: this = XK_Super_R; break;
case XK_Hyper_R: this = XK_Hyper_L; break;
case XK_Alt_R: this = XK_Alt_L; break;
case XK_Control_R: this = XK_Control_L; break;
case XK_Shift_R: this = XK_Shift_L; break;
default: this = sym; break;
}
if (this != type && /* conflicting keysyms */
/* but ignore conflicts with the previous version of
this very key! */
code2 != keycode)
{
conflict_code = code2;
conflict_sym = sym;
conflict_bit = modifier_index;
goto DONE;
}
}
}
DONE:
if (conflict_code)
{
KeyWidget kw = keycode_to_key (widget, conflict_code);
return (y_or_n_p_with_args (widget, "modifiersConflictWarning",
"ok", "cancel", 0,
keysym_to_name (basic_keysym),
index_to_name (conflict_bit),
(char *) conflict_code,
(kw ? kw->key.key_name : "???"),
keysym_to_name (conflict_sym),
0));
}
/* Check that the semantically equivalent keys do not generate
different modifier bits than this one. */
conflict_sym = 0;
conflict_bit = 0;
conflict_code = 0;
for (modifier_index = 0; modifier_index < 8; modifier_index++)
/* Ignore modifier bits which this key generates. */
if ((1 << modifier_index) & modbits)
this_bit = modifier_index;
else if (conflict_code)
;
else
for (modifier_key = 0; modifier_key < mkpm; modifier_key++)
{
int column;
for (column = 0; column < 4; column += 2)
{
KeyCode code2 = modmap->modifiermap [modifier_index * mkpm
+ modifier_key];
KeySym sym = (code2
? XKeycodeToKeysym (dpy, code2, column)
: 0);
if (sym &&
!conflict_code &&
(sym == basic_keysym || sym == companion) &&
code2 != keycode)
{
conflict_code = code2;
conflict_sym = sym;
conflict_bit = modifier_index;
/* keep going to find this_bit */
break;
}
}
}
if (conflict_code)
{
KeyWidget kw = keycode_to_key (widget, conflict_code);
return (y_or_n_p_with_args (widget, "modifiersConflictWarning2",
"ok", "cancel", 0,
keysym_to_name (basic_keysym),
index_to_name (this_bit),
(char *) conflict_code,
(kw ? kw->key.key_name : "???"),
keysym_to_name (conflict_sym),
index_to_name (conflict_bit)
));
}
}
/* Should we also issue a message along the lines of
This key is not normally a `chording' key (that is, a key that is
held down to modify some other keypress.) It is unlikely that
attaching a modifier to it will do anything sensible. If you want
this to be a {Control,Shift,Lock,Meta} key, change its keysym to
***_L or ***_R.
That wouldn't be appropriate for the default layout of the OpenWound
keyboard, which attaches modifiers to random function keys (I imagine
this has something to do with drag-and-drop, but I don't know how it
works.)
Actually maybe a different message would be appropriate for Multi_key,
since people sometimes misinterpret the description of that key as being
a modifier key, when in fact it's a prefix key and shouldn't have any
modifier bits on it.
*/
return 0;
}
|