src/Screen.cc (raw)
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 |
// Screen.cc for Fluxbox Window Manager // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) // // Screen.cc for Blackbox - an X11 Window manager // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // $Id: Screen.cc,v 1.187 2003/06/20 01:48:06 fluxgen Exp $ #include "Screen.hh" #include "I18n.hh" #include "fluxbox.hh" #include "ImageControl.hh" #include "Toolbar.hh" #include "Window.hh" #include "Workspace.hh" #include "StringUtil.hh" #include "Netizen.hh" #include "Directory.hh" #include "WinButton.hh" #include "SimpleCommand.hh" #include "FbWinFrameTheme.hh" #include "MenuTheme.hh" #include "RootTheme.hh" #include "WinButtonTheme.hh" #include "FbCommands.hh" #include "BoolMenuItem.hh" #include "IntResMenuItem.hh" #include "MacroCommand.hh" #include "XLayerItem.hh" #include "MultLayers.hh" #include "FbMenu.hh" #include "LayerMenu.hh" #include "WinClient.hh" #include "Subject.hh" #include "FbWinFrame.hh" #include "FbWindow.hh" #include "Strut.hh" //use GNU extensions #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif // _GNU_SOURCE #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H #ifdef SLIT #include "Slit.hh" #endif // SLIT #ifdef STDC_HEADERS #include <sys/types.h> #endif // STDC_HEADERS #ifdef HAVE_CTYPE_H #include <ctype.h> #endif // HAVE_CTYPE_H #ifdef HAVE_DIRENT_H #include <dirent.h> #endif // HAVE_DIRENT_H #ifdef HAVE_LOCALE_H #include <locale.h> #endif // HAVE_LOCALE_H #ifdef HAVE_UNISTD_H #include <sys/types.h> #include <unistd.h> #endif // HAVE_UNISTD_H #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif // HAVE_SYS_STAT_H #ifdef HAVE_STDARG_H #include <stdarg.h> #endif // HAVE_STDARG_H #ifdef TIME_WITH_SYS_TIME #include <sys/time.h> #include <time.h> #else // !TIME_WITH_SYS_TIME #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #else // !HAVE_SYS_TIME_H #include <time.h> #endif // HAVE_SYS_TIME_H #endif // TIME_WITH_SYS_TIME #ifndef MAXPATHLEN #define MAXPATHLEN 255 #endif // MAXPATHLEN #include <X11/Xatom.h> #include <X11/keysym.h> #include <X11/cursorfont.h> #ifdef XINERAMA extern "C" { #include <X11/extensions/Xinerama.h> } #endif // XINERAMA #include <iostream> #include <memory> #include <algorithm> #include <functional> using namespace std; static bool running = true; namespace { int anotherWMRunning(Display *display, XErrorEvent *) { cerr<<I18n::instance()-> getMessage(FBNLS::ScreenSet, FBNLS::ScreenAnotherWMRunning, "BScreen::BScreen: an error occured while querying the X server.\n" " another window manager already running on display ")<<DisplayString(display)<<endl; running = false; return -1; } FbTk::Menu *createMenuFromScreen(BScreen &screen) { FbTk::Menu *menu = new FbMenu(*screen.menuTheme(), screen.screenNumber(), screen.imageControl(), *screen.layerManager().getLayer(Fluxbox::instance()->getMenuLayer())); return menu; } class FocusModelMenuItem : public FbTk::MenuItem { public: FocusModelMenuItem(const char *label, BScreen &screen, Fluxbox::FocusModel model, FbTk::RefCount<FbTk::Command> &cmd): FbTk::MenuItem(label, cmd), m_screen(screen), m_focusmodel(model) { } bool isEnabled() const { return m_screen.getFocusModel() != m_focusmodel; } void click(int button, int time) { m_screen.saveFocusModel(m_focusmodel); FbTk::MenuItem::click(button, time); } private: BScreen &m_screen; Fluxbox::FocusModel m_focusmodel; }; }; // End anonymous namespace template<> void FbTk::Resource<Toolbar::Placement>:: setFromString(const char *strval) { if (strcasecmp(strval, "TopLeft")==0) m_value = Toolbar::TOPLEFT; else if (strcasecmp(strval, "BottomLeft")==0) m_value = Toolbar::BOTTOMLEFT; else if (strcasecmp(strval, "TopCenter")==0) m_value = Toolbar::TOPCENTER; else if (strcasecmp(strval, "BottomCenter")==0) m_value = Toolbar::BOTTOMCENTER; else if (strcasecmp(strval, "TopRight")==0) m_value = Toolbar::TOPRIGHT; else if (strcasecmp(strval, "BottomRight")==0) m_value = Toolbar::BOTTOMRIGHT; else if (strcasecmp(strval, "LeftTop") == 0) m_value = Toolbar::LEFTTOP; else if (strcasecmp(strval, "LeftCenter") == 0) m_value = Toolbar::LEFTCENTER; else if (strcasecmp(strval, "LeftBottom") == 0) m_value = Toolbar::LEFTBOTTOM; else if (strcasecmp(strval, "RightTop") == 0) m_value = Toolbar::RIGHTTOP; else if (strcasecmp(strval, "RightCenter") == 0) m_value = Toolbar::RIGHTCENTER; else if (strcasecmp(strval, "RightBottom") == 0) m_value = Toolbar::RIGHTBOTTOM; else setDefaultValue(); } template<> void FbTk::Resource<ToolbarHandler::ToolbarMode>:: setFromString(const char *strval) { if (strcasecmp(strval, "Off") == 0) m_value = ToolbarHandler::OFF; else if (strcasecmp(strval, "None") == 0) m_value = ToolbarHandler::NONE; else if (strcasecmp(strval, "Icons") == 0) m_value = ToolbarHandler::ICONS; else if (strcasecmp(strval, "WorkspaceIcons") == 0) m_value = ToolbarHandler::WORKSPACEICONS; else if (strcasecmp(strval, "Workspace") == 0) m_value = ToolbarHandler::WORKSPACE; else if (strcasecmp(strval, "AllWindows") == 0) m_value = ToolbarHandler::ALLWINDOWS; else setDefaultValue(); } string FbTk::Resource<Toolbar::Placement>:: getString() { switch (m_value) { case Toolbar::TOPLEFT: return string("TopLeft"); break; case Toolbar::BOTTOMLEFT: return string("BottomLeft"); break; case Toolbar::TOPCENTER: return string("TopCenter"); break; case Toolbar::BOTTOMCENTER: return string("BottomCenter"); break; case Toolbar::TOPRIGHT: return string("TopRight"); break; case Toolbar::BOTTOMRIGHT: return string("BottomRight"); break; case Toolbar::LEFTTOP: return string("LeftTop"); break; case Toolbar::LEFTCENTER: return string("LeftCenter"); break; case Toolbar::LEFTBOTTOM: return string("LeftBottom"); break; case Toolbar::RIGHTTOP: return string("RightTop"); break; case Toolbar::RIGHTCENTER: return string("RightCenter"); break; case Toolbar::RIGHTBOTTOM: return string("RightBottom"); break; } //default string return string("BottomCenter"); } template<> string FbTk::Resource<ToolbarHandler::ToolbarMode>:: getString() { switch (m_value) { case ToolbarHandler::OFF: return string("Off"); break; case ToolbarHandler::NONE: return string("None"); break; case ToolbarHandler::LASTMODE: case ToolbarHandler::ICONS: return string("Icons"); break; case ToolbarHandler::WORKSPACEICONS: return string("WorkspaceIcons"); break; case ToolbarHandler::WORKSPACE: return string("Workspace"); break; case ToolbarHandler::ALLWINDOWS: return string("AllWindows"); break; } // default string return string("Icons"); } namespace { class AddWorkspaceCmd:public FbTk::Command { public: explicit AddWorkspaceCmd(BScreen &scrn):m_screen(scrn) { } void execute() { m_screen.addWorkspace(); } private: BScreen &m_screen; }; class RemoveLastWorkspaceCmd:public FbTk::Command { public: explicit RemoveLastWorkspaceCmd(BScreen &scrn):m_screen(scrn) { } void execute() { m_screen.removeLastWorkspace(); } private: BScreen &m_screen; }; class ReloadStyleCmd: public FbTk::Command { public: void execute() { FbCommands::SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename()); cmd.execute(); } }; void setupWorkspacemenu(BScreen &scr, FbTk::Menu &menu) { menu.removeAll(); // clear all items using namespace FbTk; menu.setLabel("Workspace"); RefCount<Command> new_workspace(new AddWorkspaceCmd(scr)); RefCount<Command> remove_last(new RemoveLastWorkspaceCmd(scr)); menu.insert("New Workspace", new_workspace); menu.insert("Remove Last", remove_last); // for each workspace add workspace name and it's menu to our workspace menu for (size_t workspace = 0; workspace < scr.getCount(); ++workspace) { Workspace *wkspc = scr.getWorkspace(workspace); menu.insert(wkspc->name().c_str(), &wkspc->menu()); } // update graphics menu.update(); } }; template<> void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) { if (strcasecmp(strval, "TopLeft")==0) m_value = Slit::TOPLEFT; else if (strcasecmp(strval, "CenterLeft")==0) m_value = Slit::CENTERLEFT; else if (strcasecmp(strval, "BottomLeft")==0) m_value = Slit::BOTTOMLEFT; else if (strcasecmp(strval, "TopCenter")==0) m_value = Slit::TOPCENTER; else if (strcasecmp(strval, "BottomCenter")==0) m_value = Slit::BOTTOMCENTER; else if (strcasecmp(strval, "TopRight")==0) m_value = Slit::TOPRIGHT; else if (strcasecmp(strval, "CenterRight")==0) m_value = Slit::CENTERRIGHT; else if (strcasecmp(strval, "BottomRight")==0) m_value = Slit::BOTTOMRIGHT; else setDefaultValue(); } template<> void FbTk::Resource<Slit::Direction>::setFromString(const char *strval) { if (strcasecmp(strval, "Vertical") == 0) m_value = Slit::VERTICAL; else if (strcasecmp(strval, "Horizontal") == 0) m_value = Slit::HORIZONTAL; else setDefaultValue(); } string FbTk::Resource<Slit::Placement>::getString() { switch (m_value) { case Slit::TOPLEFT: return string("TopLeft"); break; case Slit::CENTERLEFT: return string("CenterLeft"); break; case Slit::BOTTOMLEFT: return string("BottomLeft"); break; case Slit::TOPCENTER: return string("TopCenter"); break; case Slit::BOTTOMCENTER: return string("BottomCenter"); break; case Slit::TOPRIGHT: return string("TopRight"); break; case Slit::CENTERRIGHT: return string("CenterRight"); break; case Slit::BOTTOMRIGHT: return string("BottomRight"); break; } //default string return string("BottomRight"); } template<> string FbTk::Resource<Slit::Direction>::getString() { switch (m_value) { case Slit::VERTICAL: return string("Vertical"); break; case Slit::HORIZONTAL: return string("Horizontal"); break; } // default string return string("Vertical"); } template <> void FbTk::ThemeItem<std::string>::load() { } template <> void FbTk::ThemeItem<std::string>::setDefaultValue() { *(*this) = ""; } template <> void FbTk::ThemeItem<std::string>::setFromString(const char *str) { *(*this) = (str ? str : ""); } template <> void FbTk::ThemeItem<int>::load() { } template <> void FbTk::ThemeItem<int>::setDefaultValue() { *(*this) = 0; } template <> void FbTk::ThemeItem<int>::setFromString(const char *str) { if (str == 0) return; sscanf(str, "%d", &m_value); } BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm, const std::string &scrname, const std::string &altscrname): toolbar_auto_hide(rm, false, scrname+".toolbar.autoHide", altscrname+".Toolbar.AutoHide"), image_dither(rm, false, scrname+".imageDither", altscrname+".ImageDither"), opaque_move(rm, false, "session.opaqueMove", "Session.OpaqueMove"), full_max(rm, true, scrname+".fullMaximization", altscrname+".FullMaximization"), sloppy_window_grouping(rm, true, scrname+".sloppywindowgrouping", altscrname+".SloppyWindowGrouping"), workspace_warping(rm, true, scrname+".workspacewarping", altscrname+".WorkspaceWarping"), desktop_wheeling(rm, true, scrname+".desktopwheeling", altscrname+".DesktopWheeling"), show_window_pos(rm, true, scrname+".showwindowposition", altscrname+".ShowWindowPosition"), focus_last(rm, true, scrname+".focusLastWindow", altscrname+".FocusLastWindow"), focus_new(rm, true, scrname+".focusNewWindows", altscrname+".FocusNewWindows"), antialias(rm, false, scrname+".antialias", altscrname+".Antialias"), auto_raise(rm, false, scrname+".autoRaise", altscrname+".AutoRaise"), click_raises(rm, true, scrname+".clickRaises", altscrname+".ClickRaises"), rootcommand(rm, "", scrname+".rootCommand", altscrname+".RootCommand"), focus_model(rm, Fluxbox::CLICKTOFOCUS, scrname+".focusModel", altscrname+".FocusModel"), workspaces(rm, 1, scrname+".workspaces", altscrname+".Workspaces"), toolbar_width_percent(rm, 65, scrname+".toolbar.widthPercent", altscrname+".Toolbar.WidthPercent"), edge_snap_threshold(rm, 0, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"), menu_alpha(rm, 255, scrname+".menuAlpha", altscrname+".MenuAlpha"), toolbar_layernum(rm, Fluxbox::Layer(Fluxbox::instance()->getDesktopLayer()), scrname+".toolbar.layer", altscrname+".Toolbar.Layer"), toolbar_mode(rm, ToolbarHandler::ICONS, scrname+".toolbar.mode", altscrname+".Toolbar.Mode"), toolbar_on_head(rm, 0, scrname+".toolbar.onhead", altscrname+".Toolbar.onHead"), toolbar_placement(rm, Toolbar::BOTTOMCENTER, scrname+".toolbar.placement", altscrname+".Toolbar.Placement") { }; BScreen::BScreen(FbTk::ResourceManager &rm, const string &screenname, const string &altscreenname, int scrn, int num_layers) : m_clientlist_sig(*this), // client signal m_workspacecount_sig(*this), // workspace count signal m_workspacenames_sig(*this), // workspace names signal m_currentworkspace_sig(*this), // current workspace signal m_layermanager(num_layers), cycling_focus(false), cycling_last(0), m_windowtheme(new FbWinFrameTheme(scrn)), // the order of windowtheme and winbutton theme is important // because winbutton need to rescale the pixmaps in winbutton theme // after fbwinframe have resized them m_winbutton_theme(new WinButtonTheme(scrn)), m_menutheme(new FbTk::MenuTheme(scrn)), m_root_theme(new RootTheme(scrn, *resource.rootcommand)), m_root_window(scrn), resource(rm, screenname, altscreenname), m_name(screenname), m_altname(altscreenname), m_resource_manager(rm), m_toolbarhandler(0), m_available_workspace_area(new Strut(0, 0, 0, 0)), m_xinerama_headinfo(0) { Display *disp = FbTk::App::instance()->display(); initXinerama(); // setup error handler to catch "screen already managed by other wm" XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning); rootWindow().setEventMask(ColormapChangeMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask| SubstructureNotifyMask); XSync(disp, False); XSetErrorHandler((XErrorHandler) old); managed = running; if (! managed) return; I18n *i18n = I18n::instance(); fprintf(stderr, i18n->getMessage(FBNLS::ScreenSet, FBNLS::ScreenManagingScreen, "BScreen::BScreen: managing screen %d " "using visual 0x%lx, depth %d\n"), screenNumber(), XVisualIDFromVisual(rootWindow().visual()), rootWindow().depth()); cycling_window = focused_list.end(); rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); Fluxbox *fluxbox = Fluxbox::instance(); // setup image cache engine m_image_control.reset(new FbTk::ImageControl(scrn, true, fluxbox->colorsPerChannel(), fluxbox->getCacheLife(), fluxbox->getCacheMax())); imageControl().installRootColormap(); root_colormap_installed = true; // load this screens resources fluxbox->load_rc(*this); FbTk::Menu::setAlpha(*resource.menu_alpha); imageControl().setDither(*resource.image_dither); // setup windowtheme, toolbartheme for antialias // before we load the theme winFrameTheme().font().setAntialias(*resource.antialias); menuTheme()->titleFont().setAntialias(*resource.antialias); menuTheme()->frameFont().setAntialias(*resource.antialias); // load database for theme engine FbTk::ThemeManager::instance().load(fluxbox->getStyleFilename().c_str()); // create geometry window const char *s = i18n->getMessage(FBNLS::ScreenSet, FBNLS::ScreenPositionLength, "W: 0000 x H: 0000"); int geom_h = winFrameTheme().font().height() + m_root_theme->bevelWidth()*2; int geom_w = winFrameTheme().font().textWidth(s, strlen(s)) + m_root_theme->bevelWidth()*2; XSetWindowAttributes attrib; unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder; attrib.border_pixel = m_root_theme->borderColor().pixel(); attrib.colormap = rootWindow().colormap(); attrib.save_under = true; m_geom_window = XCreateWindow(disp, rootWindow().window(), 0, 0, geom_w, geom_h, rootTheme().borderWidth(), rootWindow().depth(), InputOutput, rootWindow().visual(), mask, &attrib); geom_visible = false; geom_pixmap = 0; renderGeomWindow(); // setup workspaces and workspace menu workspacemenu.reset(createMenuFromScreen(*this)); workspacemenu->setInternalMenu(); if (*resource.workspaces != 0) { for (int i = 0; i < *resource.workspaces; ++i) { Workspace *wkspc = new Workspace(*this, m_layermanager, getNameOfWorkspace(m_workspaces_list.size()), m_workspaces_list.size()); m_workspaces_list.push_back(wkspc); } } else { // create at least one workspace Workspace *wkspc = new Workspace(*this, m_layermanager, getNameOfWorkspace(m_workspaces_list.size()), m_workspaces_list.size()); m_workspaces_list.push_back(wkspc); } setupWorkspacemenu(*this, *workspacemenu); m_current_workspace = m_workspaces_list.front(); #ifdef SLIT m_slit.reset(new Slit(*this, *layerManager().getLayer(Fluxbox::instance()->getDesktopLayer()), Fluxbox::instance()->getSlitlistFilename().c_str())); //!! TODO: we shouldn't do this more than once, but since slit handles it's own resources // we must do this. fluxbox->load_rc(*this); #endif // SLIT // create toolbarhandler for toolbar m_toolbarhandler.reset(new ToolbarHandler(*this, toolbarMode())); m_configmenu.reset(createMenuFromScreen(*this)); setupConfigmenu(*m_configmenu.get()); m_configmenu->setInternalMenu(); workspacemenu->setItemSelected(2, true); // if toolbar needs initialisation, do it in ToolbarHandler instead // so it will work when destroyed later etc initMenu(); // create and initiate rootmenu //update menus m_rootmenu->update(); m_configmenu->update(); #ifdef SLIT if (m_slit.get()) m_slit->reconfigure(); #endif // SLIT // start with workspace 0 changeWorkspaceID(0); updateNetizenWorkspaceCount(); int i; unsigned int nchild; Window r, p, *children; XQueryTree(disp, rootWindow().window(), &r, &p, &children, &nchild); // preen the window list of all icon windows... for better dockapp support for (i = 0; i < (int) nchild; i++) { if (children[i] == None) continue; XWMHints *wmhints = XGetWMHints(FbTk::App::instance()->display(), children[i]); if (wmhints) { if ((wmhints->flags & IconWindowHint) && (wmhints->icon_window != children[i])) for (int j = 0; j < (int) nchild; j++) { if (children[j] == wmhints->icon_window) { children[j] = None; break; } } XFree(wmhints); } } // manage shown windows for (i = 0; i < (int) nchild; ++i) { if (children[i] == None || (! fluxbox->validateWindow(children[i]))) continue; XWindowAttributes attrib; if (XGetWindowAttributes(disp, children[i], &attrib)) { if (attrib.override_redirect) continue; if (attrib.map_state != IsUnmapped) { FluxboxWindow *win = createWindow(children[i]); if (win) { XMapRequestEvent mre; mre.window = children[i]; win->mapRequestEvent(mre); } } } } if (! isSloppyFocus() && toolbar() != 0) { XSetInputFocus(disp, toolbar()->window().window(), RevertToParent, CurrentTime); } // set the toolbarhandler after the windows are setup, so it catches their state properly XFree(children); XFlush(disp); } BScreen::~BScreen() { if (! managed) return; if (geom_pixmap != None) imageControl().removeImage(geom_pixmap); removeWorkspaceNames(); Workspaces::iterator w_it = m_workspaces_list.begin(); Workspaces::iterator w_it_end = m_workspaces_list.end(); for(; w_it != w_it_end; ++w_it) { delete (*w_it); } m_workspaces_list.clear(); Icons::iterator i_it = m_icon_list.begin(); Icons::iterator i_it_end = m_icon_list.end(); for(; i_it != i_it_end; ++i_it) { delete (*i_it); } m_icon_list.clear(); Netizens::iterator n_it = m_netizen_list.begin(); Netizens::iterator n_it_end = m_netizen_list.end(); for(; n_it != n_it_end; ++n_it) { delete (*n_it); } m_netizen_list.clear(); #ifdef XINERAMA if (hasXinerama() && m_xinerama_headinfo) { delete [] m_xinerama_headinfo; } #endif // XINERAMA } const FbTk::Menu &BScreen::toolbarModemenu() const { return m_toolbarhandler->getModeMenu(); } FbTk::Menu &BScreen::toolbarModemenu() { return m_toolbarhandler->getModeMenu(); } unsigned int BScreen::currentWorkspaceID() const { return m_current_workspace->workspaceID(); } Pixmap BScreen::rootPixmap() const { Pixmap root_pm = 0; Display *disp = FbTk::App::instance()->display(); Atom real_type; int real_format; unsigned long items_read, items_left; unsigned int *data; if (rootWindow().property(XInternAtom(disp, "_XROOTPMAP_ID", false), 0L, 1L, false, XA_PIXMAP, &real_type, &real_format, &items_read, &items_left, (unsigned char **) &data) && items_read) { root_pm = (Pixmap) (*data); XFree(data); } return root_pm; } unsigned int BScreen::maxLeft(int head) const { if (hasXinerama()) return getHeadX(head); else // we ignore strut if we're doing full maximization return doFullMax() ? 0 : m_available_workspace_area->left(); } unsigned int BScreen::maxRight(int head) const { if (hasXinerama()) return getHeadX(head) + getHeadWidth(head); else // we ignore strut if we're doing full maximization return doFullMax() ? width() : width() - m_available_workspace_area->right(); } unsigned int BScreen::maxTop(int head) const { if (hasXinerama()) return getHeadY(head); else // we ignore strut if we're doing full maximization return doFullMax() ? 0 : m_available_workspace_area->top(); } unsigned int BScreen::maxBottom(int head) const { if (hasXinerama()) return getHeadY(head) + getHeadHeight(head); else // we ignore strut if we're doing full maximization return doFullMax() ? height() : height() - m_available_workspace_area->bottom(); } void BScreen::reconfigure() { #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): BScreen::reconfigure"<<endl; #endif // DEBUG FbTk::Menu::setAlpha(*resource.menu_alpha); Fluxbox::instance()->loadRootCommand(*this); // setup windowtheme, toolbartheme for antialias winFrameTheme().font().setAntialias(*resource.antialias); m_menutheme->titleFont().setAntialias(*resource.antialias); m_menutheme->frameFont().setAntialias(*resource.antialias); if (toolbar() && toolbar()->theme().font().isAntialias() != *resource.antialias) toolbar()->theme().font().setAntialias(*resource.antialias); // load theme std::string theme_filename(Fluxbox::instance()->getStyleFilename()); FbTk::ThemeManager::instance().load(theme_filename.c_str()); I18n *i18n = I18n::instance(); const char *s = i18n->getMessage(FBNLS::ScreenSet, FBNLS::ScreenPositionLength, "W: 0000 x H: 0000"); int l = strlen(s); //TODO: repeated from somewhere else? int geom_h = winFrameTheme().font().height() + m_root_theme->bevelWidth()*2; int geom_w = winFrameTheme().font().textWidth(s, l) + m_root_theme->bevelWidth()*2; m_geom_window.resize(geom_w, geom_h); renderGeomWindow(); m_geom_window.setBorderWidth(m_root_theme->borderWidth()); m_geom_window.setBorderColor(m_root_theme->borderColor()); //reconfigure menus workspacemenu->reconfigure(); m_configmenu->reconfigure(); // We need to check to see if the timestamps // changed before we actually can restore the menus // in the same way, since we can't really say if // any submenu is in the same place as before if the // menu changed. // if timestamp changed then no restoring bool restore_menus = ! Fluxbox::instance()->menuTimestampsChanged(); // destroy old timestamps Fluxbox::instance()->clearMenuFilenames(); // save submenu index so we can restore them afterwards vector<int> remember_sub; if (restore_menus) { FbTk::Menu *menu = m_rootmenu.get(); while (menu) { int r = menu->currentSubmenu(); if (r < 0) break; remember_sub.push_back(r); menu = menu->find(r)->submenu(); } } initMenu(); m_rootmenu->reconfigure(); if (restore_menus) { // restore submenus, no timestamp changed FbTk::Menu *menu = m_rootmenu.get(); for (int i = 0; i < (int)remember_sub.size(); i++ ) { int sub = remember_sub[i]; if (!menu || sub < 0) break; FbTk::MenuItem *item = menu->find(sub); if (item != 0) { menu->drawSubmenu(sub); menu = item->submenu(); } else menu = 0; } } if (toolbar()) { toolbar()->setPlacement(*resource.toolbar_placement); toolbar()->reconfigure(); } #ifdef SLIT if (slit()) slit()->reconfigure(); #endif // SLIT //reconfigure workspaces for_each(m_workspaces_list.begin(), m_workspaces_list.end(), mem_fun(&Workspace::reconfigure)); //reconfigure Icons for_each(m_icon_list.begin(), m_icon_list.end(), mem_fun(&FluxboxWindow::reconfigure)); imageControl().timeout(); } void BScreen::rereadMenu() { initMenu(); m_rootmenu->reconfigure(); } void BScreen::removeWorkspaceNames() { m_workspace_names.erase(m_workspace_names.begin(), m_workspace_names.end()); } void BScreen::updateWorkspaceNamesAtom() { m_workspacenames_sig.notify(); } void BScreen::addIcon(FluxboxWindow *w) { if (! w) return; w->setWindowNumber(m_icon_list.size()); m_icon_list.push_back(w); } void BScreen::removeIcon(FluxboxWindow *w) { if (! w) return; Icons::iterator erase_it = remove_if(m_icon_list.begin(), m_icon_list.end(), bind2nd(equal_to<FluxboxWindow *>(), w)); if (erase_it != m_icon_list.end()) m_icon_list.erase(erase_it); Icons::iterator it = m_icon_list.begin(); Icons::iterator it_end = m_icon_list.end(); for (int i = 0; it != it_end; ++it, ++i) { (*it)->setWindowNumber(i); } } void BScreen::removeWindow(FluxboxWindow *win) { if (win->isIconic()) removeIcon(win); else getWorkspace(win->workspaceNumber())->removeWindow(win); } void BScreen::removeClient(WinClient &client) { WinClient *cyc = *cycling_window; FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow(); focused_list.remove(&client); if (cyc == &client) { cycling_window = focused_list.end(); } else if (focused && &focused->winClient() == &client) { // if we are focused, then give our focus to our transient parent // or revert normally if (client.transientFor() && client.transientFor()->fbwindow()) client.transientFor()->fbwindow()->setInputFocus(); else Fluxbox::instance()->revertFocus(focused->screen()); } // update client lists for_each(getWorkspacesList().begin(), getWorkspacesList().end(), mem_fun(&Workspace::updateClientmenu)); } FluxboxWindow *BScreen::getIcon(unsigned int index) { if (index < m_icon_list.size()) return m_icon_list[index]; return 0; } void BScreen::setAntialias(bool value) { if (*resource.antialias == value) return; resource.antialias = value; reconfigure(); } int BScreen::addWorkspace() { Workspace *wkspc = new Workspace(*this, m_layermanager, "", m_workspaces_list.size()); m_workspaces_list.push_back(wkspc); addWorkspaceName(wkspc->name().c_str()); // update names //add workspace to workspacemenu workspacemenu->insert(wkspc->name().c_str(), &wkspc->menu(), wkspc->workspaceID() + 2); //+2 so we add it after "remove last" item workspacemenu->update(); saveWorkspaces(m_workspaces_list.size()); if (toolbar() != 0) toolbar()->reconfigure(); updateNetizenWorkspaceCount(); return m_workspaces_list.size(); } /// removes last workspace /// @return number of desktops left int BScreen::removeLastWorkspace() { if (m_workspaces_list.size() <= 1) return 0; Workspace *wkspc = m_workspaces_list.back(); if (m_current_workspace->workspaceID() == wkspc->workspaceID()) changeWorkspaceID(m_current_workspace->workspaceID() - 1); wkspc->removeAll(); workspacemenu->remove(wkspc->workspaceID()+2); // + 2 is where workspaces starts workspacemenu->update(); //remove last workspace m_workspaces_list.pop_back(); delete wkspc; if (toolbar() != 0) toolbar()->reconfigure(); updateNetizenWorkspaceCount(); saveWorkspaces(m_workspaces_list.size()); return m_workspaces_list.size(); } void BScreen::changeWorkspaceID(unsigned int id) { if (! m_current_workspace || id >= m_workspaces_list.size() || id == m_current_workspace->workspaceID()) return; XSync(FbTk::App::instance()->display(), true); FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow(); #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): focused = "<<focused<<endl; #endif // DEBUG if (focused && focused->isMoving()) { if (doOpaqueMove()) reassociateWindow(focused, id, true); // don't reassociate if not opaque moving focused->pauseMoving(); } // reassociate all windows that are stuck to the new workspace Workspace *wksp = currentWorkspace(); Workspace::Windows wins = wksp->windowList(); Workspace::Windows::iterator it = wins.begin(); for (; it != wins.end(); ++it) { if ((*it)->isStuck()) { reassociateWindow(*it, id, true); } } currentWorkspace()->hideAll(); workspacemenu->setItemSelected(currentWorkspace()->workspaceID() + 2, false); // set new workspace m_current_workspace = getWorkspace(id); workspacemenu->setItemSelected(currentWorkspace()->workspaceID() + 2, true); if (toolbar() != 0) toolbar()->redrawWorkspaceLabel(true); currentWorkspace()->showAll(); if (focused && (focused->isStuck() || focused->isMoving())) { focused->setInputFocus(); } else Fluxbox::instance()->revertFocus(*this); if (focused && focused->isMoving()) { focused->resumeMoving(); } updateNetizenCurrentWorkspace(); } void BScreen::sendToWorkspace(unsigned int id, FluxboxWindow *win, bool changeWS) { if (! m_current_workspace || id >= m_workspaces_list.size()) return; if (!win) win = Fluxbox::instance()->getFocusedWindow(); if (id != currentWorkspace()->workspaceID()) { XSync(FbTk::App::instance()->display(), True); if (win && &win->screen() == this && (! win->isStuck())) { if (win->isIconic()) { win->deiconify(); } win->withdraw(); reassociateWindow(win, id, true); // change workspace ? if (changeWS) { changeWorkspaceID(id); win->setInputFocus(); } #ifdef DEBUG cerr<<__FILE__<<": Sending to id = "<<id<<endl; cerr<<__FILE__<<": win->workspaceId="<<win->workspaceNumber()<<endl; #endif //DEBUG } } } void BScreen::addNetizen(Window win) { Netizen *net = new Netizen(*this, win); m_netizen_list.push_back(net); net->sendWorkspaceCount(); net->sendCurrentWorkspace(); // send all windows to netizen Workspaces::iterator it = m_workspaces_list.begin(); Workspaces::iterator it_end = m_workspaces_list.end(); for (; it != it_end; ++it) { Workspace::Windows::iterator win_it = (*it)->windowList().begin(); Workspace::Windows::iterator win_it_end = (*it)->windowList().end(); for (; win_it != win_it_end; ++win_it) { net->sendWindowAdd((*win_it)->clientWindow(), (*it)->workspaceID()); } } Window f = ((Fluxbox::instance()->getFocusedWindow()) ? Fluxbox::instance()->getFocusedWindow()->clientWindow() : None); net->sendWindowFocus(f); } void BScreen::removeNetizen(Window w) { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); for (; it != it_end; ++it) { if ((*it)->window() == w) { Netizen *n = *it; delete n; m_netizen_list.erase(it); break; } } } void BScreen::updateNetizenCurrentWorkspace() { m_currentworkspace_sig.notify(); for_each(m_netizen_list.begin(), m_netizen_list.end(), mem_fun(&Netizen::sendCurrentWorkspace)); } void BScreen::updateNetizenWorkspaceCount() { for_each(m_netizen_list.begin(), m_netizen_list.end(), mem_fun(&Netizen::sendWorkspaceCount)); m_workspacecount_sig.notify(); } void BScreen::updateNetizenWindowFocus() { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); Window f = ((Fluxbox::instance()->getFocusedWindow()) ? Fluxbox::instance()->getFocusedWindow()->clientWindow() : None); for (; it != it_end; ++it) { (*it)->sendWindowFocus(f); } } void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); for (; it != it_end; ++it) { (*it)->sendWindowAdd(w, p); } m_clientlist_sig.notify(); } void BScreen::updateNetizenWindowDel(Window w) { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); for (; it != it_end; ++it) { (*it)->sendWindowDel(w); } m_clientlist_sig.notify(); } void BScreen::updateNetizenWindowRaise(Window w) { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); for (; it != it_end; ++it) { (*it)->sendWindowRaise(w); } } void BScreen::updateNetizenWindowLower(Window w) { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); for (; it != it_end; ++it) { (*it)->sendWindowLower(w); } } void BScreen::updateNetizenConfigNotify(XEvent *e) { Netizens::iterator it = m_netizen_list.begin(); Netizens::iterator it_end = m_netizen_list.end(); for (; it != it_end; ++it) { (*it)->sendConfigNotify(e); } } FluxboxWindow *BScreen::createWindow(Window client) { FluxboxWindow *win = new FluxboxWindow(client, *this, winFrameTheme(), *menuTheme(), *layerManager().getLayer(Fluxbox::instance()->getNormalLayer())); #ifdef SLIT if (win->initialState() == WithdrawnState) { delete win; win = 0; slit()->addClient(client); return 0; } #endif // SLIT if (!win->isManaged()) { delete win; return 0; } else { // always put on end of focused list, if it gets focused it'll get pushed up // there is only the one win client at this stage if (doFocusNew()) focused_list.push_front(&win->winClient()); else focused_list.push_back(&win->winClient()); //TODO: is next line needed? Fluxbox::instance()->saveWindowSearch(client, win); setupWindowActions(*win); Fluxbox::instance()->attachSignals(*win); } if (win->workspaceNumber() == currentWorkspaceID() || win->isStuck()) { win->show(); } XSync(FbTk::App::instance()->display(), False); return win; } FluxboxWindow *BScreen::createWindow(WinClient &client) { FluxboxWindow *win = new FluxboxWindow(client, *this, winFrameTheme(), *menuTheme(), *layerManager().getLayer(Fluxbox::instance()->getNormalLayer())); #ifdef SLIT if (win->initialState() == WithdrawnState) slit()->addClient(win->clientWindow()); #endif // SLIT if (!win->isManaged()) { delete win; return 0; } // don't add to focused_list, as it should already be in there (since the // WinClient already exists). Fluxbox::instance()->saveWindowSearch(client.window(), win); setupWindowActions(*win); Fluxbox::instance()->attachSignals(*win); if (win->workspaceNumber() == currentWorkspaceID() || win->isStuck()) { win->show(); } return win; } void BScreen::setupWindowActions(FluxboxWindow &win) { FbWinFrame &frame = win.frame(); typedef FbTk::RefCount<FbTk::Command> CommandRef; using namespace FbTk; typedef RefCount<Command> CommandRef; typedef SimpleCommand<FluxboxWindow> WindowCmd; CommandRef iconify_cmd(new WindowCmd(win, &FluxboxWindow::iconify)); CommandRef maximize_cmd(new WindowCmd(win, &FluxboxWindow::maximize)); CommandRef maximize_vert_cmd(new WindowCmd(win, &FluxboxWindow::maximizeVertical)); CommandRef maximize_horiz_cmd(new WindowCmd(win, &FluxboxWindow::maximizeHorizontal)); CommandRef close_cmd(new WindowCmd(win, &FluxboxWindow::close)); CommandRef shade_cmd(new WindowCmd(win, &FluxboxWindow::shade)); CommandRef raise_cmd(new WindowCmd(win, &FluxboxWindow::raise)); CommandRef lower_cmd(new WindowCmd(win, &FluxboxWindow::lower)); CommandRef raise_and_focus_cmd(new WindowCmd(win, &FluxboxWindow::raiseAndFocus)); CommandRef stick_cmd(new WindowCmd(win, &FluxboxWindow::stick)); CommandRef show_menu_cmd(new WindowCmd(win, &FluxboxWindow::popupMenu)); // clear old buttons from frame frame.removeAllButtons(); //!! TODO: fix this ugly hack // get titlebar configuration const vector<Fluxbox::Titlebar> *dir = &Fluxbox::instance()->getTitlebarLeft(); for (char c=0; c<2; c++) { for (size_t i=0; i< dir->size(); ++i) { //create new buttons FbTk::Button *newbutton = 0; if (win.isIconifiable() && (*dir)[i] == Fluxbox::MINIMIZE) { newbutton = new WinButton(win, *m_winbutton_theme.get(), WinButton::MINIMIZE, frame.titlebar(), 0, 0, 10, 10); newbutton->setOnClick(iconify_cmd); } else if (win.isMaximizable() && (*dir)[i] == Fluxbox::MAXIMIZE) { newbutton = new WinButton(win, *m_winbutton_theme.get(), WinButton::MAXIMIZE, frame.titlebar(), 0, 0, 10, 10); newbutton->setOnClick(maximize_cmd, 1); newbutton->setOnClick(maximize_horiz_cmd, 3); newbutton->setOnClick(maximize_vert_cmd, 2); } else if (win.isClosable() && (*dir)[i] == Fluxbox::CLOSE) { newbutton = new WinButton(win, *m_winbutton_theme.get(), WinButton::CLOSE, frame.titlebar(), 0, 0, 10, 10); newbutton->setOnClick(close_cmd); #ifdef DEBUG cerr<<__FILE__<<": Creating close button"<<endl; #endif // DEBUG } else if ((*dir)[i] == Fluxbox::STICK) { WinButton *winbtn = new WinButton(win, *m_winbutton_theme.get(), WinButton::STICK, frame.titlebar(), 0, 0, 10, 10); win.stateSig().attach(winbtn); winbtn->setOnClick(stick_cmd); newbutton = winbtn; } else if ((*dir)[i] == Fluxbox::SHADE) { WinButton *winbtn = new WinButton(win, *m_winbutton_theme.get(), WinButton::SHADE, frame.titlebar(), 0, 0, 10, 10); winbtn->setOnClick(shade_cmd); } if (newbutton != 0) { newbutton->show(); if (c == 0) frame.addLeftButton(newbutton); else frame.addRightButton(newbutton); } } //end for i dir = &Fluxbox::instance()->getTitlebarRight(); } // end for c frame.reconfigure(); // setup titlebar frame.setOnClickTitlebar(raise_and_focus_cmd, 1, false, true); // on press with button 1 frame.setOnClickTitlebar(shade_cmd, 1, true); // doubleclick with button 1 frame.setOnClickTitlebar(show_menu_cmd, 3); // on release with button 3 frame.setOnClickTitlebar(lower_cmd, 2); // on release with button 2 frame.setDoubleClickTime(Fluxbox::instance()->getDoubleClickInterval()); // setup menu FbTk::Menu &menu = win.menu(); menu.removeAll(); // clear old items menu.disableTitle(); // not titlebar // set new menu items menu.insert("Shade", shade_cmd); menu.insert("Stick", stick_cmd); menu.insert("Maximize", maximize_cmd); menu.insert("Maximize Vertical", maximize_vert_cmd); menu.insert("Maximize Horizontal", maximize_horiz_cmd); menu.insert("Iconify", iconify_cmd); menu.insert("Raise", raise_cmd); menu.insert("Lower", lower_cmd); menu.insert("Layer...", &win.layermenu()); CommandRef next_client_cmd(new WindowCmd(win, &FluxboxWindow::nextClient)); CommandRef prev_client_cmd(new WindowCmd(win, &FluxboxWindow::prevClient)); menu.insert("Next Client", next_client_cmd); menu.insert("Prev Client", prev_client_cmd); menu.insert("ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ"); menu.insert("Close", close_cmd); menu.reconfigure(); // update graphics } Strut *BScreen::requestStrut(int left, int right, int top, int bottom) { Strut *str = new Strut(left, right, top, bottom); m_strutlist.push_back(str); return str; } void BScreen::clearStrut(Strut *str) { if (str == 0) return; // find strut and erase it std::list<Strut *>::iterator pos = find(m_strutlist.begin(), m_strutlist.end(), str); if (pos == m_strutlist.end()) return; m_strutlist.erase(pos); delete str; } /// helper class for for_each in BScreen::updateAvailableWorkspaceArea() namespace { class MaxArea { public: MaxArea(Strut &max_area):m_max_area(max_area) { } void operator ()(const Strut *str) { static int left, right, bottom, top; left = std::max(m_max_area.left(), str->left()); right = std::max(m_max_area.right(), str->right()); bottom = std::max(m_max_area.bottom(), str->bottom()); top = std::max(m_max_area.top(), str->top()); m_max_area = Strut(left, right, top, bottom); } private: Strut &m_max_area; }; }; // end anonymous namespace void BScreen::updateAvailableWorkspaceArea() { // find max of left, right, top and bottom and set avaible workspace area // clear old area m_available_workspace_area.reset(new Strut(0, 0, 0, 0)); // calculate max area for_each(m_strutlist.begin(), m_strutlist.end(), MaxArea(*m_available_workspace_area.get())); } void BScreen::saveStrftimeFormat(const char *format) { //make sure std::string don't get 0 string resource.strftime_format = (format ? format : ""); } void BScreen::addWorkspaceName(const char *name) { m_workspace_names.push_back(name); } string BScreen::getNameOfWorkspace(unsigned int workspace) const { if (workspace < m_workspace_names.size()) { return m_workspace_names[workspace]; } else { return ""; } } void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, bool ignore_sticky) { if (w == 0) return; if (wkspc_id >= getCount()) { wkspc_id = currentWorkspace()->workspaceID(); #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): wkspc_id >= getCount()"<<endl; #endif // DEBUG } if (!w->isIconic() && w->workspaceNumber() == wkspc_id) return; if (w->isIconic()) { removeIcon(w); getWorkspace(wkspc_id)->addWindow(*w); } else if (ignore_sticky || ! w->isStuck()) { getWorkspace(w->workspaceNumber())->removeWindow(w); getWorkspace(wkspc_id)->addWindow(*w); } } void BScreen::nextFocus(int opts) { bool have_focused = false; int focused_window_number = -1; FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow(); const int num_windows = currentWorkspace()->numberOfWindows(); if (focused != 0) { if (focused->screen().screenNumber() == screenNumber()) { have_focused = true; focused_window_number = focused->windowNumber(); } } if (num_windows >= 1) { if (!(opts & CYCLELINEAR)) { if (!cycling_focus) { cycling_focus = True; cycling_window = focused_list.begin(); cycling_last = 0; } else { // already cycling, so restack to put windows back in their proper order m_layermanager.restack(); } // if it is stacked, we want the highest window in the focused list // that is on the same workspace FocusedWindows::iterator it = cycling_window; FocusedWindows::iterator it_end = focused_list.end(); while (true) { ++it; if (it == it_end) { it = focused_list.begin(); } // give up [do nothing] if we reach the current focused again if ((*it) == (*cycling_window)) { break; } FluxboxWindow *fbwin = (*it)->m_win; if (fbwin && !fbwin->isIconic() && (fbwin->isStuck() || fbwin->workspaceNumber() == currentWorkspaceID())) { // either on this workspace, or stuck // keep track of the originally selected window in a set WinClient &last_client = fbwin->winClient(); if (! (doSkipWindow(**it, opts) || !fbwin->setCurrentClient(**it)) ) { // moved onto a new fbwin if (!cycling_last || cycling_last->fbwindow() != fbwin) { if (cycling_last) // set back to orig current Client in that fbwin cycling_last->fbwindow()->setCurrentClient(*cycling_last, false); cycling_last = &last_client; } fbwin->tempRaise(); break; } } } cycling_window = it; } else { // not stacked cycling Workspace *wksp = currentWorkspace(); Workspace::Windows &wins = wksp->windowList(); Workspace::Windows::iterator it = wins.begin(); if (!have_focused) { focused = (*it); } else { for (; (*it) != focused; ++it) //get focused window iterator continue; } do { ++it; if (it == wins.end()) it = wins.begin(); // see if the window should be skipped if (! (doSkipWindow((*it)->winClient(), opts) || !(*it)->setInputFocus()) ) break; } while ((*it) != focused); if ((*it) != focused && it != wins.end()) (*it)->raise(); } } } void BScreen::prevFocus(int opts) { bool have_focused = false; int focused_window_number = -1; FluxboxWindow *focused; int num_windows = currentWorkspace()->numberOfWindows(); if ((focused = Fluxbox::instance()->getFocusedWindow())) { if (focused->screen().screenNumber() == screenNumber()) { have_focused = true; focused_window_number = focused->windowNumber(); } } if (num_windows >= 1) { if (!(opts & CYCLELINEAR)) { if (!cycling_focus) { cycling_focus = true; cycling_window = focused_list.end(); cycling_last = 0; } else { // already cycling, so restack to put windows back in their proper order m_layermanager.restack(); } // if it is stacked, we want the highest window in the focused list // that is on the same workspace FocusedWindows::iterator it = cycling_window; FocusedWindows::iterator it_end = focused_list.end(); while (true) { --it; if (it == it_end) { it = focused_list.end(); --it; } // give up [do nothing] if we reach the current focused again if ((*it) == (*cycling_window)) { break; } FluxboxWindow *fbwin = (*it)->m_win; if (fbwin && !fbwin->isIconic() && (fbwin->isStuck() || fbwin->workspaceNumber() == currentWorkspaceID())) { // either on this workspace, or stuck // keep track of the originally selected window in a set WinClient &last_client = fbwin->winClient(); if (! (doSkipWindow(**it, opts) || !fbwin->setCurrentClient(**it)) ) { // moved onto a new fbwin if (!cycling_last || cycling_last->fbwindow() != fbwin) { if (cycling_last) // set back to orig current Client in that fbwin cycling_last->fbwindow()->setCurrentClient(*cycling_last, false); cycling_last = &last_client; } fbwin->tempRaise(); break; } } } cycling_window = it; } else { // not stacked cycling Workspace *wksp = currentWorkspace(); Workspace::Windows &wins = wksp->windowList(); Workspace::Windows::iterator it = wins.begin(); if (!have_focused) { focused = (*it); } else { for (; (*it) != focused; ++it) //get focused window iterator continue; } do { if (it == wins.begin()) it = wins.end(); --it; // see if the window should be skipped if (! (doSkipWindow((*it)->winClient(), opts) || !(*it)->setInputFocus()) ) break; } while ((*it) != focused); if ((*it) != focused && it != wins.end()) (*it)->raise(); } } } void BScreen::raiseFocus() { bool have_focused = false; int focused_window_number = -1; Fluxbox * const fb = Fluxbox::instance(); if (fb->getFocusedWindow()) if (fb->getFocusedWindow()->screen().screenNumber() == screenNumber()) { have_focused = true; focused_window_number = fb->getFocusedWindow()->windowNumber(); } if ((currentWorkspace()->numberOfWindows() > 1) && have_focused) fb->getFocusedWindow()->raise(); } void BScreen::setFocusedWindow(WinClient &winclient) { // raise newly focused window to the top of the focused list if (!cycling_focus) { // don't change the order if we're cycling focused_list.remove(&winclient); focused_list.push_front(&winclient); cycling_window = focused_list.begin(); } } void BScreen::dirFocus(FluxboxWindow &win, FocusDir dir) { // change focus to the window in direction dir from the given window // we scan through the list looking for the window that is "closest" // in the given direction FluxboxWindow *foundwin = 0; int weight = 999999, exposure = 0; // extreme values int borderW = m_root_theme->borderWidth(), top = win.y(), bottom = win.y() + win.height() + 2*borderW, left = win.x(), right = win.x() + win.width() + 2*borderW; Workspace::Windows &wins = currentWorkspace()->windowList(); Workspace::Windows::iterator it = wins.begin(); for (; it != wins.end(); ++it) { if ((*it) == &win) continue; // skip self // we check things against an edge, and within the bounds (draw a picture) int edge=0, upper=0, lower=0, oedge=0, oupper=0, olower=0; int otop = (*it)->y(), obottom = (*it)->y() + (*it)->height() + 2*borderW, oleft = (*it)->x(), oright = (*it)->x() + (*it)->width() + 2*borderW; // check if they intersect switch (dir) { case FOCUSUP: edge = obottom; oedge = bottom; upper = left; oupper = oleft; lower = right; olower = oright; break; case FOCUSDOWN: edge = top; oedge = otop; upper = left; oupper = oleft; lower = right; olower = oright; break; case FOCUSLEFT: edge = oright; oedge = right; upper = top; oupper = otop; lower = bottom; olower = obottom; break; case FOCUSRIGHT: edge = left; oedge = oleft; upper = top; oupper = otop; lower = bottom; olower = obottom; break; } if (oedge < edge) continue; // not in the right direction if (olower <= upper || oupper >= lower) { // outside our horz bounds, get a heavy weight penalty int myweight = 100000 + oedge - edge + abs(upper-oupper)+abs(lower-olower); if (myweight < weight) { foundwin = *it; exposure = 0; weight = myweight; } } else if ((oedge - edge) < weight) { foundwin = *it; weight = oedge - edge; exposure = ((lower < olower)?lower:olower) - ((upper > oupper)?upper:oupper); } else if (foundwin && oedge - edge == weight) { int myexp = ((lower < olower)?lower:olower) - ((upper > oupper)?upper:oupper); if (myexp > exposure) { foundwin = *it; // weight is same exposure = myexp; } } // else not improvement } if (foundwin) foundwin->setInputFocus(); } void BScreen::initMenu() { I18n *i18n = I18n::instance(); if (m_rootmenu.get()) { // since all menus in root is submenus in m_rootmenu // just remove every item in m_rootmenu and then clear m_rootmenu_list while (m_rootmenu->numberOfItems()) m_rootmenu->remove(0); m_rootmenu_list.clear(); } else m_rootmenu.reset(createMenuFromScreen(*this)); bool defaultMenu = true; Fluxbox * const fb = Fluxbox::instance(); if (fb->getMenuFilename()) { ifstream menu_file(fb->getMenuFilename()); if (!menu_file.fail()) { if (! menu_file.eof()) { string line; int row = 0; while (getline(menu_file, line) && ! menu_file.eof()) { row++; if (line[0] != '#') { string key; int pos=0; int err = FbTk::StringUtil:: getStringBetween(key, line.c_str(), '[', ']'); if (key == "begin") { pos += err; string label; err = FbTk::StringUtil:: getStringBetween(label, line.c_str()+pos, '(', ')'); if (err>0) { m_rootmenu->setLabel(label.c_str()); defaultMenu = parseMenuFile(menu_file, *m_rootmenu.get(), row); } else cerr<<"Error in menufile. Line("<<row<<")"<<endl; break; } } } } else { fprintf(stderr, i18n->getMessage( FBNLS::ScreenSet, FBNLS::ScreenEmptyMenuFile, "%s: Empty menu file"), fb->getMenuFilename()); } menu_file.close(); } else perror(fb->getMenuFilename()); } if (defaultMenu) { FbTk::RefCount<FbTk::Command> restart_fb(new FbCommands::RestartFluxboxCmd("")); FbTk::RefCount<FbTk::Command> exit_fb(new FbCommands::ExitFluxboxCmd()); FbTk::RefCount<FbTk::Command> execute_xterm(new FbCommands::ExecuteCmd("xterm", screenNumber())); m_rootmenu->setInternalMenu(); m_rootmenu->insert(i18n->getMessage( FBNLS::ScreenSet, FBNLS::Screenxterm, "xterm"), execute_xterm); m_rootmenu->insert(i18n->getMessage( FBNLS::ScreenSet, FBNLS::ScreenRestart, "Restart"), restart_fb); m_rootmenu->insert(i18n->getMessage( FBNLS::ScreenSet, FBNLS::ScreenExit, "Exit"), exit_fb); } else fb->saveMenuFilename(fb->getMenuFilename()); } /// looks through a menufile and adds correct items to the root-menu. bool BScreen::parseMenuFile(ifstream &file, FbTk::Menu &menu, int &row) { string line; FbTk::RefCount<FbTk::Command> hide_menu(new FbTk::SimpleCommand<FbTk::Menu>(menu, &FbTk::Menu::hide)); while (! file.eof()) { if (getline(file, line)) { row++; if (line[0] != '#') { //the line is commented int parse_pos = 0, err = 0; std::string str_key, str_label, str_cmd; err = FbTk::StringUtil:: getStringBetween(str_key, line.c_str(), '[', ']'); if (err > 0 ) { parse_pos += err; err = FbTk::StringUtil:: getStringBetween(str_label, line.c_str() + parse_pos, '(', ')'); if (err>0) { parse_pos += err; FbTk::StringUtil:: getStringBetween(str_cmd, line.c_str() + parse_pos, '{', '}'); } } else continue; //read next line if (!str_key.size()) continue; //read next line I18n *i18n = I18n::instance(); if (str_key == "end") { return ((menu.numberOfItems() == 0) ? true : false); } else if (str_key == "nop") { menu.insert(str_label.c_str()); } else if (str_key == "exec") { // exec if (!(str_label.size() && str_cmd.size())) { fprintf(stderr, i18n->getMessage( FBNLS::ScreenSet, FBNLS::ScreenEXECError, "BScreen::parseMenuFile: [exec] error, " "no menu label and/or command defined\n")); cerr<<"Row: "<<row<<endl; } else { FbTk::RefCount<FbTk::Command> exec_cmd(new FbCommands::ExecuteCmd(str_cmd, screenNumber())); FbTk::MacroCommand *exec_and_hide = new FbTk::MacroCommand(); exec_and_hide->add(hide_menu); exec_and_hide->add(exec_cmd); FbTk::RefCount<FbTk::Command> exec_and_hide_cmd(exec_and_hide); menu.insert(str_label.c_str(), exec_and_hide_cmd); } } else if (str_key == "exit") { // exit if (!str_label.size()) { fprintf(stderr, i18n->getMessage( FBNLS::ScreenSet, FBNLS::ScreenEXITError, "BScreen::parseMenuFile: [exit] error, " "no menu label defined\n")); cerr<<"Row: "<<row<<endl; } else { FbTk::RefCount<FbTk::Command> exit_fb_cmd(new FbCommands::ExitFluxboxCmd()); menu.insert(str_label.c_str(), exit_fb_cmd); } } else if (str_key == "style") { // style if (!( str_label.size() && str_cmd.size())) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenSTYLEError, "BScreen::parseMenuFile: [style] error, " "no menu label and/or filename defined\n")); cerr<<"Row: "<<row<<endl; } else { // perform shell style ~ home directory expansion // and insert style FbTk::RefCount<FbTk::Command> setstyle_cmd(new FbCommands:: SetStyleCmd(FbTk::StringUtil:: expandFilename(str_cmd))); menu.insert(str_label.c_str(), setstyle_cmd); } } else if (str_key == "config") { if (! str_label.size()) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenCONFIGError, "BScreen::parseMenufile: [config] error, " "no label defined")); cerr<<"Row: "<<row<<endl; } else { #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<< "): inserts configmenu: "<<m_configmenu.get()<<endl; #endif // DEBUG menu.insert(str_label.c_str(), m_configmenu.get()); } } // end of config else if ( str_key == "include") { // include if (!str_label.size()) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenINCLUDEError, "BScreen::parseMenuFile: [include] error, " "no filename defined\n")); cerr<<"Row: "<<row<<endl; } else { // start of else 'x' // perform shell style ~ home directory expansion string newfile(FbTk::StringUtil::expandFilename(str_label)); if (newfile.size() != 0) { FILE *submenufile = fopen(newfile.c_str(), "r"); if (submenufile) { struct stat buf; if (fstat(fileno(submenufile), &buf) || (! S_ISREG(buf.st_mode))) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenINCLUDEErrorReg, "BScreen::parseMenuFile: [include] error: " "'%s' is not a regular file\n"), newfile.c_str()); cerr<<"Row: "<<row<<endl; } if (! feof(submenufile)) { fclose(submenufile); ifstream subfile(newfile.c_str()); if (! parseMenuFile(subfile, menu, row)) Fluxbox::instance()->saveMenuFilename(newfile.c_str()); } } else perror(newfile.c_str()); } } // end of else 'x' } // end of include else if (str_key == "submenu") { // sub if (!str_label.size()) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenSUBMENUError, "BScreen::parseMenuFile: [submenu] error, " "no menu label defined\n")); cerr<<"Row: "<<row<<endl; } else { FbTk::Menu *submenu = createMenuFromScreen(*this); if (str_cmd.size()) submenu->setLabel(str_cmd.c_str()); else submenu->setLabel(str_label.c_str()); parseMenuFile(file, *submenu, row); submenu->update(); menu.insert(str_label.c_str(), submenu); // save to list so we can delete it later m_rootmenu_list.push_back(submenu); } } // end of sub else if (str_key == "restart") { if (!str_label.size()) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenRESTARTError, "BScreen::parseMenuFile: [restart] error, " "no menu label defined\n")); cerr<<"Row: "<<row<<endl; } else { FbTk::RefCount<FbTk::Command> restart_fb(new FbCommands::RestartFluxboxCmd(str_cmd)); menu.insert(str_label.c_str(), restart_fb); } } // end of restart else if (str_key == "reconfig") { // reconf if (!str_label.c_str()) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenRECONFIGError, "BScreen::parseMenuFile: [reconfig] error, " "no menu label defined\n")); cerr<<"Row: "<<row<<endl; } else { FbTk::RefCount<FbTk::Command> reconfig_fb_cmd(new FbCommands::ReconfigureFluxboxCmd()); menu.insert(str_label.c_str(), reconfig_fb_cmd); } } else if (str_key == "stylesdir" || str_key == "stylesmenu") { bool newmenu = (str_key == "stylesmenu"); if (!( str_label.size() && str_cmd.size()) && newmenu) { fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenSTYLESDIRError, "BScreen::parseMenuFile: [stylesdir/stylesmenu]" " error, no directory defined\n")); cerr<<"Row: "<<row<<endl; } else { createStyleMenu(menu, str_label.c_str(), newmenu ? str_cmd.c_str() : str_label.c_str()); } } // end of stylesdir else if (str_key == "workspaces") { if (!str_label.size()) { fprintf(stderr, i18n->getMessage( FBNLS::ScreenSet, FBNLS::ScreenWORKSPACESError, "BScreen:parseMenuFile: [workspaces] error, " "no menu label defined\n")); cerr<<"Row: "<<row<<endl; } else menu.insert(str_label.c_str(), workspacemenu.get()); } // end of work } } } return ((menu.numberOfItems() == 0) ? true : false); } void BScreen::setupConfigmenu(FbTk::Menu &menu) { I18n *i18n = I18n::instance(); using namespace FBNLS; FbTk::MacroCommand *s_a_reconf_macro = new FbTk::MacroCommand(); FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(*Fluxbox::instance(), &Fluxbox::save_rc)); FbTk::RefCount<FbTk::Command> reconf_cmd(new FbCommands::ReconfigureFluxboxCmd()); s_a_reconf_macro->add(saverc_cmd); s_a_reconf_macro->add(reconf_cmd); FbTk::RefCount<FbTk::Command> save_and_reconfigure(s_a_reconf_macro); // create focus menu // we don't set this to internal menu so will // be deleted toghether with the parent FbTk::Menu *focus_menu = createMenuFromScreen(*this); focus_menu->insert(new FocusModelMenuItem(i18n->getMessage( ConfigmenuSet, ConfigmenuClickToFocus, "Click To Focus"), *this, Fluxbox::CLICKTOFOCUS, save_and_reconfigure)); focus_menu->insert(new FocusModelMenuItem(i18n->getMessage( ConfigmenuSet, ConfigmenuSloppyFocus, "Sloppy Focus"), *this, Fluxbox::SLOPPYFOCUS, save_and_reconfigure)); focus_menu->insert(new FocusModelMenuItem(i18n->getMessage( ConfigmenuSet, ConfigmenuSemiSloppyFocus, "Semi Sloppy Focus"), *this, Fluxbox::SEMISLOPPYFOCUS, save_and_reconfigure)); focus_menu->insert(new BoolMenuItem(i18n->getMessage( ConfigmenuSet, ConfigmenuAutoRaise, "Auto Raise"), *resource.auto_raise, save_and_reconfigure)); focus_menu->update(); menu.insert(i18n->getMessage( ConfigmenuSet, ConfigmenuFocusModel, "Focus Model"), focus_menu); #ifdef SLIT if (slit() != 0) { slit()->menu().setInternalMenu(); menu.insert("Slit", &slit()->menu()); } #endif // SLIT menu.insert(i18n->getMessage(ToolbarSet, ToolbarToolbarTitle, "Toolbar"), &m_toolbarhandler->getToolbarMenu()); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuImageDithering, "Image Dithering"), *resource.image_dither, save_and_reconfigure)); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuOpaqueMove, "Opaque Window Moving"), *resource.opaque_move, saverc_cmd)); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuFullMax, "Full Maximization"), *resource.full_max, saverc_cmd)); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusNew, "Focus New Windows"), *resource.focus_new, saverc_cmd)); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusLast, "Focus Last Window on Workspace"), *resource.focus_last, saverc_cmd)); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuWorkspaceWarping, "Workspace Warping"), *resource.workspace_warping, saverc_cmd)); menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuDesktopWheeling, "Desktop MouseWheel Switching"), *resource.desktop_wheeling, saverc_cmd)); menu.insert(new BoolMenuItem("Click Raises", *resource.click_raises, saverc_cmd)); // setup antialias cmd to reload style and save resource on toggle menu.insert(new BoolMenuItem(i18n->getMessage(ConfigmenuSet, ConfigmenuAntiAlias, "AntiAlias"), *resource.antialias, save_and_reconfigure)); FbTk::MenuItem *menu_alpha_item = new IntResMenuItem("Menu Alpha", resource.menu_alpha, 0, 255); menu_alpha_item->setCommand(saverc_cmd); menu.insert(menu_alpha_item); // finaly update menu menu.update(); } void BScreen::createStyleMenu(FbTk::Menu &menu, const char *label, const char *directory) { // perform shell style ~ home directory expansion string stylesdir(FbTk::StringUtil::expandFilename(directory ? directory : "")); I18n *i18n = I18n::instance(); struct stat statbuf; if (! stat(stylesdir.c_str(), &statbuf)) { if (S_ISDIR(statbuf.st_mode)) { // is a directory? FbTk::Directory dir(stylesdir.c_str()); // create a vector of all the filenames in the directory // add sort it std::vector<std::string> filelist(dir.entries()); for (size_t file_index = 0; file_index < dir.entries(); ++file_index) filelist[file_index] = dir.readFilename(); std::sort(filelist.begin(), filelist.end(), less<string>()); int slen = stylesdir.size(); // for each file in directory add filename and path to menu for (size_t file_index = 0; file_index < dir.entries(); file_index++) { int nlen = filelist[file_index].size(); char style[MAXPATHLEN + 1]; strncpy(style, stylesdir.c_str(), slen); *(style + slen) = '/'; strncpy(style + slen + 1, filelist[file_index].c_str(), nlen + 1); if ( !stat(style, &statbuf) && S_ISREG(statbuf.st_mode)) { FbTk::RefCount<FbTk::Command> setstyle_cmd(new FbCommands:: SetStyleCmd(style)); menu.insert(filelist[file_index].c_str(), setstyle_cmd); } } // update menu graphics menu.update(); Fluxbox::instance()->saveMenuFilename(stylesdir.c_str()); } else { // no directory fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenSTYLESDIRErrorNotDir, "BScreen::parseMenuFile:" " [stylesdir/stylesmenu] error, %s is not a" " directory\n"), stylesdir.c_str()); } // end of directory check } else { // stat failed fprintf(stderr, i18n-> getMessage( FBNLS::ScreenSet, FBNLS::ScreenSTYLESDIRErrorNoExist, "BScreen::parseMenuFile: [stylesdir/stylesmenu]" " error, %s does not exist\n"), stylesdir.c_str()); } // end of stat } void BScreen::shutdown() { Display *disp = FbTk::App::instance()->display(); rootWindow().setEventMask(NoEventMask); XSync(disp, False); for_each(m_workspaces_list.begin(), m_workspaces_list.end(), mem_fun(&Workspace::shutdown)); #ifdef SLIT if (m_slit.get()) m_slit->shutdown(); #endif // SLIT } void BScreen::showPosition(int x, int y) { if (! geom_visible) { if (hasXinerama()) { unsigned int head = getCurrHead(); m_geom_window.move(getHeadX(head) + (getHeadWidth(head) - m_geom_window.width()) / 2, getHeadY(head) + (getHeadHeight(head) - m_geom_window.height()) / 2); } else { m_geom_window.move((width() - m_geom_window.width()) / 2, (height() - m_geom_window.height()) / 2); } m_geom_window.show(); m_geom_window.raise(); geom_visible = true; } char label[256]; sprintf(label, I18n::instance()->getMessage(FBNLS::ScreenSet, FBNLS::ScreenPositionFormat, "X: %4d x Y: %4d"), x, y); m_geom_window.clear(); winFrameTheme().font().drawText(m_geom_window.window(), screenNumber(), winFrameTheme().labelTextFocusGC(), label, strlen(label), m_root_theme->bevelWidth(), m_root_theme->bevelWidth() + winFrameTheme().font().ascent()); } void BScreen::showGeometry(unsigned int gx, unsigned int gy) { if (! geom_visible) { if (hasXinerama()) { unsigned int head = getCurrHead(); m_geom_window.move(getHeadX(head) + (getHeadWidth(head) - m_geom_window.width()) / 2, getHeadY(head) + (getHeadHeight(head) - m_geom_window.height()) / 2); } else { m_geom_window.move((width() - m_geom_window.width()) / 2, (height() - m_geom_window.height()) / 2); } m_geom_window.show(); m_geom_window.raise(); geom_visible = true; } char label[256]; sprintf(label, I18n::instance()->getMessage( FBNLS::ScreenSet, FBNLS::ScreenGeometryFormat, "W: %4d x H: %4d"), gx, gy); m_geom_window.clear(); //TODO: geom window again?! repeated winFrameTheme().font().drawText(m_geom_window.window(), screenNumber(), winFrameTheme().labelTextFocusGC(), label, strlen(label), m_root_theme->bevelWidth(), m_root_theme->bevelWidth() + winFrameTheme().font().ascent()); } void BScreen::hideGeometry() { if (geom_visible) { m_geom_window.hide(); geom_visible = false; } } void BScreen::setLayer(FbTk::XLayerItem &item, int layernum) { m_layermanager.moveToLayer(item, layernum); } /** Goes to the workspace "right" of the current */ void BScreen::nextWorkspace(const int delta) { changeWorkspaceID( (currentWorkspaceID() + delta) % getCount()); } /** Goes to the workspace "left" of the current */ void BScreen::prevWorkspace(const int delta) { changeWorkspaceID( (currentWorkspaceID() - delta + getCount()) % getCount()); } /** Goes to the workspace "right" of the current */ void BScreen::rightWorkspace(const int delta) { if (currentWorkspaceID()+delta < getCount()) changeWorkspaceID(currentWorkspaceID()+delta); } /** Goes to the workspace "left" of the current */ void BScreen::leftWorkspace(const int delta) { if (currentWorkspaceID() >= static_cast<unsigned int>(delta)) changeWorkspaceID(currentWorkspaceID()-delta); } /** @return true if the windows should be skiped else false */ bool BScreen::doSkipWindow(const WinClient &winclient, int opts) { const FluxboxWindow *win = winclient.fbwindow(); return (!win || (opts & CYCLESKIPSTUCK) != 0 && win->isStuck() || // skip if stuck // skip if not active client (i.e. only visit each fbwin once) (opts & CYCLEGROUPS) != 0 && win->winClient() != winclient.window() || (opts & CYCLESKIPSHADED) != 0 && win->isShaded() // skip if shaded ); } void BScreen::renderGeomWindow() { Pixmap tmp = geom_pixmap; if (winFrameTheme().labelFocusTexture().type() & FbTk::Texture::PARENTRELATIVE) { if (winFrameTheme().titleFocusTexture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { geom_pixmap = None; m_geom_window.setBackgroundColor(winFrameTheme().titleFocusTexture().color()); } else { geom_pixmap = imageControl().renderImage(m_geom_window.width(), m_geom_window.height(), winFrameTheme().titleFocusTexture()); m_geom_window.setBackgroundPixmap(geom_pixmap); } } else { if (winFrameTheme().labelFocusTexture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { geom_pixmap = None; m_geom_window.setBackgroundColor(winFrameTheme().labelFocusTexture().color()); } else { geom_pixmap = imageControl().renderImage(m_geom_window.width(), m_geom_window.height(), winFrameTheme().labelFocusTexture()); m_geom_window.setBackgroundPixmap(geom_pixmap); } } if (tmp) imageControl().removeImage(tmp); } /** Called when a set of watched modifiers has been released */ void BScreen::notifyReleasedKeys(XKeyEvent &ke) { if (cycling_focus) { cycling_focus = false; cycling_last = 0; // put currently focused window to top WinClient *client = *cycling_window; focused_list.erase(cycling_window); focused_list.push_front(client); client->fbwindow()->raise(); } } /** * Used to find out which window was last focused on the given workspace * If workspace is outside the ID range, then the absolute last focused window * is given. */ WinClient *BScreen::getLastFocusedWindow(int workspace) { if (focused_list.empty()) return 0; if (workspace < 0 || workspace >= (int) getCount()) return focused_list.front(); FocusedWindows::iterator it = focused_list.begin(); FocusedWindows::iterator it_end = focused_list.end(); for (; it != it_end; ++it) if ((*it)->fbwindow() && (((int)(*it)->fbwindow()->workspaceNumber()) == workspace && !(*it)->fbwindow()->isIconic() && (!(*it)->fbwindow()->isStuck() || (*it)->fbwindow()->isFocused()))) // only give focus to a stuck window if it is currently focused // otherwise they tend to override normal workspace focus return *it; return 0; } /** Access and clear the auto-group window */ FluxboxWindow* BScreen::useAutoGroupWindow() { Window w = auto_group_window; auto_group_window = 0; return w ? Fluxbox::instance()->searchWindow(w) : 0; } void BScreen::updateSize() { rootWindow().updateGeometry(); // reconfigure anything that depends on root window size // reset background m_root_theme->reconfigTheme(); if (toolbar()) toolbar()->reconfigure(); if (slit()) slit()->reconfigure(); //!! TODO: should we re-maximize the maximized windows? } void BScreen::initXinerama() { #ifdef XINERAMA Display *display = FbTk::App::instance()->display(); if (!XineramaIsActive(display)) { m_xinerama_avail = false; m_xinerama_headinfo = 0; m_xinerama_num_heads = 0; return; } m_xinerama_avail = true; XineramaScreenInfo *screen_info; int number; screen_info = XineramaQueryScreens(display, &number); m_xinerama_headinfo = new XineramaHeadInfo[number]; m_xinerama_num_heads = number; for (int i=0; i < number; i++) { m_xinerama_headinfo[i].x = screen_info[i].x_org; m_xinerama_headinfo[i].y = screen_info[i].y_org; m_xinerama_headinfo[i].width = screen_info[i].width; m_xinerama_headinfo[i].height = screen_info[i].height; } #else // XINERAMA // no xinerama m_xinerama_avail = false; m_xinerama_num_heads = 0; #endif // XINERAMA } int BScreen::getHead(int x, int y) const { if (!hasXinerama()) return 0; #ifdef XINERAMA for (int i=0; i < m_xinerama_num_heads; i++) { if (x >= m_xinerama_headinfo[i].x && x < (m_xinerama_headinfo[i].x + m_xinerama_headinfo[i].width) && y >= m_xinerama_headinfo[i].y && y < (m_xinerama_headinfo[i].y + m_xinerama_headinfo[i].height)) { return i+1; } } #endif // XINERAMA return 0; } int BScreen::getHead(FbTk::FbWindow &win) const { if (hasXinerama()) return getHead(win.x() + win.width()/2, win.y() + win.height()/2); else return 0; } int BScreen::getCurrHead() const { if (!hasXinerama()) return 0; int root_x = 0, root_y = 0; #ifdef XINERAMA int ignore_i; unsigned int ignore_ui; Window ignore_w; XQueryPointer(FbTk::App::instance()->display(), rootWindow().window(), &ignore_w, &ignore_w, &root_x, &root_y, &ignore_i, &ignore_i, &ignore_ui); #endif // XINERAMA return getHead(root_x, root_y); } int BScreen::getHeadX(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return 0; return m_xinerama_headinfo[head-1].x; #else return 0; #endif // XINERAMA } int BScreen::getHeadY(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return 0; return m_xinerama_headinfo[head-1].y; #else return 0; #endif // XINERAMA } int BScreen::getHeadWidth(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return width(); return m_xinerama_headinfo[head-1].width; #else return width(); #endif // XINERAMA } int BScreen::getHeadHeight(int head) const { #ifdef XINERAMA if (head == 0 || head > m_xinerama_num_heads) return height(); return m_xinerama_headinfo[head-1].height; #else return height(); #endif // XINERAMA } template <> int BScreen::getOnHead<Toolbar>(Toolbar &tbar) { return getToolbarOnHead(); } template <> void BScreen::setOnHead<Toolbar>(Toolbar &tbar, int head) { saveToolbarOnHead(head); tbar.reconfigure(); } |