src/fluxbox.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 |
// fluxbox.cc for Fluxbox Window Manager // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) // // blackbox.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: fluxbox.cc,v 1.116 2003/04/25 09:07:14 rathnor Exp $ #include "fluxbox.hh" #include "i18n.hh" #include "Screen.hh" #include "Toolbar.hh" #include "Window.hh" #include "Workspace.hh" #include "StringUtil.hh" #include "Resource.hh" #include "XrmDatabaseHelper.hh" #include "AtomHandler.hh" #include "ImageControl.hh" #include "EventManager.hh" #include "FbCommands.hh" #include "WinClient.hh" #include "Keys.hh" #include "FbAtoms.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 USE_GNOME #include "Gnome.hh" #endif // USE_GNOME #ifdef USE_NEWWMSPEC #include "Ewmh.hh" #endif //USE_NEWWMSPEC // X headers #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xresource.h> #include <X11/Xatom.h> #include <X11/keysym.h> #include <X11/cursorfont.h> #ifdef SHAPE #include <X11/extensions/shape.h> #endif // SHAPE #include <cstdio> #include <cstdlib> #include <cstring> #ifdef HAVE_UNISTD_H #include <sys/types.h> #include <unistd.h> #endif // HAVE_UNISTD_H #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif // HAVE_SYS_PARAM_H #ifndef MAXPATHLEN #define MAXPATHLEN 255 #endif // MAXPATHLEN #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif // HAVE_SYS_SELECT_H #ifdef HAVE_SYS_STAT_H #include <sys/types.h> #include <sys/stat.h> #endif // HAVE_SYS_STAT_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 #ifdef HAVE_LIBGEN_H # include <libgen.h> #endif // HAVE_LIBGEN_H #include <sys/wait.h> #include <iostream> #include <string> #include <memory> #include <algorithm> #include <typeinfo> using namespace std; using namespace FbTk; #ifndef HAVE_BASENAME namespace { char *basename (char *s) { char *save = s; while (*s) { if (*s++ == '/') save = s; } return save; } }; // end anonymous namespace #endif // HAVE_BASENAME #define RC_PATH "fluxbox" #define RC_INIT_FILE "init" //----------------------------------------------------------------- //---- accessors for int, bool, and some enums with Resource ------ //----------------------------------------------------------------- template<> void Resource<int>:: setFromString(const char* strval) { int val; if (sscanf(strval, "%d", &val)==1) *this = val; } template<> void Resource<std::string>:: setFromString(const char *strval) { *this = strval; } template<> void Resource<bool>:: setFromString(char const *strval) { if (strcasecmp(strval, "true")==0) *this = true; else *this = false; } template<> void Resource<Fluxbox::FocusModel>:: setFromString(char const *strval) { // auto raise options here for backwards read compatibility // they are not supported for saving purposes. Nor does the "AutoRaise" // part actually do anything if (strcasecmp(strval, "SloppyFocus") == 0 || strcasecmp(strval, "AutoRaiseSloppyFocus") == 0) m_value = Fluxbox::SLOPPYFOCUS; else if (strcasecmp(strval, "SemiSloppyFocus") == 0 || strcasecmp(strval, "AutoRaiseSemiSloppyFocus") == 0) m_value = Fluxbox::SEMISLOPPYFOCUS; else if (strcasecmp(strval, "ClickToFocus") == 0) m_value = Fluxbox::CLICKTOFOCUS; else setDefaultValue(); } template<> void Resource<Fluxbox::TitlebarList>:: setFromString(char const *strval) { vector<std::string> val; StringUtil::stringtok(val, strval); int size=val.size(); //clear old values m_value.clear(); for (int i=0; i<size; i++) { if (strcasecmp(val[i].c_str(), "Maximize")==0) m_value.push_back(Fluxbox::MAXIMIZE); else if (strcasecmp(val[i].c_str(), "Minimize")==0) m_value.push_back(Fluxbox::MINIMIZE); else if (strcasecmp(val[i].c_str(), "Shade")==0) m_value.push_back(Fluxbox::SHADE); else if (strcasecmp(val[i].c_str(), "Stick")==0) m_value.push_back(Fluxbox::STICK); else if (strcasecmp(val[i].c_str(), "Menu")==0) m_value.push_back(Fluxbox::MENU); else if (strcasecmp(val[i].c_str(), "Close")==0) m_value.push_back(Fluxbox::CLOSE); } } template<> void Resource<unsigned int>:: setFromString(const char *strval) { if (sscanf(strval, "%ul", &m_value) != 1) setDefaultValue(); } //----------------------------------------------------------------- //---- manipulators for int, bool, and some enums with Resource --- //----------------------------------------------------------------- template<> std::string Resource<bool>:: getString() { return std::string(**this == true ? "true" : "false"); } template<> std::string Resource<int>:: getString() { char strval[256]; sprintf(strval, "%d", **this); return std::string(strval); } template<> std::string Resource<std::string>:: getString() { return **this; } template<> std::string Resource<Fluxbox::FocusModel>:: getString() { switch (m_value) { case Fluxbox::SLOPPYFOCUS: return string("SloppyFocus"); case Fluxbox::SEMISLOPPYFOCUS: return string("SemiSloppyFocus"); case Fluxbox::CLICKTOFOCUS: return string("ClickToFocus"); } // default string return string("ClickToFocus"); } template<> std::string Resource<Fluxbox::TitlebarList>:: getString() { string retval; int size=m_value.size(); for (int i=0; i<size; i++) { switch (m_value[i]) { case Fluxbox::SHADE: retval.append("Shade"); break; case Fluxbox::MINIMIZE: retval.append("Minimize"); break; case Fluxbox::MAXIMIZE: retval.append("Maximize"); break; case Fluxbox::CLOSE: retval.append("Close"); break; case Fluxbox::STICK: retval.append("Stick"); break; case Fluxbox::MENU: retval.append("Menu"); break; default: break; } retval.append(" "); } return retval; } template<> string Resource<unsigned int>:: getString() { char tmpstr[128]; sprintf(tmpstr, "%ul", m_value); return string(tmpstr); } template<> void Resource<Fluxbox::Layer>:: setFromString(const char *strval) { int tempnum = 0; if (sscanf(strval, "%d", &tempnum) == 1) m_value = tempnum; else if (strcasecmp(strval, "Menu") == 0) m_value = Fluxbox::instance()->getMenuLayer(); else if (strcasecmp(strval, "AboveDock") == 0) m_value = Fluxbox::instance()->getAboveDockLayer(); else if (strcasecmp(strval, "Dock") == 0) m_value = Fluxbox::instance()->getDockLayer(); else if (strcasecmp(strval, "Top") == 0) m_value = Fluxbox::instance()->getTopLayer(); else if (strcasecmp(strval, "Normal") == 0) m_value = Fluxbox::instance()->getNormalLayer(); else if (strcasecmp(strval, "Bottom") == 0) m_value = Fluxbox::instance()->getBottomLayer(); else if (strcasecmp(strval, "Desktop") == 0) m_value = Fluxbox::instance()->getDesktopLayer(); else setDefaultValue(); } template<> string Resource<Fluxbox::Layer>:: getString() { if (m_value.getNum() == Fluxbox::instance()->getMenuLayer()) return string("Menu"); else if (m_value.getNum() == Fluxbox::instance()->getAboveDockLayer()) return string("AboveDock"); else if (m_value.getNum() == Fluxbox::instance()->getDockLayer()) return string("Dock"); else if (m_value.getNum() == Fluxbox::instance()->getTopLayer()) return string("Top"); else if (m_value.getNum() == Fluxbox::instance()->getNormalLayer()) return string("Normal"); else if (m_value.getNum() == Fluxbox::instance()->getBottomLayer()) return string("Bottom"); else if (m_value.getNum() == Fluxbox::instance()->getDesktopLayer()) return string("Desktop"); else { char tmpstr[128]; sprintf(tmpstr, "%d", m_value.getNum()); return string(tmpstr); } } //static singleton var Fluxbox *Fluxbox::singleton=0; //default values for titlebar left and right //don't forget to change last value in m_rc_titlebar_* if you add more to these Fluxbox::Titlebar Fluxbox::m_titlebar_left[] = {STICK}; Fluxbox::Titlebar Fluxbox::m_titlebar_right[] = {MINIMIZE, MAXIMIZE, CLOSE}; Fluxbox::Fluxbox(int m_argc, char **m_argv, const char *dpy_name, const char *rc) : BaseDisplay(m_argv[0], dpy_name), m_fbatoms(new FbAtoms()), m_resourcemanager(), m_screen_rm(), m_rc_tabs(m_resourcemanager, true, "session.tabs", "Session.Tabs"), m_rc_iconbar(m_resourcemanager, true, "session.iconbar", "Session.Iconbar"), m_rc_colors_per_channel(m_resourcemanager, 4, "session.colorsPerChannel", "Session.ColorsPerChannel"), m_rc_numlayers(m_resourcemanager, 13, "session.numLayers", "Session.NumLayers"), m_rc_stylefile(m_resourcemanager, "", "session.styleFile", "Session.StyleFile"), m_rc_menufile(m_resourcemanager, DEFAULTMENU, "session.menuFile", "Session.MenuFile"), m_rc_keyfile(m_resourcemanager, DEFAULTKEYSFILE, "session.keyFile", "Session.KeyFile"), m_rc_slitlistfile(m_resourcemanager, "", "session.slitlistFile", "Session.SlitlistFile"), m_rc_groupfile(m_resourcemanager, "", "session.groupFile", "Session.GroupFile"), m_rc_titlebar_left(m_resourcemanager, TitlebarList(&m_titlebar_left[0], &m_titlebar_left[1]), "session.titlebar.left", "Session.Titlebar.Left"), m_rc_titlebar_right(m_resourcemanager, TitlebarList(&m_titlebar_right[0], &m_titlebar_right[3]), "session.titlebar.right", "Session.Titlebar.Right"), m_rc_cache_life(m_resourcemanager, 5, "session.cacheLife", "Session.CacheLife"), m_rc_cache_max(m_resourcemanager, 200, "session.cacheMax", "Session.CacheMax"), focused_window(0), masked_window(0), timer(this), watching_screen(0), watch_keyrelease(0), no_focus(false), rc_file(rc ? rc : ""), argv(m_argv), argc(m_argc), key(0) { if (singleton != 0) { cerr<<"Fatal! There can only one instance of fluxbox class."<<endl; abort(); } //catch system signals SignalHandler *sigh = SignalHandler::instance(); sigh->registerHandler(SIGSEGV, this); sigh->registerHandler(SIGFPE, this); sigh->registerHandler(SIGTERM, this); sigh->registerHandler(SIGINT, this); sigh->registerHandler(SIGCHLD, this); sigh->registerHandler(SIGHUP, this); sigh->registerHandler(SIGUSR1, this); sigh->registerHandler(SIGUSR2, this); //setup cursor bitmaps cursor.session = XCreateFontCursor(getXDisplay(), XC_left_ptr); cursor.move = XCreateFontCursor(getXDisplay(), XC_fleur); cursor.ll_angle = XCreateFontCursor(getXDisplay(), XC_ll_angle); cursor.lr_angle = XCreateFontCursor(getXDisplay(), XC_lr_angle); //singleton pointer singleton = this; // setup atom handlers #ifdef USE_GNOME m_atomhandler.push_back(new Gnome()); // for gnome 1 atom support #endif //USE_GNOME #ifdef USE_NEWWMSPEC m_atomhandler.push_back(new Ewmh()); // for Extended window manager atom support #endif // USE_NEWWMSPEC grab(); setupConfigFiles(); if (! XSupportsLocale()) cerr<<"Warning: X server does not support locale"<<endl; if (XSetLocaleModifiers("") == 0) cerr<<"Warning: cannot set locale modifiers"<<endl; // Set default values to member variables resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0; masked = None; #ifdef HAVE_GETPID fluxbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False); #endif // HAVE_GETPID int i; load_rc(); //allocate screens for (i = 0; i < getNumberOfScreens(); i++) { char scrname[128], altscrname[128]; sprintf(scrname, "session.screen%d", i); sprintf(altscrname, "session.Screen%d", i); BScreen *screen = new BScreen(m_screen_rm, scrname, altscrname, i, getNumberOfLayers()); if (! screen->isScreenManaged()) { delete screen; continue; } screenList.push_back(screen); m_atomhandler.push_back(&screen->getToolbarHandler()); // attach screen signals to this screen->currentWorkspaceSig().attach(this); screen->workspaceCountSig().attach(this); screen->workspaceNamesSig().attach(this); screen->clientListSig().attach(this); // initiate atomhandler for screen specific stuff for (size_t atomh=0; atomh<m_atomhandler.size(); ++atomh) { m_atomhandler[atomh]->initForScreen(*screen); } } I18n *i18n = I18n::instance(); if (screenList.size() == 0) { throw string( i18n-> getMessage( FBNLS::blackboxSet, FBNLS::blackboxNoManagableScreens, "Fluxbox::Fluxbox: no managable screens found, aborting.")); } XSynchronize(getXDisplay(), False); XSync(getXDisplay(), False); reconfigure_wait = reread_menu_wait = false; timer.setTimeout(0); timer.fireOnce(True); //create keybindings handler and load keys file key.reset(new Keys(StringUtil::expandFilename(*m_rc_keyfile).c_str())); ungrab(); } Fluxbox::~Fluxbox() { // destroy atomhandlers while (!m_atomhandler.empty()) { delete m_atomhandler.back(); m_atomhandler.pop_back(); } std::list<MenuTimestamp *>::iterator it = menuTimestamps.begin(); std::list<MenuTimestamp *>::iterator it_end = menuTimestamps.end(); for (; it != it_end; ++it) { MenuTimestamp *ts = *it; if (ts->filename) delete [] ts->filename; delete ts; } } /** setup the configutation files in home directory */ void Fluxbox::setupConfigFiles() { bool createInit, createKeys, createMenu; createInit = createKeys = createMenu = false; string dirname = getenv("HOME")+string("/.")+string(RC_PATH) + "/"; string initFile, keysFile, menuFile, slitlistFile; initFile = dirname+RC_INIT_FILE; keysFile = dirname+"keys"; menuFile = dirname+"menu"; struct stat buf; // is file/dir already there? if (! stat(dirname.c_str(), &buf)) { /*TODO: this if (! (buf.st_mode & S_IFDIR)) { cerr << dirname.c_str() << "!" << endl; return 1; } */ // check if anything with those name exists, if not create new if (stat(initFile.c_str(), &buf)) createInit = true; if (stat(keysFile.c_str(), &buf)) createKeys = true; if (stat(menuFile.c_str(), &buf)) createMenu = true; } else { #ifdef DEBUG cerr <<__FILE__<<"("<<__LINE__<<"): Creating dir: " << dirname.c_str() << endl; #endif // DEBUG // create directory with perm 700 if (mkdir(dirname.c_str(), 0700)) { cerr << "Can't create " << dirname << " directory!" << endl; return; } //mark creation of files createInit = createKeys = createMenu = true; } // should we copy key configuraion? if (createKeys) { ifstream from(DEFAULTKEYSFILE); ofstream to(keysFile.c_str()); if (! to.good()) { cerr << "Can't write file" << endl; } else if (from.good()) { #ifdef DEBUG cerr << "Copying file: " << DEFAULTKEYSFILE << endl; #endif // DEBUG to<<from.rdbuf(); //copy file } else { cerr<<"Can't copy default keys file."<<endl; } } // should we copy menu configuraion? if (createMenu) { ifstream from(DEFAULTMENU); ofstream to(menuFile.c_str()); if (! to.good()) { cerr << "Can't open " << menuFile.c_str() << "for writing" << endl; } else if (from.good()) { #ifdef DEBUG cerr << "Copying file: " << DEFAULTMENU << endl; #endif // DEBUG to<<from.rdbuf(); //copy file } else { cerr<<"Can't copy default menu file."<<endl; } } // should we copy default init file? if (createInit) { ifstream from(DEFAULT_INITFILE); ofstream to(initFile.c_str()); if (! to.good()) { cerr << "Can't open " << initFile.c_str() << "for writing" << endl; } else if (from.good()) { #ifdef DEBUG cerr << "Copying file: " << DEFAULT_INITFILE << endl; #endif // DEBUG to<<from.rdbuf(); //copy file } else { cerr<<"Can't copy default init file."<<endl; } } } void Fluxbox::handleEvent(XEvent * const e) { // it is possible (e.g. during moving) for a window // to mask all events to go to it if ((masked == e->xany.window) && masked_window) { if (e->type == MotionNotify) { last_time = e->xmotion.time; masked_window->motionNotifyEvent(e->xmotion); return; } else if (e->type == ButtonRelease) { e->xbutton.window = masked_window->getFbWindow().window(); } } // try FbTk::EventHandler first FbTk::EventManager::instance()->handleEvent(*e); switch (e->type) { case ButtonRelease: case ButtonPress: handleButtonEvent(e->xbutton); break; case ConfigureRequest: { FluxboxWindow *win = (FluxboxWindow *) 0; if ((win = searchWindow(e->xconfigurerequest.window))) { // already handled in FluxboxWindow::handleEvent } else { grab(); if (validateWindow(e->xconfigurerequest.window)) { XWindowChanges xwc; xwc.x = e->xconfigurerequest.x; xwc.y = e->xconfigurerequest.y; xwc.width = e->xconfigurerequest.width; xwc.height = e->xconfigurerequest.height; xwc.border_width = e->xconfigurerequest.border_width; xwc.sibling = e->xconfigurerequest.above; xwc.stack_mode = e->xconfigurerequest.detail; XConfigureWindow(FbTk::App::instance()->display(), e->xconfigurerequest.window, e->xconfigurerequest.value_mask, &xwc); } ungrab(); } } break; case MapRequest: { #ifdef DEBUG cerr<<"MapRequest for 0x"<<hex<<e->xmaprequest.window<<dec<<endl; #endif // DEBUG FluxboxWindow *win = searchWindow(e->xmaprequest.window); if (! win) { //!!! TODO BScreen *scr = searchScreen(e->xmaprequest.parent); cerr<<"screen = "<<scr<<endl; if (scr != 0) win = scr->createWindow(e->xmaprequest.window); else cerr<<"Fluxbox Warning! Could not find screen to map window on!"<<endl; } // handled in FluxboxWindow::handleEvent if (win) win->mapRequestEvent(e->xmaprequest); } break; case MapNotify: { // handled directly in FluxboxWindow::handleEvent FluxboxWindow *win = searchWindow(e->xmap.window); if (win) win->mapNotifyEvent(e->xmap); } break; case UnmapNotify: handleUnmapNotify(e->xunmap); break; case MappingNotify: // Update stored modifier mapping #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): MappingNotify"<<endl; #endif // DEBUG if (key.get()) { key->loadModmap(); } break; case CreateNotify: break; case DestroyNotify: { #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): DestroyNotify window="<<hex<< e->xdestroywindow.window<<dec<<endl; #endif // DEBUG FluxboxWindow *win = searchWindow(e->xdestroywindow.window); if (win != 0) { WinClient *client = win->findClient(e->xdestroywindow.window); if (client != 0) { win->destroyNotifyEvent(e->xdestroywindow); delete client; if (win->numClients() == 0 || &win->winClient() == client && win->numClients() == 1) { delete win; } } } } break; case MotionNotify: break; case PropertyNotify: { last_time = e->xproperty.time; if (e->xproperty.state != PropertyDelete) { FluxboxWindow *win = searchWindow(e->xproperty.window); if (win) win->propertyNotifyEvent(e->xproperty.atom); } } break; case EnterNotify: { last_time = e->xcrossing.time; BScreen *screen = 0; if (e->xcrossing.mode == NotifyGrab) break; if ((e->xcrossing.window == e->xcrossing.root) && (screen = searchScreen(e->xcrossing.window))) { screen->getImageControl()->installRootColormap(); } } break; case LeaveNotify: { last_time = e->xcrossing.time; } break; case Expose: { FluxboxWindow *win = (FluxboxWindow *) 0; if ((win = searchWindow(e->xexpose.window))) win->exposeEvent(e->xexpose); } break; case KeyRelease: case KeyPress: handleKeyEvent(e->xkey); break; case ColormapNotify: { BScreen *screen = searchScreen(e->xcolormap.window); if (screen != 0) { screen->setRootColormapInstalled((e->xcolormap.state == ColormapInstalled) ? True : False); } } break; case FocusIn: { if (e->xfocus.mode == NotifyUngrab || e->xfocus.detail == NotifyPointer) break; FluxboxWindow *win = searchWindow(e->xfocus.window); if (win && ! win->isFocused()) setFocusedWindow(win); } break; case FocusOut: break; case ClientMessage: handleClientMessage(e->xclient); break; default: { #ifdef SHAPE if (e->type == getShapeEventBase()) { XShapeEvent *shape_event = (XShapeEvent *) e; FluxboxWindow *win = (FluxboxWindow *) 0; if ((win = searchWindow(e->xany.window)) || (shape_event->kind != ShapeBounding)) win->shapeEvent(shape_event); } #endif // SHAPE } } } void Fluxbox::handleButtonEvent(XButtonEvent &be) { switch (be.type) { case ButtonPress: { last_time = be.time; ScreenList::iterator it = screenList.begin(); ScreenList::iterator it_end = screenList.end(); for (; it != it_end; ++it) { BScreen *screen = *it; if (be.window != screen->getRootWindow()) continue; if (be.button == 1) { if (! screen->isRootColormapInstalled()) screen->getImageControl()->installRootColormap(); if (screen->getWorkspacemenu()->isVisible()) screen->getWorkspacemenu()->hide(); if (screen->getRootmenu()->isVisible()) screen->getRootmenu()->hide(); } else if (be.button == 2) { int mx = be.x_root - (screen->getWorkspacemenu()->width() / 2); int my = be.y_root - (screen->getWorkspacemenu()->titleHeight() / 2); if (mx < 0) mx = 0; if (my < 0) my = 0; if (mx + screen->getWorkspacemenu()->width() > screen->getWidth()) { mx = screen->getWidth() - screen->getWorkspacemenu()->width() - screen->getBorderWidth(); } if (my + screen->getWorkspacemenu()->height() > screen->getHeight()) { my = screen->getHeight() - screen->getWorkspacemenu()->height() - screen->getBorderWidth(); } screen->getWorkspacemenu()->move(mx, my); if (! screen->getWorkspacemenu()->isVisible()) { screen->getWorkspacemenu()->removeParent(); screen->getWorkspacemenu()->show(); } } else if (be.button == 3) { //calculate placement of workspace menu //and show/hide it int mx = be.x_root - (screen->getRootmenu()->width() / 2); int my = be.y_root - (screen->getRootmenu()->titleHeight() / 2); if (mx < 0) mx = 0; if (my < 0) my = 0; if (mx + screen->getRootmenu()->width() > screen->getWidth()) { mx = screen->getWidth() - screen->getRootmenu()->width() - screen->getBorderWidth(); } if (my + screen->getRootmenu()->height() > screen->getHeight()) { my = screen->getHeight() - screen->getRootmenu()->height() - screen->getBorderWidth(); } screen->getRootmenu()->move(mx, my); if (! screen->getRootmenu()->isVisible()) { checkMenu(); screen->getRootmenu()->show(); } } else if (screen->isDesktopWheeling() && be.button == 4) { screen->nextWorkspace(1); } else if (screen->isDesktopWheeling() && be.button == 5) { screen->prevWorkspace(1); } } // end for } break; case ButtonRelease: { last_time = be.time; FluxboxWindow *win = (FluxboxWindow *) 0; if ((win = searchWindow(be.window))) win->buttonReleaseEvent(be); } break; default: break; } } void Fluxbox::handleUnmapNotify(XUnmapEvent &ue) { FluxboxWindow *win = 0; BScreen *screen = searchScreen(ue.event); if ( ue.event != ue.window && (screen != 0 || !ue.send_event)) return; if ((win = searchWindow(ue.window)) != 0) { WinClient *client = win->findClient(ue.window); if (client != 0) { win->unmapNotifyEvent(ue); client = 0; // it's invalid now when win destroyed the client if (win == focused_window) focused_window = 0; // finaly destroy window if empty if (win->numClients() == 0) { delete win; win = 0; } } } } /** * Handles XClientMessageEvent */ void Fluxbox::handleClientMessage(XClientMessageEvent &ce) { #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): ClientMessage. data.l[0]=0x"<<hex<<ce.data.l[0]<< " message_type=0x"<<ce.message_type<<dec<<endl; #endif // DEBUG if (ce.format != 32) return; if (ce.message_type == m_fbatoms->getWMChangeStateAtom()) { FluxboxWindow *win = searchWindow(ce.window); if (! win || ! win->validateClient()) return; if (ce.data.l[0] == IconicState) win->iconify(); if (ce.data.l[0] == NormalState) win->deiconify(); } else if (ce.message_type == m_fbatoms->getFluxboxChangeWorkspaceAtom()) { BScreen *screen = searchScreen(ce.window); if (screen && ce.data.l[0] >= 0 && ce.data.l[0] < (signed)screen->getCount()) screen->changeWorkspaceID(ce.data.l[0]); } else if (ce.message_type == m_fbatoms->getFluxboxChangeWindowFocusAtom()) { FluxboxWindow *win = searchWindow(ce.window); if (win && win->isVisible() && win->setInputFocus()) win->installColormap(True); } else if (ce.message_type == m_fbatoms->getFluxboxCycleWindowFocusAtom()) { BScreen *screen = searchScreen(ce.window); if (screen) { if (! ce.data.l[0]) screen->prevFocus(); else screen->nextFocus(); } } else if (ce.message_type == m_fbatoms->getFluxboxChangeAttributesAtom()) { FluxboxWindow *win = searchWindow(ce.window); if (win && win->validateClient()) { BlackboxHints net; net.flags = ce.data.l[0]; net.attrib = ce.data.l[1]; net.workspace = ce.data.l[2]; net.stack = ce.data.l[3]; net.decoration = static_cast<int>(ce.data.l[4]); win->changeBlackboxHints(net); } } else { FluxboxWindow *win = searchWindow(ce.window); BScreen *screen = searchScreen(ce.window); for (size_t i=0; i<m_atomhandler.size(); ++i) { m_atomhandler[i]->checkClientMessage(ce, screen, win); } } } /** Handles KeyRelease and KeyPress events */ void Fluxbox::handleKeyEvent(XKeyEvent &ke) { switch (ke.type) { case KeyPress: { BScreen *screen = searchScreen(ke.window); if (screen == 0) break; #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): KeyEvent"<<endl; #endif //find action Keys::KeyAction action = key->getAction(&ke); #ifdef DEBUG const char *actionstr = key->getActionStr(action); if (actionstr) cerr<<"KeyAction("<<actionstr<<")"<<endl; #endif if (action==Keys::LASTKEYGRAB) //if action not found end case break; // what to allow if moving if (focused_window && focused_window->isMoving()) { int allowed = false; switch (action) { case Keys::WORKSPACE: case Keys::SENDTOWORKSPACE: case Keys::WORKSPACE1: case Keys::WORKSPACE2: case Keys::WORKSPACE3: case Keys::WORKSPACE4: case Keys::WORKSPACE5: case Keys::WORKSPACE6: case Keys::WORKSPACE7: case Keys::WORKSPACE8: case Keys::WORKSPACE9: case Keys::WORKSPACE10: case Keys::WORKSPACE11: case Keys::WORKSPACE12: case Keys::NEXTWORKSPACE: case Keys::PREVWORKSPACE: case Keys::LEFTWORKSPACE: case Keys::RIGHTWORKSPACE: allowed = true; break; default: allowed = false; } if (!allowed) break; } switch (action) { case Keys::WORKSPACE: // Workspace1 has id 0, hence -1 screen->changeWorkspaceID(key->getParam()-1); break; case Keys::SENDTOWORKSPACE: // Workspace1 has id 0, hence -1 screen->sendToWorkspace(key->getParam()-1); break; // NOTE!!! The WORKSPACEn commands are not needed anymore case Keys::WORKSPACE1: screen->changeWorkspaceID(0); break; case Keys::WORKSPACE2: screen->changeWorkspaceID(1); break; case Keys::WORKSPACE3: screen->changeWorkspaceID(2); break; case Keys::WORKSPACE4: screen->changeWorkspaceID(3); break; case Keys::WORKSPACE5: screen->changeWorkspaceID(4); break; case Keys::WORKSPACE6: screen->changeWorkspaceID(5); break; case Keys::WORKSPACE7: screen->changeWorkspaceID(6); break; case Keys::WORKSPACE8: screen->changeWorkspaceID(7); break; case Keys::WORKSPACE9: screen->changeWorkspaceID(8); break; case Keys::WORKSPACE10: screen->changeWorkspaceID(9); break; case Keys::WORKSPACE11: screen->changeWorkspaceID(10); break; case Keys::WORKSPACE12: screen->changeWorkspaceID(11); break; case Keys::NEXTWORKSPACE: screen->nextWorkspace(key->getParam()); break; case Keys::PREVWORKSPACE: screen->prevWorkspace(key->getParam()); break; case Keys::LEFTWORKSPACE: screen->leftWorkspace(key->getParam()); break; case Keys::RIGHTWORKSPACE: screen->rightWorkspace(key->getParam()); break; case Keys::KILLWINDOW: //kill the current window if (focused_window) { XKillClient(screen->getBaseDisplay()->getXDisplay(), focused_window->getClientWindow()); } break; case Keys::NEXTWINDOW: //activate next window if (!watching_screen && !(key->getParam() & BScreen::CYCLELINEAR)) { // if stacked cycling, then set a watch for // the release of exactly these modifiers watchKeyRelease(screen, Keys::cleanMods(ke.state)); } screen->nextFocus(key->getParam()); break; case Keys::PREVWINDOW: //activate prev window if (!watching_screen && !(key->getParam() & BScreen::CYCLELINEAR)) { // if stacked cycling, then set a watch for // the release of exactly these modifiers watchKeyRelease(screen, Keys::cleanMods(ke.state)); } screen->prevFocus(key->getParam()); break; case Keys::FOCUSUP: if (focused_window) screen->dirFocus(*focused_window, BScreen::FOCUSUP); break; case Keys::FOCUSDOWN: if (focused_window) screen->dirFocus(*focused_window, BScreen::FOCUSDOWN); break; case Keys::FOCUSLEFT: if (focused_window) screen->dirFocus(*focused_window, BScreen::FOCUSLEFT); break; case Keys::FOCUSRIGHT: if (focused_window) screen->dirFocus(*focused_window, BScreen::FOCUSRIGHT); break; case Keys::NEXTTAB: if (focused_window && focused_window->numClients() > 1) focused_window->nextClient(); break; case Keys::PREVTAB: if (focused_window && focused_window->numClients() > 1) focused_window->prevClient(); break; case Keys::FIRSTTAB: cerr<<"FIRSTTAB TODO!"<<endl; break; case Keys::LASTTAB: cerr<<"LASTTAB TODO!"<<endl; break; case Keys::MOVETABPREV: cerr<<"MOVETABPREV TODO!"<<endl; break; case Keys::MOVETABNEXT: cerr<<"MOVETABNEXT TODO!"<<endl; break; case Keys::ATTACHLAST: //!! just attach last window to focused window if (focused_window) { Workspace *space = screen->getCurrentWorkspace(); Workspace::Windows &wins = space->getWindowList(); if (wins.size() == 1) break; BScreen::FocusedWindows &fwins = screen->getFocusedList(); BScreen::FocusedWindows::iterator it = fwins.begin(); for (; it != fwins.end(); ++it) { if ((*it)->fbwindow() != focused_window && (*it)->fbwindow()->getWorkspaceNumber() == screen->getCurrentWorkspaceID()) { focused_window->attachClient(**it); break; } } } break; case Keys::DETACHCLIENT: if (focused_window) { focused_window->detachClient(focused_window->winClient()); } break; case Keys::EXECUTE: //execute command on keypress { FbCommands::ExecuteCmd cmd(key->getExecCommand()); cmd.execute(); } break; case Keys::QUIT: { shutdown(); } break; case Keys::ROOTMENU: //show root menu { ScreenList::iterator it = screenList.begin(); ScreenList::iterator it_end = screenList.end(); for (; it != it_end; ++it) { BScreen *screen = (*it); if (ke.window != screen->getRootWindow()) continue; //calculate placement of workspace menu //and show/hide it int mx = ke.x_root - (screen->getRootmenu()->width() / 2); int my = ke.y_root - (screen->getRootmenu()->titleHeight() / 2); if (mx < 0) mx = 0; if (my < 0) my = 0; if (mx + screen->getRootmenu()->width() > screen->getWidth()) { mx = screen->getWidth() - screen->getRootmenu()->width() - screen->getBorderWidth(); } if (my + screen->getRootmenu()->height() > screen->getHeight()) { my = screen->getHeight() - screen->getRootmenu()->height() - screen->getBorderWidth(); } screen->getRootmenu()->move(mx, my); if (! screen->getRootmenu()->isVisible()) { checkMenu(); screen->getRootmenu()->show(); } } } break; default: //try to see if its a window action doWindowAction(action, key->getParam()); } break; } case KeyRelease: { // we ignore most key releases unless we need to use // a release to stop something (e.g. window cycling). // we notify if _all_ of the watched modifiers are released if (watching_screen && watch_keyrelease) { // mask the mod of the released key out // won't mask anything if it isn't a mod ke.state &= ~key->keycodeToModmask(ke.keycode); if ((watch_keyrelease & ke.state) == 0) { watching_screen->notifyReleasedKeys(ke); XUngrabKeyboard(getXDisplay(), CurrentTime); // once they are released, we drop the watch watching_screen = 0; watch_keyrelease = 0; } } break; } default: break; } } void Fluxbox::doWindowAction(int action, const int param) { if (!focused_window) return; switch (action) { case Keys::ICONIFY: focused_window->iconify(); break; case Keys::RAISE: focused_window->raise(); break; case Keys::LOWER: focused_window->lower(); break; case Keys::RAISELAYER: focused_window->raiseLayer(); break; case Keys::LOWERLAYER: focused_window->lowerLayer(); break; case Keys::TOPLAYER: focused_window->moveToLayer(getBottomLayer()); break; case Keys::BOTTOMLAYER: focused_window->moveToLayer(getTopLayer()); break; case Keys::CLOSE: focused_window->close(); break; case Keys::SHADE: focused_window->shade(); // this has to be done in THIS order break; case Keys::MAXIMIZE: focused_window->maximize(); break; case Keys::STICK: focused_window->stick(); break; case Keys::VERTMAX: if (focused_window->isResizable()) focused_window->maximizeVertical(); break; case Keys::HORIZMAX: if (focused_window->isResizable()) focused_window->maximizeHorizontal(); break; case Keys::NUDGERIGHT: focused_window->moveResize( focused_window->getXFrame()+param, focused_window->getYFrame(), focused_window->getWidth(), focused_window->getHeight()); break; case Keys::NUDGELEFT: focused_window->moveResize( focused_window->getXFrame()-param, focused_window->getYFrame(), focused_window->getWidth(), focused_window->getHeight()); break; case Keys::NUDGEUP: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame()-param, focused_window->getWidth(), focused_window->getHeight()); break; case Keys::NUDGEDOWN: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame()+param, focused_window->getWidth(), focused_window->getHeight()); break; // NOTE !!! BIGNUDGExxxx is not needed, just use 10 as a parameter case Keys::BIGNUDGERIGHT: focused_window->moveResize( focused_window->getXFrame()+10, focused_window->getYFrame(), focused_window->getWidth(), focused_window->getHeight()); break; case Keys::BIGNUDGELEFT: focused_window->moveResize( focused_window->getXFrame()-10, focused_window->getYFrame(), focused_window->getWidth(), focused_window->getHeight()); break; case Keys::BIGNUDGEUP: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame()-10, focused_window->getWidth(), focused_window->getHeight()); break; case Keys::BIGNUDGEDOWN: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame()+10, focused_window->getWidth(), focused_window->getHeight()); break; case Keys::HORIZINC: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame(), focused_window->getWidth()+10, focused_window->getHeight()); break; case Keys::VERTINC: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame(), focused_window->getWidth(), focused_window->getHeight()+10); break; case Keys::HORIZDEC: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame(), focused_window->getWidth()-10, focused_window->getHeight()); break; case Keys::VERTDEC: focused_window->moveResize( focused_window->getXFrame(), focused_window->getYFrame(), focused_window->getWidth(), focused_window->getHeight()-10); break; case Keys::TOGGLEDECOR: focused_window->toggleDecoration(); break; case Keys::TOGGLETAB: cerr<<"TOGGLETAB TODO!"<<endl; break; default: //do nothing break; } } /// handle system signals void Fluxbox::handleSignal(int signum) { I18n *i18n = I18n::instance(); static int re_enter = 0; switch (signum) { case SIGCHLD: // we don't want the child process to kill us waitpid(-1, 0, WNOHANG | WUNTRACED); break; case SIGHUP: load_rc(); break; case SIGUSR1: reload_rc(); break; case SIGUSR2: rereadMenu(); break; case SIGSEGV: abort(); break; case SIGFPE: case SIGINT: case SIGTERM: shutdown(); break; default: fprintf(stderr, i18n->getMessage( FBNLS::BaseDisplaySet, FBNLS::BaseDisplaySignalCaught, "%s: signal %d caught\n"), getApplicationName(), signum); if (! isStartup() && ! re_enter) { re_enter = 1; fprintf(stderr, i18n->getMessage( FBNLS::BaseDisplaySet, FBNLS::BaseDisplayShuttingDown, "shutting down\n")); shutdown(); } fprintf(stderr, i18n->getMessage( FBNLS::BaseDisplaySet, FBNLS::BaseDisplayAborting, "aborting... dumping core\n")); abort(); break; } } void Fluxbox::update(FbTk::Subject *changedsub) { //TODO: fix signaling, this does not look good if (typeid(*changedsub) == typeid(FluxboxWindow::WinSubject)) { FluxboxWindow::WinSubject *winsub = dynamic_cast<FluxboxWindow::WinSubject *>(changedsub); FluxboxWindow &win = winsub->win(); if ((&(win.hintSig())) == changedsub) { // hint signal for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateHints(win); } } else if ((&(win.stateSig())) == changedsub) { // state signal for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateState(win); } // if window changed to iconic state // add to icon list if (win.isIconic()) { Workspace *space = win.getScreen().getWorkspace(win.getWorkspaceNumber()); if (space != 0) space->removeWindow(&win); win.getScreen().addIcon(&win); } if (win.isStuck()) { // if we're sticky then reassociate window // to all workspaces BScreen &scr = win.getScreen(); if (scr.getCurrentWorkspaceID() != win.getWorkspaceNumber()) { scr.reassociateWindow(&win, scr.getCurrentWorkspaceID(), true); } } } else if ((&(win.layerSig())) == changedsub) { // layer signal for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateLayer(win); } } else if ((&(win.dieSig())) == changedsub) { // window death signal for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateWindowClose(win); } // make sure each workspace get this BScreen &scr = win.getScreen(); scr.removeWindow(&win); } else if ((&(win.workspaceSig())) == changedsub) { // workspace signal for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateWorkspace(win); } } else { #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): WINDOW uncought signal from "<<&win<<endl; #endif // DEBUG } } else if (typeid(*changedsub) == typeid(BScreen::ScreenSubject)) { BScreen::ScreenSubject *subj = dynamic_cast<BScreen::ScreenSubject *>(changedsub); BScreen &screen = subj->screen(); if ((&(screen.workspaceCountSig())) == changedsub) { for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateWorkspaceCount(screen); } } else if ((&(screen.workspaceNamesSig())) == changedsub) { for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateWorkspaceNames(screen); } } else if ((&(screen.currentWorkspaceSig())) == changedsub) { for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateCurrentWorkspace(screen); } } else if ((&(screen.clientListSig())) == changedsub) { for (size_t i=0; i<m_atomhandler.size(); ++i) { if (m_atomhandler[i]->update()) m_atomhandler[i]->updateClientList(screen); } } } else if (typeid(*changedsub) == typeid(WinClient::WinClientSubj)) { WinClient::WinClientSubj *subj = dynamic_cast<WinClient::WinClientSubj *>(changedsub); WinClient &client = subj->winClient(); if (client.fbwindow()) { BScreen &screen = client.fbwindow()->getScreen(); screen.updateNetizenWindowDel(client.window()); screen.removeClient(client); } removeWindowSearch(client.window()); //!! TODO #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<") TODO: signal stuff for client death!!"<<endl; #endif // DEBUG } } void Fluxbox::attachSignals(FluxboxWindow &win) { win.hintSig().attach(this); win.stateSig().attach(this); win.workspaceSig().attach(this); win.layerSig().attach(this); win.winClient().dieSig().attach(this); win.dieSig().attach(this); for (size_t i=0; i<m_atomhandler.size(); ++i) { m_atomhandler[i]->setupWindow(win); } } BScreen *Fluxbox::searchScreen(Window window) { BScreen *screen = 0; ScreenList::iterator it = screenList.begin(); ScreenList::iterator it_end = screenList.end(); for (; it != it_end; ++it) { if (*it) { if ((*it)->getRootWindow() == window) { screen = (*it); return screen; } } } return 0; } FluxboxWindow *Fluxbox::searchWindow(Window window) { std::map<Window, FluxboxWindow *>::iterator it = windowSearch.find(window); return it == windowSearch.end() ? 0 : it->second; } FluxboxWindow *Fluxbox::searchGroup(Window window, FluxboxWindow *win) { std::map<Window, FluxboxWindow *>::iterator it = groupSearch.find(window); return it == groupSearch.end() ? 0 : it->second; } void Fluxbox::saveWindowSearch(Window window, FluxboxWindow *data) { windowSearch[window] = data; } void Fluxbox::saveGroupSearch(Window window, FluxboxWindow *data) { groupSearch[window] = data; } void Fluxbox::removeWindowSearch(Window window) { windowSearch.erase(window); } void Fluxbox::removeGroupSearch(Window window) { groupSearch.erase(window); } void Fluxbox::restart(const char *prog) { shutdown(); if (prog) { execlp(prog, prog, NULL); perror(prog); } // fall back in case the above execlp doesn't work execvp(argv[0], argv); execvp(basename(argv[0]), argv); } void Fluxbox::shutdown() { BaseDisplay::shutdown(); XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime); //send shutdown to all screens ScreenList::iterator it = screenList.begin(); ScreenList::iterator it_end = screenList.end(); for (; it != it_end; ++it) { if(*it) (*it)->shutdown(); } XSync(getXDisplay(), False); } //------ save_rc -------- //saves resources //---------------------- void Fluxbox::save_rc() { XrmDatabase new_blackboxrc = 0; char rc_string[1024]; string dbfile(getRcFilename()); if (dbfile.size() != 0) { m_resourcemanager.save(dbfile.c_str(), dbfile.c_str()); m_screen_rm.save(dbfile.c_str(), dbfile.c_str()); } else cerr<<"database filename is invalid!"<<endl; sprintf(rc_string, "session.doubleClickInterval: %lu", resource.double_click_interval); XrmPutLineResource(&new_blackboxrc, rc_string); sprintf(rc_string, "session.autoRaiseDelay: %lu", ((resource.auto_raise_delay.tv_sec * 1000) + (resource.auto_raise_delay.tv_usec / 1000))); XrmPutLineResource(&new_blackboxrc, rc_string); ScreenList::iterator it = screenList.begin(); ScreenList::iterator it_end = screenList.end(); //Save screen resources for (; it != it_end; ++it) { BScreen *screen = *it; int screen_number = screen->getScreenNumber(); /* #ifdef SLIT string slit_placement; switch (screen->getSlitPlacement()) { case Slit::TOPLEFT: slit_placement = "TopLeft"; break; case Slit::CENTERLEFT: slit_placement = "CenterLeft"; break; case Slit::BOTTOMLEFT: slit_placement = "BottomLeft"; break; case Slit::TOPCENTER: slit_placement = "TopCenter"; break; case Slit::BOTTOMCENTER: slit_placement = "BottomCenter"; break; case Slit::TOPRIGHT: slit_placement = "TopRight"; break; case Slit::BOTTOMRIGHT: slit_placement = "BottomRight"; break; case Slit::CENTERRIGHT: default: slit_placement = "CenterRight"; break; } sprintf(rc_string, "session.screen%d.slit.placement: %s", screen_number, slit_placement.c_str()); XrmPutLineResource(&new_blackboxrc, rc_string); sprintf(rc_string, "session.screen%d.slit.direction: %s", screen_number, ((screen->getSlitDirection() == Slit::HORIZONTAL) ? "Horizontal" : "Vertical")); XrmPutLineResource(&new_blackboxrc, rc_string); sprintf(rc_string, "session.screen%d.slit.autoHide: %s", screen_number, ((screen->getSlit()->doAutoHide()) ? "True" : "False")); XrmPutLineResource(&new_blackboxrc, rc_string); /* #ifdef XINERAMA sprintf(rc_string, "session.screen%d.slit.onHead: %d", screen_number, screen->getSlitOnHead()); XrmPutLineResource(&new_blackboxrc, rc_string); #endif // XINERAMA *//* #endif // SLIT */ sprintf(rc_string, "session.screen%d.rowPlacementDirection: %s", screen_number, ((screen->getRowPlacementDirection() == BScreen::LEFTRIGHT) ? "LeftToRight" : "RightToLeft")); XrmPutLineResource(&new_blackboxrc, rc_string); sprintf(rc_string, "session.screen%d.colPlacementDirection: %s", screen_number, ((screen->getColPlacementDirection() == BScreen::TOPBOTTOM) ? "TopToBottom" : "BottomToTop")); XrmPutLineResource(&new_blackboxrc, rc_string); string placement; switch (screen->getPlacementPolicy()) { case BScreen::CASCADEPLACEMENT: placement = "CascadePlacement"; break; case BScreen::COLSMARTPLACEMENT: placement = "ColSmartPlacement"; break; case BScreen::UNDERMOUSEPLACEMENT: placement = "UnderMousePlacement"; break; default: case BScreen::ROWSMARTPLACEMENT: placement = "RowSmartPlacement"; break; } sprintf(rc_string, "session.screen%d.windowPlacement: %s", screen_number, placement.c_str()); XrmPutLineResource(&new_blackboxrc, rc_string); // load_rc(screen); // these are static, but may not be saved in the users resource file, // writing these resources will allow the user to edit them at a later // time... but loading the defaults before saving allows us to rewrite the // users changes... #ifdef HAVE_STRFTIME sprintf(rc_string, "session.screen%d.strftimeFormat: %s", screen_number, screen->getStrftimeFormat()); XrmPutLineResource(&new_blackboxrc, rc_string); #else // !HAVE_STRFTIME sprintf(rc_string, "session.screen%d.dateFormat: %s", screen_number, ((screen->getDateFormat() == B_EUROPEANDATE) ? "European" : "American")); XrmPutLineResource(&new_blackboxrc, rc_string); sprintf(rc_string, "session.screen%d.clockFormat: %d", screen_number, ((screen->isClock24Hour()) ? 24 : 12)); XrmPutLineResource(&new_blackboxrc, rc_string); #endif // HAVE_STRFTIME // write out the users workspace names sprintf(rc_string, "session.screen%d.workspaceNames: ", screen_number); string workspaces_string(rc_string); for (unsigned int workspace=0; workspace < screen->getCount(); workspace++) { if (screen->getWorkspace(workspace)->name().size()!=0) workspaces_string.append(screen->getWorkspace(workspace)->name()); else workspaces_string.append("Null"); workspaces_string.append(","); } XrmPutLineResource(&new_blackboxrc, workspaces_string.c_str()); } XrmDatabase old_blackboxrc = XrmGetFileDatabase(dbfile.c_str()); XrmMergeDatabases(new_blackboxrc, &old_blackboxrc); //merge database together XrmPutFileDatabase(old_blackboxrc, dbfile.c_str()); XrmDestroyDatabase(old_blackboxrc); #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<<endl; #endif // DEBUG } //-------- getRcFilename ------------- // Returns filename of resource file //------------------------------------ string Fluxbox::getRcFilename() { if (rc_file.size() == 0) { // set default filename string defaultfile(getenv("HOME")+string("/.")+RC_PATH+string("/")+RC_INIT_FILE); return defaultfile; } return rc_file; } //-------- getDefaultDataFilename ------------- // Provides default filename of data file //--------------------------------------------- void Fluxbox::getDefaultDataFilename(char *name, string &filename) { filename = string(getenv("HOME")+string("/.")+RC_PATH+string("/")+name); } void Fluxbox::load_rc() { XrmDatabaseHelper database; //get resource filename string dbfile(getRcFilename()); if (dbfile.size() != 0) { if (!m_resourcemanager.load(dbfile.c_str())) { cerr<<"Faild to load database:"<<dbfile<<endl; cerr<<"Trying with: "<<DEFAULT_INITFILE<<endl; if (!m_resourcemanager.load(DEFAULT_INITFILE)) cerr<<"Faild to load database: "<<DEFAULT_INITFILE<<endl; } } else { if (!m_resourcemanager.load(DEFAULT_INITFILE)) cerr<<"Faild to load database: "<<DEFAULT_INITFILE<<endl; } XrmValue value; char *value_type; if (m_rc_menufile->size()) { *m_rc_menufile = StringUtil::expandFilename(*m_rc_menufile); if (!m_rc_menufile->size()) m_rc_menufile.setDefaultValue(); } else m_rc_menufile.setDefaultValue(); if (m_rc_slitlistfile->size() != 0) { *m_rc_slitlistfile = StringUtil::expandFilename(*m_rc_slitlistfile); } else { string filename; getDefaultDataFilename("slitlist", filename); m_rc_slitlistfile.setFromString(filename.c_str()); } if (*m_rc_colors_per_channel < 2) *m_rc_colors_per_channel = 2; else if (*m_rc_colors_per_channel > 6) *m_rc_colors_per_channel = 6; if (m_rc_stylefile->size() == 0) *m_rc_stylefile = DEFAULTSTYLE; else // expand tilde *m_rc_stylefile = StringUtil::expandFilename(*m_rc_stylefile); //load file database = XrmGetFileDatabase(dbfile.c_str()); if (database==0) { cerr<<"Fluxbox: Cant open "<<dbfile<<" !"<<endl; cerr<<"Using: "<<DEFAULT_INITFILE<<endl; database = XrmGetFileDatabase(DEFAULT_INITFILE); } if (XrmGetResource(*database, "session.doubleClickInterval", "Session.DoubleClickInterval", &value_type, &value)) { if (sscanf(value.addr, "%lu", &resource.double_click_interval) != 1) resource.double_click_interval = 250; } else resource.double_click_interval = 250; if (XrmGetResource(*database, "session.autoRaiseDelay", "Session.AutoRaiseDelay", &value_type, &value)) { if (sscanf(value.addr, "%lu", &resource.auto_raise_delay.tv_usec) != 1) resource.auto_raise_delay.tv_usec = 250; } else resource.auto_raise_delay.tv_usec = 250; resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000; resource.auto_raise_delay.tv_usec -= (resource.auto_raise_delay.tv_sec * 1000); resource.auto_raise_delay.tv_usec *= 1000; // expand tilde *m_rc_groupfile = StringUtil::expandFilename(*m_rc_groupfile); #ifdef DEBUG cerr<<__FILE__<<": Loading groups ("<<*m_rc_groupfile<<")"<<endl; #endif // DEBUG if (!Workspace::loadGroups(*m_rc_groupfile)) { cerr<<"Faild to load groupfile: "<<*m_rc_groupfile<<endl; } } void Fluxbox::load_rc(BScreen &screen) { //get resource filename string dbfile(getRcFilename()); if (dbfile.size() != 0) { if (!m_screen_rm.load(dbfile.c_str())) { cerr<<"Faild to load database:"<<dbfile<<endl; cerr<<"Trying with: "<<DEFAULT_INITFILE<<endl; if (!m_screen_rm.load(DEFAULT_INITFILE)) cerr<<"Faild to load database: "<<DEFAULT_INITFILE<<endl; } } else { if (!m_screen_rm.load(DEFAULT_INITFILE)) cerr<<"Faild to load database: "<<DEFAULT_INITFILE<<endl; } XrmDatabaseHelper database; database = XrmGetFileDatabase(dbfile.c_str()); if (database==0) database = XrmGetFileDatabase(DEFAULT_INITFILE); XrmValue value; char *value_type, name_lookup[1024], class_lookup[1024]; int screen_number = screen.getScreenNumber(); sprintf(name_lookup, "session.screen%d.rowPlacementDirection", screen_number); sprintf(class_lookup, "Session.Screen%d.RowPlacementDirection", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (! strncasecmp(value.addr, "righttoleft", value.size)) screen.saveRowPlacementDirection(BScreen::RIGHTLEFT); else screen.saveRowPlacementDirection(BScreen::LEFTRIGHT); } else screen.saveRowPlacementDirection(BScreen::LEFTRIGHT); sprintf(name_lookup, "session.screen%d.colPlacementDirection", screen_number); sprintf(class_lookup, "Session.Screen%d.ColPlacementDirection", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (! strncasecmp(value.addr, "bottomtotop", value.size)) screen.saveColPlacementDirection(BScreen::BOTTOMTOP); else screen.saveColPlacementDirection(BScreen::TOPBOTTOM); } else screen.saveColPlacementDirection(BScreen::TOPBOTTOM); screen.removeWorkspaceNames(); sprintf(name_lookup, "session.screen%d.workspaceNames", screen_number); sprintf(class_lookup, "Session.Screen%d.WorkspaceNames", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): Workspaces="<< screen.getNumberOfWorkspaces()<<endl; #endif // DEBUG char *search = StringUtil::strdup(value.addr); int i; for (i = 0; i < screen.getNumberOfWorkspaces(); i++) { char *nn; if (! i) nn = strtok(search, ","); else nn = strtok(0, ","); if (nn) screen.addWorkspaceName(nn); else break; } delete [] search; } sprintf(name_lookup, "session.screen%d.windowPlacement", screen_number); sprintf(class_lookup, "Session.Screen%d.WindowPlacement", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (! strncasecmp(value.addr, "RowSmartPlacement", value.size)) screen.savePlacementPolicy(BScreen::ROWSMARTPLACEMENT); else if (! strncasecmp(value.addr, "ColSmartPlacement", value.size)) screen.savePlacementPolicy(BScreen::COLSMARTPLACEMENT); else if (! strncasecmp(value.addr, "UnderMousePlacement", value.size)) screen.savePlacementPolicy(BScreen::UNDERMOUSEPLACEMENT); else screen.savePlacementPolicy(BScreen::CASCADEPLACEMENT); } else screen.savePlacementPolicy(BScreen::ROWSMARTPLACEMENT); #ifdef SLIT sprintf(name_lookup, "session.screen%d.slit.placement", screen_number); sprintf(class_lookup, "Session.Screen%d.Slit.Placement", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (! strncasecmp(value.addr, "TopLeft", value.size)) screen.saveSlitPlacement(Slit::TOPLEFT); else if (! strncasecmp(value.addr, "CenterLeft", value.size)) screen.saveSlitPlacement(Slit::CENTERLEFT); else if (! strncasecmp(value.addr, "BottomLeft", value.size)) screen.saveSlitPlacement(Slit::BOTTOMLEFT); else if (! strncasecmp(value.addr, "TopCenter", value.size)) screen.saveSlitPlacement(Slit::TOPCENTER); else if (! strncasecmp(value.addr, "BottomCenter", value.size)) screen.saveSlitPlacement(Slit::BOTTOMCENTER); else if (! strncasecmp(value.addr, "TopRight", value.size)) screen.saveSlitPlacement(Slit::TOPRIGHT); else if (! strncasecmp(value.addr, "BottomRight", value.size)) screen.saveSlitPlacement(Slit::BOTTOMRIGHT); else screen.saveSlitPlacement(Slit::CENTERRIGHT); } else screen.saveSlitPlacement(Slit::CENTERRIGHT); sprintf(name_lookup, "session.screen%d.slit.direction", screen_number); sprintf(class_lookup, "Session.Screen%d.Slit.Direction", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (! strncasecmp(value.addr, "Horizontal", value.size)) screen.saveSlitDirection(Slit::HORIZONTAL); else screen.saveSlitDirection(Slit::VERTICAL); } else screen.saveSlitDirection(Slit::VERTICAL); sprintf(name_lookup, "session.screen%d.slit.autoHide", screen_number); sprintf(class_lookup, "Session.Screen%d.Slit.AutoHide", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (! strncasecmp(value.addr, "True", value.size)) screen.saveSlitAutoHide(true); else screen.saveSlitAutoHide(false); } else screen.saveSlitAutoHide(false); /* #ifdef XINERAMA int tmp_head; sprintf(name_lookup, "session.screen%d.slit.onHead", screen_number); sprintf(class_lookup, "Session.Screen%d.Slit.OnHead", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (sscanf(value.addr, "%d", &tmp_head) != 1) tmp_head = 0; } else tmp_head = 0; screen->saveSlitOnHead(tmp_head); #endif // XINERAMA */ #endif // SLIT #ifdef HAVE_STRFTIME sprintf(name_lookup, "session.screen%d.strftimeFormat", screen_number); sprintf(class_lookup, "Session.Screen%d.StrftimeFormat", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) screen.saveStrftimeFormat(value.addr); else screen.saveStrftimeFormat("%I:%M %p"); #else // HAVE_STRFTIME sprintf(name_lookup, "session.screen%d.dateFormat", screen_number); sprintf(class_lookup, "Session.Screen%d.DateFormat", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { if (strncasecmp(value.addr, "european", value.size)) screen.saveDateFormat(B_AMERICANDATE); else screen.saveDateFormat(B_EUROPEANDATE); } else screen.saveDateFormat(B_AMERICANDATE); sprintf(name_lookup, "session.screen%d.clockFormat", screen_number); sprintf(class_lookup, "Session.Screen%d.ClockFormat", screen_number); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { int clock; if (sscanf(value.addr, "%d", &clock) != 1) screen.saveClock24Hour(False); else if (clock == 24) screen.saveClock24Hour(True); else screen.saveClock24Hour(False); } else screen.saveClock24Hour(False); #endif // HAVE_STRFTIME //check size on toolbarwidth percent if (screen.getToolbarWidthPercent() <= 0 || screen.getToolbarWidthPercent() > 100) screen.saveToolbarWidthPercent(66); } void Fluxbox::loadRootCommand(BScreen &screen) { string dbfile(getRcFilename()); XrmDatabaseHelper database(dbfile.c_str()); if (!*database) database = XrmGetFileDatabase(DEFAULT_INITFILE); XrmValue value; char *value_type, name_lookup[1024], class_lookup[1024]; sprintf(name_lookup, "session.screen%d.rootCommand", screen.getScreenNumber()); sprintf(class_lookup, "Session.Screen%d.RootCommand", screen.getScreenNumber()); if (XrmGetResource(*database, name_lookup, class_lookup, &value_type, &value)) { screen.saveRootCommand(value.addr==0 ? "": value.addr); } else screen.saveRootCommand(""); } void Fluxbox::reload_rc() { load_rc(); reconfigure(); } void Fluxbox::reconfigure() { reconfigure_wait = true; if (! timer.isTiming()) timer.start(); } void Fluxbox::real_reconfigure() { XrmDatabase new_blackboxrc = (XrmDatabase) 0; string dbfile(getRcFilename()); XrmDatabase old_blackboxrc = XrmGetFileDatabase(dbfile.c_str()); XrmMergeDatabases(new_blackboxrc, &old_blackboxrc); XrmPutFileDatabase(old_blackboxrc, dbfile.c_str()); if (old_blackboxrc) XrmDestroyDatabase(old_blackboxrc); std::list<MenuTimestamp *>::iterator it = menuTimestamps.begin(); std::list<MenuTimestamp *>::iterator it_end = menuTimestamps.end(); for (; it != it_end; ++it) { MenuTimestamp *ts = *it; if (ts) { if (ts->filename) delete [] ts->filename; delete ts; } } menuTimestamps.erase(menuTimestamps.begin(), menuTimestamps.end()); ScreenList::iterator sit = screenList.begin(); ScreenList::iterator sit_end = screenList.end(); for (; sit != sit_end; ++sit) (*sit)->reconfigure(); //reconfigure keys key->reconfigure(StringUtil::expandFilename(*m_rc_keyfile).c_str()); } void Fluxbox::checkMenu() { Bool reread = False; std::list<MenuTimestamp *>::iterator it = menuTimestamps.begin(); std::list<MenuTimestamp *>::iterator it_end = menuTimestamps.end(); for (; it != it_end && (! reread); ++it) { struct stat buf; if (! stat((*it)->filename, &buf)) { if ((*it)->timestamp != buf.st_ctime) reread = True; } else reread = True; } if (reread) rereadMenu(); } void Fluxbox::rereadMenu() { reread_menu_wait = True; if (! timer.isTiming()) timer.start(); } void Fluxbox::real_rereadMenu() { std::list<MenuTimestamp *>::iterator it = menuTimestamps.begin(); std::list<MenuTimestamp *>::iterator it_end = menuTimestamps.end(); for (; it != it_end; ++it) { MenuTimestamp *ts = *it; if (ts) { if (ts->filename) delete [] ts->filename; delete ts; } } menuTimestamps.erase(menuTimestamps.begin(), menuTimestamps.end()); ScreenList::iterator sit = screenList.begin(); ScreenList::iterator sit_end = screenList.end(); for (; sit != sit_end; ++sit) { (*sit)->rereadMenu(); } } void Fluxbox::saveMenuFilename(const char *filename) { Bool found = False; std::list<MenuTimestamp *>::iterator it = menuTimestamps.begin(); std::list<MenuTimestamp *>::iterator it_end = menuTimestamps.end(); for (; it != it_end; ++it) { if (! strcmp((*it)->filename, filename)) found = True; } if (! found) { struct stat buf; if (! stat(filename, &buf)) { MenuTimestamp *ts = new MenuTimestamp; ts->filename = StringUtil::strdup(filename); ts->timestamp = buf.st_ctime; menuTimestamps.push_back(ts); } } } void Fluxbox::timeout() { if (reconfigure_wait) real_reconfigure(); if (reread_menu_wait) real_rereadMenu(); reconfigure_wait = reread_menu_wait = false; } // set focused window void Fluxbox::setFocusedWindow(FluxboxWindow *win) { BScreen *old_screen = 0, *screen = 0; FluxboxWindow *old_win = 0; Toolbar *old_tbar = 0, *tbar = 0; Workspace *old_wkspc = 0, *wkspc = 0; if (focused_window != 0) { old_win = focused_window; old_screen = &old_win->getScreen(); old_tbar = old_screen->getToolbar(); old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber()); old_win->setFocusFlag(False); old_wkspc->menu().setItemSelected(old_win->getWindowNumber(), false); } if (win && ! win->isIconic()) { // make sure we have a valid win pointer with a valid screen ScreenList::iterator winscreen = std::find(screenList.begin(), screenList.end(), &win->getScreen()); if (winscreen == screenList.end()) { focused_window = 0; // the window pointer wasn't valid, mark no window focused } else { screen = *winscreen; tbar = screen->getToolbar(); wkspc = screen->getWorkspace(win->getWorkspaceNumber()); focused_window = win; // update focused window win->setFocusFlag(True); // set focus flag // select this window in workspace menu if (wkspc != 0) wkspc->menu().setItemSelected(win->getWindowNumber(), true); } } else focused_window = 0; if (tbar != 0) tbar->redrawWindowLabel(True); if (screen != 0) screen->updateNetizenWindowFocus(); if (old_tbar && old_tbar != tbar) old_tbar->redrawWindowLabel(True); if (old_screen && old_screen != screen) old_screen->updateNetizenWindowFocus(); } void Fluxbox::watchKeyRelease(BScreen *screen, unsigned int mods) { watching_screen = screen; watch_keyrelease = mods; XGrabKeyboard(getXDisplay(),screen->getRootWindow(), True, GrabModeAsync, GrabModeAsync, CurrentTime); } |