src/Window.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 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 |
// Window.cc for Fluxbox Window Manager // Copyright (c) 2001 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) // // Window.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. #include "Window.hh" #include "WinClient.hh" #include "fluxbox.hh" #include "Keys.hh" #include "Screen.hh" #include "FbWinFrameTheme.hh" #include "FbAtoms.hh" #include "RootTheme.hh" #include "Workspace.hh" #include "FbWinFrame.hh" #include "WinButton.hh" #include "WinButtonTheme.hh" #include "WindowCmd.hh" #include "Remember.hh" #include "MenuCreator.hh" #include "FocusControl.hh" #include "Layer.hh" #include "IconButton.hh" #include "ScreenPlacement.hh" #include "FbTk/StringUtil.hh" #include "FbTk/Compose.hh" #include "FbTk/EventManager.hh" #include "FbTk/KeyUtil.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/Select2nd.hh" #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H #ifdef SHAPE #include <X11/extensions/shape.h> #endif // SHAPE //use GNU extensions #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif // _GNU_SOURCE #include <X11/Xatom.h> #include <X11/keysym.h> #ifdef HAVE_CSTRING #include <cstring> #else #include <string.h> #endif #ifdef HAVE_CSTDIO #include <cstdio> #else #include <stdio.h> #endif #include <iostream> #ifdef HAVE_CASSERT #include <cassert> #else #include <assert.h> #endif #include <functional> #include <algorithm> using std::cerr; using std::endl; using std::string; using std::vector; using std::bind2nd; using std::mem_fun; using std::equal_to; using std::max; using std::swap; using namespace FbTk; #ifdef DEBUG using std::dec; using std::hex; #endif // DEBUG namespace { // X event scanner for enter/leave notifies - adapted from twm typedef struct scanargs { Window w; Bool leave, inferior, enter; } scanargs; // look for valid enter or leave events (that may invalidate the earlier one we are interested in) static Bool queueScanner(Display *, XEvent *e, char *args) { if (e->type == LeaveNotify && e->xcrossing.window == ((scanargs *) args)->w && e->xcrossing.mode == NotifyNormal) { ((scanargs *) args)->leave = true; ((scanargs *) args)->inferior = (e->xcrossing.detail == NotifyInferior); } else if (e->type == EnterNotify && e->xcrossing.mode == NotifyUngrab) ((scanargs *) args)->enter = true; return false; } /// returns the deepest transientFor, asserting against a close loop WinClient *getRootTransientFor(WinClient *client) { while (client && client->transientFor()) { assert(client != client->transientFor()); client = client->transientFor(); } return client; } /// raise window and do the same for each transient of the current window void raiseFluxboxWindow(FluxboxWindow &win) { if (win.oplock) return; if (win.isIconic()) return; win.oplock = true; // we need to lock actual restacking so that raising above active transient // won't do anything nasty if (!win.winClient().transientList().empty()) win.screen().layerManager().lock(); win.layerItem().raise(); // for each transient do raise WinClient::TransientList::const_iterator it = win.winClient().transientList().begin(); WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end(); for (; it != it_end; ++it) { if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic()) // TODO: should we also check if it is the active client? raiseFluxboxWindow(*(*it)->fbwindow()); } win.oplock = false; if (!win.winClient().transientList().empty()) win.screen().layerManager().unlock(); } /// lower window and do the same for each transient it holds void lowerFluxboxWindow(FluxboxWindow &win) { if (win.oplock) return; if (win.isIconic()) return; win.oplock = true; // we need to lock actual restacking so that raising above active transient // won't do anything nasty if (!win.winClient().transientList().empty()) win.screen().layerManager().lock(); // lower the windows from the top down, so they don't change stacking order WinClient::TransientList::const_reverse_iterator it = win.winClient().transientList().rbegin(); WinClient::TransientList::const_reverse_iterator it_end = win.winClient().transientList().rend(); for (; it != it_end; ++it) { if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic()) // TODO: should we also check if it is the active client? lowerFluxboxWindow(*(*it)->fbwindow()); } win.layerItem().lower(); win.oplock = false; if (!win.winClient().transientList().empty()) win.screen().layerManager().unlock(); } /// raise window and do the same for each transient it holds void tempRaiseFluxboxWindow(FluxboxWindow &win) { if (win.oplock) return; win.oplock = true; if (!win.isIconic()) { win.layerItem().tempRaise(); } // for each transient do raise WinClient::TransientList::const_iterator it = win.winClient().transientList().begin(); WinClient::TransientList::const_iterator it_end = win.winClient().transientList().end(); for (; it != it_end; ++it) { if ((*it)->fbwindow() && !(*it)->fbwindow()->isIconic()) // TODO: should we also check if it is the active client? tempRaiseFluxboxWindow(*(*it)->fbwindow()); } win.oplock = false; } class SetClientCmd:public FbTk::Command<void> { public: explicit SetClientCmd(WinClient &client):m_client(client) { } void execute() { m_client.focus(); } private: WinClient &m_client; }; /// helper class for some STL routines class ChangeProperty { public: ChangeProperty(Display *disp, Atom prop, int mode, unsigned char *state, int num):m_disp(disp), m_prop(prop), m_state(state), m_num(num), m_mode(mode){ } void operator () (FbTk::FbWindow *win) { XChangeProperty(m_disp, win->window(), m_prop, m_prop, 32, m_mode, m_state, m_num); } private: Display *m_disp; Atom m_prop; unsigned char *m_state; int m_num; int m_mode; }; }; int FluxboxWindow::s_num_grabs = 0; FluxboxWindow::FluxboxWindow(WinClient &client, FbTk::XLayer &layer): Focusable(client.screen(), this), oplock(false), m_hintsig(*this), m_statesig(*this), m_layersig(*this), m_workspacesig(*this), m_creation_time(0), moving(false), resizing(false), shaded(false), iconic(false), stuck(false), m_initialized(false), fullscreen(false), maximized(WindowState::MAX_NONE), m_attaching_tab(0), display(FbTk::App::instance()->display()), m_button_grab_x(0), m_button_grab_y(0), m_last_move_x(0), m_last_move_y(0), m_last_resize_h(1), m_last_resize_w(1), m_workspace_number(0), m_current_state(0), m_old_decoration_mask(0), m_client(&client), m_toggled_decos(false), m_icon_hidden(false), m_focus_hidden(false), m_focus_new(BoolAcc(screen().focusControl(), &FocusControl::focusNew)), m_mouse_focus(BoolAcc(screen().focusControl(), &FocusControl::isMouseFocus)), m_click_focus(true), m_last_button_x(0), m_last_button_y(0), m_button_theme(*this, screen().focusedWinButtonTheme(), screen().unfocusedWinButtonTheme()), m_theme(*this, screen().focusedWinFrameTheme(), screen().unfocusedWinFrameTheme()), m_frame(client.screen(), m_theme, client.screen().imageControl(), layer, 0, 0, 100, 100), m_placed(false), m_layernum(layer.getLayerNum()), m_old_layernum(0), m_parent(client.screen().rootWindow()), m_resize_corner(RIGHTBOTTOM) { m_theme.reconfigSig().attach(this); m_frame.frameExtentSig().attach(this); init(); if (!isManaged()) return; // add the window to the focus list // always add to front on startup to keep the focus order the same if (m_focused || Fluxbox::instance()->isStartup()) screen().focusControl().addFocusWinFront(*this); else screen().focusControl().addFocusWinBack(*this); Fluxbox::instance()->keys()->registerWindow(frame().window().window(), *this, Keys::ON_WINDOW); } FluxboxWindow::~FluxboxWindow() { if (WindowCmd<void>::window() == this) WindowCmd<void>::setWindow(0); if (FbMenu::window() == this) FbMenu::setWindow(0); if ( Fluxbox::instance()->keys() != 0 ) { Fluxbox::instance()->keys()-> unregisterWindow(frame().window().window()); } #ifdef DEBUG const char* title = m_client ? m_client->title().c_str() : "" ; cerr<<__FILE__<<"("<<__LINE__<<"): starting ~FluxboxWindow("<<this<<","<<title<<")"<<endl; cerr<<__FILE__<<"("<<__LINE__<<"): num clients = "<<numClients()<<endl; cerr<<__FILE__<<"("<<__LINE__<<"): curr client = "<<m_client<<endl; cerr<<__FILE__<<"("<<__LINE__<<"): m_labelbuttons.size = "<<m_labelbuttons.size()<<endl; #endif // DEBUG if (moving) stopMoving(true); if (resizing) stopResizing(true); if (m_attaching_tab) attachTo(0, 0, true); // no longer a valid window to do stuff with Fluxbox::instance()->removeWindowSearchGroup(frame().window().window()); Fluxbox::instance()->removeWindowSearchGroup(frame().tabcontainer().window()); Client2ButtonMap::iterator it = m_labelbuttons.begin(); Client2ButtonMap::iterator it_end = m_labelbuttons.end(); for (; it != it_end; ++it) frame().removeTab((*it).second); m_labelbuttons.clear(); m_timer.stop(); // notify die m_diesig.notify(); if (m_client != 0 && !m_screen.isShuttingdown()) delete m_client; // this also removes client from our list m_client = 0; if (m_clientlist.size() > 1) { cerr<<__FILE__<<"(~FluxboxWindow()) WARNING! clientlist > 1"<<endl; while (!m_clientlist.empty()) { detachClient(*m_clientlist.back()); } } if (!screen().isShuttingdown()) screen().focusControl().removeWindow(*this); #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): ~FluxboxWindow("<<this<<")"<<endl; #endif // DEBUG } void FluxboxWindow::init() { m_attaching_tab = 0; // fetch client size and placement XWindowAttributes wattrib; if (! m_client->getAttrib(wattrib) || !wattrib.screen || // no screen? ?? wattrib.override_redirect || // override redirect m_client->initial_state == WithdrawnState) // Slit client return; m_client->setFluxboxWindow(this); m_client->setGroupLeftWindow(None); // nothing to the left. if (Fluxbox::instance()->haveShape()) Shape::setShapeNotify(winClient()); //!! TODO init of client should be better // we don't want to duplicate code here and in attachClient m_clientlist.push_back(m_client); #ifdef DEBUG cerr<<__FILE__<<": FluxboxWindow::init(this="<<this<<", client="<<hex<< m_client->window()<<", frame = "<<frame().window().window()<<dec<<")"<<endl; #endif // DEBUG Fluxbox &fluxbox = *Fluxbox::instance(); associateClient(*m_client); frame().setLabelButtonFocus(*m_labelbuttons[m_client]); // redirect events from frame to us frame().setEventHandler(*this); fluxbox.saveWindowSearchGroup(frame().window().window(), this); fluxbox.saveWindowSearchGroup(frame().tabcontainer().window(), this); m_workspace_number = m_screen.currentWorkspaceID(); // set default decorations but don't apply them setDecorationMask(WindowState::getDecoMaskFromString(screen().defaultDeco()), false); functions.resize = functions.move = functions.iconify = functions.maximize = functions.close = functions.tabable = true; updateMWMHintsFromClient(*m_client); m_timer.setTimeout(fluxbox.getAutoRaiseDelay()); FbTk::RefCount<FbTk::Command<void> > raise_cmd(new FbTk::SimpleCommand<FluxboxWindow>(*this, &FluxboxWindow::raise)); m_timer.setCommand(raise_cmd); m_timer.fireOnce(true); /**************************************************/ /* Read state above here, apply state below here. */ /**************************************************/ if (m_client->isTransient()) { if (m_client->transientFor()->fbwindow()) stuck = m_client->transientFor()->fbwindow()->isStuck(); if (!screen().decorateTransient()) { decorations.maximize = functions.maximize = false; decorations.handle = false; } } if (!m_client->sizeHints().isResizable()) { functions.resize = functions.maximize = false; decorations.tab = false; //no tab for this window } associateClientWindow(); setWindowType(m_client->getWindowType()); if (fluxbox.isStartup()) m_placed = true; else if (m_client->isTransient() || m_client->normal_hint_flags & (PPosition|USPosition)) { int real_x = frame().x(); int real_y = frame().y(); if (real_x >= 0 && real_y >= 0 && real_x <= (signed) screen().width() && real_y <= (signed) screen().height()) m_placed = true; } else setOnHead(screen().getCurrHead()); // we must do this now, or else resizing may not work properly applyDecorations(); Fluxbox::instance()->attachSignals(*this); // this window is managed, we are now allowed to modify actual state m_initialized = true; if (m_workspace_number >= screen().numberOfWorkspaces()) m_workspace_number = screen().currentWorkspaceID(); // if we're a transient then we should be on the same layer as our parent if (m_client->isTransient() && m_client->transientFor()->fbwindow() && m_client->transientFor()->fbwindow() != this) layerItem().setLayer(m_client->transientFor()->fbwindow()->layerItem().getLayer()); else // if no parent then set default layer moveToLayer(m_layernum, m_layernum != ::Layer::NORMAL); // transients should be on the same workspace as parent if (m_client->isTransient() && m_client->transientFor()->fbwindow()) { m_workspace_number = m_client->transientFor()->fbwindow()->workspaceNumber(); } #ifdef DEBUG cerr<<"FluxboxWindow::init("<<title()<<") transientFor: "<< m_client->transientFor()<<endl; if (m_client->transientFor() && m_client->transientFor()->fbwindow()) { cerr<<"FluxboxWindow::init("<<title()<<") transientFor->title(): "<< m_client->transientFor()->fbwindow()->title()<<endl; } #endif // DEBUG unsigned int real_width = frame().width(), real_height = frame().height(); frame().applySizeHints(real_width, real_height); if (m_placed) moveResize(frame().x(), frame().y(), real_width, real_height); if (!m_placed) placeWindow(getOnHead()); screen().getWorkspace(m_workspace_number)->addWindow(*this); setFocusFlag(false); // update graphics before mapping if (stuck) { stuck = false; stick(); } if (shaded) { // start shaded shaded = false; shade(); } if (iconic) { iconic = false; iconify(); } else if (m_workspace_number == screen().currentWorkspaceID()) { iconic = true; deiconify(false); // check if we should prevent this window from gaining focus m_focused = false; // deiconify sets this if (!Fluxbox::instance()->isStartup() && m_focus_new) { m_focused = focusRequestFromClient(*m_client); if (!m_focused) lower(); } } if (fullscreen) { fullscreen = false; setFullscreen(true); } if (maximized) { int tmp = maximized; maximized = WindowState::MAX_NONE; setMaximizedState(tmp); } m_workspacesig.notify(); struct timeval now; gettimeofday(&now, NULL); m_creation_time = now.tv_sec; frame().frameExtentSig().notify(); setupWindow(); FbTk::App::instance()->sync(false); } /// attach a client to this window and destroy old window void FluxboxWindow::attachClient(WinClient &client, int x, int y) { //!! TODO: check for isGroupable in client if (client.fbwindow() == this) return; menu().hide(); // reparent client win to this frame frame().setClientWindow(client); bool was_focused = false; WinClient *focused_win = 0; // get the current window on the end of our client list Window leftwin = None; if (!clientList().empty()) leftwin = clientList().back()->window(); client.setGroupLeftWindow(leftwin); if (client.fbwindow() != 0) { FluxboxWindow *old_win = client.fbwindow(); // store old window if (FocusControl::focusedFbWindow() == old_win) was_focused = true; ClientList::iterator client_insert_pos = getClientInsertPosition(x, y); FbTk::TextButton *button_insert_pos = NULL; if (client_insert_pos != m_clientlist.end()) button_insert_pos = m_labelbuttons[*client_insert_pos]; // make sure we set new window search for each client ClientList::iterator client_it = old_win->clientList().begin(); ClientList::iterator client_it_end = old_win->clientList().end(); for (; client_it != client_it_end; ++client_it) { // reparent window to this frame().setClientWindow(**client_it); moveResizeClient(**client_it); // create a labelbutton for this client and // associate it with the pointer associateClient(*(*client_it)); //null if we want the new button at the end of the list if (x >= 0 && button_insert_pos) frame().moveLabelButtonLeftOf(*m_labelbuttons[*client_it], *button_insert_pos); } // add client and move over all attached clients // from the old window to this list m_clientlist.splice(client_insert_pos, old_win->m_clientlist); updateClientLeftWindow(); old_win->m_client = 0; delete old_win; } else { // client.fbwindow() == 0 associateClient(client); moveResizeClient(client); // right now, this block only happens with new windows or on restart bool is_startup = Fluxbox::instance()->isStartup(); // we use m_focused as a signal to focus the window when mapped if (m_focus_new && !is_startup) m_focused = focusRequestFromClient(client); focused_win = (m_focus_new || is_startup) ? &client : m_client; m_clientlist.push_back(&client); } // make sure that the state etc etc is updated for the new client // TODO: one day these should probably be neatened to only act on the // affected clients if possible m_statesig.notify(); m_workspacesig.notify(); m_layersig.notify(); if (was_focused) { // don't ask me why, but client doesn't seem to keep focus in new window // and we don't seem to get a FocusIn event from setInputFocus client.focus(); FocusControl::setFocusedWindow(&client); } else { if (!focused_win) focused_win = screen().focusControl().lastFocusedWindow(*this); if (focused_win) { setCurrentClient(*focused_win, false); if (isIconic() && m_focused) deiconify(); } } frame().reconfigure(); } /// detach client from window and create a new window for it bool FluxboxWindow::detachClient(WinClient &client) { if (client.fbwindow() != this || numClients() <= 1) return false; Window leftwin = None; ClientList::iterator client_it, client_it_after; client_it = client_it_after = find(clientList().begin(), clientList().end(), &client); if (client_it != clientList().begin()) leftwin = (*(--client_it))->window(); if (++client_it_after != clientList().end()) (*client_it_after)->setGroupLeftWindow(leftwin); removeClient(client); screen().createWindow(client); return true; } void FluxboxWindow::detachCurrentClient() { // should only operate if we had more than one client if (numClients() <= 1) return; WinClient &client = *m_client; detachClient(*m_client); if (client.fbwindow() != 0) client.fbwindow()->show(); } /// removes client from client list, does not create new fluxboxwindow for it bool FluxboxWindow::removeClient(WinClient &client) { if (client.fbwindow() != this || numClients() == 0) return false; #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<")["<<this<<"]"<<endl; #endif // DEBUG // if it is our active client, deal with it... if (m_client == &client) { WinClient *next_client = screen().focusControl().lastFocusedWindow(*this, m_client); if (next_client != 0) setCurrentClient(*next_client, false); } menu().hide(); m_clientlist.remove(&client); if (m_client == &client) { if (m_clientlist.empty()) m_client = 0; else // this really shouldn't happen m_client = m_clientlist.back(); } FbTk::EventManager &evm = *FbTk::EventManager::instance(); evm.remove(client.window()); IconButton *label_btn = m_labelbuttons[&client]; if (label_btn != 0) { frame().removeTab(label_btn); label_btn = 0; } m_labelbuttons.erase(&client); frame().reconfigure(); updateClientLeftWindow(); #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<")["<<this<<"] numClients = "<<numClients()<<endl; #endif // DEBUG return true; } /// returns WinClient of window we're searching for WinClient *FluxboxWindow::findClient(Window win) { ClientList::iterator it = find_if(clientList().begin(), clientList().end(), Compose(bind2nd(equal_to<Window>(), win), mem_fun(&WinClient::window))); return (it == clientList().end() ? 0 : *it); } /// raise and focus next client void FluxboxWindow::nextClient() { if (numClients() <= 1) return; ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), m_client); if (it == m_clientlist.end()) return; ++it; if (it == m_clientlist.end()) it = m_clientlist.begin(); setCurrentClient(**it, isFocused()); } void FluxboxWindow::prevClient() { if (numClients() <= 1) return; ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), m_client); if (it == m_clientlist.end()) return; if (it == m_clientlist.begin()) it = m_clientlist.end(); --it; setCurrentClient(**it, isFocused()); } void FluxboxWindow::moveClientLeft() { if (m_clientlist.size() == 1 || *m_clientlist.begin() == &winClient()) return; // move client in clientlist to the left ClientList::iterator oldpos = find(m_clientlist.begin(), m_clientlist.end(), &winClient()); ClientList::iterator newpos = oldpos; newpos--; swap(*newpos, *oldpos); frame().moveLabelButtonLeft(*m_labelbuttons[&winClient()]); updateClientLeftWindow(); } void FluxboxWindow::moveClientRight() { if (m_clientlist.size() == 1 || *m_clientlist.rbegin() == &winClient()) return; ClientList::iterator oldpos = find(m_clientlist.begin(), m_clientlist.end(), &winClient()); ClientList::iterator newpos = oldpos; newpos++; swap(*newpos, *oldpos); frame().moveLabelButtonRight(*m_labelbuttons[&winClient()]); updateClientLeftWindow(); } FluxboxWindow::ClientList::iterator FluxboxWindow::getClientInsertPosition(int x, int y) { int dest_x = 0, dest_y = 0; Window labelbutton = 0; if (!XTranslateCoordinates(FbTk::App::instance()->display(), parent().window(), frame().tabcontainer().window(), x, y, &dest_x, &dest_y, &labelbutton)) return m_clientlist.end(); Client2ButtonMap::iterator it = find_if(m_labelbuttons.begin(), m_labelbuttons.end(), Compose(bind2nd(equal_to<Window>(), labelbutton), Compose(mem_fun(&TextButton::window), Select2nd<Client2ButtonMap::value_type>()))); // label button not found if (it == m_labelbuttons.end()) return m_clientlist.end(); Window child_return=0; // make x and y relative to our labelbutton if (!XTranslateCoordinates(FbTk::App::instance()->display(), frame().tabcontainer().window(), labelbutton, dest_x, dest_y, &x, &y, &child_return)) return m_clientlist.end(); ClientList::iterator client = find(m_clientlist.begin(), m_clientlist.end(), it->first); if (x > static_cast<signed>((*it).second->width()) / 2) client++; return client; } void FluxboxWindow::moveClientTo(WinClient &win, int x, int y) { int dest_x = 0, dest_y = 0; Window labelbutton = 0; if (!XTranslateCoordinates(FbTk::App::instance()->display(), parent().window(), frame().tabcontainer().window(), x, y, &dest_x, &dest_y, &labelbutton)) return; Client2ButtonMap::iterator it = find_if(m_labelbuttons.begin(), m_labelbuttons.end(), Compose(bind2nd(equal_to<Window>(), labelbutton), Compose(mem_fun(&TextButton::window), Select2nd<Client2ButtonMap::value_type>()))); // label button not found if (it == m_labelbuttons.end()) return; Window child_return = 0; //make x and y relative to our labelbutton if (!XTranslateCoordinates(FbTk::App::instance()->display(), frame().tabcontainer().window(), labelbutton, dest_x, dest_y, &x, &y, &child_return)) return; if (x > static_cast<signed>((*it).second->width()) / 2) moveClientRightOf(win, *it->first); else moveClientLeftOf(win, *it->first); } void FluxboxWindow::moveClientLeftOf(WinClient &win, WinClient &dest) { frame().moveLabelButtonLeftOf(*m_labelbuttons[&win], *m_labelbuttons[&dest]); ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), &win); ClientList::iterator new_pos = find(m_clientlist.begin(), m_clientlist.end(), &dest); // make sure we found them if (it == m_clientlist.end() || new_pos==m_clientlist.end()) return; //moving a button to the left of itself results in no change if (new_pos == it) return; //remove from list m_clientlist.erase(it); //insert on the new place m_clientlist.insert(new_pos, &win); updateClientLeftWindow(); } void FluxboxWindow::moveClientRightOf(WinClient &win, WinClient &dest) { frame().moveLabelButtonRightOf(*m_labelbuttons[&win], *m_labelbuttons[&dest]); ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), &win); ClientList::iterator new_pos = find(m_clientlist.begin(), m_clientlist.end(), &dest); // make sure we found them if (it == m_clientlist.end() || new_pos==m_clientlist.end()) return; //moving a button to the right of itself results in no change if (new_pos == it) return; //remove from list m_clientlist.erase(it); //need to insert into the next position new_pos++; //insert on the new place if (new_pos == m_clientlist.end()) m_clientlist.push_back(&win); else m_clientlist.insert(new_pos, &win); updateClientLeftWindow(); } /// Update LEFT window atom on all clients. void FluxboxWindow::updateClientLeftWindow() { if (clientList().empty()) return; // It should just update the affected clients but that // would require more complex code and we're assuming // the user dont have alot of windows grouped so this // wouldn't be too time consuming and it's easier to // implement. ClientList::iterator it = clientList().begin(); ClientList::iterator it_end = clientList().end(); // set no left window on first tab (*it)->setGroupLeftWindow(0); WinClient *last_client = *it; ++it; for (; it != it_end; ++it) { (*it)->setGroupLeftWindow(last_client->window()); last_client = *it; } } bool FluxboxWindow::setCurrentClient(WinClient &client, bool setinput) { // make sure it's in our list if (client.fbwindow() != this) return false; IconButton *button = m_labelbuttons[&client]; // in case the window is being destroyed, but this should never happen if (!button) return false; WinClient *old = m_client; m_client = &client; bool ret = setinput && focus(); if (setinput) { m_client = old; return ret; } m_client->raise(); if (m_focused) { m_client->focusSig().notify(); if (old) old->focusSig().notify(); } if (old != &client) titleSig().notify(); #ifdef DEBUG cerr<<"FluxboxWindow::"<<__FUNCTION__<<": labelbutton[client] = "<< button<<endl; #endif // DEBUG // frame focused doesn't necessarily mean input focused frame().setLabelButtonFocus(*button); frame().setShapingClient(&client, false); return ret; } bool FluxboxWindow::isGroupable() const { if (isResizable() && isMaximizable() && !winClient().isTransient()) return true; return false; } void FluxboxWindow::associateClientWindow() { frame().setShapingClient(m_client, false); frame().moveResizeForClient(m_client->x(), m_client->y(), m_client->width(), m_client->height(), m_client->gravity(), m_client->old_bw); updateSizeHints(); frame().setClientWindow(*m_client); } void FluxboxWindow::updateSizeHints() { m_size_hint = m_client->sizeHints(); ClientList::const_iterator it = clientList().begin(); ClientList::const_iterator it_end = clientList().end(); for (; it != it_end; ++it) { if ((*it) == m_client) continue; const SizeHints &hint = (*it)->sizeHints(); if (m_size_hint.min_width < hint.min_width) m_size_hint.min_width = hint.min_width; if (m_size_hint.max_width > hint.max_width) m_size_hint.max_width = hint.max_width; if (m_size_hint.min_height < hint.min_height) m_size_hint.min_height = hint.min_height; if (m_size_hint.max_height > hint.max_height) m_size_hint.max_height = hint.max_height; // lcm could end up a bit silly, and the situation is bad no matter what if (m_size_hint.width_inc < hint.width_inc) m_size_hint.width_inc = hint.width_inc; if (m_size_hint.height_inc < hint.height_inc) m_size_hint.height_inc = hint.height_inc; if (m_size_hint.base_width < hint.base_width) m_size_hint.base_width = hint.base_width; if (m_size_hint.base_height < hint.base_height) m_size_hint.base_height = hint.base_height; if (m_size_hint.min_aspect_x * hint.min_aspect_y > m_size_hint.min_aspect_y * hint.min_aspect_x) { m_size_hint.min_aspect_x = hint.min_aspect_x; m_size_hint.min_aspect_y = hint.min_aspect_y; } if (m_size_hint.max_aspect_x * hint.max_aspect_y > m_size_hint.max_aspect_y * hint.max_aspect_x) { m_size_hint.max_aspect_x = hint.max_aspect_x; m_size_hint.max_aspect_y = hint.max_aspect_y; } } frame().setSizeHints(m_size_hint); } void FluxboxWindow::grabButtons() { // needed for click to focus XGrabButton(display, Button1, AnyModifier, frame().window().window(), True, ButtonPressMask, GrabModeSync, GrabModeSync, None, None); XUngrabButton(display, Button1, Mod1Mask|Mod2Mask|Mod3Mask, frame().window().window()); } void FluxboxWindow::reconfigure() { applyDecorations(); setFocusFlag(m_focused); moveResize(frame().x(), frame().y(), frame().width(), frame().height()); m_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay()); updateButtons(); frame().reconfigure(); menu().reconfigure(); Client2ButtonMap::iterator it = m_labelbuttons.begin(), it_end = m_labelbuttons.end(); for (; it != it_end; ++it) it->second->setPixmap(screen().getTabsUsePixmap()); } void FluxboxWindow::updateMWMHintsFromClient(WinClient &client) { const WinClient::MwmHints *hint = client.getMwmHint(); if (!hint) return; if (!m_toggled_decos && hint->flags & MwmHintsDecorations) { if (hint->decorations & MwmDecorAll) { decorations.titlebar = decorations.handle = decorations.border = decorations.iconify = decorations.maximize = decorations.close = decorations.menu = true; } else { decorations.titlebar = decorations.handle = decorations.border = decorations.iconify = decorations.maximize = decorations.close = decorations.tab = false; decorations.menu = true; if (hint->decorations & MwmDecorBorder) decorations.border = true; if (hint->decorations & MwmDecorHandle) decorations.handle = true; if (hint->decorations & MwmDecorTitle) { //only tab on windows with titlebar decorations.titlebar = decorations.tab = true; } if (hint->decorations & MwmDecorMenu) decorations.menu = true; if (hint->decorations & MwmDecorIconify) decorations.iconify = true; if (hint->decorations & MwmDecorMaximize) decorations.maximize = true; } } unsigned int mask = decorationMask(); mask &= WindowState::getDecoMaskFromString(screen().defaultDeco()); setDecorationMask(mask, false); // functions.tabable is ours, not special one // note that it means this window is "tabbable" if (hint->flags & MwmHintsFunctions) { if (hint->functions & MwmFuncAll) { functions.resize = functions.move = functions.iconify = functions.maximize = functions.close = true; } else { functions.resize = functions.move = functions.iconify = functions.maximize = functions.close = false; if (hint->functions & MwmFuncResize) functions.resize = true; if (hint->functions & MwmFuncMove) functions.move = true; if (hint->functions & MwmFuncIconify) functions.iconify = true; if (hint->functions & MwmFuncMaximize) functions.maximize = true; if (hint->functions & MwmFuncClose) functions.close = true; } } } void FluxboxWindow::updateFunctions() { if (!m_client) return; bool changed = false; if (m_client->isClosable() != functions.close) { functions.close = m_client->isClosable(); changed = true; } if (changed) setupWindow(); } void FluxboxWindow::move(int x, int y) { moveResize(x, y, frame().width(), frame().height()); } void FluxboxWindow::resize(unsigned int width, unsigned int height) { // don't set window as placed, since we're only resizing bool placed = m_placed; moveResize(frame().x(), frame().y(), width, height); m_placed = placed; } // send_event is just an override void FluxboxWindow::moveResize(int new_x, int new_y, unsigned int new_width, unsigned int new_height, bool send_event) { m_placed = true; send_event = send_event || frame().x() != new_x || frame().y() != new_y; if ((new_width != frame().width() || new_height != frame().height()) && isResizable() && !isShaded()) { if ((((signed) frame().width()) + new_x) < 0) new_x = 0; if ((((signed) frame().height()) + new_y) < 0) new_y = 0; frame().moveResize(new_x, new_y, new_width, new_height); setFocusFlag(m_focused); send_event = true; } else if (send_event) frame().move(new_x, new_y); if (send_event && ! moving) { sendConfigureNotify(); } if (!moving) { m_last_resize_x = new_x; m_last_resize_y = new_y; } } void FluxboxWindow::moveResizeForClient(int new_x, int new_y, unsigned int new_width, unsigned int new_height, int gravity, unsigned int client_bw) { m_placed = true; frame().moveResizeForClient(new_x, new_y, new_width, new_height, gravity, client_bw); setFocusFlag(m_focused); shaded = false; sendConfigureNotify(); if (!moving) { m_last_resize_x = new_x; m_last_resize_y = new_y; } } void FluxboxWindow::getMaxSize(unsigned int* width, unsigned int* height) const { if (width) *width = m_size_hint.max_width; if (height) *height = m_size_hint.max_height; } // returns whether the focus was "set" to this window // it doesn't guarantee that it has focus, but says that we have // tried. A FocusIn event should eventually arrive for that // window if it actually got the focus, then setFocusFlag is called, // which updates all the graphics etc bool FluxboxWindow::focus() { if (((signed) (frame().x() + frame().width())) < 0) { if (((signed) (frame().y() + frame().height())) < 0) { moveResize(frame().window().borderWidth(), frame().window().borderWidth(), frame().width(), frame().height()); } else if (frame().y() > (signed) screen().height()) { moveResize(frame().window().borderWidth(), screen().height() - frame().height(), frame().width(), frame().height()); } else { moveResize(frame().window().borderWidth(), frame().y() + frame().window().borderWidth(), frame().width(), frame().height()); } } else if (frame().x() > (signed) screen().width()) { if (((signed) (frame().y() + frame().height())) < 0) { moveResize(screen().width() - frame().width(), frame().window().borderWidth(), frame().width(), frame().height()); } else if (frame().y() > (signed) screen().height()) { moveResize(screen().width() - frame().width(), screen().height() - frame().height(), frame().width(), frame().height()); } else { moveResize(screen().width() - frame().width(), frame().y() + frame().window().borderWidth(), frame().width(), frame().height()); } } if (! m_client->validateClient()) return false; if (screen().currentWorkspaceID() != workspaceNumber() && !isStuck()) { BScreen::FollowModel model = screen().getUserFollowModel(); if (model == BScreen::IGNORE_OTHER_WORKSPACES) return false; // fetch the window to the current workspace if (model == BScreen::FETCH_ACTIVE_WINDOW || (isIconic() && model == BScreen::SEMIFOLLOW_ACTIVE_WINDOW)) screen().sendToWorkspace(screen().currentWorkspaceID(), this, false); // warp to the workspace of the window else screen().changeWorkspaceID(workspaceNumber(), false); } if (isIconic()) { deiconify(); m_focused = true; // signal to mapNotifyEvent to set focus when mapped return true; // the window probably will get focused, just not yet } // this needs to be here rather than setFocusFlag because // FocusControl::revertFocus will return before FocusIn events arrive m_screen.focusControl().setScreenFocusedWindow(*m_client); #ifdef DEBUG cerr<<"FluxboxWindow::"<<__FUNCTION__<<" isModal() = "<<m_client->isModal()<<endl; cerr<<"FluxboxWindow::"<<__FUNCTION__<<" transient size = "<<m_client->transients.size()<<endl; #endif // DEBUG if (!m_client->transients.empty() && m_client->isModal()) { #ifdef DEBUG cerr<<__FUNCTION__<<": isModal and have transients client = "<< hex<<m_client->window()<<dec<<endl; cerr<<__FUNCTION__<<": this = "<<this<<endl; #endif // DEBUG WinClient::TransientList::iterator it = m_client->transients.begin(); WinClient::TransientList::iterator it_end = m_client->transients.end(); for (; it != it_end; ++it) { #ifdef DEBUG cerr<<__FUNCTION__<<": transient 0x"<<(*it)<<endl; #endif // DEBUG if ((*it)->isStateModal()) return (*it)->focus(); } } if (m_client->isModal()) return false; return m_client->sendFocus(); } // don't hide the frame directly, use this function void FluxboxWindow::hide(bool interrupt_moving) { #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<")["<<this<<"]"<<endl; #endif // DEBUG // resizing always stops on hides if (resizing) stopResizing(true); if (interrupt_moving) { if (moving) stopMoving(true); if (m_attaching_tab) attachTo(0, 0, true); } setState(IconicState, false); menu().hide(); frame().hide(); if (FocusControl::focusedFbWindow() == this) FocusControl::setFocusedWindow(0); } void FluxboxWindow::show() { frame().show(); setState(NormalState, false); } void FluxboxWindow::toggleIconic() { if (isIconic()) deiconify(); else iconify(); } /** Unmaps the window and removes it from workspace list */ void FluxboxWindow::iconify() { if (isIconic()) // no need to iconify if we're already return; iconic = true; m_statesig.notify(); hide(true); screen().focusControl().setFocusBack(*this); ClientList::iterator client_it = m_clientlist.begin(); const ClientList::iterator client_it_end = m_clientlist.end(); for (; client_it != client_it_end; ++client_it) { WinClient &client = *(*client_it); WinClient::TransientList::iterator it = client.transientList().begin(); WinClient::TransientList::iterator it_end = client.transientList().end(); for (; it != it_end; it++) if ((*it)->fbwindow()) (*it)->fbwindow()->iconify(); } // focus revert is done elsewhere (based on signal) } void FluxboxWindow::deiconify(bool do_raise) { if (numClients() == 0 || !iconic || oplock) return; oplock = true; // reassociate first, so it gets removed from screen's icon list screen().reassociateWindow(this, m_workspace_number, false); iconic = false; m_statesig.notify(); // deiconify all transients ClientList::iterator client_it = clientList().begin(); ClientList::iterator client_it_end = clientList().end(); for (; client_it != client_it_end; ++client_it) { WinClient::TransientList::iterator trans_it = (*client_it)->transientList().begin(); WinClient::TransientList::iterator trans_it_end = (*client_it)->transientList().end(); for (; trans_it != trans_it_end; ++trans_it) { if ((*trans_it)->fbwindow()) (*trans_it)->fbwindow()->deiconify(false); } } if (m_workspace_number != screen().currentWorkspaceID()) return; show(); // focus new, OR if it's the only window on the workspace // but not on startup: focus will be handled after creating everything // we use m_focused as a signal to focus the window when mapped if (screen().currentWorkspace()->numberOfWindows() == 1 || m_focus_new || m_client->isTransient()) m_focused = true; oplock = false; if (do_raise) raise(); } /** setFullscreen mode: - maximize as big as the screen is, dont care about slit / toolbar - raise to toplayer */ void FluxboxWindow::setFullscreen(bool flag) { if (!m_initialized) { // this will interfere with window placement, so we delay it fullscreen = flag; return; } if (flag && !isFullscreen()) { m_old_layernum = layerNum(); fullscreen = true; frame().setFullscreen(true); setFullscreenLayer(); // calls stateSig().notify() if (!isFocused()) screen().focusedWindowSig().attach(this); } else if (!flag && isFullscreen()) { fullscreen = false; frame().setFullscreen(false); moveToLayer(m_old_layernum); stateSig().notify(); } } void FluxboxWindow::setFullscreenLayer() { FluxboxWindow *foc = FocusControl::focusedFbWindow(); // if another window on the same head is focused, make sure we can see it if (isFocused() || !foc || &foc->screen() != &screen() || getOnHead() != foc->getOnHead()) { moveToLayer(::Layer::ABOVE_DOCK); } else { moveToLayer(::Layer::DESKTOP); } stateSig().notify(); } /** Maximize window both horizontal and vertical */ void FluxboxWindow::maximize(int type) { // nothing to do if (type == WindowState::MAX_NONE) return; int new_max = maximized; // toggle maximize vertically? // when _don't_ we want to toggle? // - type is horizontal maximise, or // - type is full and we are not maximised horz but already vertically if (type != WindowState::MAX_HORZ && (type != WindowState::MAX_FULL || maximized != WindowState::MAX_VERT)) new_max ^= WindowState::MAX_VERT; // maximize horizontally? if (type != WindowState::MAX_VERT && (type != WindowState::MAX_FULL || maximized != WindowState::MAX_HORZ)) new_max ^= WindowState::MAX_HORZ; setMaximizedState(new_max); } void FluxboxWindow::setMaximizedState(int type) { if (!m_initialized || type == maximized) { // this will interfere with window placement, so we delay it maximized = type; return; } if (isResizing()) stopResizing(); maximized = type; frame().setMaximized(type); // notify when struts change, so we can resize accordingly if (maximized) screen().workspaceAreaSig().attach(this); else screen().workspaceAreaSig().detach(this); // notify listeners that we changed state stateSig().notify(); } /** * Maximize window horizontal */ void FluxboxWindow::maximizeHorizontal() { maximize(WindowState::MAX_HORZ); } /** * Maximize window vertical */ void FluxboxWindow::maximizeVertical() { maximize(WindowState::MAX_VERT); } /** * Maximize window fully */ void FluxboxWindow::maximizeFull() { maximize(WindowState::MAX_FULL); } void FluxboxWindow::setWorkspace(int n) { unsigned int old_wkspc = m_workspace_number; m_workspace_number = n; // notify workspace change if (m_initialized && !stuck && old_wkspc != m_workspace_number) { #ifdef DEBUG cerr<<this<<" notify workspace signal"<<endl; #endif // DEBUG m_workspacesig.notify(); } } void FluxboxWindow::setLayerNum(int layernum) { m_layernum = layernum; if (m_initialized) { #ifdef DEBUG cerr<<this<<" notify layer signal"<<endl; #endif // DEBUG m_layersig.notify(); } } void FluxboxWindow::shade() { // we can only shade if we have a titlebar if (!decorations.titlebar) return; // we're toggling, so if they're equal now, we need to change it if (m_initialized && m_frame.isShaded() == shaded) frame().shade(); shaded = !shaded; stateSig().notify(); // TODO: this should set IconicState, but then we can't focus the window } void FluxboxWindow::shadeOn() { if (!shaded) shade(); } void FluxboxWindow::shadeOff() { if (shaded) shade(); } void FluxboxWindow::setShaded(bool val) { if (val != shaded) shade(); } void FluxboxWindow::stick() { stuck = !stuck; if (m_initialized) { stateSig().notify(); // notify since some things consider "stuck" to be a pseudo-workspace m_workspacesig.notify(); } ClientList::iterator client_it = clientList().begin(); ClientList::iterator client_it_end = clientList().end(); for (; client_it != client_it_end; ++client_it) { WinClient::TransientList::const_iterator it = (*client_it)->transientList().begin(); WinClient::TransientList::const_iterator it_end = (*client_it)->transientList().end(); for (; it != it_end; ++it) { if ((*it)->fbwindow()) (*it)->fbwindow()->setStuck(stuck); } } } void FluxboxWindow::setStuck(bool val) { if (val != stuck) stick(); } void FluxboxWindow::setIconic(bool val) { if (!val && isIconic()) deiconify(); if (val && !isIconic()) iconify(); } void FluxboxWindow::raise() { if (isIconic()) return; #ifdef DEBUG cerr<<"FluxboxWindow("<<title()<<")::raise()[layer="<<layerNum()<<"]"<<endl; #endif // DEBUG // get root window WinClient *client = getRootTransientFor(m_client); // if we have transient_for then we should put ourself last in // transients list so we get raised last and thus gets above the other transients if (m_client->transientFor() && m_client != m_client->transientFor()->transientList().back()) { // remove and push back so this window gets raised last m_client->transientFor()->transientList().remove(m_client); m_client->transientFor()->transientList().push_back(m_client); } // raise this window and every transient in it with this one last if (client->fbwindow()) { // doing this on startup messes up the focus order if (!Fluxbox::instance()->isStartup() && client->fbwindow() != this && &client->fbwindow()->winClient() != client) // activate the client so the transient won't get pushed back down client->fbwindow()->setCurrentClient(*client, false); raiseFluxboxWindow(*client->fbwindow()); } } void FluxboxWindow::lower() { if (isIconic()) return; #ifdef DEBUG cerr<<"FluxboxWindow("<<title()<<")::lower()"<<endl; #endif // DEBUG // get root window WinClient *client = getRootTransientFor(m_client); if (client->fbwindow()) lowerFluxboxWindow(*client->fbwindow()); } void FluxboxWindow::tempRaise() { // Note: currently, this causes a problem with cycling through minimized // clients if this window has more than one tab, since the window will not // match isIconic() when the rest of the tabs get checked if (isIconic()) deiconify(); // the root transient will get raised when we stop cycling // raising it here causes problems when it isn't the active tab tempRaiseFluxboxWindow(*this); } void FluxboxWindow::raiseLayer() { moveToLayer(m_layernum-1); } void FluxboxWindow::lowerLayer() { moveToLayer(m_layernum+1); } void FluxboxWindow::moveToLayer(int layernum, bool force) { #ifdef DEBUG cerr<<"FluxboxWindow("<<title()<<")::moveToLayer("<<layernum<<")"<<endl; #endif // DEBUG // don't let it set its layer into menu area if (layernum <= ::Layer::MENU) layernum = ::Layer::MENU + 1; else if (layernum >= ::Layer::NUM_LAYERS) layernum = ::Layer::NUM_LAYERS - 1; if (!m_initialized) m_layernum = layernum; if ((m_layernum == layernum && !force) || !m_client) return; // get root window WinClient *client = getRootTransientFor(m_client); FluxboxWindow *win = client->fbwindow(); if (!win) return; win->layerItem().moveToLayer(layernum); // remember number just in case a transient happens to revisit this window layernum = win->layerItem().getLayerNum(); win->setLayerNum(layernum); // move all the transients, too ClientList::iterator client_it = win->clientList().begin(); ClientList::iterator client_it_end = win->clientList().end(); for (; client_it != client_it_end; ++client_it) { WinClient::TransientList::const_iterator it = (*client_it)->transientList().begin(); WinClient::TransientList::const_iterator it_end = (*client_it)->transientList().end(); for (; it != it_end; ++it) { FluxboxWindow *fbwin = (*it)->fbwindow(); if (fbwin && !fbwin->isIconic()) { fbwin->layerItem().moveToLayer(layernum); fbwin->setLayerNum(layernum); } } } } void FluxboxWindow::setFocusHidden(bool value) { m_focus_hidden = value; if (m_initialized) m_statesig.notify(); } void FluxboxWindow::setIconHidden(bool value) { m_icon_hidden= value; if (m_initialized) m_statesig.notify(); } // window has actually RECEIVED focus (got a FocusIn event) // so now we make it a focused frame etc void FluxboxWindow::setFocusFlag(bool focus) { if (!m_client) return; bool was_focused = isFocused(); m_focused = focus; #ifdef DEBUG cerr<<"FluxboxWindow("<<title()<<")::setFocusFlag("<<focus<<")"<<endl; #endif // DEBUG installColormap(focus); // if we're fullscreen and another window gains focus on the same head, // then we need to let the user see it if (fullscreen && !focus) screen().focusedWindowSig().attach(this); if (fullscreen && focus) { moveToLayer(::Layer::ABOVE_DOCK); screen().focusedWindowSig().detach(this); } if (focus != frame().focused()) frame().setFocus(focus); if (focus && screen().focusControl().isCycling()) tempRaise(); else if (screen().doAutoRaise()) { if (m_focused) m_timer.start(); else m_timer.stop(); } // did focus change? notify listeners if (was_focused != focus) { m_attention_state = false; m_focussig.notify(); if (m_client) m_client->focusSig().notify(); Fluxbox::instance()->keys()->doAction(focus ? FocusIn : FocusOut, 0, 0, Keys::ON_WINDOW, m_client); } } void FluxboxWindow::installColormap(bool install) { if (m_client == 0) return; Fluxbox *fluxbox = Fluxbox::instance(); fluxbox->grab(); if (! m_client->validateClient()) return; int i = 0, ncmap = 0; Colormap *cmaps = XListInstalledColormaps(display, m_client->window(), &ncmap); XWindowAttributes wattrib; if (cmaps) { //!! if (m_client->getAttrib(wattrib)) { if (install) { // install the window's colormap for (i = 0; i < ncmap; i++) { if (*(cmaps + i) == wattrib.colormap) { // this window is using an installed color map... do not install install = false; break; //end for-loop (we dont need to check more) } } // otherwise, install the window's colormap if (install) XInstallColormap(display, wattrib.colormap); } else { for (i = 0; i < ncmap; i++) { // uninstall the window's colormap if (*(cmaps + i) == wattrib.colormap) XUninstallColormap(display, wattrib.colormap); } } } XFree(cmaps); } fluxbox->ungrab(); } /** Sets state on each client in our list Use setting_up for setting startup state - it may not be committed yet That'll happen when its mapped */ void FluxboxWindow::setState(unsigned long new_state, bool setting_up) { m_current_state = new_state; if (numClients() == 0 || setting_up) return; unsigned long state[2]; state[0] = (unsigned long) m_current_state; state[1] = (unsigned long) None; for_each(m_clientlist.begin(), m_clientlist.end(), ChangeProperty(display, FbAtoms::instance()->getWMStateAtom(), PropModeReplace, (unsigned char *)state, 2)); ClientList::iterator it = clientList().begin(); ClientList::iterator it_end = clientList().end(); for (; it != it_end; ++it) { (*it)->setEventMask(NoEventMask); if (new_state == IconicState) (*it)->hide(); else if (new_state == NormalState) (*it)->show(); (*it)->setEventMask(PropertyChangeMask | StructureNotifyMask | FocusChangeMask | KeyPressMask); } } bool FluxboxWindow::getState() { Atom atom_return; bool ret = false; int foo; unsigned long *state, ulfoo, nitems; if (!m_client->property(FbAtoms::instance()->getWMStateAtom(), 0l, 2l, false, FbAtoms::instance()->getWMStateAtom(), &atom_return, &foo, &nitems, &ulfoo, (unsigned char **) &state) || !state) return false; if (nitems >= 1) { m_current_state = static_cast<unsigned long>(state[0]); ret = true; } XFree(static_cast<void *>(state)); return ret; } /** Show the window menu at pos mx, my */ void FluxboxWindow::showMenu(int menu_x, int menu_y) { menu().reloadHelper()->checkReload(); int head = screen().getHead(menu_x, menu_y); // move menu directly under titlebar but not off the screen if (menu_y < static_cast<signed>(screen().maxTop(head))) menu_y = screen().maxTop(head); else if (menu_y + menu().height() >= screen().maxBottom(head)) menu_y = screen().maxBottom(head) - menu().height() - 1 - menu().fbwindow().borderWidth(); if (menu_x < static_cast<signed>(screen().maxLeft(head))) menu_x = screen().maxLeft(head); else if (menu_x + static_cast<signed>(menu().width()) >= static_cast<signed>(screen().maxRight(head))) menu_x = screen().maxRight(head) - menu().width() - 1; FbMenu::setWindow(this); menu().move(menu_x, menu_y); menu().show(); menu().raise(); menu().grabInputFocus(); } void FluxboxWindow::popupMenu(int x, int y) { // hide menu if it was opened for this window before if (menu().isVisible() && FbMenu::window() == this) { menu().hide(); return; } menu().disableTitle(); showMenu(x, y); } /** Moves the menu to last button press position and shows it, if it's already visible it'll be hidden */ void FluxboxWindow::popupMenu() { if (m_last_button_x < x() || m_last_button_x > x() + static_cast<signed>(width())) m_last_button_x = x(); popupMenu(m_last_button_x, frame().titlebarHeight() + frame().y()); } /** Redirect any unhandled event to our handlers */ void FluxboxWindow::handleEvent(XEvent &event) { switch (event.type) { case ConfigureRequest: #ifdef DEBUG cerr<<"ConfigureRequest("<<title()<<")"<<endl; #endif // DEBUG configureRequestEvent(event.xconfigurerequest); break; case MapNotify: mapNotifyEvent(event.xmap); break; // This is already handled in Fluxbox::handleEvent // case MapRequest: // mapRequestEvent(event.xmaprequest); //break; case PropertyNotify: { #ifdef DEBUG char *atomname = XGetAtomName(display, event.xproperty.atom); cerr<<"PropertyNotify("<<title()<<"), property = "<<atomname<<endl; if (atomname) XFree(atomname); #endif // DEBUG WinClient *client = findClient(event.xproperty.window); if (client) propertyNotifyEvent(*client, event.xproperty.atom); } break; default: #ifdef SHAPE if (Fluxbox::instance()->haveShape() && event.type == Fluxbox::instance()->shapeEventbase() + ShapeNotify) { #ifdef DEBUG cerr<<"ShapeNotify("<<title()<<")"<<endl; #endif // DEBUG XShapeEvent *shape_event = (XShapeEvent *)&event; if (shape_event->shaped) frame().setShapingClient(m_client, true); else frame().setShapingClient(0, true); FbTk::App::instance()->sync(false); break; } #endif // SHAPE break; } } void FluxboxWindow::mapRequestEvent(XMapRequestEvent &re) { // we're only concerned about client window event WinClient *client = findClient(re.window); if (client == 0) { #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): Can't find client!"<<endl; #endif // DEBUG return; } // Note: this function never gets called from WithdrawnState // initial state is handled in init() setCurrentClient(*client, false); // focus handled on MapNotify deiconify(); if (m_focus_new) { m_focused = false; // deiconify sets this m_focused = focusRequestFromClient(*client); if (!m_focused) lower(); } } bool FluxboxWindow::focusRequestFromClient(WinClient &from) { if (from.fbwindow() != this) return false; bool ret = true; // check what to do if window is on another workspace if (screen().currentWorkspaceID() != workspaceNumber() && !isStuck() && screen().getFollowModel() == BScreen::IGNORE_OTHER_WORKSPACES) ret = false; FluxboxWindow *cur = FocusControl::focusedFbWindow(); WinClient *client = FocusControl::focusedWindow(); if (ret && cur && getRootTransientFor(&from) != getRootTransientFor(client)) ret = !(cur->isFullscreen() && getOnHead() == cur->getOnHead()) && !cur->isTyping(); if (!ret) Fluxbox::instance()->attentionHandler().addAttention(from); return ret; } void FluxboxWindow::mapNotifyEvent(XMapEvent &ne) { WinClient *client = findClient(ne.window); if (!client || client != m_client) return; if (ne.override_redirect || !isVisible() || !client->validateClient()) return; iconic = false; // setting state will cause all tabs to be mapped, but we only want the // original tab to be focused if (m_current_state != NormalState) setState(NormalState, false); // we use m_focused as a signal that this should be focused when mapped if (m_focused) { m_focused = false; focus(); } } /** Unmaps frame window and client window if event.window == m_client->window */ void FluxboxWindow::unmapNotifyEvent(XUnmapEvent &ue) { WinClient *client = findClient(ue.window); if (client == 0) return; #ifdef DEBUG cerr<<__FILE__<<"("<<__FUNCTION__<<"): 0x"<<hex<<client->window()<<dec<<endl; cerr<<__FILE__<<"("<<__FUNCTION__<<"): title="<<client->title()<<endl; #endif // DEBUG restore(client, false); } /** Checks if event is for m_client->window. If it isn't, we leave it until the window is unmapped, if it is, we just hide it for now. */ void FluxboxWindow::destroyNotifyEvent(XDestroyWindowEvent &de) { if (de.window == m_client->window()) { #ifdef DEBUG cerr<<__FILE__<<"("<<__LINE__<<"): DestroyNotifyEvent this="<<this<<" title = "<<title()<<endl; #endif // DEBUG delete m_client; if (numClients() == 0) delete this; } } void FluxboxWindow::propertyNotifyEvent(WinClient &client, Atom atom) { switch(atom) { case XA_WM_CLASS: case XA_WM_CLIENT_MACHINE: case XA_WM_COMMAND: break; case XA_WM_TRANSIENT_FOR: { bool was_transient = client.isTransient(); client.updateTransientInfo(); // update our layer to be the same layer as our transient for if (client.isTransient() && !was_transient && client.transientFor()->fbwindow()) layerItem().setLayer(client.transientFor()->fbwindow()->layerItem().getLayer()); } break; case XA_WM_HINTS: client.updateWMHints(); titleSig().notify(); // nothing uses this yet // hintSig().notify(); // notify listeners break; case XA_WM_ICON_NAME: // we don't use icon title, since many apps don't update it, // and we don't show icons anyway break; case XA_WM_NAME: client.updateTitle(); break; case XA_WM_NORMAL_HINTS: { #ifdef DEBUG cerr<<"XA_WM_NORMAL_HINTS("<<title()<<")"<<endl; #endif // DEBUG unsigned int old_max_width = client.maxWidth(); unsigned int old_min_width = client.minWidth(); unsigned int old_min_height = client.minHeight(); unsigned int old_max_height = client.maxHeight(); bool changed = false; client.updateWMNormalHints(); if (client.minWidth() != old_min_width || client.maxWidth() != old_max_width || client.minHeight() != old_min_height || client.maxHeight() != old_max_height) { if (!client.sizeHints().isResizable()) { if (functions.resize || functions.maximize) changed = true; functions.resize=false; functions.maximize=false; } else { // TODO: is broken while handled by FbW, needs to be in WinClient if (!client.isTransient() || screen().decorateTransient()) { if (!functions.maximize) changed = true; functions.maximize = true; } if (!functions.resize) changed = true; functions.resize = true; } if (changed) { setupWindow(); applyDecorations(); } } moveResize(frame().x(), frame().y(), frame().width(), frame().height()); break; } default: FbAtoms *fbatoms = FbAtoms::instance(); if (atom == fbatoms->getWMProtocolsAtom()) { client.updateWMProtocols(); } else if (atom == fbatoms->getMWMHintsAtom()) { client.updateMWMHints(); updateMWMHintsFromClient(client); if (!m_toggled_decos) { Remember::instance().updateDecoStateFromClient(client); } applyDecorations(); // update decorations (if they changed) } break; } } void FluxboxWindow::exposeEvent(XExposeEvent &ee) { frame().exposeEvent(ee); } void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) { WinClient *client = findClient(cr.window); if (client == 0 || isIconic()) return; int old_x = frame().x(), old_y = frame().y(); unsigned int old_w = frame().width(); unsigned int old_h = frame().height() - frame().titlebarHeight() - frame().handleHeight(); int cx = old_x, cy = old_y, ignore = 0; unsigned int cw = old_w, ch = old_h; // make sure the new width/height would be ok with all clients, or else they // could try to resize the window back and forth if (cr.value_mask & CWWidth || cr.value_mask & CWHeight) { unsigned int new_w = (cr.value_mask & CWWidth) ? cr.width : cw; unsigned int new_h = (cr.value_mask & CWHeight) ? cr.height : ch; ClientList::iterator it = clientList().begin(); ClientList::iterator it_end = clientList().end(); for (; it != it_end; ++it) { if (*it != client && !(*it)->sizeHints().valid(new_w, new_h)) cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); } } // don't allow moving/resizing fullscreen or maximized windows if (isFullscreen() || (isMaximizedHorz() && screen().getMaxIgnoreIncrement())) cr.value_mask = cr.value_mask & ~(CWWidth | CWX); if (isFullscreen() || (isMaximizedVert() && screen().getMaxIgnoreIncrement())) cr.value_mask = cr.value_mask & ~(CWHeight | CWY); #ifdef REMEMBER // don't let misbehaving clients (e.g. MPlayer) move/resize their windows // just after creation if the user has a saved position/size if (m_creation_time) { struct timeval now; gettimeofday(&now, NULL); Remember& rinst = Remember::instance(); if (now.tv_sec > m_creation_time + 1) m_creation_time = 0; else if (rinst.isRemembered(*client, Remember::REM_MAXIMIZEDSTATE) || rinst.isRemembered(*client, Remember::REM_FULLSCREENSTATE)) { cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); cr.value_mask = cr.value_mask & ~(CWX | CWY); } else { if (rinst.isRemembered(*client, Remember::REM_DIMENSIONS)) cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); if (rinst.isRemembered(*client, Remember::REM_POSITION)) cr.value_mask = cr.value_mask & ~(CWX | CWY); } } #endif // REMEMBER if (cr.value_mask & CWBorderWidth) client->old_bw = cr.border_width; if ((cr.value_mask & CWX) && (cr.value_mask & CWY)) { cx = cr.x; cy = cr.y; frame().gravityTranslate(cx, cy, client->gravity(), client->old_bw, false); frame().setActiveGravity(client->gravity(), client->old_bw); } else if (cr.value_mask & CWX) { cx = cr.x; frame().gravityTranslate(cx, ignore, client->gravity(), client->old_bw, false); frame().setActiveGravity(client->gravity(), client->old_bw); } else if (cr.value_mask & CWY) { cy = cr.y; frame().gravityTranslate(ignore, cy, client->gravity(), client->old_bw, false); frame().setActiveGravity(client->gravity(), client->old_bw); } if (cr.value_mask & CWWidth) cw = cr.width; if (cr.value_mask & CWHeight) ch = cr.height; // the request is for client window so we resize the frame to it first if (old_w != cw || old_h != ch) { if (old_x != cx || old_y != cy) frame().moveResizeForClient(cx, cy, cw, ch); else frame().resizeForClient(cw, ch); } else if (old_x != cx || old_y != cy) { frame().move(cx, cy); } if (cr.value_mask & CWStackMode) { switch (cr.detail) { case Above: case TopIf: default: if ((isFocused() && focusRequestFromClient(*client)) || !FocusControl::focusedWindow()) { setCurrentClient(*client, true); raise(); } else if (getRootTransientFor(client) == getRootTransientFor(FocusControl::focusedWindow())) { setCurrentClient(*client, false); raise(); } break; case Below: case BottomIf: lower(); break; } } sendConfigureNotify(); } // keep track of last keypress in window, so we can decide not to focusNew void FluxboxWindow::keyPressEvent(XKeyEvent &ke) { // if there's a modifier key down, the user probably expects the new window if (FbTk::KeyUtil::instance().cleanMods(ke.state)) return; // we need to ignore modifier keys themselves, too KeySym ks; char keychar[1]; XLookupString(&ke, keychar, 1, &ks, 0); if (IsModifierKey(ks)) return; // if the key was return/enter, the user probably expects the window // e.g., typed the command in a terminal if (ks == XK_KP_Enter || ks == XK_Return) { // we'll actually reset the time for this one m_last_keypress_time.tv_sec = 0; return; } // otherwise, make a note that the user is typing gettimeofday(&m_last_keypress_time, 0); } bool FluxboxWindow::isTyping() const { timeval now; if (gettimeofday(&now, NULL) == -1) return false; unsigned int diff = 1000*(now.tv_sec - m_last_keypress_time.tv_sec); diff += (now.tv_usec - m_last_keypress_time.tv_usec)/1000; return (diff < screen().noFocusWhileTypingDelay()); } void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { m_last_button_x = be.x_root; m_last_button_y = be.y_root; bool onTitlebar = frame().gripLeft().window() != be.window && frame().gripRight().window() != be.window && frame().handle().window() != be.window && frame().window() != be.window; if (onTitlebar && be.button == 1) raise(); // check keys file first Keys *k = Fluxbox::instance()->keys(); if ((onTitlebar && k->doAction(be.type, be.state, be.button, Keys::ON_TITLEBAR, m_client, be.time)) || k->doAction(be.type, be.state, be.button, Keys::ON_WINDOW, m_client, be.time)) { return; } frame().tabcontainer().tryButtonPressEvent(be); if (be.button == 1) { if (!m_focused && acceptsFocus() && m_click_focus) //check focus focus(); if (frame().window().window() == be.window || frame().tabcontainer().window() == be.window) { if (screen().clickRaises()) raise(); #ifdef DEBUG cerr<<"FluxboxWindow::buttonPressEvent: AllowEvent"<<endl; #endif // DEBUG XAllowEvents(display, ReplayPointer, be.time); m_button_grab_x = be.x_root - frame().x() - frame().window().borderWidth(); m_button_grab_y = be.y_root - frame().y() - frame().window().borderWidth(); } else if (frame().handle() == be.window) raise(); menu().hide(); } } void FluxboxWindow::buttonReleaseEvent(XButtonEvent &re) { if (isMoving()) stopMoving(); else if (isResizing()) stopResizing(); else if (m_attaching_tab) attachTo(re.x_root, re.y_root); else frame().tabcontainer().tryButtonReleaseEvent(re); } void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) { if (isMoving() && me.window == parent()) { me.window = frame().window().window(); } bool inside_titlebar = frame().gripLeft().window() != me.window && frame().gripRight().window() != me.window && frame().window() != me.window; if (Fluxbox::instance()->getIgnoreBorder() && m_attaching_tab == 0 && !(isMoving() || isResizing())) { int borderw = frame().window().borderWidth(); //!! TODO(tabs): the below test ought to be in FbWinFrame // if mouse is currently on the window border, ignore it if ((me.x_root < (frame().x() + borderw) || me.y_root < (frame().y() + borderw) || me.x_root >= (frame().x() + (int)frame().width() + borderw) || me.y_root >= (frame().y() + (int)frame().height() + borderw)) && (!frame().externalTabMode() || (me.x_root < (frame().tabcontainer().x() + borderw) || me.y_root < (frame().tabcontainer().y() + borderw) || me.x_root >= (frame().tabcontainer().x() + (int)frame().tabcontainer().width() + borderw) || me.y_root >= (frame().tabcontainer().y() + (int)frame().tabcontainer().height() + borderw))) // or if mouse was on border when it was last clicked || (m_last_button_x < (frame().x() + borderw) || m_last_button_y < (frame().y() + borderw) || m_last_button_x >= (frame().x() + (int)frame().width() + borderw) || m_last_button_y >= (frame().y() + (int)frame().height() + borderw)) && (!frame().externalTabMode() || (m_last_button_x < (frame().tabcontainer().x() + borderw) || m_last_button_y < (frame().tabcontainer().y() + borderw) || m_last_button_x >= (frame().tabcontainer().x() + (int)frame().tabcontainer().width() + borderw) || m_last_button_y >= (frame().tabcontainer().y() + (int)frame().tabcontainer().height() + borderw)))) return; } if (moving || ((me.state & Button1Mask) && functions.move && inside_titlebar && !isResizing() && m_attaching_tab == 0)) { if (! isMoving()) { startMoving(me.x_root, me.y_root); } else { // Warp to next or previous workspace?, must have moved sideways some int moved_x = me.x_root - m_last_resize_x; // save last event point m_last_resize_x = me.x_root; m_last_resize_y = me.y_root; if (moved_x && screen().isWorkspaceWarping()) { unsigned int cur_id = screen().currentWorkspaceID(); unsigned int new_id = cur_id; const int warpPad = screen().getEdgeSnapThreshold(); // 1) if we're inside the border threshold // 2) if we moved in the right direction if (me.x_root >= int(screen().width()) - warpPad - 1 && moved_x > 0) { //warp right new_id = (cur_id + 1) % screen().numberOfWorkspaces(); m_last_resize_x = 0; // move mouse back to x=0 } else if (me.x_root <= warpPad && moved_x < 0) { //warp left new_id = (cur_id + screen().numberOfWorkspaces() - 1) % screen().numberOfWorkspaces(); m_last_resize_x = screen().width() - 1; // move mouse to screen width - 1 } if (new_id != cur_id) { // remove motion events from queue to avoid repeated warps XEvent e; while (XCheckTypedEvent(display, MotionNotify, &e)) { // might as well update the y-coordinate m_last_resize_y = e.xmotion.y_root; } // move the pointer to (m_last_resize_x,m_last_resize_y) XWarpPointer(display, None, me.root, 0, 0, 0, 0, m_last_resize_x, m_last_resize_y); screen().sendToWorkspace(new_id, this, true); } } int dx = m_last_resize_x - m_button_grab_x, dy = m_last_resize_y - m_button_grab_y; dx -= frame().window().borderWidth(); dy -= frame().window().borderWidth(); // dx = current left side, dy = current top doSnapping(dx, dy); if (! screen().doOpaqueMove()) { parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, frame().width() + 2*frame().window().borderWidth()-1, frame().height() + 2*frame().window().borderWidth()-1); parent().drawRectangle(screen().rootTheme()->opGC(), dx, dy, frame().width() + 2*frame().window().borderWidth()-1, frame().height() + 2*frame().window().borderWidth()-1); m_last_move_x = dx; m_last_move_y = dy; } else { //moveResize(dx, dy, frame().width(), frame().height()); // need to move the base window without interfering with transparency frame().quietMoveResize(dx, dy, frame().width(), frame().height()); } screen().showPosition(dx, dy); } // end if moving } else if (resizing || (m_attaching_tab == 0 && functions.resize && (((me.state & Button1Mask) && (me.window == frame().gripRight() || me.window == frame().gripLeft())) || me.window == frame().window()))) { if (! resizing) { ReferenceCorner resize_corner = RIGHTBOTTOM; if (me.window == frame().gripRight()) resize_corner = RIGHTBOTTOM; else if (me.window == frame().gripLeft()) resize_corner = LEFTBOTTOM; else // dragging border of window, so choose nearest corner resize_corner = getResizeDirection(me.x, me.y, QUADRANTRESIZE); // We are grabbing frame window in startResizing // we need to translate coordinates to it. int start_x = me.x, start_y = me.y; Window child; XTranslateCoordinates(display, me.window, fbWindow().window(), start_x, start_y, &start_x, &start_y, &child); startResizing(start_x, start_y, resize_corner); } else if (resizing) { int old_resize_x = m_last_resize_x; int old_resize_y = m_last_resize_y; unsigned int old_resize_w = m_last_resize_w; unsigned int old_resize_h = m_last_resize_h; int dx = me.x - m_button_grab_x; int dy = me.y - m_button_grab_y; if (m_resize_corner == LEFTTOP || m_resize_corner == LEFTBOTTOM || m_resize_corner == LEFT) { m_last_resize_w = frame().width() - dx; m_last_resize_x = frame().x() + dx; } if (m_resize_corner == LEFTTOP || m_resize_corner == RIGHTTOP || m_resize_corner == TOP) { m_last_resize_h = frame().height() - dy; m_last_resize_y = frame().y() + dy; } if (m_resize_corner == LEFTBOTTOM || m_resize_corner == BOTTOM || m_resize_corner == RIGHTBOTTOM) m_last_resize_h = frame().height() + dy; if (m_resize_corner == RIGHTBOTTOM || m_resize_corner == RIGHTTOP || m_resize_corner == RIGHT) m_last_resize_w = frame().width() + dx; if (m_resize_corner == CENTER) { // dx or dy must be at least 2 if (abs(dx) >= 2 || abs(dy) >= 2) { // take max and make it even int diff = 2 * (max(dx, dy) / 2); m_last_resize_h = frame().height() + diff; m_last_resize_w = frame().width() + diff; m_last_resize_x = frame().x() - diff/2; m_last_resize_y = frame().y() - diff/2; } } fixsize(); frame().displaySize(m_last_resize_w, m_last_resize_h); if (old_resize_x != m_last_resize_x || old_resize_y != m_last_resize_y || old_resize_w != m_last_resize_w || old_resize_h != m_last_resize_h ) { // draw over old rect parent().drawRectangle(screen().rootTheme()->opGC(), old_resize_x, old_resize_y, old_resize_w - 1 + 2 * frame().window().borderWidth(), old_resize_h - 1 + 2 * frame().window().borderWidth()); // draw resize rectangle parent().drawRectangle(screen().rootTheme()->opGC(), m_last_resize_x, m_last_resize_y, m_last_resize_w - 1 + 2 * frame().window().borderWidth(), m_last_resize_h - 1 + 2 * frame().window().borderWidth()); } } } else if (m_attaching_tab != 0) { // // drag'n'drop code for tabs // // we already grabed and started to drag'n'drop tab // so we update drag'n'drop-rectangle int dx = me.x_root - m_button_grab_x, dy = me.y_root - m_button_grab_y; parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, m_last_resize_w, m_last_resize_h); parent().drawRectangle(screen().rootTheme()->opGC(), dx, dy, m_last_resize_w, m_last_resize_h); // change remembered position of rectangle m_last_move_x = dx; m_last_move_y = dy; } } void FluxboxWindow::enterNotifyEvent(XCrossingEvent &ev) { // ignore grab activates, or if we're not visible if (ev.mode == NotifyGrab || ev.mode == NotifyUngrab || !isVisible()) { return; } if (ev.window == frame().window()) Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0, Keys::ON_WINDOW, m_client); WinClient *client = 0; if (screen().focusControl().isMouseTabFocus()) { // determine if we're in a label button (tab) Client2ButtonMap::iterator it = find_if(m_labelbuttons.begin(), m_labelbuttons.end(), Compose(bind2nd(equal_to<Window>(), ev.window), Compose(mem_fun(&TextButton::window), Select2nd<Client2ButtonMap::value_type>()))); if (it != m_labelbuttons.end()) client = (*it).first; } if (ev.window == frame().window() || ev.window == m_client->window() || client) { if (m_mouse_focus && !isFocused() && acceptsFocus()) { // check that there aren't any subsequent leave notify events in the // X event queue XEvent dummy; scanargs sa; sa.w = ev.window; sa.enter = sa.leave = False; XCheckIfEvent(display, &dummy, queueScanner, (char *) &sa); if ((!sa.leave || sa.inferior) && !screen().focusControl().isCycling() ) { focus(); } } } if (screen().focusControl().isMouseTabFocus() && client && client != m_client) { setCurrentClient(*client, isFocused()); } } void FluxboxWindow::leaveNotifyEvent(XCrossingEvent &ev) { // ignore grab activates, or if we're not visible if (ev.mode == NotifyGrab || ev.mode == NotifyUngrab || !isVisible()) { return; } // still inside? if (ev.x_root > frame().x() && ev.y_root > frame().y() && ev.x_root <= (int)(frame().x() + frame().width()) && ev.y_root <= (int)(frame().y() + frame().height())) return; Fluxbox::instance()->keys()->doAction(ev.type, ev.state, 0, Keys::ON_WINDOW, m_client); // I hope commenting this out is right - simon 21jul2003 //if (ev.window == frame().window()) //installColormap(false); } void FluxboxWindow::update(FbTk::Subject *subj) { if (subj && typeid(*subj) == typeid(Focusable::FocusSubject)) { Focusable::FocusSubject &fsubj = static_cast<Focusable::FocusSubject &>(*subj); Focusable &win = fsubj.win(); if (&fsubj == &win.titleSig() && &win == m_client) { frame().setFocusTitle(win.title()); titleSig().notify(); } } else if (subj == &screen().focusedWindowSig()) { if (FocusControl::focusedFbWindow()) setFullscreenLayer(); } else if (subj == &m_theme.reconfigSig()) { frame().applyDecorations(); sendConfigureNotify(); } else if (subj == &screen().workspaceAreaSig()) { frame().applyState(); } else if (m_initialized && subj == &m_frame.frameExtentSig()) { Fluxbox::instance()->updateFrameExtents(*this); sendConfigureNotify(); } } // commit current decoration values to actual displayed things void FluxboxWindow::applyDecorations() { frame().setDecorationMask(decorationMask()); frame().applyDecorations(); } void FluxboxWindow::toggleDecoration() { //don't toggle decor if the window is shaded if (isShaded() || isFullscreen()) return; m_toggled_decos = !m_toggled_decos; if (m_toggled_decos) { m_old_decoration_mask = decorationMask(); if (decorations.titlebar | decorations.tab) setDecorationMask(WindowState::DECOR_NONE); else setDecorationMask(WindowState::DECOR_NORMAL); } else //revert back to old decoration setDecorationMask(m_old_decoration_mask); } unsigned int FluxboxWindow::decorationMask() const { unsigned int ret = 0; if (decorations.titlebar) ret |= WindowState::DECORM_TITLEBAR; if (decorations.handle) ret |= WindowState::DECORM_HANDLE; if (decorations.border) ret |= WindowState::DECORM_BORDER; if (decorations.iconify) ret |= WindowState::DECORM_ICONIFY; if (decorations.maximize) ret |= WindowState::DECORM_MAXIMIZE; if (decorations.close) ret |= WindowState::DECORM_CLOSE; if (decorations.menu) ret |= WindowState::DECORM_MENU; if (decorations.sticky) ret |= WindowState::DECORM_STICKY; if (decorations.shade) ret |= WindowState::DECORM_SHADE; if (decorations.tab) ret |= WindowState::DECORM_TAB; if (decorations.enabled) ret |= WindowState::DECORM_ENABLED; return ret; } void FluxboxWindow::setDecorationMask(unsigned int mask, bool apply) { decorations.titlebar = mask & WindowState::DECORM_TITLEBAR; decorations.handle = mask & WindowState::DECORM_HANDLE; decorations.border = mask & WindowState::DECORM_BORDER; decorations.iconify = mask & WindowState::DECORM_ICONIFY; decorations.maximize = mask & WindowState::DECORM_MAXIMIZE; decorations.close = mask & WindowState::DECORM_CLOSE; decorations.menu = mask & WindowState::DECORM_MENU; decorations.sticky = mask & WindowState::DECORM_STICKY; decorations.shade = mask & WindowState::DECORM_SHADE; decorations.tab = mask & WindowState::DECORM_TAB; decorations.enabled = mask & WindowState::DECORM_ENABLED; // we don't want to do this during initialization if (apply) applyDecorations(); } void FluxboxWindow::startMoving(int x, int y) { if (s_num_grabs > 0) return; if (isMaximized() && screen().getMaxDisableMove()) return; // save first event point m_last_resize_x = x; m_last_resize_y = y; m_button_grab_x = x - frame().x() - frame().window().borderWidth(); m_button_grab_y = y - frame().y() - frame().window().borderWidth(); moving = true; Fluxbox *fluxbox = Fluxbox::instance(); // grabbing (and masking) on the root window allows us to // freely map and unmap the window we're moving. grabPointer(screen().rootWindow().window(), False, ButtonMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, screen().rootWindow().window(), frame().theme()->moveCursor(), CurrentTime); if (menu().isVisible()) menu().hide(); fluxbox->maskWindowEvents(screen().rootWindow().window(), this); m_last_move_x = frame().x(); m_last_move_y = frame().y(); if (! screen().doOpaqueMove()) { fluxbox->grab(); parent().drawRectangle(screen().rootTheme()->opGC(), frame().x(), frame().y(), frame().width() + 2*frame().window().borderWidth()-1, frame().height() + 2*frame().window().borderWidth()-1); screen().showPosition(frame().x(), frame().y()); } } void FluxboxWindow::stopMoving(bool interrupted) { moving = false; Fluxbox *fluxbox = Fluxbox::instance(); fluxbox->maskWindowEvents(0, 0); // if no real movement happend -> raise if clickrais is disabled if (m_last_move_x - frame().x() == 0 && m_last_move_y - frame().y() == 0 && !screen().clickRaises()) { raise(); } if (! screen().doOpaqueMove()) { parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, frame().width() + 2*frame().window().borderWidth()-1, frame().height() + 2*frame().window().borderWidth()-1); if (!interrupted) { moveResize(m_last_move_x, m_last_move_y, frame().width(), frame().height()); if (m_workspace_number != screen().currentWorkspaceID()) { screen().reassociateWindow(this, screen().currentWorkspaceID(), true); frame().show(); focus(); } } fluxbox->ungrab(); } else if (!interrupted) { moveResize(frame().x(), frame().y(), frame().width(), frame().height(), true); frame().notifyMoved(true); } screen().hidePosition(); ungrabPointer(CurrentTime); FbTk::App::instance()->sync(false); //make sure the redraw is made before we continue } void FluxboxWindow::pauseMoving() { if (screen().doOpaqueMove()) { return; } parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, frame().width() + 2*frame().window().borderWidth()-1, frame().height() + 2*frame().window().borderWidth()-1); } void FluxboxWindow::resumeMoving() { if (screen().doOpaqueMove()) { return; } if (m_workspace_number == screen().currentWorkspaceID()) { frame().show(); focus(); } FbTk::App::instance()->sync(false); parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, frame().width() + 2*frame().window().borderWidth()-1, frame().height() + 2*frame().window().borderWidth()-1); } /** * Helper function that snaps a window to another window * We snap if we're closer than the x/ylimits. */ inline void snapToWindow(int &xlimit, int &ylimit, int left, int right, int top, int bottom, int oleft, int oright, int otop, int obottom) { // Only snap if we're adjacent to the edge we're looking at // for left + right, need to be in the right y range if (top <= obottom && bottom >= otop) { // left if (abs(left-oleft) < abs(xlimit)) xlimit = -(left-oleft); if (abs(right-oleft) < abs(xlimit)) xlimit = -(right-oleft); // right if (abs(left-oright) < abs(xlimit)) xlimit = -(left-oright); if (abs(right-oright) < abs(xlimit)) xlimit = -(right-oright); } // for top + bottom, need to be in the right x range if (left <= oright && right >= oleft) { // top if (abs(top-otop) < abs(ylimit)) ylimit = -(top-otop); if (abs(bottom-otop) < abs(ylimit)) ylimit = -(bottom-otop); // bottom if (abs(top-obottom) < abs(ylimit)) ylimit = -(top-obottom); if (abs(bottom-obottom) < abs(ylimit)) ylimit = -(bottom-obottom); } } /* * Do Whatever snapping magic is necessary, and return using the orig_left * and orig_top variables to indicate the new x,y position */ void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) { /* * Snap to screen/head edges * Snap to windows */ if (screen().getEdgeSnapThreshold() == 0) return; // Keep track of our best offsets so far // We need to find things less than or equal to the threshold int dx = screen().getEdgeSnapThreshold() + 1; int dy = screen().getEdgeSnapThreshold() + 1; // we only care about the left/top etc that includes borders int borderW = 0; if (decorationMask() & (WindowState::DECORM_BORDER|WindowState::DECORM_HANDLE)) borderW = frame().window().borderWidth(); int top = orig_top; // orig include the borders int left = orig_left; int right = orig_left + width() + 2 * borderW; int bottom = orig_top + height() + 2 * borderW; // test against tabs too bool i_have_tabs = frame().externalTabMode(); int xoff = 0, yoff = 0, woff = 0, hoff = 0; if (i_have_tabs) { xoff = xOffset(); yoff = yOffset(); woff = widthOffset(); hoff = heightOffset(); } ///////////////////////////////////// // begin by checking the screen (or Xinerama head) edges int starth = 0; // head "0" == whole screen width + height, which we skip since the // sum of all the heads covers those edges, if >1 head if (screen().numHeads() > 0) starth=1; for (int h=starth; h <= screen().numHeads(); h++) { snapToWindow(dx, dy, left, right, top, bottom, screen().maxLeft(h), screen().maxRight(h), screen().maxTop(h), screen().maxBottom(h)); if (i_have_tabs) snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, screen().maxLeft(h), screen().maxRight(h), screen().maxTop(h), screen().maxBottom(h)); } for (int h=starth; h <= screen().numHeads(); h++) { snapToWindow(dx, dy, left, right, top, bottom, screen().getHeadX(h), screen().getHeadX(h) + screen().getHeadWidth(h), screen().getHeadY(h), screen().getHeadY(h) + screen().getHeadHeight(h)); if (i_have_tabs) snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, screen().getHeadX(h), screen().getHeadX(h) + screen().getHeadWidth(h), screen().getHeadY(h), screen().getHeadY(h) + screen().getHeadHeight(h)); } ///////////////////////////////////// // now check window edges Workspace::Windows &wins = screen().currentWorkspace()->windowList(); Workspace::Windows::iterator it = wins.begin(); Workspace::Windows::iterator it_end = wins.end(); unsigned int bw; for (; it != it_end; it++) { if ((*it) == this) continue; // skip myself bw = (*it)->decorationMask() & (WindowState::DECORM_BORDER|WindowState::DECORM_HANDLE) ? (*it)->frame().window().borderWidth() : 0; snapToWindow(dx, dy, left, right, top, bottom, (*it)->x(), (*it)->x() + (*it)->width() + 2 * bw, (*it)->y(), (*it)->y() + (*it)->height() + 2 * bw); if (i_have_tabs) snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, (*it)->x(), (*it)->x() + (*it)->width() + 2 * bw, (*it)->y(), (*it)->y() + (*it)->height() + 2 * bw); // also snap to the box containing the tabs (don't bother with actual // tab edges, since they're dynamic if ((*it)->frame().externalTabMode()) snapToWindow(dx, dy, left, right, top, bottom, (*it)->x() - (*it)->xOffset(), (*it)->x() - (*it)->xOffset() + (*it)->width() + 2 * bw + (*it)->widthOffset(), (*it)->y() - (*it)->yOffset(), (*it)->y() - (*it)->yOffset() + (*it)->height() + 2 * bw + (*it)->heightOffset()); if (i_have_tabs) snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, (*it)->x() - (*it)->xOffset(), (*it)->x() - (*it)->xOffset() + (*it)->width() + 2 * bw + (*it)->widthOffset(), (*it)->y() - (*it)->yOffset(), (*it)->y() - (*it)->yOffset() + (*it)->height() + 2 * bw + (*it)->heightOffset()); } // commit if (dx <= screen().getEdgeSnapThreshold()) orig_left += dx; if (dy <= screen().getEdgeSnapThreshold()) orig_top += dy; } FluxboxWindow::ReferenceCorner FluxboxWindow::getResizeDirection(int x, int y, ResizeModel model) const { int cx = frame().width() / 2; int cy = frame().height() / 2; if (model == CENTERRESIZE) return CENTER; if (model == NEARESTEDGERESIZE) { if (cy - abs(y - cy) < cx - abs(x - cx)) // y is nearest return (y > cy) ? BOTTOM : TOP; return (x > cx) ? RIGHT : LEFT; } if (model == QUADRANTRESIZE) { if (x < cx) return (y < cy) ? LEFTTOP : LEFTBOTTOM; return (y < cy) ? RIGHTTOP : RIGHTBOTTOM; } if (model == TOPLEFTRESIZE) return LEFTTOP; if (model == TOPRESIZE) return TOP; if (model == TOPRIGHTRESIZE) return RIGHTTOP; if (model == LEFTRESIZE) return LEFT; if (model == RIGHTRESIZE) return RIGHT; if (model == BOTTOMLEFTRESIZE) return LEFTBOTTOM; if (model == BOTTOMRESIZE) return BOTTOM; return RIGHTBOTTOM; } void FluxboxWindow::startResizing(int x, int y, ReferenceCorner dir) { if (s_num_grabs > 0 || isShaded() || isIconic() ) return; if (isMaximized() && screen().getMaxDisableResize()) return; m_resize_corner = dir; resizing = true; maximized = WindowState::MAX_NONE; frame().setMaximized(maximized); const Cursor& cursor = (m_resize_corner == LEFTTOP) ? frame().theme()->upperLeftAngleCursor() : (m_resize_corner == RIGHTTOP) ? frame().theme()->upperRightAngleCursor() : (m_resize_corner == RIGHTBOTTOM) ? frame().theme()->lowerRightAngleCursor() : (m_resize_corner == LEFT) ? frame().theme()->leftSideCursor() : (m_resize_corner == RIGHT) ? frame().theme()->rightSideCursor() : (m_resize_corner == TOP) ? frame().theme()->topSideCursor() : (m_resize_corner == BOTTOM) ? frame().theme()->bottomSideCursor() : frame().theme()->lowerLeftAngleCursor(); grabPointer(fbWindow().window(), false, ButtonMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime); m_button_grab_x = x; m_button_grab_y = y; m_last_resize_x = frame().x(); m_last_resize_y = frame().y(); m_last_resize_w = frame().width(); m_last_resize_h = frame().height(); fixsize(); frame().displaySize(m_last_resize_w, m_last_resize_h); parent().drawRectangle(screen().rootTheme()->opGC(), m_last_resize_x, m_last_resize_y, m_last_resize_w - 1 + 2 * frame().window().borderWidth(), m_last_resize_h - 1 + 2 * frame().window().borderWidth()); } void FluxboxWindow::stopResizing(bool interrupted) { resizing = false; parent().drawRectangle(screen().rootTheme()->opGC(), m_last_resize_x, m_last_resize_y, m_last_resize_w - 1 + 2 * frame().window().borderWidth(), m_last_resize_h - 1 + 2 * frame().window().borderWidth()); screen().hideGeometry(); if (!interrupted) { fixsize(); moveResize(m_last_resize_x, m_last_resize_y, m_last_resize_w, m_last_resize_h); } ungrabPointer(CurrentTime); } void FluxboxWindow::startTabbing(const XButtonEvent &be) { if (s_num_grabs > 0) return; m_attaching_tab = 0; // determine if we're in titlebar Client2ButtonMap::iterator it = find_if(m_labelbuttons.begin(), m_labelbuttons.end(), Compose(bind2nd(equal_to<Window>(), be.window), Compose(mem_fun(&TextButton::window), Select2nd<Client2ButtonMap::value_type>()))); if (it != m_labelbuttons.end()) m_attaching_tab = it->first; // start drag'n'drop for tab grabPointer(be.window, False, ButtonMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, frame().theme()->moveCursor(), CurrentTime); // relative position on the button m_button_grab_x = be.x; m_button_grab_y = be.y; // position of the button m_last_move_x = be.x_root - be.x; m_last_move_y = be.y_root - be.y; // hijack extra vars for initial grab location m_last_resize_x = be.x_root; m_last_resize_y = be.y_root; Fluxbox::instance()->grab(); if (m_attaching_tab) { FbTk::TextButton &active_button = *m_labelbuttons[m_attaching_tab]; m_last_resize_w = active_button.width(); m_last_resize_h = active_button.height(); } else { m_attaching_tab = m_client; unsigned int bw = 2*frame().window().borderWidth()-1; m_last_resize_w = frame().width() + bw; m_last_resize_h = frame().height() + bw; } parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, m_last_resize_w, m_last_resize_h); menu().hide(); } void FluxboxWindow::attachTo(int x, int y, bool interrupted) { if (m_attaching_tab == 0) return; parent().drawRectangle(screen().rootTheme()->opGC(), m_last_move_x, m_last_move_y, m_last_resize_w, m_last_resize_h); ungrabPointer(CurrentTime); Fluxbox::instance()->ungrab(); // make sure we clean up here, since this object may be deleted inside attachClient WinClient *old_attached = m_attaching_tab; m_attaching_tab = 0; if (interrupted) return; int dest_x = 0, dest_y = 0; Window child = 0; if (XTranslateCoordinates(display, parent().window(), parent().window(), x, y, &dest_x, &dest_y, &child)) { bool inside_titlebar = false; // search for a fluxboxwindow WinClient *client = Fluxbox::instance()->searchWindow(child); FluxboxWindow *attach_to_win = 0; if (client) { inside_titlebar = client->fbwindow()->hasTitlebar() && client->fbwindow()->y() + static_cast<signed>(client->fbwindow()->titlebarHeight()) > dest_y; Fluxbox::TabsAttachArea area= Fluxbox::instance()->getTabsAttachArea(); if (area == Fluxbox::ATTACH_AREA_WINDOW) attach_to_win = client->fbwindow(); else if (area == Fluxbox::ATTACH_AREA_TITLEBAR && inside_titlebar) { attach_to_win = client->fbwindow(); } } if (attach_to_win != this && attach_to_win != 0 && attach_to_win->isTabable()) { attach_to_win->attachClient(*old_attached,x,y ); // we could be deleted here, DO NOT do anything else that alters this object } else if (attach_to_win != this || (attach_to_win == this && !inside_titlebar)) { // disconnect client if we didn't drop on a window WinClient &client = *old_attached; detachClient(*old_attached); // move window by relative amount of mouse movement // since just detached, move relative to old location if (client.fbwindow() != 0) { client.fbwindow()->move(frame().x() - m_last_resize_x + x, frame().y() - m_last_resize_y + y); } } else if( attach_to_win == this && attach_to_win->isTabable()) { //reording of tabs within a frame moveClientTo(*old_attached, x, y); } } } void FluxboxWindow::restore(WinClient *client, bool remap) { if (client->fbwindow() != this) return; XChangeSaveSet(display, client->window(), SetModeDelete); client->setEventMask(NoEventMask); int wx = frame().x(), wy = frame().y(); // don't move the frame, in case there are other tabs in it // just set the new coordinates on the reparented window frame().gravityTranslate(wx, wy, -client->gravity(), client->old_bw, false); // negative to invert // Why was this hide done? It broke vncviewer (and mplayer?), // since it would reparent when going fullscreen. // is it needed for anything? Reparent should imply unmap // ok, it should hide sometimes, e.g. if the reparent was sent by a client //client->hide(); // restore old border width client->setBorderWidth(client->old_bw); XEvent xev; if (! XCheckTypedWindowEvent(display, client->window(), ReparentNotify, &xev)) { #ifdef DEBUG cerr<<"FluxboxWindow::restore: reparent 0x"<<hex<<client->window()<<dec<<" to root"<<endl; #endif // DEBUG // reparent to root window client->reparent(screen().rootWindow(), wx, wy, false); if (!remap) client->hide(); } if (remap) client->show(); installColormap(false); delete client; #ifdef DEBUG cerr<<"FluxboxWindow::restore: remap = "<<remap<<endl; cerr<<__FILE__<<"("<<__FUNCTION__<<"): numClients() = "<<numClients()<<endl; #endif // DEBUG if (numClients() == 0) delete this; } void FluxboxWindow::restore(bool remap) { if (numClients() == 0) return; #ifdef DEBUG cerr<<"restore("<<remap<<")"<<endl; #endif // DEBUG while (!clientList().empty()) { restore(clientList().back(), remap); // deleting winClient removes it from the clientList } } bool FluxboxWindow::isVisible() const { return frame().isVisible(); } FbTk::FbWindow &FluxboxWindow::fbWindow() { return frame().window(); } const FbTk::FbWindow &FluxboxWindow::fbWindow() const { return frame().window(); } FbMenu &FluxboxWindow::menu() { return screen().windowMenu(); } bool FluxboxWindow::acceptsFocus() const { return (m_client ? m_client->acceptsFocus() : false); } const FbTk::PixmapWithMask &FluxboxWindow::icon() const { return (m_client ? m_client->icon() : m_icon); } const FbMenu &FluxboxWindow::menu() const { return screen().windowMenu(); } unsigned int FluxboxWindow::titlebarHeight() const { return frame().titlebarHeight(); } Window FluxboxWindow::clientWindow() const { if (m_client == 0) return 0; return m_client->window(); } const string &FluxboxWindow::title() const { return (m_client ? m_client->title() : m_title); } const std::string &FluxboxWindow::getWMClassName() const { return (m_client ? m_client->getWMClassName() : getWMClassName()); } const std::string &FluxboxWindow::getWMClassClass() const { return (m_client ? m_client->getWMClassClass() : getWMClassClass()); } std::string FluxboxWindow::getWMRole() const { return (m_client ? m_client->getWMRole() : "FluxboxWindow"); } Focusable::WindowType FluxboxWindow::getWindowType() const { return (m_client ? m_client->getWindowType() : Focusable::TYPE_NORMAL); } bool FluxboxWindow::isTransient() const { return (m_client && m_client->isTransient()); } int FluxboxWindow::initialState() const { return m_client->initial_state; } void FluxboxWindow::fixsize() { frame().applySizeHints(m_last_resize_w, m_last_resize_h); // move X if necessary if (m_resize_corner == LEFTTOP || m_resize_corner == LEFTBOTTOM || m_resize_corner == LEFT) { m_last_resize_x = frame().x() + frame().width() - m_last_resize_w; } if (m_resize_corner == LEFTTOP || m_resize_corner == RIGHTTOP || m_resize_corner == TOP) { m_last_resize_y = frame().y() + frame().height() - m_last_resize_h; } } void FluxboxWindow::moveResizeClient(WinClient &client) { client.moveResize(frame().clientArea().x(), frame().clientArea().y(), frame().clientArea().width(), frame().clientArea().height()); client.sendConfigureNotify(frame().x() + frame().clientArea().x() + frame().window().borderWidth(), frame().y() + frame().clientArea().y() + frame().window().borderWidth(), frame().clientArea().width(), frame().clientArea().height()); } void FluxboxWindow::sendConfigureNotify() { ClientList::iterator client_it = m_clientlist.begin(); ClientList::iterator client_it_end = m_clientlist.end(); for (; client_it != client_it_end; ++client_it) { WinClient &client = *(*client_it); /* Send event telling where the root position of the client window is. (ie frame pos + client pos inside the frame = send pos) */ //!! moveResizeClient(client); } // end for } void FluxboxWindow::close() { if (WindowCmd<void>::window() == this && WindowCmd<void>::client()) WindowCmd<void>::client()->sendClose(false); else if (m_client) m_client->sendClose(false); } void FluxboxWindow::kill() { if (WindowCmd<void>::window() == this && WindowCmd<void>::client()) WindowCmd<void>::client()->sendClose(true); else if (m_client) m_client->sendClose(true); } void FluxboxWindow::setupWindow() { // sets up our window // we allow both to be done at once to share the commands using namespace FbTk; typedef FbTk::Resource<vector<WinButton::Type> > WinButtonsResource; string titlebar_name[2]; string titlebar_alt_name[2]; titlebar_name[0] = screen().name() + ".titlebar.left"; titlebar_alt_name[0] = screen().altName() + ".Titlebar.Left"; titlebar_name[1] = screen().name() + ".titlebar.right"; titlebar_alt_name[1] = screen().altName() + ".Titlebar.Right"; WinButtonsResource *titlebar_side[2]; ResourceManager &rm = screen().resourceManager(); // create resource for titlebar for (int i=0; i < 2; ++i) { titlebar_side[i] = dynamic_cast<WinButtonsResource *>( rm.findResource( titlebar_name[i] ) ); if (titlebar_side[i] != 0) continue; // find next resource too WinButton::Type titlebar_left[] = { WinButton::STICK }; WinButton::Type titlebar_right[] = { WinButton::MINIMIZE, WinButton::MAXIMIZE, WinButton::CLOSE }; WinButton::Type *begin = 0; WinButton::Type *end = 0; if (i == 0) { begin = titlebar_left; end = titlebar_left + 1; } else { begin = titlebar_right; end = titlebar_right + 3; } titlebar_side[i] = new WinButtonsResource(rm, WinButtonsResource::Type(begin, end), titlebar_name[i], titlebar_alt_name[i]); screen().addManagedResource(titlebar_side[i]); } updateButtons(); // end setup frame } void FluxboxWindow::updateButtons() { string titlebar_name[2]; titlebar_name[0] = screen().name() + ".titlebar.left"; titlebar_name[1] = screen().name() + ".titlebar.right"; typedef FbTk::Resource<vector<WinButton::Type> > WinButtonsResource; WinButtonsResource *titlebar_side[2]; ResourceManager &rm = screen().resourceManager(); bool need_update = false; // get resource for titlebar for (int i=0; i < 2; ++i) { titlebar_side[i] = dynamic_cast<WinButtonsResource *>( rm.findResource( titlebar_name[i] ) ); // check if we need to update our buttons size_t new_size = (*titlebar_side[i])->size(); if (new_size != m_titlebar_buttons[i].size() || need_update) need_update = true; else { for (size_t j=0; j < new_size && !need_update; j++) { if ((*(*titlebar_side[i]))[j] != m_titlebar_buttons[i][j]) need_update = true; } } } if (!need_update) return; // clear old buttons from frame frame().removeAllButtons(); using namespace FbTk; typedef RefCount<Command<void> > CommandRef; typedef SimpleCommand<FluxboxWindow> WindowCmd; CommandRef iconify_cmd(new WindowCmd(*this, &FluxboxWindow::iconify)); CommandRef maximize_cmd(new WindowCmd(*this, &FluxboxWindow::maximizeFull)); CommandRef maximize_vert_cmd(new WindowCmd(*this, &FluxboxWindow::maximizeVertical)); CommandRef maximize_horiz_cmd(new WindowCmd(*this, &FluxboxWindow::maximizeHorizontal)); CommandRef close_cmd(new WindowCmd(*this, &FluxboxWindow::close)); CommandRef shade_cmd(new WindowCmd(*this, &FluxboxWindow::shade)); CommandRef stick_cmd(new WindowCmd(*this, &FluxboxWindow::stick)); CommandRef show_menu_cmd(new WindowCmd(*this, &FluxboxWindow::popupMenu)); for (size_t c = 0; c < 2 ; c++) { // get titlebar configuration for current side const vector<WinButton::Type> &dir = *(*titlebar_side[c]); m_titlebar_buttons[c] = dir; for (size_t i=0; i < dir.size(); ++i) { //create new buttons WinButton *winbtn = 0; switch (dir[i]) { case WinButton::MINIMIZE: if (isIconifiable()) { winbtn = new WinButton(*this, m_button_theme, screen().pressedWinButtonTheme(), WinButton::MINIMIZE, frame().titlebar(), 0, 0, 10, 10); winbtn->setOnClick(iconify_cmd); } break; case WinButton::MAXIMIZE: if (isMaximizable()) { winbtn = new WinButton(*this, m_button_theme, screen().pressedWinButtonTheme(), dir[i], frame().titlebar(), 0, 0, 10, 10); winbtn->setOnClick(maximize_cmd, 1); winbtn->setOnClick(maximize_horiz_cmd, 3); winbtn->setOnClick(maximize_vert_cmd, 2); } break; case WinButton::CLOSE: if (m_client->isClosable()) { winbtn = new WinButton(*this, m_button_theme, screen().pressedWinButtonTheme(), dir[i], frame().titlebar(), 0, 0, 10, 10); winbtn->setOnClick(close_cmd); stateSig().attach(winbtn); } break; case WinButton::STICK: winbtn = new WinButton(*this, m_button_theme, screen().pressedWinButtonTheme(), dir[i], frame().titlebar(), 0, 0, 10, 10); stateSig().attach(winbtn); winbtn->setOnClick(stick_cmd); break; case WinButton::SHADE: winbtn = new WinButton(*this, m_button_theme, screen().pressedWinButtonTheme(), dir[i], frame().titlebar(), 0, 0, 10, 10); stateSig().attach(winbtn); winbtn->setOnClick(shade_cmd); break; case WinButton::MENUICON: winbtn = new WinButton(*this, m_button_theme, screen().pressedWinButtonTheme(), dir[i], frame().titlebar(), 0, 0, 10, 10); titleSig().attach(winbtn); winbtn->setOnClick(show_menu_cmd); break; } if (winbtn != 0) { winbtn->show(); if (c == 0) frame().addLeftButton(winbtn); else frame().addRightButton(winbtn); } } //end for i } // end for c frame().reconfigure(); } // grab pointer and increase counter. // we need this to count grab pointers, // especially at startup, where we can drag/resize while starting // and causing it to send events to windows later on and make // two different windows do grab pointer which only one window // should do at the time void FluxboxWindow::grabPointer(Window grab_window, Bool owner_events, unsigned int event_mask, int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor, Time time) { XGrabPointer(FbTk::App::instance()->display(), grab_window, owner_events, event_mask, pointer_mode, keyboard_mode, confine_to, cursor, time); s_num_grabs++; } // ungrab and decrease counter void FluxboxWindow::ungrabPointer(Time time) { XUngrabPointer(FbTk::App::instance()->display(), time); s_num_grabs--; if (s_num_grabs < 0) s_num_grabs = 0; } void FluxboxWindow::associateClient(WinClient &client) { IconButton *btn = new IconButton(frame().tabcontainer(), frame().theme().focusedTheme()->iconbarTheme(), frame().theme().unfocusedTheme()->iconbarTheme(), client); frame().createTab(*btn); FbTk::RefCount<FbTk::Command<void> > setcmd(new SetClientCmd(client)); btn->setOnClick(setcmd, 1); btn->setTextPadding(Fluxbox::instance()->getTabsPadding()); btn->setPixmap(screen().getTabsUsePixmap()); m_labelbuttons[&client] = btn; FbTk::EventManager &evm = *FbTk::EventManager::instance(); evm.add(*this, btn->window()); // we take care of button events for this evm.add(*this, client.window()); client.setFluxboxWindow(this); client.titleSig().attach(this); } FluxboxWindow::ReferenceCorner FluxboxWindow::getCorner(string str) { str = FbTk::StringUtil::toLower(str); if (str == "lefttop" || str == "topleft" || str == "upperleft" || str == "") return LEFTTOP; if (str == "top" || str == "upper" || str == "topcenter") return TOP; if (str == "righttop" || str == "topright" || str == "upperright") return RIGHTTOP; if (str == "left" || str == "leftcenter") return LEFT; if (str == "center" || str == "wincenter") return CENTER; if (str == "right" || str == "rightcenter") return RIGHT; if (str == "leftbottom" || str == "bottomleft" || str == "lowerleft") return LEFTBOTTOM; if (str == "bottom" || str == "bottomcenter") return BOTTOM; if (str == "rightbottom" || str == "bottomright" || str == "lowerright") return RIGHTBOTTOM; return ERROR; } void FluxboxWindow::translateCoords(int &x, int &y, ReferenceCorner dir) const { int head = getOnHead(), bw = 2 * frame().window().borderWidth(), left = screen().maxLeft(head), right = screen().maxRight(head), top = screen().maxTop(head), bottom = screen().maxBottom(head); if (dir == LEFTTOP || dir == LEFT || dir == LEFTBOTTOM) x += left; if (dir == RIGHTTOP || dir == RIGHT || dir == RIGHTBOTTOM) x = right - width() - bw - x; if (dir == TOP || dir == CENTER || dir == BOTTOM) x += (left + right - width() - bw)/2; if (dir == LEFTTOP || dir == TOP || dir == RIGHTTOP) y += top; if (dir == LEFTBOTTOM || dir == BOTTOM || dir == RIGHTBOTTOM) y = bottom - height() - bw - y; if (dir == LEFT || dir == CENTER || dir == RIGHT) y += (top + bottom - height() - bw)/2; } int FluxboxWindow::getOnHead() const { return screen().getHead(fbWindow()); } void FluxboxWindow::setOnHead(int head) { if (head > 0 && head <= screen().numHeads()) { int cur = screen().getHead(fbWindow()); bool placed = m_placed; move(screen().getHeadX(head) + frame().x() - screen().getHeadX(cur), screen().getHeadY(head) + frame().y() - screen().getHeadY(cur)); m_placed = placed; } } void FluxboxWindow::placeWindow(int head) { int place_x, place_y; // we ignore the return value, // the screen placement strategy is guaranteed to succeed. screen().placementStrategy().placeWindow(*this, head, place_x, place_y); move(place_x, place_y); } void FluxboxWindow::setWindowType(Focusable::WindowType type) { switch (type) { case Focusable::TYPE_DOCK: /* From Extended Window Manager Hints, draft 1.3: * * _NET_WM_WINDOW_TYPE_DOCK indicates a dock or panel feature. * Typically a Window Manager would keep such windows on top * of all other windows. * */ setFocusHidden(true); setIconHidden(true); setFocusNew(false); setMouseFocus(false); setClickFocus(false); setDecorationMask(WindowState::DECOR_NONE); moveToLayer(::Layer::DOCK); break; case Focusable::TYPE_DESKTOP: /* * _NET_WM_WINDOW_TYPE_DESKTOP indicates a "false desktop" window * We let it be the size it wants, but it gets no decoration, * is hidden in the toolbar and window cycling list, plus * windows don't tab with it and is right on the bottom. */ setFocusHidden(true); setIconHidden(true); setFocusNew(false); setMouseFocus(false); moveToLayer(::Layer::DESKTOP); setDecorationMask(WindowState::DECOR_NONE); setTabable(false); setMovable(false); setResizable(false); stick(); break; case Focusable::TYPE_SPLASH: /* * _NET_WM_WINDOW_TYPE_SPLASH indicates that the * window is a splash screen displayed as an application * is starting up. */ setDecorationMask(WindowState::DECOR_NONE); setFocusHidden(true); setIconHidden(true); setFocusNew(false); setMouseFocus(false); setClickFocus(false); setMovable(false); break; case Focusable::TYPE_DIALOG: setTabable(false); break; case Focusable::TYPE_MENU: case Focusable::TYPE_TOOLBAR: /* * _NET_WM_WINDOW_TYPE_TOOLBAR and _NET_WM_WINDOW_TYPE_MENU * indicate toolbar and pinnable menu windows, respectively * (i.e. toolbars and menus "torn off" from the main * application). Windows of this type may set the * WM_TRANSIENT_FOR hint indicating the main application window. */ setDecorationMask(WindowState::DECOR_TOOL); setIconHidden(true); moveToLayer(::Layer::ABOVE_DOCK); break; case Focusable::TYPE_NORMAL: default: break; } /* * NOT YET IMPLEMENTED: * _NET_WM_WINDOW_TYPE_UTILITY */ } |