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
|
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
/*
This file contains things relevant to geometry, i.e. workspace size,
window positions and window sizes.
*/
#include "client.h"
#include "composite.h"
#include "cursor.h"
#include "netinfo.h"
#include "workspace.h"
#include "placement.h"
#include "geometrytip.h"
#include "rules.h"
#include "screens.h"
#include "effects.h"
#include "screenedge.h"
#include <QApplication>
#include <QDebug>
#include <QVarLengthArray>
#include "outline.h"
#include "shell_client.h"
#include "wayland_server.h"
#include <KDecoration2/Decoration>
#include <KDecoration2/DecoratedClient>
namespace KWin
{
static inline int sign(int v) {
return (v > 0) - (v < 0);
}
//********************************************
// Workspace
//********************************************
extern int screen_number;
extern bool is_multihead;
/*!
Resizes the workspace after an XRANDR screen size change
*/
void Workspace::desktopResized()
{
QRect geom = screens()->geometry();
if (rootInfo()) {
NETSize desktop_geometry;
desktop_geometry.width = geom.width();
desktop_geometry.height = geom.height();
rootInfo()->setDesktopGeometry(desktop_geometry);
}
updateClientArea();
saveOldScreenSizes(); // after updateClientArea(), so that one still uses the previous one
// TODO: emit a signal instead and remove the deep function calls into edges and effects
ScreenEdges::self()->recreateEdges();
if (effects) {
static_cast<EffectsHandlerImpl*>(effects)->desktopResized(geom.size());
}
}
void Workspace::saveOldScreenSizes()
{
olddisplaysize = screens()->displaySize();
oldscreensizes.clear();
for( int i = 0;
i < screens()->count();
++i )
oldscreensizes.append( screens()->geometry( i ));
}
/*!
Updates the current client areas according to the current clients.
If the area changes or force is true, the new areas are propagated to the world.
The client area is the area that is available for clients (that
which is not taken by windows like panels, the top-of-screen menu
etc).
\sa clientArea()
*/
void Workspace::updateClientArea(bool force)
{
const Screens *s = Screens::self();
int nscreens = s->count();
const int numberOfDesktops = VirtualDesktopManager::self()->count();
QVector< QRect > new_wareas(numberOfDesktops + 1);
QVector< StrutRects > new_rmoveareas(numberOfDesktops + 1);
QVector< QVector< QRect > > new_sareas(numberOfDesktops + 1);
QVector< QRect > screens(nscreens);
QRect desktopArea;
for (int i = 0; i < nscreens; i++) {
desktopArea |= s->geometry(i);
}
for (int iS = 0;
iS < nscreens;
iS ++) {
screens [iS] = s->geometry(iS);
}
for (int i = 1;
i <= numberOfDesktops;
++i) {
new_wareas[ i ] = desktopArea;
new_sareas[ i ].resize(nscreens);
for (int iS = 0;
iS < nscreens;
iS ++)
new_sareas[ i ][ iS ] = screens[ iS ];
}
for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) {
if (!(*it)->hasStrut())
continue;
QRect r = (*it)->adjustedClientArea(desktopArea, desktopArea);
// sanity check that a strut doesn't exclude a complete screen geometry
// this is a violation to EWMH, as KWin just ignores the strut
for (int i = 0; i < Screens::self()->count(); i++) {
if (!r.intersects(Screens::self()->geometry(i))) {
qCDebug(KWIN_CORE) << "Adjusted client area would exclude a complete screen, ignore";
r = desktopArea;
break;
}
}
StrutRects strutRegion = (*it)->strutRects();
const QRect clientsScreenRect = KWin::screens()->geometry((*it)->screen());
for (auto strut = strutRegion.begin(); strut != strutRegion.end(); strut++) {
*strut = StrutRect((*strut).intersected(clientsScreenRect), (*strut).area());
}
// Ignore offscreen xinerama struts. These interfere with the larger monitors on the setup
// and should be ignored so that applications that use the work area to work out where
// windows can go can use the entire visible area of the larger monitors.
// This goes against the EWMH description of the work area but it is a toss up between
// having unusable sections of the screen (Which can be quite large with newer monitors)
// or having some content appear offscreen (Relatively rare compared to other).
bool hasOffscreenXineramaStrut = (*it)->hasOffscreenXineramaStrut();
if ((*it)->isOnAllDesktops()) {
for (int i = 1;
i <= numberOfDesktops;
++i) {
if (!hasOffscreenXineramaStrut)
new_wareas[ i ] = new_wareas[ i ].intersected(r);
new_rmoveareas[ i ] += strutRegion;
for (int iS = 0;
iS < nscreens;
iS ++) {
const auto geo = new_sareas[ i ][ iS ].intersected(
(*it)->adjustedClientArea(desktopArea, screens[ iS ]));
// ignore the geometry if it results in the screen getting removed completely
if (!geo.isEmpty()) {
new_sareas[ i ][ iS ] = geo;
}
}
}
} else {
if (!hasOffscreenXineramaStrut)
new_wareas[(*it)->desktop()] = new_wareas[(*it)->desktop()].intersected(r);
new_rmoveareas[(*it)->desktop()] += strutRegion;
for (int iS = 0;
iS < nscreens;
iS ++) {
// qDebug() << "adjusting new_sarea: " << screens[ iS ];
const auto geo = new_sareas[(*it)->desktop()][ iS ].intersected(
(*it)->adjustedClientArea(desktopArea, screens[ iS ]));
// ignore the geometry if it results in the screen getting removed completely
if (!geo.isEmpty()) {
new_sareas[(*it)->desktop()][ iS ] = geo;
}
}
}
}
if (waylandServer()) {
auto updateStrutsForWaylandClient = [&] (ShellClient *c) {
// assuming that only docks have "struts" and that all docks have a strut
if (!c->hasStrut()) {
return;
}
auto margins = [c] (const QRect &geometry) {
QMargins margins;
if (!geometry.intersects(c->geometry())) {
return margins;
}
// figure out which areas of the overall screen setup it borders
const bool left = c->geometry().left() == geometry.left();
const bool right = c->geometry().right() == geometry.right();
const bool top = c->geometry().top() == geometry.top();
const bool bottom = c->geometry().bottom() == geometry.bottom();
const bool horizontal = c->geometry().width() >= c->geometry().height();
if (left && ((!top && !bottom) || !horizontal)) {
margins.setLeft(c->geometry().width());
}
if (right && ((!top && !bottom) || !horizontal)) {
margins.setRight(c->geometry().width());
}
if (top && ((!left && !right) || horizontal)) {
margins.setTop(c->geometry().height());
}
if (bottom && ((!left && !right) || horizontal)) {
margins.setBottom(c->geometry().height());
}
return margins;
};
auto marginsToStrutArea = [] (const QMargins &margins) {
if (margins.left() != 0) {
return StrutAreaLeft;
}
if (margins.right() != 0) {
return StrutAreaRight;
}
if (margins.top() != 0) {
return StrutAreaTop;
}
if (margins.bottom() != 0) {
return StrutAreaBottom;
}
return StrutAreaInvalid;
};
const auto strut = margins(KWin::screens()->geometry(c->screen()));
const StrutRects strutRegion = StrutRects{StrutRect(c->geometry(), marginsToStrutArea(strut))};
QRect r = desktopArea - margins(KWin::screens()->geometry());
if (c->isOnAllDesktops()) {
for (int i = 1; i <= numberOfDesktops; ++i) {
new_wareas[ i ] = new_wareas[ i ].intersected(r);
for (int iS = 0; iS < nscreens; ++iS) {
new_sareas[ i ][ iS ] = new_sareas[ i ][ iS ].intersected(screens[iS] - margins(screens[iS]));
}
new_rmoveareas[ i ] += strutRegion;
}
} else {
new_wareas[c->desktop()] = new_wareas[c->desktop()].intersected(r);
for (int iS = 0; iS < nscreens; iS++) {
new_sareas[c->desktop()][ iS ] = new_sareas[c->desktop()][ iS ].intersected(screens[iS] - margins(screens[iS]));
}
new_rmoveareas[ c->desktop() ] += strutRegion;
}
};
const auto clients = waylandServer()->clients();
for (auto c : clients) {
updateStrutsForWaylandClient(c);
}
const auto internalClients = waylandServer()->internalClients();
for (auto c : internalClients) {
updateStrutsForWaylandClient(c);
}
}
#if 0
for (int i = 1;
i <= numberOfDesktops();
++i) {
for (int iS = 0;
iS < nscreens;
iS ++)
qCDebug(KWIN_CORE) << "new_sarea: " << new_sareas[ i ][ iS ];
}
#endif
bool changed = force;
if (screenarea.isEmpty())
changed = true;
for (int i = 1;
!changed && i <= numberOfDesktops;
++i) {
if (workarea[ i ] != new_wareas[ i ])
changed = true;
if (restrictedmovearea[ i ] != new_rmoveareas[ i ])
changed = true;
if (screenarea[ i ].size() != new_sareas[ i ].size())
changed = true;
for (int iS = 0;
!changed && iS < nscreens;
iS ++)
if (new_sareas[ i ][ iS ] != screenarea [ i ][ iS ])
changed = true;
}
if (changed) {
workarea = new_wareas;
oldrestrictedmovearea = restrictedmovearea;
restrictedmovearea = new_rmoveareas;
screenarea = new_sareas;
if (rootInfo()) {
NETRect r;
for (int i = 1; i <= numberOfDesktops; i++) {
r.pos.x = workarea[ i ].x();
r.pos.y = workarea[ i ].y();
r.size.width = workarea[ i ].width();
r.size.height = workarea[ i ].height();
rootInfo()->setWorkArea(i, r);
}
}
for (auto it = m_allClients.constBegin();
it != m_allClients.constEnd();
++it)
(*it)->checkWorkspacePosition();
for (ClientList::ConstIterator it = desktops.constBegin();
it != desktops.constEnd();
++it)
(*it)->checkWorkspacePosition();
oldrestrictedmovearea.clear(); // reset, no longer valid or needed
}
}
void Workspace::updateClientArea()
{
updateClientArea(false);
}
/*!
returns the area available for clients. This is the desktop
geometry minus windows on the dock. Placement algorithms should
refer to this rather than geometry().
\sa geometry()
*/
QRect Workspace::clientArea(clientAreaOption opt, int screen, int desktop) const
{
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0)
desktop = VirtualDesktopManager::self()->current();
if (screen == -1)
screen = screens()->current();
const QSize displaySize = screens()->displaySize();
QRect sarea, warea;
if (is_multihead) {
sarea = (!screenarea.isEmpty()
&& screen < screenarea[ desktop ].size()) // screens may be missing during KWin initialization or screen config changes
? screenarea[ desktop ][ screen_number ]
: screens()->geometry(screen_number);
warea = workarea[ desktop ].isNull()
? screens()->geometry(screen_number)
: workarea[ desktop ];
} else {
sarea = (!screenarea.isEmpty()
&& screen < screenarea[ desktop ].size()) // screens may be missing during KWin initialization or screen config changes
? screenarea[ desktop ][ screen ]
: screens()->geometry(screen);
warea = workarea[ desktop ].isNull()
? QRect(0, 0, displaySize.width(), displaySize.height())
: workarea[ desktop ];
}
switch(opt) {
case MaximizeArea:
case PlacementArea:
return sarea;
case MaximizeFullArea:
case FullScreenArea:
case MovementArea:
case ScreenArea:
if (is_multihead)
return screens()->geometry(screen_number);
else
return screens()->geometry(screen);
case WorkArea:
if (is_multihead)
return sarea;
else
return warea;
case FullArea:
return QRect(0, 0, displaySize.width(), displaySize.height());
}
abort();
}
QRect Workspace::clientArea(clientAreaOption opt, const QPoint& p, int desktop) const
{
return clientArea(opt, screens()->number(p), desktop);
}
QRect Workspace::clientArea(clientAreaOption opt, const AbstractClient* c) const
{
return clientArea(opt, c->geometry().center(), c->desktop());
}
QRegion Workspace::restrictedMoveArea(int desktop, StrutAreas areas) const
{
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0)
desktop = VirtualDesktopManager::self()->current();
QRegion region;
foreach (const StrutRect & rect, restrictedmovearea[desktop])
if (areas & rect.area())
region += rect;
return region;
}
bool Workspace::inUpdateClientArea() const
{
return !oldrestrictedmovearea.isEmpty();
}
QRegion Workspace::previousRestrictedMoveArea(int desktop, StrutAreas areas) const
{
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0)
desktop = VirtualDesktopManager::self()->current();
QRegion region;
foreach (const StrutRect & rect, oldrestrictedmovearea.at(desktop))
if (areas & rect.area())
region += rect;
return region;
}
QVector< QRect > Workspace::previousScreenSizes() const
{
return oldscreensizes;
}
int Workspace::oldDisplayWidth() const
{
return olddisplaysize.width();
}
int Workspace::oldDisplayHeight() const
{
return olddisplaysize.height();
}
/*!
Client \a c is moved around to position \a pos. This gives the
workspace the opportunity to interveniate and to implement
snap-to-windows functionality.
The parameter \a snapAdjust is a multiplier used to calculate the
effective snap zones. When 1.0, it means that the snap zones will be
used without change.
*/
QPoint Workspace::adjustClientPosition(AbstractClient* c, QPoint pos, bool unrestricted, double snapAdjust)
{
QSize borderSnapZone(options->borderSnapZone(), options->borderSnapZone());
QRect maxRect;
int guideMaximized = MaximizeRestore;
if (c->maximizeMode() != MaximizeRestore) {
maxRect = clientArea(MaximizeArea, pos + c->rect().center(), c->desktop());
QRect geo = c->geometry();
if (c->maximizeMode() & MaximizeHorizontal && (geo.x() == maxRect.left() || geo.right() == maxRect.right())) {
guideMaximized |= MaximizeHorizontal;
borderSnapZone.setWidth(qMax(borderSnapZone.width() + 2, maxRect.width() / 16));
}
if (c->maximizeMode() & MaximizeVertical && (geo.y() == maxRect.top() || geo.bottom() == maxRect.bottom())) {
guideMaximized |= MaximizeVertical;
borderSnapZone.setHeight(qMax(borderSnapZone.height() + 2, maxRect.height() / 16));
}
}
if (options->windowSnapZone() || !borderSnapZone.isNull() || options->centerSnapZone()) {
const bool sOWO = options->isSnapOnlyWhenOverlapping();
const int screen = screens()->number(pos + c->rect().center());
if (maxRect.isNull())
maxRect = clientArea(MovementArea, screen, c->desktop());
const int xmin = maxRect.left();
const int xmax = maxRect.right() + 1; //desk size
const int ymin = maxRect.top();
const int ymax = maxRect.bottom() + 1;
const int cx(pos.x());
const int cy(pos.y());
const int cw(c->width());
const int ch(c->height());
const int rx(cx + cw);
const int ry(cy + ch); //these don't change
int nx(cx), ny(cy); //buffers
int deltaX(xmax);
int deltaY(ymax); //minimum distance to other clients
int lx, ly, lrx, lry; //coords and size for the comparison client, l
// border snap
const int snapX = borderSnapZone.width() * snapAdjust; //snap trigger
const int snapY = borderSnapZone.height() * snapAdjust;
if (snapX || snapY) {
QRect geo = c->geometry();
const QPoint cp = c->clientPos();
const QSize cs = geo.size() - c->clientSize();
int padding[4] = { cp.x(), cs.width() - cp.x(), cp.y(), cs.height() - cp.y() };
// snap to titlebar / snap to window borders on inner screen edges
Client::Position titlePos = c->titlebarPosition();
if (padding[0] && (titlePos == Client::PositionLeft || (c->maximizeMode() & MaximizeHorizontal) ||
screens()->intersecting(geo.translated(maxRect.x() - (padding[0] + geo.x()), 0)) > 1))
padding[0] = 0;
if (padding[1] && (titlePos == Client::PositionRight || (c->maximizeMode() & MaximizeHorizontal) ||
screens()->intersecting(geo.translated(maxRect.right() + padding[1] - geo.right(), 0)) > 1))
padding[1] = 0;
if (padding[2] && (titlePos == Client::PositionTop || (c->maximizeMode() & MaximizeVertical) ||
screens()->intersecting(geo.translated(0, maxRect.y() - (padding[2] + geo.y()))) > 1))
padding[2] = 0;
if (padding[3] && (titlePos == Client::PositionBottom || (c->maximizeMode() & MaximizeVertical) ||
screens()->intersecting(geo.translated(0, maxRect.bottom() + padding[3] - geo.bottom())) > 1))
padding[3] = 0;
if ((sOWO ? (cx < xmin) : true) && (qAbs(xmin - cx) < snapX)) {
deltaX = xmin - cx;
nx = xmin - padding[0];
}
if ((sOWO ? (rx > xmax) : true) && (qAbs(rx - xmax) < snapX) && (qAbs(xmax - rx) < deltaX)) {
deltaX = rx - xmax;
nx = xmax - cw + padding[1];
}
if ((sOWO ? (cy < ymin) : true) && (qAbs(ymin - cy) < snapY)) {
deltaY = ymin - cy;
ny = ymin - padding[2];
}
if ((sOWO ? (ry > ymax) : true) && (qAbs(ry - ymax) < snapY) && (qAbs(ymax - ry) < deltaY)) {
deltaY = ry - ymax;
ny = ymax - ch + padding[3];
}
}
// windows snap
int snap = options->windowSnapZone() * snapAdjust;
if (snap) {
for (auto l = m_allClients.constBegin(); l != m_allClients.constEnd(); ++l) {
if ((*l) == c)
continue;
if ((*l)->isMinimized())
continue; // is minimized
if (!(*l)->isShown(false))
continue;
if ((*l)->tabGroup() && (*l) != (*l)->tabGroup()->current())
continue; // is not active tab
if (!((*l)->isOnDesktop(c->desktop()) || c->isOnDesktop((*l)->desktop())))
continue; // wrong virtual desktop
if (!(*l)->isOnCurrentActivity())
continue; // wrong activity
if ((*l)->isDesktop() || (*l)->isSplash())
continue;
lx = (*l)->x();
ly = (*l)->y();
lrx = lx + (*l)->width();
lry = ly + (*l)->height();
if (!(guideMaximized & MaximizeHorizontal) &&
(((cy <= lry) && (cy >= ly)) || ((ry >= ly) && (ry <= lry)) || ((cy <= ly) && (ry >= lry)))) {
if ((sOWO ? (cx < lrx) : true) && (qAbs(lrx - cx) < snap) && (qAbs(lrx - cx) < deltaX)) {
deltaX = qAbs(lrx - cx);
nx = lrx;
}
if ((sOWO ? (rx > lx) : true) && (qAbs(rx - lx) < snap) && (qAbs(rx - lx) < deltaX)) {
deltaX = qAbs(rx - lx);
nx = lx - cw;
}
}
if (!(guideMaximized & MaximizeVertical) &&
(((cx <= lrx) && (cx >= lx)) || ((rx >= lx) && (rx <= lrx)) || ((cx <= lx) && (rx >= lrx)))) {
if ((sOWO ? (cy < lry) : true) && (qAbs(lry - cy) < snap) && (qAbs(lry - cy) < deltaY)) {
deltaY = qAbs(lry - cy);
ny = lry;
}
//if ( (qAbs( ry-ly ) < snap) && (qAbs( ry - ly ) < deltaY ))
if ((sOWO ? (ry > ly) : true) && (qAbs(ry - ly) < snap) && (qAbs(ry - ly) < deltaY)) {
deltaY = qAbs(ry - ly);
ny = ly - ch;
}
}
// Corner snapping
if (!(guideMaximized & MaximizeVertical) && (nx == lrx || nx + cw == lx)) {
if ((sOWO ? (ry > lry) : true) && (qAbs(lry - ry) < snap) && (qAbs(lry - ry) < deltaY)) {
deltaY = qAbs(lry - ry);
ny = lry - ch;
}
if ((sOWO ? (cy < ly) : true) && (qAbs(cy - ly) < snap) && (qAbs(cy - ly) < deltaY)) {
deltaY = qAbs(cy - ly);
ny = ly;
}
}
if (!(guideMaximized & MaximizeHorizontal) && (ny == lry || ny + ch == ly)) {
if ((sOWO ? (rx > lrx) : true) && (qAbs(lrx - rx) < snap) && (qAbs(lrx - rx) < deltaX)) {
deltaX = qAbs(lrx - rx);
nx = lrx - cw;
}
if ((sOWO ? (cx < lx) : true) && (qAbs(cx - lx) < snap) && (qAbs(cx - lx) < deltaX)) {
deltaX = qAbs(cx - lx);
nx = lx;
}
}
}
}
// center snap
snap = options->centerSnapZone() * snapAdjust; //snap trigger
if (snap) {
int diffX = qAbs((xmin + xmax) / 2 - (cx + cw / 2));
int diffY = qAbs((ymin + ymax) / 2 - (cy + ch / 2));
if (diffX < snap && diffY < snap && diffX < deltaX && diffY < deltaY) {
// Snap to center of screen
nx = (xmin + xmax) / 2 - cw / 2;
ny = (ymin + ymax) / 2 - ch / 2;
} else if (options->borderSnapZone()) {
// Enhance border snap
if ((nx == xmin || nx == xmax - cw) && diffY < snap && diffY < deltaY) {
// Snap to vertical center on screen edge
ny = (ymin + ymax) / 2 - ch / 2;
} else if (((unrestricted ? ny == ymin : ny <= ymin) || ny == ymax - ch) &&
diffX < snap && diffX < deltaX) {
// Snap to horizontal center on screen edge
nx = (xmin + xmax) / 2 - cw / 2;
}
}
}
pos = QPoint(nx, ny);
}
return pos;
}
QRect Workspace::adjustClientSize(AbstractClient* c, QRect moveResizeGeom, int mode)
{
//adapted from adjustClientPosition on 29May2004
//this function is called when resizing a window and will modify
//the new dimensions to snap to other windows/borders if appropriate
if (options->windowSnapZone() || options->borderSnapZone()) { // || options->centerSnapZone )
const bool sOWO = options->isSnapOnlyWhenOverlapping();
const QRect maxRect = clientArea(MovementArea, c->rect().center(), c->desktop());
const int xmin = maxRect.left();
const int xmax = maxRect.right(); //desk size
const int ymin = maxRect.top();
const int ymax = maxRect.bottom();
const int cx(moveResizeGeom.left());
const int cy(moveResizeGeom.top());
const int rx(moveResizeGeom.right());
const int ry(moveResizeGeom.bottom());
int newcx(cx), newcy(cy); //buffers
int newrx(rx), newry(ry);
int deltaX(xmax);
int deltaY(ymax); //minimum distance to other clients
int lx, ly, lrx, lry; //coords and size for the comparison client, l
// border snap
int snap = options->borderSnapZone(); //snap trigger
if (snap) {
deltaX = int(snap);
deltaY = int(snap);
#define SNAP_BORDER_TOP \
if ((sOWO?(newcy<ymin):true) && (qAbs(ymin-newcy)<deltaY)) \
{ \
deltaY = qAbs(ymin-newcy); \
newcy = ymin; \
}
#define SNAP_BORDER_BOTTOM \
if ((sOWO?(newry>ymax):true) && (qAbs(ymax-newry)<deltaY)) \
{ \
deltaY = qAbs(ymax-newcy); \
newry = ymax; \
}
#define SNAP_BORDER_LEFT \
if ((sOWO?(newcx<xmin):true) && (qAbs(xmin-newcx)<deltaX)) \
{ \
deltaX = qAbs(xmin-newcx); \
newcx = xmin; \
}
#define SNAP_BORDER_RIGHT \
if ((sOWO?(newrx>xmax):true) && (qAbs(xmax-newrx)<deltaX)) \
{ \
deltaX = qAbs(xmax-newrx); \
newrx = xmax; \
}
switch(mode) {
case Client::PositionBottomRight:
SNAP_BORDER_BOTTOM
SNAP_BORDER_RIGHT
break;
case Client::PositionRight:
SNAP_BORDER_RIGHT
break;
case Client::PositionBottom:
SNAP_BORDER_BOTTOM
break;
case Client::PositionTopLeft:
SNAP_BORDER_TOP
SNAP_BORDER_LEFT
break;
case Client::PositionLeft:
SNAP_BORDER_LEFT
break;
case Client::PositionTop:
SNAP_BORDER_TOP
break;
case Client::PositionTopRight:
SNAP_BORDER_TOP
SNAP_BORDER_RIGHT
break;
case Client::PositionBottomLeft:
SNAP_BORDER_BOTTOM
SNAP_BORDER_LEFT
break;
default:
abort();
break;
}
}
// windows snap
snap = options->windowSnapZone();
if (snap) {
deltaX = int(snap);
deltaY = int(snap);
for (auto l = m_allClients.constBegin(); l != m_allClients.constEnd(); ++l) {
if ((*l)->isOnDesktop(VirtualDesktopManager::self()->current()) &&
!(*l)->isMinimized()
&& (*l) != c) {
lx = (*l)->x() - 1;
ly = (*l)->y() - 1;
lrx = (*l)->x() + (*l)->width();
lry = (*l)->y() + (*l)->height();
#define WITHIN_HEIGHT ((( newcy <= lry ) && ( newcy >= ly )) || \
(( newry >= ly ) && ( newry <= lry )) || \
(( newcy <= ly ) && ( newry >= lry )) )
#define WITHIN_WIDTH ( (( cx <= lrx ) && ( cx >= lx )) || \
(( rx >= lx ) && ( rx <= lrx )) || \
(( cx <= lx ) && ( rx >= lrx )) )
#define SNAP_WINDOW_TOP if ( (sOWO?(newcy<lry):true) \
&& WITHIN_WIDTH \
&& (qAbs( lry - newcy ) < deltaY) ) { \
deltaY = qAbs( lry - newcy ); \
newcy=lry; \
}
#define SNAP_WINDOW_BOTTOM if ( (sOWO?(newry>ly):true) \
&& WITHIN_WIDTH \
&& (qAbs( ly - newry ) < deltaY) ) { \
deltaY = qAbs( ly - newry ); \
newry=ly; \
}
#define SNAP_WINDOW_LEFT if ( (sOWO?(newcx<lrx):true) \
&& WITHIN_HEIGHT \
&& (qAbs( lrx - newcx ) < deltaX)) { \
deltaX = qAbs( lrx - newcx ); \
newcx=lrx; \
}
#define SNAP_WINDOW_RIGHT if ( (sOWO?(newrx>lx):true) \
&& WITHIN_HEIGHT \
&& (qAbs( lx - newrx ) < deltaX)) \
{ \
deltaX = qAbs( lx - newrx ); \
newrx=lx; \
}
#define SNAP_WINDOW_C_TOP if ( (sOWO?(newcy<ly):true) \
&& (newcx == lrx || newrx == lx) \
&& qAbs(ly-newcy) < deltaY ) { \
deltaY = qAbs( ly - newcy + 1 ); \
newcy = ly + 1; \
}
#define SNAP_WINDOW_C_BOTTOM if ( (sOWO?(newry>lry):true) \
&& (newcx == lrx || newrx == lx) \
&& qAbs(lry-newry) < deltaY ) { \
deltaY = qAbs( lry - newry - 1 ); \
newry = lry - 1; \
}
#define SNAP_WINDOW_C_LEFT if ( (sOWO?(newcx<lx):true) \
&& (newcy == lry || newry == ly) \
&& qAbs(lx-newcx) < deltaX ) { \
deltaX = qAbs( lx - newcx + 1 ); \
newcx = lx + 1; \
}
#define SNAP_WINDOW_C_RIGHT if ( (sOWO?(newrx>lrx):true) \
&& (newcy == lry || newry == ly) \
&& qAbs(lrx-newrx) < deltaX ) { \
deltaX = qAbs( lrx - newrx - 1 ); \
newrx = lrx - 1; \
}
switch(mode) {
case Client::PositionBottomRight:
SNAP_WINDOW_BOTTOM
SNAP_WINDOW_RIGHT
SNAP_WINDOW_C_BOTTOM
SNAP_WINDOW_C_RIGHT
break;
case Client::PositionRight:
SNAP_WINDOW_RIGHT
SNAP_WINDOW_C_RIGHT
break;
case Client::PositionBottom:
SNAP_WINDOW_BOTTOM
SNAP_WINDOW_C_BOTTOM
break;
case Client::PositionTopLeft:
SNAP_WINDOW_TOP
SNAP_WINDOW_LEFT
SNAP_WINDOW_C_TOP
SNAP_WINDOW_C_LEFT
break;
case Client::PositionLeft:
SNAP_WINDOW_LEFT
SNAP_WINDOW_C_LEFT
break;
case Client::PositionTop:
SNAP_WINDOW_TOP
SNAP_WINDOW_C_TOP
break;
case Client::PositionTopRight:
SNAP_WINDOW_TOP
SNAP_WINDOW_RIGHT
SNAP_WINDOW_C_TOP
SNAP_WINDOW_C_RIGHT
break;
case Client::PositionBottomLeft:
SNAP_WINDOW_BOTTOM
SNAP_WINDOW_LEFT
SNAP_WINDOW_C_BOTTOM
SNAP_WINDOW_C_LEFT
break;
default:
abort();
break;
}
}
}
}
// center snap
//snap = options->centerSnapZone;
//if (snap)
// {
// // Don't resize snap to center as it interferes too much
// // There are two ways of implementing this if wanted:
// // 1) Snap only to the same points that the move snap does, and
// // 2) Snap to the horizontal and vertical center lines of the screen
// }
moveResizeGeom = QRect(QPoint(newcx, newcy), QPoint(newrx, newry));
}
return moveResizeGeom;
}
/*!
Marks the client as being moved around by the user.
*/
void Workspace::setClientIsMoving(AbstractClient *c)
{
Q_ASSERT(!c || !movingClient); // Catch attempts to move a second
// window while still moving the first one.
movingClient = c;
if (movingClient)
++block_focus;
else
--block_focus;
}
// When kwin crashes, windows will not be gravitated back to their original position
// and will remain offset by the size of the decoration. So when restarting, fix this
// (the property with the size of the frame remains on the window after the crash).
void Workspace::fixPositionAfterCrash(xcb_window_t w, const xcb_get_geometry_reply_t *geometry)
{
NETWinInfo i(connection(), w, rootWindow(), NET::WMFrameExtents, 0);
NETStrut frame = i.frameExtents();
if (frame.left != 0 || frame.top != 0) {
// left and top needed due to narrowing conversations restrictions in C++11
const uint32_t left = frame.left;
const uint32_t top = frame.top;
const uint32_t values[] = { geometry->x - left, geometry->y - top };
xcb_configure_window(connection(), w, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
}
}
//********************************************
// Client
//********************************************
/*!
Returns \a area with the client's strut taken into account.
Used from Workspace in updateClientArea.
*/
// TODO move to Workspace?
QRect Client::adjustedClientArea(const QRect &desktopArea, const QRect& area) const
{
QRect r = area;
NETExtendedStrut str = strut();
QRect stareaL = QRect(
0,
str . left_start,
str . left_width,
str . left_end - str . left_start + 1);
QRect stareaR = QRect(
desktopArea . right() - str . right_width + 1,
str . right_start,
str . right_width,
str . right_end - str . right_start + 1);
QRect stareaT = QRect(
str . top_start,
0,
str . top_end - str . top_start + 1,
str . top_width);
QRect stareaB = QRect(
str . bottom_start,
desktopArea . bottom() - str . bottom_width + 1,
str . bottom_end - str . bottom_start + 1,
str . bottom_width);
QRect screenarea = workspace()->clientArea(ScreenArea, this);
// HACK: workarea handling is not xinerama aware, so if this strut
// reserves place at a xinerama edge that's inside the virtual screen,
// ignore the strut for workspace setting.
if (area == QRect(QPoint(0, 0), screens()->displaySize())) {
if (stareaL.left() < screenarea.left())
stareaL = QRect();
if (stareaR.right() > screenarea.right())
stareaR = QRect();
if (stareaT.top() < screenarea.top())
stareaT = QRect();
if (stareaB.bottom() < screenarea.bottom())
stareaB = QRect();
}
// Handle struts at xinerama edges that are inside the virtual screen.
// They're given in virtual screen coordinates, make them affect only
// their xinerama screen.
stareaL.setLeft(qMax(stareaL.left(), screenarea.left()));
stareaR.setRight(qMin(stareaR.right(), screenarea.right()));
stareaT.setTop(qMax(stareaT.top(), screenarea.top()));
stareaB.setBottom(qMin(stareaB.bottom(), screenarea.bottom()));
if (stareaL . intersects(area)) {
// qDebug() << "Moving left of: " << r << " to " << stareaL.right() + 1;
r . setLeft(stareaL . right() + 1);
}
if (stareaR . intersects(area)) {
// qDebug() << "Moving right of: " << r << " to " << stareaR.left() - 1;
r . setRight(stareaR . left() - 1);
}
if (stareaT . intersects(area)) {
// qDebug() << "Moving top of: " << r << " to " << stareaT.bottom() + 1;
r . setTop(stareaT . bottom() + 1);
}
if (stareaB . intersects(area)) {
// qDebug() << "Moving bottom of: " << r << " to " << stareaB.top() - 1;
r . setBottom(stareaB . top() - 1);
}
return r;
}
NETExtendedStrut Client::strut() const
{
NETExtendedStrut ext = info->extendedStrut();
NETStrut str = info->strut();
const QSize displaySize = screens()->displaySize();
if (ext.left_width == 0 && ext.right_width == 0 && ext.top_width == 0 && ext.bottom_width == 0
&& (str.left != 0 || str.right != 0 || str.top != 0 || str.bottom != 0)) {
// build extended from simple
if (str.left != 0) {
ext.left_width = str.left;
ext.left_start = 0;
ext.left_end = displaySize.height();
}
if (str.right != 0) {
ext.right_width = str.right;
ext.right_start = 0;
ext.right_end = displaySize.height();
}
if (str.top != 0) {
ext.top_width = str.top;
ext.top_start = 0;
ext.top_end = displaySize.width();
}
if (str.bottom != 0) {
ext.bottom_width = str.bottom;
ext.bottom_start = 0;
ext.bottom_end = displaySize.width();
}
}
return ext;
}
StrutRect Client::strutRect(StrutArea area) const
{
assert(area != StrutAreaAll); // Not valid
const QSize displaySize = screens()->displaySize();
NETExtendedStrut strutArea = strut();
switch(area) {
case StrutAreaTop:
if (strutArea.top_width != 0)
return StrutRect(QRect(
strutArea.top_start, 0,
strutArea.top_end - strutArea.top_start, strutArea.top_width
), StrutAreaTop);
break;
case StrutAreaRight:
if (strutArea.right_width != 0)
return StrutRect(QRect(
displaySize.width() - strutArea.right_width, strutArea.right_start,
strutArea.right_width, strutArea.right_end - strutArea.right_start
), StrutAreaRight);
break;
case StrutAreaBottom:
if (strutArea.bottom_width != 0)
return StrutRect(QRect(
strutArea.bottom_start, displaySize.height() - strutArea.bottom_width,
strutArea.bottom_end - strutArea.bottom_start, strutArea.bottom_width
), StrutAreaBottom);
break;
case StrutAreaLeft:
if (strutArea.left_width != 0)
return StrutRect(QRect(
0, strutArea.left_start,
strutArea.left_width, strutArea.left_end - strutArea.left_start
), StrutAreaLeft);
break;
default:
abort(); // Not valid
}
return StrutRect(); // Null rect
}
StrutRects Client::strutRects() const
{
StrutRects region;
region += strutRect(StrutAreaTop);
region += strutRect(StrutAreaRight);
region += strutRect(StrutAreaBottom);
region += strutRect(StrutAreaLeft);
return region;
}
bool Client::hasStrut() const
{
NETExtendedStrut ext = strut();
if (ext.left_width == 0 && ext.right_width == 0 && ext.top_width == 0 && ext.bottom_width == 0)
return false;
return true;
}
bool Client::hasOffscreenXineramaStrut() const
{
// Get strut as a QRegion
QRegion region;
region += strutRect(StrutAreaTop);
region += strutRect(StrutAreaRight);
region += strutRect(StrutAreaBottom);
region += strutRect(StrutAreaLeft);
// Remove all visible areas so that only the invisible remain
for (int i = 0; i < screens()->count(); i ++)
region -= screens()->geometry(i);
// If there's anything left then we have an offscreen strut
return !region.isEmpty();
}
void AbstractClient::checkWorkspacePosition(QRect oldGeometry, int oldDesktop, QRect oldClientGeometry)
{
enum { Left = 0, Top, Right, Bottom };
const int border[4] = { borderLeft(), borderTop(), borderRight(), borderBottom() };
if( !oldGeometry.isValid())
oldGeometry = geometry();
if( oldDesktop == -2 )
oldDesktop = desktop();
if (!oldClientGeometry.isValid())
oldClientGeometry = oldGeometry.adjusted(border[Left], border[Top], -border[Right], -border[Bottom]);
if (isDesktop())
return;
if (isFullScreen()) {
QRect area = workspace()->clientArea(FullScreenArea, this);
if (geometry() != area)
setGeometry(area);
return;
}
if (isDock())
return;
if (maximizeMode() != MaximizeRestore) {
// TODO update geom_restore?
changeMaximize(false, false, true); // adjust size
const QRect screenArea = workspace()->clientArea(ScreenArea, this);
QRect geom = geometry();
checkOffscreenPosition(&geom, screenArea);
setGeometry(geom);
return;
}
if (quickTileMode() != QuickTileMode(QuickTileFlag::None)) {
setGeometry(electricBorderMaximizeGeometry(geometry().center(), desktop()));
return;
}
// this can be true only if this window was mapped before KWin
// was started - in such case, don't adjust position to workarea,
// because the window already had its position, and if a window
// with a strut altering the workarea would be managed in initialization
// after this one, this window would be moved
if (!workspace() || workspace()->initializing())
return;
// If the window was touching an edge before but not now move it so it is again.
// Old and new maximums have different starting values so windows on the screen
// edge will move when a new strut is placed on the edge.
QRect oldScreenArea;
QRect oldGeomTall;
QRect oldGeomWide;
const auto displaySize = screens()->displaySize();
if( workspace()->inUpdateClientArea()) {
// we need to find the screen area as it was before the change
oldScreenArea = QRect( 0, 0, workspace()->oldDisplayWidth(), workspace()->oldDisplayHeight());
oldGeomTall = QRect(oldGeometry.x(), 0, oldGeometry.width(), workspace()->oldDisplayHeight()); // Full screen height
oldGeomWide = QRect(0, oldGeometry.y(), workspace()->oldDisplayWidth(), oldGeometry.height()); // Full screen width
int distance = INT_MAX;
foreach(const QRect &r, workspace()->previousScreenSizes()) {
int d = r.contains( oldGeometry.center()) ? 0 : ( r.center() - oldGeometry.center()).manhattanLength();
if( d < distance ) {
distance = d;
oldScreenArea = r;
}
}
} else {
oldScreenArea = workspace()->clientArea(ScreenArea, oldGeometry.center(), oldDesktop);
oldGeomTall = QRect(oldGeometry.x(), 0, oldGeometry.width(), displaySize.height()); // Full screen height
oldGeomWide = QRect(0, oldGeometry.y(), displaySize.width(), oldGeometry.height()); // Full screen width
}
int oldTopMax = oldScreenArea.y();
int oldRightMax = oldScreenArea.x() + oldScreenArea.width();
int oldBottomMax = oldScreenArea.y() + oldScreenArea.height();
int oldLeftMax = oldScreenArea.x();
const QRect screenArea = workspace()->clientArea(ScreenArea, geometryRestore().center(), desktop());
int topMax = screenArea.y();
int rightMax = screenArea.x() + screenArea.width();
int bottomMax = screenArea.y() + screenArea.height();
int leftMax = screenArea.x();
QRect newGeom = geometryRestore(); // geometry();
QRect newClientGeom = newGeom.adjusted(border[Left], border[Top], -border[Right], -border[Bottom]);
const QRect newGeomTall = QRect(newGeom.x(), 0, newGeom.width(), displaySize.height()); // Full screen height
const QRect newGeomWide = QRect(0, newGeom.y(), displaySize.width(), newGeom.height()); // Full screen width
// Get the max strut point for each side where the window is (E.g. Highest point for
// the bottom struts bounded by the window's left and right sides).
// These 4 compute old bounds ...
auto moveAreaFunc = workspace()->inUpdateClientArea() ?
&Workspace::previousRestrictedMoveArea : //... the restricted areas changed
&Workspace::restrictedMoveArea; //... when e.g. active desktop or screen changes
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop).rects()) {
QRect rect = r & oldGeomTall;
if (!rect.isEmpty())
oldTopMax = qMax(oldTopMax, rect.y() + rect.height());
}
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaRight).rects()) {
QRect rect = r & oldGeomWide;
if (!rect.isEmpty())
oldRightMax = qMin(oldRightMax, rect.x());
}
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaBottom).rects()) {
QRect rect = r & oldGeomTall;
if (!rect.isEmpty())
oldBottomMax = qMin(oldBottomMax, rect.y());
}
foreach (const QRect & r, (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaLeft).rects()) {
QRect rect = r & oldGeomWide;
if (!rect.isEmpty())
oldLeftMax = qMax(oldLeftMax, rect.x() + rect.width());
}
// These 4 compute new bounds
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaTop).rects()) {
QRect rect = r & newGeomTall;
if (!rect.isEmpty())
topMax = qMax(topMax, rect.y() + rect.height());
}
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaRight).rects()) {
QRect rect = r & newGeomWide;
if (!rect.isEmpty())
rightMax = qMin(rightMax, rect.x());
}
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaBottom).rects()) {
QRect rect = r & newGeomTall;
if (!rect.isEmpty())
bottomMax = qMin(bottomMax, rect.y());
}
foreach (const QRect & r, workspace()->restrictedMoveArea(desktop(), StrutAreaLeft).rects()) {
QRect rect = r & newGeomWide;
if (!rect.isEmpty())
leftMax = qMax(leftMax, rect.x() + rect.width());
}
// Check if the sides were inside or touching but are no longer
bool keep[4] = {false, false, false, false};
bool save[4] = {false, false, false, false};
int padding[4] = {0, 0, 0, 0};
if (oldGeometry.x() >= oldLeftMax)
save[Left] = newGeom.x() < leftMax;
if (oldGeometry.x() == oldLeftMax)
keep[Left] = newGeom.x() != leftMax;
else if (oldClientGeometry.x() == oldLeftMax && newClientGeom.x() != leftMax) {
padding[0] = border[Left];
keep[Left] = true;
}
if (oldGeometry.y() >= oldTopMax)
save[Top] = newGeom.y() < topMax;
if (oldGeometry.y() == oldTopMax)
keep[Top] = newGeom.y() != topMax;
else if (oldClientGeometry.y() == oldTopMax && newClientGeom.y() != topMax) {
padding[1] = border[Left];
keep[Top] = true;
}
if (oldGeometry.right() <= oldRightMax - 1)
save[Right] = newGeom.right() > rightMax - 1;
if (oldGeometry.right() == oldRightMax - 1)
keep[Right] = newGeom.right() != rightMax - 1;
else if (oldClientGeometry.right() == oldRightMax - 1 && newClientGeom.right() != rightMax - 1) {
padding[2] = border[Right];
keep[Right] = true;
}
if (oldGeometry.bottom() <= oldBottomMax - 1)
save[Bottom] = newGeom.bottom() > bottomMax - 1;
if (oldGeometry.bottom() == oldBottomMax - 1)
keep[Bottom] = newGeom.bottom() != bottomMax - 1;
else if (oldClientGeometry.bottom() == oldBottomMax - 1 && newClientGeom.bottom() != bottomMax - 1) {
padding[3] = border[Bottom];
keep[Bottom] = true;
}
// if randomly touches opposing edges, do not favor either
if (keep[Left] && keep[Right]) {
keep[Left] = keep[Right] = false;
padding[0] = padding[2] = 0;
}
if (keep[Top] && keep[Bottom]) {
keep[Top] = keep[Bottom] = false;
padding[1] = padding[3] = 0;
}
if (save[Left] || keep[Left])
newGeom.moveLeft(qMax(leftMax, screenArea.x()) - padding[0]);
if (padding[0] && screens()->intersecting(newGeom) > 1)
newGeom.moveLeft(newGeom.left() + padding[0]);
if (save[Top] || keep[Top])
newGeom.moveTop(qMax(topMax, screenArea.y()) - padding[1]);
if (padding[1] && screens()->intersecting(newGeom) > 1)
newGeom.moveTop(newGeom.top() + padding[1]);
if (save[Right] || keep[Right])
newGeom.moveRight(qMin(rightMax - 1, screenArea.right()) + padding[2]);
if (padding[2] && screens()->intersecting(newGeom) > 1)
newGeom.moveRight(newGeom.right() - padding[2]);
if (oldGeometry.x() >= oldLeftMax && newGeom.x() < leftMax)
newGeom.setLeft(qMax(leftMax, screenArea.x()));
else if (oldClientGeometry.x() >= oldLeftMax && newGeom.x() + border[Left] < leftMax) {
newGeom.setLeft(qMax(leftMax, screenArea.x()) - border[Left]);
if (screens()->intersecting(newGeom) > 1)
newGeom.setLeft(newGeom.left() + border[Left]);
}
if (save[Bottom] || keep[Bottom])
newGeom.moveBottom(qMin(bottomMax - 1, screenArea.bottom()) + padding[3]);
if (padding[3] && screens()->intersecting(newGeom) > 1)
newGeom.moveBottom(newGeom.bottom() - padding[3]);
if (oldGeometry.y() >= oldTopMax && newGeom.y() < topMax)
newGeom.setTop(qMax(topMax, screenArea.y()));
else if (oldClientGeometry.y() >= oldTopMax && newGeom.y() + border[Top] < topMax) {
newGeom.setTop(qMax(topMax, screenArea.y()) - border[Top]);
if (screens()->intersecting(newGeom) > 1)
newGeom.setTop(newGeom.top() + border[Top]);
}
checkOffscreenPosition(&newGeom, screenArea);
// Obey size hints. TODO: We really should make sure it stays in the right place
if (!isShade())
newGeom.setSize(adjustedSize(newGeom.size()));
if (newGeom != geometry())
setGeometry(newGeom);
}
void AbstractClient::checkOffscreenPosition(QRect* geom, const QRect& screenArea)
{
if (geom->left() > screenArea.right()) {
geom->moveLeft(screenArea.right() - screenArea.width()/4);
} else if (geom->right() < screenArea.left()) {
geom->moveRight(screenArea.left() + screenArea.width()/4);
}
if (geom->top() > screenArea.bottom()) {
geom->moveTop(screenArea.bottom() - screenArea.height()/4);
} else if (geom->bottom() < screenArea.top()) {
geom->moveBottom(screenArea.top() + screenArea.width()/4);
}
}
/*!
Adjust the frame size \a frame according to he window's size hints.
*/
QSize AbstractClient::adjustedSize(const QSize& frame, Sizemode mode) const
{
// first, get the window size for the given frame size s
QSize wsize(frame.width() - (borderLeft() + borderRight()),
frame.height() - (borderTop() + borderBottom()));
if (wsize.isEmpty())
wsize = QSize(qMax(wsize.width(), 1), qMax(wsize.height(), 1));
return sizeForClientSize(wsize, mode, false);
}
// this helper returns proper size even if the window is shaded
// see also the comment in Client::setGeometry()
QSize AbstractClient::adjustedSize() const
{
return sizeForClientSize(clientSize());
}
/*!
Calculate the appropriate frame size for the given client size \a
wsize.
\a wsize is adapted according to the window's size hints (minimum,
maximum and incremental size changes).
*/
QSize Client::sizeForClientSize(const QSize& wsize, Sizemode mode, bool noframe) const
{
int w = wsize.width();
int h = wsize.height();
if (w < 1 || h < 1) {
qCWarning(KWIN_CORE) << "sizeForClientSize() with empty size!" ;
}
if (w < 1) w = 1;
if (h < 1) h = 1;
// basesize, minsize, maxsize, paspect and resizeinc have all values defined,
// even if they're not set in flags - see getWmNormalHints()
QSize min_size = tabGroup() ? tabGroup()->minSize() : minSize();
QSize max_size = tabGroup() ? tabGroup()->maxSize() : maxSize();
if (isDecorated()) {
QSize decominsize(0, 0);
QSize border_size(borderLeft() + borderRight(), borderTop() + borderBottom());
if (border_size.width() > decominsize.width()) // just in case
decominsize.setWidth(border_size.width());
if (border_size.height() > decominsize.height())
decominsize.setHeight(border_size.height());
if (decominsize.width() > min_size.width())
min_size.setWidth(decominsize.width());
if (decominsize.height() > min_size.height())
min_size.setHeight(decominsize.height());
}
w = qMin(max_size.width(), w);
h = qMin(max_size.height(), h);
w = qMax(min_size.width(), w);
h = qMax(min_size.height(), h);
int w1 = w;
int h1 = h;
int width_inc = m_geometryHints.resizeIncrements().width();
int height_inc = m_geometryHints.resizeIncrements().height();
int basew_inc = m_geometryHints.baseSize().width();
int baseh_inc = m_geometryHints.baseSize().height();
if (!m_geometryHints.hasBaseSize()) {
basew_inc = m_geometryHints.minSize().width();
baseh_inc = m_geometryHints.minSize().height();
}
w = int((w - basew_inc) / width_inc) * width_inc + basew_inc;
h = int((h - baseh_inc) / height_inc) * height_inc + baseh_inc;
// code for aspect ratios based on code from FVWM
/*
* The math looks like this:
*
* minAspectX dwidth maxAspectX
* ---------- <= ------- <= ----------
* minAspectY dheight maxAspectY
*
* If that is multiplied out, then the width and height are
* invalid in the following situations:
*
* minAspectX * dheight > minAspectY * dwidth
* maxAspectX * dheight < maxAspectY * dwidth
*
*/
if (m_geometryHints.hasAspect()) {
double min_aspect_w = m_geometryHints.minAspect().width(); // use doubles, because the values can be MAX_INT
double min_aspect_h = m_geometryHints.minAspect().height(); // and multiplying would go wrong otherwise
double max_aspect_w = m_geometryHints.maxAspect().width();
double max_aspect_h = m_geometryHints.maxAspect().height();
// According to ICCCM 4.1.2.3 PMinSize should be a fallback for PBaseSize for size increments,
// but not for aspect ratio. Since this code comes from FVWM, handles both at the same time,
// and I have no idea how it works, let's hope nobody relies on that.
const QSize baseSize = m_geometryHints.baseSize();
w -= baseSize.width();
h -= baseSize.height();
int max_width = max_size.width() - baseSize.width();
int min_width = min_size.width() - baseSize.width();
int max_height = max_size.height() - baseSize.height();
int min_height = min_size.height() - baseSize.height();
#define ASPECT_CHECK_GROW_W \
if ( min_aspect_w * h > min_aspect_h * w ) \
{ \
int delta = int( min_aspect_w * h / min_aspect_h - w ) / width_inc * width_inc; \
if ( w + delta <= max_width ) \
w += delta; \
}
#define ASPECT_CHECK_SHRINK_H_GROW_W \
if ( min_aspect_w * h > min_aspect_h * w ) \
{ \
int delta = int( h - w * min_aspect_h / min_aspect_w ) / height_inc * height_inc; \
if ( h - delta >= min_height ) \
h -= delta; \
else \
{ \
int delta = int( min_aspect_w * h / min_aspect_h - w ) / width_inc * width_inc; \
if ( w + delta <= max_width ) \
w += delta; \
} \
}
#define ASPECT_CHECK_GROW_H \
if ( max_aspect_w * h < max_aspect_h * w ) \
{ \
int delta = int( w * max_aspect_h / max_aspect_w - h ) / height_inc * height_inc; \
if ( h + delta <= max_height ) \
h += delta; \
}
#define ASPECT_CHECK_SHRINK_W_GROW_H \
if ( max_aspect_w * h < max_aspect_h * w ) \
{ \
int delta = int( w - max_aspect_w * h / max_aspect_h ) / width_inc * width_inc; \
if ( w - delta >= min_width ) \
w -= delta; \
else \
{ \
int delta = int( w * max_aspect_h / max_aspect_w - h ) / height_inc * height_inc; \
if ( h + delta <= max_height ) \
h += delta; \
} \
}
switch(mode) {
case SizemodeAny:
#if 0 // make SizemodeAny equal to SizemodeFixedW - prefer keeping fixed width,
// so that changing aspect ratio to a different value and back keeps the same size (#87298)
{
ASPECT_CHECK_SHRINK_H_GROW_W
ASPECT_CHECK_SHRINK_W_GROW_H
ASPECT_CHECK_GROW_H
ASPECT_CHECK_GROW_W
break;
}
#endif
case SizemodeFixedW: {
// the checks are order so that attempts to modify height are first
ASPECT_CHECK_GROW_H
ASPECT_CHECK_SHRINK_H_GROW_W
ASPECT_CHECK_SHRINK_W_GROW_H
ASPECT_CHECK_GROW_W
break;
}
case SizemodeFixedH: {
ASPECT_CHECK_GROW_W
ASPECT_CHECK_SHRINK_W_GROW_H
ASPECT_CHECK_SHRINK_H_GROW_W
ASPECT_CHECK_GROW_H
break;
}
case SizemodeMax: {
// first checks that try to shrink
ASPECT_CHECK_SHRINK_H_GROW_W
ASPECT_CHECK_SHRINK_W_GROW_H
ASPECT_CHECK_GROW_W
ASPECT_CHECK_GROW_H
break;
}
}
#undef ASPECT_CHECK_SHRINK_H_GROW_W
#undef ASPECT_CHECK_SHRINK_W_GROW_H
#undef ASPECT_CHECK_GROW_W
#undef ASPECT_CHECK_GROW_H
w += baseSize.width();
h += baseSize.height();
}
if (!rules()->checkStrictGeometry(!isFullScreen())) {
// disobey increments and aspect by explicit rule
w = w1;
h = h1;
}
if (!noframe) {
w += borderLeft() + borderRight();
h += borderTop() + borderBottom();
}
return rules()->checkSize(QSize(w, h));
}
/*!
Gets the client's normal WM hints and reconfigures itself respectively.
*/
void Client::getWmNormalHints()
{
const bool hadFixedAspect = m_geometryHints.hasAspect();
// roundtrip to X server
m_geometryHints.fetch();
m_geometryHints.read();
if (!hadFixedAspect && m_geometryHints.hasAspect()) {
// align to eventual new contraints
maximize(max_mode);
}
// Update min/max size of this group
if (tabGroup())
tabGroup()->updateMinMaxSize();
if (isManaged()) {
// update to match restrictions
QSize new_size = adjustedSize();
if (new_size != size() && !isFullScreen()) {
QRect origClientGeometry(pos() + clientPos(), clientSize());
resizeWithChecks(new_size);
if ((!isSpecialWindow() || isToolbar()) && !isFullScreen()) {
// try to keep the window in its xinerama screen if possible,
// if that fails at least keep it visible somewhere
QRect area = workspace()->clientArea(MovementArea, this);
if (area.contains(origClientGeometry))
keepInArea(area);
area = workspace()->clientArea(WorkArea, this);
if (area.contains(origClientGeometry))
keepInArea(area);
}
}
}
updateAllowedActions(); // affects isResizeable()
}
QSize Client::minSize() const
{
return rules()->checkMinSize(m_geometryHints.minSize());
}
QSize Client::maxSize() const
{
return rules()->checkMaxSize(m_geometryHints.maxSize());
}
QSize Client::basicUnit() const
{
return m_geometryHints.resizeIncrements();
}
/*!
Auxiliary function to inform the client about the current window
configuration.
*/
void Client::sendSyntheticConfigureNotify()
{
xcb_configure_notify_event_t c;
memset(&c, 0, sizeof(c));
c.response_type = XCB_CONFIGURE_NOTIFY;
c.event = window();
c.window = window();
c.x = x() + clientPos().x();
c.y = y() + clientPos().y();
c.width = clientSize().width();
c.height = clientSize().height();
c.border_width = 0;
c.above_sibling = XCB_WINDOW_NONE;
c.override_redirect = 0;
xcb_send_event(connection(), true, c.event, XCB_EVENT_MASK_STRUCTURE_NOTIFY, reinterpret_cast<const char*>(&c));
xcb_flush(connection());
}
const QPoint Client::calculateGravitation(bool invert, int gravity) const
{
int dx, dy;
dx = dy = 0;
if (gravity == 0) // default (nonsense) value for the argument
gravity = m_geometryHints.windowGravity();
// dx, dy specify how the client window moves to make space for the frame
switch(gravity) {
case NorthWestGravity: // move down right
default:
dx = borderLeft();
dy = borderTop();
break;
case NorthGravity: // move right
dx = 0;
dy = borderTop();
break;
case NorthEastGravity: // move down left
dx = -borderRight();
dy = borderTop();
break;
case WestGravity: // move right
dx = borderLeft();
dy = 0;
break;
case CenterGravity:
break; // will be handled specially
case StaticGravity: // don't move
dx = 0;
dy = 0;
break;
case EastGravity: // move left
dx = -borderRight();
dy = 0;
break;
case SouthWestGravity: // move up right
dx = borderLeft() ;
dy = -borderBottom();
break;
case SouthGravity: // move up
dx = 0;
dy = -borderBottom();
break;
case SouthEastGravity: // move up left
dx = -borderRight();
dy = -borderBottom();
break;
}
if (gravity != CenterGravity) {
// translate from client movement to frame movement
dx -= borderLeft();
dy -= borderTop();
} else {
// center of the frame will be at the same position client center without frame would be
dx = - (borderLeft() + borderRight()) / 2;
dy = - (borderTop() + borderBottom()) / 2;
}
if (!invert)
return QPoint(x() + dx, y() + dy);
else
return QPoint(x() - dx, y() - dy);
}
void Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, int gravity, bool from_tool)
{
// "maximized" is a user setting -> we do not allow the client to resize itself
// away from this & against the users explicit wish
qCDebug(KWIN_CORE) << this << bool(value_mask & (CWX|CWWidth|CWY|CWHeight)) <<
bool(maximizeMode() & MaximizeVertical) <<
bool(maximizeMode() & MaximizeHorizontal);
// we want to (partially) ignore the request when the window is somehow maximized or quicktiled
bool ignore = !app_noborder && (quickTileMode() != QuickTileMode(QuickTileFlag::None) || maximizeMode() != MaximizeRestore);
// however, the user shall be able to force obedience despite and also disobedience in general
ignore = rules()->checkIgnoreGeometry(ignore);
if (!ignore) { // either we're not max'd / q'tiled or the user allowed the client to break that - so break it.
updateQuickTileMode(QuickTileFlag::None);
max_mode = MaximizeRestore;
emit quickTileModeChanged();
} else if (!app_noborder && quickTileMode() == QuickTileMode(QuickTileFlag::None) &&
(maximizeMode() == MaximizeVertical || maximizeMode() == MaximizeHorizontal)) {
// ignoring can be, because either we do, or the user does explicitly not want it.
// for partially maximized windows we want to allow configures in the other dimension.
// so we've to ask the user again - to know whether we just ignored for the partial maximization.
// the problem here is, that the user can explicitly permit configure requests - even for maximized windows!
// we cannot distinguish that from passing "false" for partially maximized windows.
ignore = rules()->checkIgnoreGeometry(false);
if (!ignore) { // the user is not interested, so we fix up dimensions
if (maximizeMode() == MaximizeVertical)
value_mask &= ~(CWY|CWHeight);
if (maximizeMode() == MaximizeHorizontal)
value_mask &= ~(CWX|CWWidth);
if (!(value_mask & (CWX|CWWidth|CWY|CWHeight))) {
ignore = true; // the modification turned the request void
}
}
}
if (ignore) {
qCDebug(KWIN_CORE) << "DENIED";
return; // nothing to (left) to do for use - bugs #158974, #252314, #321491
}
qCDebug(KWIN_CORE) << "PERMITTED" << this << bool(value_mask & (CWX|CWWidth|CWY|CWHeight));
if (gravity == 0) // default (nonsense) value for the argument
gravity = m_geometryHints.windowGravity();
if (value_mask & (CWX | CWY)) {
QPoint new_pos = calculateGravitation(true, gravity); // undo gravitation
if (value_mask & CWX)
new_pos.setX(rx);
if (value_mask & CWY)
new_pos.setY(ry);
// clever(?) workaround for applications like xv that want to set
// the location to the current location but miscalculate the
// frame size due to kwin being a double-reparenting window
// manager
if (new_pos.x() == x() + clientPos().x() && new_pos.y() == y() + clientPos().y()
&& gravity == NorthWestGravity && !from_tool) {
new_pos.setX(x());
new_pos.setY(y());
}
int nw = clientSize().width();
int nh = clientSize().height();
if (value_mask & CWWidth)
nw = rw;
if (value_mask & CWHeight)
nh = rh;
QSize ns = sizeForClientSize(QSize(nw, nh)); // enforces size if needed
new_pos = rules()->checkPosition(new_pos);
int newScreen = screens()->number(QRect(new_pos, ns).center());
if (newScreen != rules()->checkScreen(newScreen))
return; // not allowed by rule
QRect origClientGeometry(pos() + clientPos(), clientSize());
GeometryUpdatesBlocker blocker(this);
move(new_pos);
plainResize(ns);
setGeometry(QRect(calculateGravitation(false, gravity), size()));
updateFullScreenHack(QRect(new_pos, QSize(nw, nh)));
QRect area = workspace()->clientArea(WorkArea, this);
if (!from_tool && (!isSpecialWindow() || isToolbar()) && !isFullScreen()
&& area.contains(origClientGeometry))
keepInArea(area);
// this is part of the kicker-xinerama-hack... it should be
// safe to remove when kicker gets proper ExtendedStrut support;
// see Workspace::updateClientArea() and
// Client::adjustedClientArea()
if (hasStrut())
workspace() -> updateClientArea();
}
if (value_mask & (CWWidth | CWHeight)
&& !(value_mask & (CWX | CWY))) { // pure resize
int nw = clientSize().width();
int nh = clientSize().height();
if (value_mask & CWWidth)
nw = rw;
if (value_mask & CWHeight)
nh = rh;
QSize ns = sizeForClientSize(QSize(nw, nh));
if (ns != size()) { // don't restore if some app sets its own size again
QRect origClientGeometry(pos() + clientPos(), clientSize());
GeometryUpdatesBlocker blocker(this);
resizeWithChecks(ns, xcb_gravity_t(gravity));
updateFullScreenHack(QRect(calculateGravitation(true, m_geometryHints.windowGravity()), QSize(nw, nh)));
if (!from_tool && (!isSpecialWindow() || isToolbar()) && !isFullScreen()) {
// try to keep the window in its xinerama screen if possible,
// if that fails at least keep it visible somewhere
QRect area = workspace()->clientArea(MovementArea, this);
if (area.contains(origClientGeometry))
keepInArea(area);
area = workspace()->clientArea(WorkArea, this);
if (area.contains(origClientGeometry))
keepInArea(area);
}
}
}
geom_restore = geometry();
// No need to send synthetic configure notify event here, either it's sent together
// with geometry change, or there's no need to send it.
// Handling of the real ConfigureRequest event forces sending it, as there it's necessary.
}
void Client::resizeWithChecks(int w, int h, xcb_gravity_t gravity, ForceGeometry_t force)
{
assert(!shade_geometry_change);
if (isShade()) {
if (h == borderTop() + borderBottom()) {
qCWarning(KWIN_CORE) << "Shaded geometry passed for size:" ;
}
}
int newx = x();
int newy = y();
QRect area = workspace()->clientArea(WorkArea, this);
// don't allow growing larger than workarea
if (w > area.width())
w = area.width();
if (h > area.height())
h = area.height();
QSize tmp = adjustedSize(QSize(w, h)); // checks size constraints, including min/max size
w = tmp.width();
h = tmp.height();
if (gravity == 0) {
gravity = m_geometryHints.windowGravity();
}
switch(gravity) {
case NorthWestGravity: // top left corner doesn't move
default:
break;
case NorthGravity: // middle of top border doesn't move
newx = (newx + width() / 2) - (w / 2);
break;
case NorthEastGravity: // top right corner doesn't move
newx = newx + width() - w;
break;
case WestGravity: // middle of left border doesn't move
newy = (newy + height() / 2) - (h / 2);
break;
case CenterGravity: // middle point doesn't move
newx = (newx + width() / 2) - (w / 2);
newy = (newy + height() / 2) - (h / 2);
break;
case StaticGravity: // top left corner of _client_ window doesn't move
// since decoration doesn't change, equal to NorthWestGravity
break;
case EastGravity: // // middle of right border doesn't move
newx = newx + width() - w;
newy = (newy + height() / 2) - (h / 2);
break;
case SouthWestGravity: // bottom left corner doesn't move
newy = newy + height() - h;
break;
case SouthGravity: // middle of bottom border doesn't move
newx = (newx + width() / 2) - (w / 2);
newy = newy + height() - h;
break;
case SouthEastGravity: // bottom right corner doesn't move
newx = newx + width() - w;
newy = newy + height() - h;
break;
}
setGeometry(newx, newy, w, h, force);
}
// _NET_MOVERESIZE_WINDOW
void Client::NETMoveResizeWindow(int flags, int x, int y, int width, int height)
{
int gravity = flags & 0xff;
int value_mask = 0;
if (flags & (1 << 8))
value_mask |= CWX;
if (flags & (1 << 9))
value_mask |= CWY;
if (flags & (1 << 10))
value_mask |= CWWidth;
if (flags & (1 << 11))
value_mask |= CWHeight;
configureRequest(value_mask, x, y, width, height, gravity, true);
}
/*!
Returns whether the window is moveable or has a fixed
position.
*/
bool Client::isMovable() const
{
if (!hasNETSupport() && !m_motif.move()) {
return false;
}
if (isFullScreen())
return false;
if (isSpecialWindow() && !isSplash() && !isToolbar()) // allow moving of splashscreens :)
return false;
if (rules()->checkPosition(invalidPoint) != invalidPoint) // forced position
return false;
return true;
}
/*!
Returns whether the window is moveable across Xinerama screens
*/
bool Client::isMovableAcrossScreens() const
{
if (!hasNETSupport() && !m_motif.move()) {
return false;
}
if (isSpecialWindow() && !isSplash() && !isToolbar()) // allow moving of splashscreens :)
return false;
if (rules()->checkPosition(invalidPoint) != invalidPoint) // forced position
return false;
return true;
}
/*!
Returns whether the window is resizable or has a fixed size.
*/
bool Client::isResizable() const
{
if (!hasNETSupport() && !m_motif.resize()) {
return false;
}
if (isFullScreen())
return false;
if (isSpecialWindow() || isSplash() || isToolbar())
return false;
if (rules()->checkSize(QSize()).isValid()) // forced size
return false;
const Position mode = moveResizePointerMode();
if ((mode == PositionTop || mode == PositionTopLeft || mode == PositionTopRight ||
mode == PositionLeft || mode == PositionBottomLeft) && rules()->checkPosition(invalidPoint) != invalidPoint)
return false;
QSize min = tabGroup() ? tabGroup()->minSize() : minSize();
QSize max = tabGroup() ? tabGroup()->maxSize() : maxSize();
return min.width() < max.width() || min.height() < max.height();
}
/*
Returns whether the window is maximizable or not
*/
bool Client::isMaximizable() const
{
if (!isResizable() || isToolbar()) // SELI isToolbar() ?
return false;
if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore && rules()->checkMaximize(MaximizeFull) != MaximizeRestore)
return true;
return false;
}
/*!
Reimplemented to inform the client about the new window position.
*/
void Client::setGeometry(int x, int y, int w, int h, ForceGeometry_t force)
{
// this code is also duplicated in Client::plainResize()
// Ok, the shading geometry stuff. Generally, code doesn't care about shaded geometry,
// simply because there are too many places dealing with geometry. Those places
// ignore shaded state and use normal geometry, which they usually should get
// from adjustedSize(). Such geometry comes here, and if the window is shaded,
// the geometry is used only for client_size, since that one is not used when
// shading. Then the frame geometry is adjusted for the shaded geometry.
// This gets more complicated in the case the code does only something like
// setGeometry( geometry()) - geometry() will return the shaded frame geometry.
// Such code is wrong and should be changed to handle the case when the window is shaded,
// for example using Client::clientSize()
if (shade_geometry_change)
; // nothing
else if (isShade()) {
if (h == borderTop() + borderBottom()) {
qCDebug(KWIN_CORE) << "Shaded geometry passed for size:";
} else {
client_size = QSize(w - borderLeft() - borderRight(), h - borderTop() - borderBottom());
h = borderTop() + borderBottom();
}
} else {
client_size = QSize(w - borderLeft() - borderRight(), h - borderTop() - borderBottom());
}
QRect g(x, y, w, h);
if (!areGeometryUpdatesBlocked() && g != rules()->checkGeometry(g)) {
qCDebug(KWIN_CORE) << "forced geometry fail:" << g << ":" << rules()->checkGeometry(g);
}
if (force == NormalGeometrySet && geom == g && pendingGeometryUpdate() == PendingGeometryNone)
return;
geom = g;
if (areGeometryUpdatesBlocked()) {
if (pendingGeometryUpdate() == PendingGeometryForced)
{} // maximum, nothing needed
else if (force == ForceGeometrySet)
setPendingGeometryUpdate(PendingGeometryForced);
else
setPendingGeometryUpdate(PendingGeometryNormal);
return;
}
QSize oldClientSize = m_frame.geometry().size();
bool resized = (geometryBeforeUpdateBlocking().size() != geom.size() || pendingGeometryUpdate() == PendingGeometryForced);
if (resized) {
resizeDecoration();
m_frame.setGeometry(x, y, w, h);
if (!isShade()) {
QSize cs = clientSize();
m_wrapper.setGeometry(QRect(clientPos(), cs));
if (!isResize() || syncRequest.counter == XCB_NONE)
m_client.setGeometry(0, 0, cs.width(), cs.height());
// SELI - won't this be too expensive?
// THOMAS - yes, but gtk+ clients will not resize without ...
sendSyntheticConfigureNotify();
}
updateShape();
} else {
if (isMoveResize()) {
if (compositing()) // Defer the X update until we leave this mode
needsXWindowMove = true;
else
m_frame.move(x, y); // sendSyntheticConfigureNotify() on finish shall be sufficient
} else {
m_frame.move(x, y);
sendSyntheticConfigureNotify();
}
// Unconditionally move the input window: it won't affect rendering
m_decoInputExtent.move(QPoint(x, y) + inputPos());
}
updateWindowRules(Rules::Position|Rules::Size);
// keep track of old maximize mode
// to detect changes
screens()->setCurrent(this);
workspace()->updateStackingOrder();
// need to regenerate decoration pixmaps when either
// - size is changed
// - maximize mode is changed to MaximizeRestore, when size unchanged
// which can happen when untabbing maximized windows
if (resized) {
if (oldClientSize != QSize(w,h))
discardWindowPixmap();
}
emit geometryShapeChanged(this, geometryBeforeUpdateBlocking());
addRepaintDuringGeometryUpdates();
updateGeometryBeforeUpdateBlocking();
// Update states of all other windows in this group
if (tabGroup())
tabGroup()->updateStates(this, TabGroup::Geometry);
// TODO: this signal is emitted too often
emit geometryChanged();
}
void Client::plainResize(int w, int h, ForceGeometry_t force)
{
// this code is also duplicated in Client::setGeometry(), and it's also commented there
if (shade_geometry_change)
; // nothing
else if (isShade()) {
if (h == borderTop() + borderBottom()) {
qCDebug(KWIN_CORE) << "Shaded geometry passed for size:";
} else {
client_size = QSize(w - borderLeft() - borderRight(), h - borderTop() - borderBottom());
h = borderTop() + borderBottom();
}
} else {
client_size = QSize(w - borderLeft() - borderRight(), h - borderTop() - borderBottom());
}
QSize s(w, h);
if (!areGeometryUpdatesBlocked() && s != rules()->checkSize(s)) {
qCDebug(KWIN_CORE) << "forced size fail:" << s << ":" << rules()->checkSize(s);
}
// resuming geometry updates is handled only in setGeometry()
assert(pendingGeometryUpdate() == PendingGeometryNone || areGeometryUpdatesBlocked());
if (force == NormalGeometrySet && geom.size() == s)
return;
geom.setSize(s);
if (areGeometryUpdatesBlocked()) {
if (pendingGeometryUpdate() == PendingGeometryForced)
{} // maximum, nothing needed
else if (force == ForceGeometrySet)
setPendingGeometryUpdate(PendingGeometryForced);
else
setPendingGeometryUpdate(PendingGeometryNormal);
return;
}
QSize oldClientSize = m_frame.geometry().size();
resizeDecoration();
m_frame.resize(w, h);
// resizeDecoration( s );
if (!isShade()) {
QSize cs = clientSize();
m_wrapper.setGeometry(QRect(clientPos(), cs));
m_client.setGeometry(0, 0, cs.width(), cs.height());
}
updateShape();
sendSyntheticConfigureNotify();
updateWindowRules(Rules::Position|Rules::Size);
screens()->setCurrent(this);
workspace()->updateStackingOrder();
if (oldClientSize != QSize(w,h))
discardWindowPixmap();
emit geometryShapeChanged(this, geometryBeforeUpdateBlocking());
addRepaintDuringGeometryUpdates();
updateGeometryBeforeUpdateBlocking();
// Update states of all other windows in this group
if (tabGroup())
tabGroup()->updateStates(this, TabGroup::Geometry);
// TODO: this signal is emitted too often
emit geometryChanged();
}
/*!
Reimplemented to inform the client about the new window position.
*/
void AbstractClient::move(int x, int y, ForceGeometry_t force)
{
// resuming geometry updates is handled only in setGeometry()
assert(pendingGeometryUpdate() == PendingGeometryNone || areGeometryUpdatesBlocked());
QPoint p(x, y);
if (!areGeometryUpdatesBlocked() && p != rules()->checkPosition(p)) {
qCDebug(KWIN_CORE) << "forced position fail:" << p << ":" << rules()->checkPosition(p);
}
if (force == NormalGeometrySet && geom.topLeft() == p)
return;
geom.moveTopLeft(p);
if (areGeometryUpdatesBlocked()) {
if (pendingGeometryUpdate() == PendingGeometryForced)
{} // maximum, nothing needed
else if (force == ForceGeometrySet)
setPendingGeometryUpdate(PendingGeometryForced);
else
setPendingGeometryUpdate(PendingGeometryNormal);
return;
}
doMove(x, y);
updateWindowRules(Rules::Position);
screens()->setCurrent(this);
workspace()->updateStackingOrder();
// client itself is not damaged
addRepaintDuringGeometryUpdates();
updateGeometryBeforeUpdateBlocking();
// Update states of all other windows in this group
updateTabGroupStates(TabGroup::Geometry);
emit geometryChanged();
}
void Client::doMove(int x, int y)
{
m_frame.move(x, y);
sendSyntheticConfigureNotify();
}
void AbstractClient::blockGeometryUpdates(bool block)
{
if (block) {
if (m_blockGeometryUpdates == 0)
m_pendingGeometryUpdate = PendingGeometryNone;
++m_blockGeometryUpdates;
} else {
if (--m_blockGeometryUpdates == 0) {
if (m_pendingGeometryUpdate != PendingGeometryNone) {
if (isShade())
setGeometry(QRect(pos(), adjustedSize()), NormalGeometrySet);
else
setGeometry(geometry(), NormalGeometrySet);
m_pendingGeometryUpdate = PendingGeometryNone;
}
}
}
}
void AbstractClient::maximize(MaximizeMode m)
{
if (m == maximizeMode()) {
return;
}
setMaximize(m & MaximizeVertical, m & MaximizeHorizontal);
}
/*!
Sets the maximization according to \a vertically and \a horizontally
*/
void AbstractClient::setMaximize(bool vertically, bool horizontally)
{
// changeMaximize() flips the state, so change from set->flip
const MaximizeMode oldMode = maximizeMode();
changeMaximize(
oldMode & MaximizeVertical ? !vertically : vertically,
oldMode & MaximizeHorizontal ? !horizontally : horizontally,
false);
const MaximizeMode newMode = maximizeMode();
if (oldMode != newMode) {
emit clientMaximizedStateChanged(this, newMode);
emit clientMaximizedStateChanged(this, vertically, horizontally);
}
}
// Update states of all other windows in this group
class TabSynchronizer
{
public:
TabSynchronizer(AbstractClient *client, TabGroup::States syncStates) :
m_client(client) , m_states(syncStates)
{
if (client->tabGroup())
client->tabGroup()->blockStateUpdates(true);
}
~TabSynchronizer()
{
syncNow();
}
void syncNow()
{
if (m_client && m_client->tabGroup()) {
m_client->tabGroup()->blockStateUpdates(false);
m_client->tabGroup()->updateStates(dynamic_cast<Client*>(m_client), m_states);
}
m_client = 0;
}
private:
AbstractClient *m_client;
TabGroup::States m_states;
};
static bool changeMaximizeRecursion = false;
void Client::changeMaximize(bool vertical, bool horizontal, bool adjust)
{
if (changeMaximizeRecursion)
return;
if (!isResizable() || isToolbar()) // SELI isToolbar() ?
return;
QRect clientArea;
if (isElectricBorderMaximizing())
clientArea = workspace()->clientArea(MaximizeArea, Cursor::pos(), desktop());
else
clientArea = workspace()->clientArea(MaximizeArea, this);
MaximizeMode old_mode = max_mode;
// 'adjust == true' means to update the size only, e.g. after changing workspace size
if (!adjust) {
if (vertical)
max_mode = MaximizeMode(max_mode ^ MaximizeVertical);
if (horizontal)
max_mode = MaximizeMode(max_mode ^ MaximizeHorizontal);
}
// if the client insist on a fix aspect ratio, we check whether the maximizing will get us
// out of screen bounds and take that as a "full maximization with aspect check" then
if (m_geometryHints.hasAspect() && // fixed aspect
(max_mode == MaximizeVertical || max_mode == MaximizeHorizontal) && // ondimensional maximization
rules()->checkStrictGeometry(true)) { // obey aspect
const QSize minAspect = m_geometryHints.minAspect();
const QSize maxAspect = m_geometryHints.maxAspect();
if (max_mode == MaximizeVertical || (old_mode & MaximizeVertical)) {
const double fx = minAspect.width(); // use doubles, because the values can be MAX_INT
const double fy = maxAspect.height(); // use doubles, because the values can be MAX_INT
if (fx*clientArea.height()/fy > clientArea.width()) // too big
max_mode = old_mode & MaximizeHorizontal ? MaximizeRestore : MaximizeFull;
} else { // max_mode == MaximizeHorizontal
const double fx = maxAspect.width();
const double fy = minAspect.height();
if (fy*clientArea.width()/fx > clientArea.height()) // too big
max_mode = old_mode & MaximizeVertical ? MaximizeRestore : MaximizeFull;
}
}
max_mode = rules()->checkMaximize(max_mode);
if (!adjust && max_mode == old_mode)
return;
GeometryUpdatesBlocker blocker(this);
// QT synchronizing required because we eventually change from QT to Maximized
TabSynchronizer syncer(this, TabGroup::Maximized|TabGroup::QuickTile);
// maximing one way and unmaximizing the other way shouldn't happen,
// so restore first and then maximize the other way
if ((old_mode == MaximizeVertical && max_mode == MaximizeHorizontal)
|| (old_mode == MaximizeHorizontal && max_mode == MaximizeVertical)) {
changeMaximize(false, false, false); // restore
}
// save sizes for restoring, if maximalizing
QSize sz;
if (isShade())
sz = sizeForClientSize(clientSize());
else
sz = size();
if (quickTileMode() == QuickTileMode(QuickTileFlag::None)) {
if (!adjust && !(old_mode & MaximizeVertical)) {
geom_restore.setTop(y());
geom_restore.setHeight(sz.height());
}
if (!adjust && !(old_mode & MaximizeHorizontal)) {
geom_restore.setLeft(x());
geom_restore.setWidth(sz.width());
}
}
// call into decoration update borders
if (isDecorated() && decoration()->client() && !(options->borderlessMaximizedWindows() && max_mode == KWin::MaximizeFull)) {
changeMaximizeRecursion = true;
const auto c = decoration()->client().data();
if ((max_mode & MaximizeVertical) != (old_mode & MaximizeVertical)) {
emit c->maximizedVerticallyChanged(max_mode & MaximizeVertical);
}
if ((max_mode & MaximizeHorizontal) != (old_mode & MaximizeHorizontal)) {
emit c->maximizedHorizontallyChanged(max_mode & MaximizeHorizontal);
}
if ((max_mode == MaximizeFull) != (old_mode == MaximizeFull)) {
emit c->maximizedChanged(max_mode & MaximizeFull);
}
changeMaximizeRecursion = false;
}
if (options->borderlessMaximizedWindows()) {
// triggers a maximize change.
// The next setNoBorder interation will exit since there's no change but the first recursion pullutes the restore geometry
changeMaximizeRecursion = true;
setNoBorder(rules()->checkNoBorder(app_noborder || (m_motif.hasDecoration() && m_motif.noBorder()) || max_mode == MaximizeFull));
changeMaximizeRecursion = false;
}
const ForceGeometry_t geom_mode = isDecorated() ? ForceGeometrySet : NormalGeometrySet;
// Conditional quick tiling exit points
if (quickTileMode() != QuickTileMode(QuickTileFlag::None)) {
if (old_mode == MaximizeFull &&
!clientArea.contains(geom_restore.center())) {
// Not restoring on the same screen
// TODO: The following doesn't work for some reason
//quick_tile_mode = QuickTileFlag::None; // And exit quick tile mode manually
} else if ((old_mode == MaximizeVertical && max_mode == MaximizeRestore) ||
(old_mode == MaximizeFull && max_mode == MaximizeHorizontal)) {
// Modifying geometry of a tiled window
updateQuickTileMode(QuickTileFlag::None); // Exit quick tile mode without restoring geometry
}
}
switch(max_mode) {
case MaximizeVertical: {
if (old_mode & MaximizeHorizontal) { // actually restoring from MaximizeFull
if (geom_restore.width() == 0 || !clientArea.contains(geom_restore.center())) {
// needs placement
plainResize(adjustedSize(QSize(width() * 2 / 3, clientArea.height()), SizemodeFixedH), geom_mode);
Placement::self()->placeSmart(this, clientArea);
} else {
setGeometry(QRect(QPoint(geom_restore.x(), clientArea.top()),
adjustedSize(QSize(geom_restore.width(), clientArea.height()), SizemodeFixedH)), geom_mode);
}
} else {
QRect r(x(), clientArea.top(), width(), clientArea.height());
r.setTopLeft(rules()->checkPosition(r.topLeft()));
r.setSize(adjustedSize(r.size(), SizemodeFixedH));
setGeometry(r, geom_mode);
}
info->setState(NET::MaxVert, NET::Max);
break;
}
case MaximizeHorizontal: {
if (old_mode & MaximizeVertical) { // actually restoring from MaximizeFull
if (geom_restore.height() == 0 || !clientArea.contains(geom_restore.center())) {
// needs placement
plainResize(adjustedSize(QSize(clientArea.width(), height() * 2 / 3), SizemodeFixedW), geom_mode);
Placement::self()->placeSmart(this, clientArea);
} else {
setGeometry(QRect(QPoint(clientArea.left(), geom_restore.y()),
adjustedSize(QSize(clientArea.width(), geom_restore.height()), SizemodeFixedW)), geom_mode);
}
} else {
QRect r(clientArea.left(), y(), clientArea.width(), height());
r.setTopLeft(rules()->checkPosition(r.topLeft()));
r.setSize(adjustedSize(r.size(), SizemodeFixedW));
setGeometry(r, geom_mode);
}
info->setState(NET::MaxHoriz, NET::Max);
break;
}
case MaximizeRestore: {
QRect restore = geometry();
// when only partially maximized, geom_restore may not have the other dimension remembered
if (old_mode & MaximizeVertical) {
restore.setTop(geom_restore.top());
restore.setBottom(geom_restore.bottom());
}
if (old_mode & MaximizeHorizontal) {
restore.setLeft(geom_restore.left());
restore.setRight(geom_restore.right());
}
if (!restore.isValid()) {
QSize s = QSize(clientArea.width() * 2 / 3, clientArea.height() * 2 / 3);
if (geom_restore.width() > 0)
s.setWidth(geom_restore.width());
if (geom_restore.height() > 0)
s.setHeight(geom_restore.height());
plainResize(adjustedSize(s));
Placement::self()->placeSmart(this, clientArea);
restore = geometry();
if (geom_restore.width() > 0)
restore.moveLeft(geom_restore.x());
if (geom_restore.height() > 0)
restore.moveTop(geom_restore.y());
geom_restore = restore; // relevant for mouse pos calculation, bug #298646
}
if (m_geometryHints.hasAspect()) {
restore.setSize(adjustedSize(restore.size(), SizemodeAny));
}
setGeometry(restore, geom_mode);
if (!clientArea.contains(geom_restore.center())) // Not restoring to the same screen
Placement::self()->place(this, clientArea);
info->setState(0, NET::Max);
updateQuickTileMode(QuickTileFlag::None);
break;
}
case MaximizeFull: {
QRect r(clientArea);
r.setTopLeft(rules()->checkPosition(r.topLeft()));
r.setSize(adjustedSize(r.size(), SizemodeMax));
if (r.size() != clientArea.size()) { // to avoid off-by-one errors...
if (isElectricBorderMaximizing() && r.width() < clientArea.width()) {
r.moveLeft(qMax(clientArea.left(), Cursor::pos().x() - r.width()/2));
r.moveRight(qMin(clientArea.right(), r.right()));
} else {
r.moveCenter(clientArea.center());
const bool closeHeight = r.height() > 97*clientArea.height()/100;
const bool closeWidth = r.width() > 97*clientArea.width() /100;
const bool overHeight = r.height() > clientArea.height();
const bool overWidth = r.width() > clientArea.width();
if (closeWidth || closeHeight) {
Position titlePos = titlebarPosition();
const QRect screenArea = workspace()->clientArea(ScreenArea, clientArea.center(), desktop());
if (closeHeight) {
bool tryBottom = titlePos == PositionBottom;
if ((overHeight && titlePos == PositionTop) ||
screenArea.top() == clientArea.top())
r.setTop(clientArea.top());
else
tryBottom = true;
if (tryBottom &&
(overHeight || screenArea.bottom() == clientArea.bottom()))
r.setBottom(clientArea.bottom());
}
if (closeWidth) {
bool tryLeft = titlePos == PositionLeft;
if ((overWidth && titlePos == PositionRight) ||
screenArea.right() == clientArea.right())
r.setRight(clientArea.right());
else
tryLeft = true;
if (tryLeft && (overWidth || screenArea.left() == clientArea.left()))
r.setLeft(clientArea.left());
}
}
}
r.moveTopLeft(rules()->checkPosition(r.topLeft()));
}
setGeometry(r, geom_mode);
if (options->electricBorderMaximize() && r.top() == clientArea.top())
updateQuickTileMode(QuickTileFlag::Maximize);
else
updateQuickTileMode(QuickTileFlag::None);
info->setState(NET::Max, NET::Max);
break;
}
default:
break;
}
syncer.syncNow(); // important because of window rule updates!
updateAllowedActions();
updateWindowRules(Rules::MaximizeVert|Rules::MaximizeHoriz|Rules::Position|Rules::Size);
emit quickTileModeChanged();
}
bool AbstractClient::isFullScreenable() const
{
return isFullScreenable(false);
}
bool AbstractClient::isFullScreenable(bool fullscreen_hack) const
{
if (!rules()->checkFullScreen(true))
return false;
if (fullscreen_hack)
return isNormalWindow();
if (rules()->checkStrictGeometry(true)) { // allow rule to ignore geometry constraints
QRect fsarea = workspace()->clientArea(FullScreenArea, this);
if (sizeForClientSize(fsarea.size(), SizemodeAny, true) != fsarea.size())
return false; // the app wouldn't fit exactly fullscreen geometry due to its strict geometry requirements
}
// don't check size constrains - some apps request fullscreen despite requesting fixed size
return !isSpecialWindow(); // also better disallow only weird types to go fullscreen
}
bool Client::userCanSetFullScreen() const
{
if (fullscreen_mode == FullScreenHack)
return false;
if (!isFullScreenable(false))
return false;
return isNormalWindow() || isDialog();
}
void Client::setFullScreen(bool set, bool user)
{
if (!isFullScreen() && !set)
return;
if (fullscreen_mode == FullScreenHack)
return;
if (user && !userCanSetFullScreen())
return;
set = rules()->checkFullScreen(set && !isSpecialWindow());
setShade(ShadeNone);
bool was_fs = isFullScreen();
if (was_fs)
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event
else
geom_fs_restore = geometry();
fullscreen_mode = set ? FullScreenNormal : FullScreenNone;
if (was_fs == isFullScreen())
return;
if (set) {
untab();
workspace()->raiseClient(this);
}
StackingUpdatesBlocker blocker1(workspace());
GeometryUpdatesBlocker blocker2(this);
workspace()->updateClientLayer(this); // active fullscreens get different layer
info->setState(isFullScreen() ? NET::FullScreen : NET::States(0), NET::FullScreen);
updateDecoration(false, false);
if (isFullScreen()) {
if (info->fullscreenMonitors().isSet())
setGeometry(fullscreenMonitorsArea(info->fullscreenMonitors()));
else
setGeometry(workspace()->clientArea(FullScreenArea, this));
}
else {
if (!geom_fs_restore.isNull()) {
int currentScreen = screen();
setGeometry(QRect(geom_fs_restore.topLeft(), adjustedSize(geom_fs_restore.size())));
if( currentScreen != screen())
workspace()->sendClientToScreen( this, currentScreen );
// TODO isShaded() ?
} else {
// does this ever happen?
setGeometry(workspace()->clientArea(MaximizeArea, this));
}
}
updateWindowRules(Rules::Fullscreen|Rules::Position|Rules::Size);
if (was_fs != isFullScreen()) {
emit clientFullScreenSet(this, set, user);
emit fullScreenChanged();
}
}
void Client::updateFullscreenMonitors(NETFullscreenMonitors topology)
{
int nscreens = screens()->count();
// qDebug() << "incoming request with top: " << topology.top << " bottom: " << topology.bottom
// << " left: " << topology.left << " right: " << topology.right
// << ", we have: " << nscreens << " screens.";
if (topology.top >= nscreens ||
topology.bottom >= nscreens ||
topology.left >= nscreens ||
topology.right >= nscreens) {
qCWarning(KWIN_CORE) << "fullscreenMonitors update failed. request higher than number of screens.";
return;
}
info->setFullscreenMonitors(topology);
if (isFullScreen())
setGeometry(fullscreenMonitorsArea(topology));
}
/*!
Calculates the bounding rectangle defined by the 4 monitor indices indicating the
top, bottom, left, and right edges of the window when the fullscreen state is enabled.
*/
QRect Client::fullscreenMonitorsArea(NETFullscreenMonitors requestedTopology) const
{
QRect top, bottom, left, right, total;
top = screens()->geometry(requestedTopology.top);
bottom = screens()->geometry(requestedTopology.bottom);
left = screens()->geometry(requestedTopology.left);
right = screens()->geometry(requestedTopology.right);
total = top.united(bottom.united(left.united(right)));
// qDebug() << "top: " << top << " bottom: " << bottom
// << " left: " << left << " right: " << right;
// qDebug() << "returning rect: " << total;
return total;
}
int Client::checkFullScreenHack(const QRect& geom) const
{
if (!options->isLegacyFullscreenSupport())
return 0;
// if it's noborder window, and has size of one screen or the whole desktop geometry, it's fullscreen hack
if (noBorder() && app_noborder && isFullScreenable(true)) {
if (geom.size() == workspace()->clientArea(FullArea, geom.center(), desktop()).size())
return 2; // full area fullscreen hack
if (geom.size() == workspace()->clientArea(ScreenArea, geom.center(), desktop()).size())
return 1; // xinerama-aware fullscreen hack
}
return 0;
}
void Client::updateFullScreenHack(const QRect& geom)
{
int type = checkFullScreenHack(geom);
if (fullscreen_mode == FullScreenNone && type != 0) {
fullscreen_mode = FullScreenHack;
updateDecoration(false, false);
QRect geom;
if (rules()->checkStrictGeometry(false)) {
geom = type == 2 // 1 - it's xinerama-aware fullscreen hack, 2 - it's full area
? workspace()->clientArea(FullArea, geom.center(), desktop())
: workspace()->clientArea(ScreenArea, geom.center(), desktop());
} else
geom = workspace()->clientArea(FullScreenArea, geom.center(), desktop());
setGeometry(geom);
emit fullScreenChanged();
} else if (fullscreen_mode == FullScreenHack && type == 0) {
fullscreen_mode = FullScreenNone;
updateDecoration(false, false);
// whoever called this must setup correct geometry
emit fullScreenChanged();
}
StackingUpdatesBlocker blocker(workspace());
workspace()->updateClientLayer(this); // active fullscreens get different layer
}
static GeometryTip* geometryTip = 0;
void Client::positionGeometryTip()
{
assert(isMove() || isResize());
// Position and Size display
if (effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::GeometryTip))
return; // some effect paints this for us
if (options->showGeometryTip()) {
if (!geometryTip) {
geometryTip = new GeometryTip(&m_geometryHints);
}
QRect wgeom(moveResizeGeometry()); // position of the frame, size of the window itself
wgeom.setWidth(wgeom.width() - (width() - clientSize().width()));
wgeom.setHeight(wgeom.height() - (height() - clientSize().height()));
if (isShade())
wgeom.setHeight(0);
geometryTip->setGeometry(wgeom);
if (!geometryTip->isVisible())
geometryTip->show();
geometryTip->raise();
}
}
bool AbstractClient::startMoveResize()
{
assert(!isMoveResize());
assert(QWidget::keyboardGrabber() == NULL);
assert(QWidget::mouseGrabber() == NULL);
stopDelayedMoveResize();
if (QApplication::activePopupWidget() != NULL)
return false; // popups have grab
if (isFullScreen() && (screens()->count() < 2 || !isMovableAcrossScreens()))
return false;
if (!doStartMoveResize()) {
return false;
}
invalidateDecorationDoubleClickTimer();
setMoveResize(true);
workspace()->setClientIsMoving(this);
const Position mode = moveResizePointerMode();
if (mode != PositionCenter) { // means "isResize()" but moveResizeMode = true is set below
if (maximizeMode() == MaximizeFull) { // partial is cond. reset in finishMoveResize
setGeometryRestore(geometry()); // "restore" to current geometry
setMaximize(false, false);
}
}
if (quickTileMode() != QuickTileMode(QuickTileFlag::None) && mode != PositionCenter) { // Cannot use isResize() yet
// Exit quick tile mode when the user attempts to resize a tiled window
updateQuickTileMode(QuickTileFlag::None); // Do so without restoring original geometry
setGeometryRestore(geometry());
emit quickTileModeChanged();
}
updateHaveResizeEffect();
updateInitialMoveResizeGeometry();
checkUnrestrictedMoveResize();
emit clientStartUserMovedResized(this);
if (ScreenEdges::self()->isDesktopSwitchingMovingClients())
ScreenEdges::self()->reserveDesktopSwitching(true, Qt::Vertical|Qt::Horizontal);
return true;
}
bool Client::doStartMoveResize()
{
bool has_grab = false;
// This reportedly improves smoothness of the moveresize operation,
// something with Enter/LeaveNotify events, looks like XFree performance problem or something *shrug*
// (http://lists.kde.org/?t=107302193400001&r=1&w=2)
QRect r = workspace()->clientArea(FullArea, this);
m_moveResizeGrabWindow.create(r, XCB_WINDOW_CLASS_INPUT_ONLY, 0, NULL, rootWindow());
m_moveResizeGrabWindow.map();
m_moveResizeGrabWindow.raise();
updateXTime();
const xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer_unchecked(connection(), false, m_moveResizeGrabWindow,
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, m_moveResizeGrabWindow, Cursor::x11Cursor(cursor()), xTime());
ScopedCPointer<xcb_grab_pointer_reply_t> pointerGrab(xcb_grab_pointer_reply(connection(), cookie, NULL));
if (!pointerGrab.isNull() && pointerGrab->status == XCB_GRAB_STATUS_SUCCESS) {
has_grab = true;
}
if (!has_grab && grabXKeyboard(frameId()))
has_grab = move_resize_has_keyboard_grab = true;
if (!has_grab) { // at least one grab is necessary in order to be able to finish move/resize
m_moveResizeGrabWindow.reset();
return false;
}
return true;
}
void AbstractClient::finishMoveResize(bool cancel)
{
GeometryUpdatesBlocker blocker(this);
const bool wasResize = isResize(); // store across leaveMoveResize
leaveMoveResize();
if (cancel)
setGeometry(initialMoveResizeGeometry());
else {
const QRect &moveResizeGeom = moveResizeGeometry();
if (wasResize) {
const bool restoreH = maximizeMode() == MaximizeHorizontal &&
moveResizeGeom.width() != initialMoveResizeGeometry().width();
const bool restoreV = maximizeMode() == MaximizeVertical &&
moveResizeGeom.height() != initialMoveResizeGeometry().height();
if (restoreH || restoreV) {
changeMaximize(restoreV, restoreH, false);
}
}
setGeometry(moveResizeGeom);
}
checkScreen(); // needs to be done because clientFinishUserMovedResized has not yet re-activated online alignment
if (screen() != moveResizeStartScreen()) {
workspace()->sendClientToScreen(this, screen()); // checks rule validity
if (maximizeMode() != MaximizeRestore)
checkWorkspacePosition();
}
if (isElectricBorderMaximizing()) {
setQuickTileMode(electricBorderMode());
setElectricBorderMaximizing(false);
} else if (!cancel) {
QRect geom_restore = geometryRestore();
if (!(maximizeMode() & MaximizeHorizontal)) {
geom_restore.setX(geometry().x());
geom_restore.setWidth(geometry().width());
}
if (!(maximizeMode() & MaximizeVertical)) {
geom_restore.setY(geometry().y());
geom_restore.setHeight(geometry().height());
}
setGeometryRestore(geom_restore);
}
// FRAME update();
emit clientFinishUserMovedResized(this);
}
void Client::leaveMoveResize()
{
if (needsXWindowMove) {
// Do the deferred move
m_frame.move(geom.topLeft());
needsXWindowMove = false;
}
if (!isResize())
sendSyntheticConfigureNotify(); // tell the client about it's new final position
if (geometryTip) {
geometryTip->hide();
delete geometryTip;
geometryTip = NULL;
}
if (move_resize_has_keyboard_grab)
ungrabXKeyboard();
move_resize_has_keyboard_grab = false;
xcb_ungrab_pointer(connection(), xTime());
m_moveResizeGrabWindow.reset();
if (syncRequest.counter == XCB_NONE) // don't forget to sanitize since the timeout will no more fire
syncRequest.isPending = false;
delete syncRequest.timeout;
syncRequest.timeout = NULL;
AbstractClient::leaveMoveResize();
}
// This function checks if it actually makes sense to perform a restricted move/resize.
// If e.g. the titlebar is already outside of the workarea, there's no point in performing
// a restricted move resize, because then e.g. resize would also move the window (#74555).
// NOTE: Most of it is duplicated from handleMoveResize().
void AbstractClient::checkUnrestrictedMoveResize()
{
if (isUnrestrictedMoveResize())
return;
const QRect &moveResizeGeom = moveResizeGeometry();
QRect desktopArea = workspace()->clientArea(WorkArea, moveResizeGeom.center(), desktop());
int left_marge, right_marge, top_marge, bottom_marge, titlebar_marge;
// restricted move/resize - keep at least part of the titlebar always visible
// how much must remain visible when moved away in that direction
left_marge = qMin(100 + borderRight(), moveResizeGeom.width());
right_marge = qMin(100 + borderLeft(), moveResizeGeom.width());
// width/height change with opaque resizing, use the initial ones
titlebar_marge = initialMoveResizeGeometry().height();
top_marge = borderBottom();
bottom_marge = borderTop();
if (isResize()) {
if (moveResizeGeom.bottom() < desktopArea.top() + top_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.right() < desktopArea.left() + left_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.left() > desktopArea.right() - right_marge)
setUnrestrictedMoveResize(true);
if (!isUnrestrictedMoveResize() && moveResizeGeom.top() < desktopArea.top()) // titlebar mustn't go out
setUnrestrictedMoveResize(true);
}
if (isMove()) {
if (moveResizeGeom.bottom() < desktopArea.top() + titlebar_marge - 1)
setUnrestrictedMoveResize(true);
// no need to check top_marge, titlebar_marge already handles it
if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge + 1) // titlebar mustn't go out
setUnrestrictedMoveResize(true);
if (moveResizeGeom.right() < desktopArea.left() + left_marge)
setUnrestrictedMoveResize(true);
if (moveResizeGeom.left() > desktopArea.right() - right_marge)
setUnrestrictedMoveResize(true);
}
}
// When the user pressed mouse on the titlebar, don't activate move immediatelly,
// since it may be just a click. Activate instead after a delay. Move used to be
// activated only after moving by several pixels, but that looks bad.
void AbstractClient::startDelayedMoveResize()
{
Q_ASSERT(!m_moveResize.delayedTimer);
m_moveResize.delayedTimer = new QTimer(this);
m_moveResize.delayedTimer->setSingleShot(true);
connect(m_moveResize.delayedTimer, &QTimer::timeout, this,
[this]() {
assert(isMoveResizePointerButtonDown());
if (!startMoveResize()) {
setMoveResizePointerButtonDown(false);
}
updateCursor();
stopDelayedMoveResize();
}
);
m_moveResize.delayedTimer->start(QApplication::startDragTime());
}
void AbstractClient::stopDelayedMoveResize()
{
delete m_moveResize.delayedTimer;
m_moveResize.delayedTimer = nullptr;
}
void AbstractClient::handleMoveResize(const QPoint &local, const QPoint &global)
{
const QRect oldGeo = geometry();
handleMoveResize(local.x(), local.y(), global.x(), global.y());
if (!isFullScreen() && isMove()) {
if (quickTileMode() != QuickTileMode(QuickTileFlag::None) && oldGeo != geometry()) {
GeometryUpdatesBlocker blocker(this);
setQuickTileMode(QuickTileFlag::None);
const QRect &geom_restore = geometryRestore();
setMoveOffset(QPoint(double(moveOffset().x()) / double(oldGeo.width()) * double(geom_restore.width()),
double(moveOffset().y()) / double(oldGeo.height()) * double(geom_restore.height())));
if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore)
setMoveResizeGeometry(geom_restore);
handleMoveResize(local.x(), local.y(), global.x(), global.y()); // fix position
} else if (quickTileMode() == QuickTileMode(QuickTileFlag::None) && isResizable()) {
checkQuickTilingMaximizationZones(global.x(), global.y());
}
}
}
bool Client::isWaitingForMoveResizeSync() const
{
return syncRequest.isPending && isResize();
}
void AbstractClient::handleMoveResize(int x, int y, int x_root, int y_root)
{
if (isWaitingForMoveResizeSync())
return; // we're still waiting for the client or the timeout
const Position mode = moveResizePointerMode();
if ((mode == PositionCenter && !isMovableAcrossScreens())
|| (mode != PositionCenter && (isShade() || !isResizable())))
return;
if (!isMoveResize()) {
QPoint p(QPoint(x/* - padding_left*/, y/* - padding_top*/) - moveOffset());
if (p.manhattanLength() >= QApplication::startDragDistance()) {
if (!startMoveResize()) {
setMoveResizePointerButtonDown(false);
updateCursor();
return;
}
updateCursor();
} else
return;
}
// ShadeHover or ShadeActive, ShadeNormal was already avoided above
if (mode != PositionCenter && shadeMode() != ShadeNone)
setShade(ShadeNone);
QPoint globalPos(x_root, y_root);
// these two points limit the geometry rectangle, i.e. if bottomleft resizing is done,
// the bottomleft corner should be at is at (topleft.x(), bottomright().y())
QPoint topleft = globalPos - moveOffset();
QPoint bottomright = globalPos + invertedMoveOffset();
QRect previousMoveResizeGeom = moveResizeGeometry();
// TODO move whole group when moving its leader or when the leader is not mapped?
auto titleBarRect = [this](bool &transposed, int &requiredPixels) -> QRect {
const QRect &moveResizeGeom = moveResizeGeometry();
QRect r(moveResizeGeom);
r.moveTopLeft(QPoint(0,0));
switch (titlebarPosition()) {
default:
case PositionTop:
r.setHeight(borderTop());
break;
case PositionLeft:
r.setWidth(borderLeft());
transposed = true;
break;
case PositionBottom:
r.setTop(r.bottom() - borderBottom());
break;
case PositionRight:
r.setLeft(r.right() - borderRight());
transposed = true;
break;
}
// When doing a restricted move we must always keep 100px of the titlebar
// visible to allow the user to be able to move it again.
requiredPixels = qMin(100 * (transposed ? r.width() : r.height()),
moveResizeGeom.width() * moveResizeGeom.height());
return r;
};
bool update = false;
if (isResize()) {
QRect orig = initialMoveResizeGeometry();
Sizemode sizemode = SizemodeAny;
auto calculateMoveResizeGeom = [this, &topleft, &bottomright, &orig, &sizemode, &mode]() {
switch(mode) {
case PositionTopLeft:
setMoveResizeGeometry(QRect(topleft, orig.bottomRight()));
break;
case PositionBottomRight:
setMoveResizeGeometry(QRect(orig.topLeft(), bottomright));
break;
case PositionBottomLeft:
setMoveResizeGeometry(QRect(QPoint(topleft.x(), orig.y()), QPoint(orig.right(), bottomright.y())));
break;
case PositionTopRight:
setMoveResizeGeometry(QRect(QPoint(orig.x(), topleft.y()), QPoint(bottomright.x(), orig.bottom())));
break;
case PositionTop:
setMoveResizeGeometry(QRect(QPoint(orig.left(), topleft.y()), orig.bottomRight()));
sizemode = SizemodeFixedH; // try not to affect height
break;
case PositionBottom:
setMoveResizeGeometry(QRect(orig.topLeft(), QPoint(orig.right(), bottomright.y())));
sizemode = SizemodeFixedH;
break;
case PositionLeft:
setMoveResizeGeometry(QRect(QPoint(topleft.x(), orig.top()), orig.bottomRight()));
sizemode = SizemodeFixedW;
break;
case PositionRight:
setMoveResizeGeometry(QRect(orig.topLeft(), QPoint(bottomright.x(), orig.bottom())));
sizemode = SizemodeFixedW;
break;
case PositionCenter:
default:
abort();
break;
}
};
// first resize (without checking constrains), then snap, then check bounds, then check constrains
calculateMoveResizeGeom();
// adjust new size to snap to other windows/borders
setMoveResizeGeometry(workspace()->adjustClientSize(this, moveResizeGeometry(), mode));
if (!isUnrestrictedMoveResize()) {
// Make sure the titlebar isn't behind a restricted area. We don't need to restrict
// the other directions. If not visible enough, move the window to the closest valid
// point. We bruteforce this by slowly moving the window back to its previous position
QRegion availableArea(workspace()->clientArea(FullArea, -1, 0)); // On the screen
availableArea -= workspace()->restrictedMoveArea(desktop()); // Strut areas
bool transposed = false;
int requiredPixels;
QRect bTitleRect = titleBarRect(transposed, requiredPixels);
int lastVisiblePixels = -1;
QRect lastTry = moveResizeGeometry();
bool titleFailed = false;
for (;;) {
const QRect titleRect(bTitleRect.translated(moveResizeGeometry().topLeft()));
int visiblePixels = 0;
int realVisiblePixels = 0;
foreach (const QRect &rect, availableArea.rects()) {
const QRect r = rect & titleRect;
realVisiblePixels += r.width() * r.height();
if ((transposed && r.width() == titleRect.width()) || // Only the full size regions...
(!transposed && r.height() == titleRect.height())) // ...prevents long slim areas
visiblePixels += r.width() * r.height();
}
if (visiblePixels >= requiredPixels)
break; // We have reached a valid position
if (realVisiblePixels <= lastVisiblePixels) {
if (titleFailed && realVisiblePixels < lastVisiblePixels)
break; // we won't become better
else {
if (!titleFailed)
setMoveResizeGeometry(lastTry);
titleFailed = true;
}
}
lastVisiblePixels = realVisiblePixels;
QRect moveResizeGeom = moveResizeGeometry();
lastTry = moveResizeGeom;
// Not visible enough, move the window to the closest valid point. We bruteforce
// this by slowly moving the window back to its previous position.
// The geometry changes at up to two edges, the one with the title (if) shall take
// precedence. The opposing edge has no impact on visiblePixels and only one of
// the adjacent can alter at a time, ie. it's enough to ignore adjacent edges
// if the title edge altered
bool leftChanged = previousMoveResizeGeom.left() != moveResizeGeom.left();
bool rightChanged = previousMoveResizeGeom.right() != moveResizeGeom.right();
bool topChanged = previousMoveResizeGeom.top() != moveResizeGeom.top();
bool btmChanged = previousMoveResizeGeom.bottom() != moveResizeGeom.bottom();
auto fixChangedState = [titleFailed](bool &major, bool &counter, bool &ad1, bool &ad2) {
counter = false;
if (titleFailed)
major = false;
if (major)
ad1 = ad2 = false;
};
switch (titlebarPosition()) {
default:
case PositionTop:
fixChangedState(topChanged, btmChanged, leftChanged, rightChanged);
break;
case PositionLeft:
fixChangedState(leftChanged, rightChanged, topChanged, btmChanged);
break;
case PositionBottom:
fixChangedState(btmChanged, topChanged, leftChanged, rightChanged);
break;
case PositionRight:
fixChangedState(rightChanged, leftChanged, topChanged, btmChanged);
break;
}
if (topChanged)
moveResizeGeom.setTop(moveResizeGeom.y() + sign(previousMoveResizeGeom.y() - moveResizeGeom.y()));
else if (leftChanged)
moveResizeGeom.setLeft(moveResizeGeom.x() + sign(previousMoveResizeGeom.x() - moveResizeGeom.x()));
else if (btmChanged)
moveResizeGeom.setBottom(moveResizeGeom.bottom() + sign(previousMoveResizeGeom.bottom() - moveResizeGeom.bottom()));
else if (rightChanged)
moveResizeGeom.setRight(moveResizeGeom.right() + sign(previousMoveResizeGeom.right() - moveResizeGeom.right()));
else
break; // no position changed - that's certainly not good
setMoveResizeGeometry(moveResizeGeom);
}
}
// Always obey size hints, even when in "unrestricted" mode
QSize size = adjustedSize(moveResizeGeometry().size(), sizemode);
// the new topleft and bottomright corners (after checking size constrains), if they'll be needed
topleft = QPoint(moveResizeGeometry().right() - size.width() + 1, moveResizeGeometry().bottom() - size.height() + 1);
bottomright = QPoint(moveResizeGeometry().left() + size.width() - 1, moveResizeGeometry().top() + size.height() - 1);
orig = moveResizeGeometry();
// if aspect ratios are specified, both dimensions may change.
// Therefore grow to the right/bottom if needed.
// TODO it should probably obey gravity rather than always using right/bottom ?
if (sizemode == SizemodeFixedH)
orig.setRight(bottomright.x());
else if (sizemode == SizemodeFixedW)
orig.setBottom(bottomright.y());
calculateMoveResizeGeom();
if (moveResizeGeometry().size() != previousMoveResizeGeom.size())
update = true;
} else if (isMove()) {
assert(mode == PositionCenter);
if (!isMovable()) { // isMovableAcrossScreens() must have been true to get here
// Special moving of maximized windows on Xinerama screens
int screen = screens()->number(globalPos);
if (isFullScreen())
setMoveResizeGeometry(workspace()->clientArea(FullScreenArea, screen, 0));
else {
QRect moveResizeGeom = workspace()->clientArea(MaximizeArea, screen, 0);
QSize adjSize = adjustedSize(moveResizeGeom.size(), SizemodeMax);
if (adjSize != moveResizeGeom.size()) {
QRect r(moveResizeGeom);
moveResizeGeom.setSize(adjSize);
moveResizeGeom.moveCenter(r.center());
}
setMoveResizeGeometry(moveResizeGeom);
}
} else {
// first move, then snap, then check bounds
QRect moveResizeGeom = moveResizeGeometry();
moveResizeGeom.moveTopLeft(topleft);
moveResizeGeom.moveTopLeft(workspace()->adjustClientPosition(this, moveResizeGeom.topLeft(),
isUnrestrictedMoveResize()));
setMoveResizeGeometry(moveResizeGeom);
if (!isUnrestrictedMoveResize()) {
const QRegion strut = workspace()->restrictedMoveArea(desktop()); // Strut areas
QRegion availableArea(workspace()->clientArea(FullArea, -1, 0)); // On the screen
availableArea -= strut; // Strut areas
bool transposed = false;
int requiredPixels;
QRect bTitleRect = titleBarRect(transposed, requiredPixels);
for (;;) {
QRect moveResizeGeom = moveResizeGeometry();
const QRect titleRect(bTitleRect.translated(moveResizeGeom.topLeft()));
int visiblePixels = 0;
foreach (const QRect &rect, availableArea.rects()) {
const QRect r = rect & titleRect;
if ((transposed && r.width() == titleRect.width()) || // Only the full size regions...
(!transposed && r.height() == titleRect.height())) // ...prevents long slim areas
visiblePixels += r.width() * r.height();
}
if (visiblePixels >= requiredPixels)
break; // We have reached a valid position
// (esp.) if there're more screens with different struts (panels) it the titlebar
// will be movable outside the movearea (covering one of the panels) until it
// crosses the panel "too much" (not enough visiblePixels) and then stucks because
// it's usually only pushed by 1px to either direction
// so we first check whether we intersect suc strut and move the window below it
// immediately (it's still possible to hit the visiblePixels >= titlebarArea break
// by moving the window slightly downwards, but it won't stuck)
// see bug #274466
// and bug #301805 for why we can't just match the titlearea against the screen
if (screens()->count() > 1) { // optimization
// TODO: could be useful on partial screen struts (half-width panels etc.)
int newTitleTop = -1;
foreach (const QRect &r, strut.rects()) {
if (r.top() == 0 && r.width() > r.height() && // "top panel"
r.intersects(moveResizeGeom) && moveResizeGeom.top() < r.bottom()) {
newTitleTop = r.bottom() + 1;
break;
}
}
if (newTitleTop > -1) {
moveResizeGeom.moveTop(newTitleTop); // invalid position, possibly on screen change
setMoveResizeGeometry(moveResizeGeom);
break;
}
}
int dx = sign(previousMoveResizeGeom.x() - moveResizeGeom.x()),
dy = sign(previousMoveResizeGeom.y() - moveResizeGeom.y());
if (visiblePixels && dx) // means there's no full width cap -> favor horizontally
dy = 0;
else if (dy)
dx = 0;
// Move it back
moveResizeGeom.translate(dx, dy);
setMoveResizeGeometry(moveResizeGeom);
if (moveResizeGeom == previousMoveResizeGeom) {
break; // Prevent lockup
}
}
}
}
if (moveResizeGeometry().topLeft() != previousMoveResizeGeom.topLeft())
update = true;
} else
abort();
if (!update)
return;
if (isResize() && !haveResizeEffect()) {
doResizeSync();
} else
performMoveResize();
if (isMove()) {
ScreenEdges::self()->check(globalPos, QDateTime::fromMSecsSinceEpoch(xTime()));
}
}
void Client::doResizeSync()
{
if (!syncRequest.timeout) {
syncRequest.timeout = new QTimer(this);
connect(syncRequest.timeout, &QTimer::timeout, this, &Client::performMoveResize);
syncRequest.timeout->setSingleShot(true);
}
if (syncRequest.counter != XCB_NONE) {
syncRequest.timeout->start(250);
sendSyncRequest();
} else { // for clients not supporting the XSYNC protocol, we
syncRequest.isPending = true; // limit the resizes to 30Hz to take pointless load from X11
syncRequest.timeout->start(33); // and the client, the mouse is still moved at full speed
} // and no human can control faster resizes anyway
const QRect &moveResizeGeom = moveResizeGeometry();
m_client.setGeometry(0, 0, moveResizeGeom.width() - (borderLeft() + borderRight()), moveResizeGeom.height() - (borderTop() + borderBottom()));
}
void AbstractClient::performMoveResize()
{
const QRect &moveResizeGeom = moveResizeGeometry();
if (isMove() || (isResize() && !haveResizeEffect())) {
setGeometry(moveResizeGeom);
}
doPerformMoveResize();
if (isResize())
addRepaintFull();
positionGeometryTip();
emit clientStepUserMovedResized(this, moveResizeGeom);
}
void Client::doPerformMoveResize()
{
if (syncRequest.counter == XCB_NONE) // client w/o XSYNC support. allow the next resize event
syncRequest.isPending = false; // NEVER do this for clients with a valid counter
// (leads to sync request races in some clients)
}
void AbstractClient::setElectricBorderMode(QuickTileMode mode)
{
if (mode != QuickTileMode(QuickTileFlag::Maximize)) {
// sanitize the mode, ie. simplify "invalid" combinations
if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Horizontal))
mode &= ~QuickTileMode(QuickTileFlag::Horizontal);
if ((mode & QuickTileFlag::Vertical) == QuickTileMode(QuickTileFlag::Vertical))
mode &= ~QuickTileMode(QuickTileFlag::Vertical);
}
m_electricMode = mode;
}
void AbstractClient::setElectricBorderMaximizing(bool maximizing)
{
m_electricMaximizing = maximizing;
if (maximizing)
outline()->show(electricBorderMaximizeGeometry(Cursor::pos(), desktop()), moveResizeGeometry());
else
outline()->hide();
elevate(maximizing);
}
QRect AbstractClient::electricBorderMaximizeGeometry(QPoint pos, int desktop)
{
if (electricBorderMode() == QuickTileMode(QuickTileFlag::Maximize)) {
if (maximizeMode() == MaximizeFull)
return geometryRestore();
else
return workspace()->clientArea(MaximizeArea, pos, desktop);
}
QRect ret = workspace()->clientArea(MaximizeArea, pos, desktop);
if (electricBorderMode() & QuickTileFlag::Left)
ret.setRight(ret.left()+ret.width()/2 - 1);
else if (electricBorderMode() & QuickTileFlag::Right)
ret.setLeft(ret.right()-(ret.width()-ret.width()/2) + 1);
if (electricBorderMode() & QuickTileFlag::Top)
ret.setBottom(ret.top()+ret.height()/2 - 1);
else if (electricBorderMode() & QuickTileFlag::Bottom)
ret.setTop(ret.bottom()-(ret.height()-ret.height()/2) + 1);
return ret;
}
void AbstractClient::setQuickTileMode(QuickTileMode mode, bool keyboard)
{
// Only allow quick tile on a regular or maximized window
if (!isResizable() && maximizeMode() != MaximizeFull)
return;
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event
GeometryUpdatesBlocker blocker(this);
if (mode == QuickTileMode(QuickTileFlag::Maximize)) {
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry|TabGroup::Maximized);
m_quickTileMode = int(QuickTileFlag::None);
if (maximizeMode() == MaximizeFull) {
setMaximize(false, false);
} else {
QRect prev_geom_restore = geometryRestore(); // setMaximize() would set moveResizeGeom as geom_restore
m_quickTileMode = int(QuickTileFlag::Maximize);
setMaximize(true, true);
QRect clientArea = workspace()->clientArea(MaximizeArea, this);
if (geometry().top() != clientArea.top()) {
QRect r(geometry());
r.moveTop(clientArea.top());
setGeometry(r);
}
setGeometryRestore(prev_geom_restore);
}
emit quickTileModeChanged();
return;
}
// sanitize the mode, ie. simplify "invalid" combinations
if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Horizontal))
mode &= ~QuickTileMode(QuickTileFlag::Horizontal);
if ((mode & QuickTileFlag::Vertical) == QuickTileMode(QuickTileFlag::Vertical))
mode &= ~QuickTileMode(QuickTileFlag::Vertical);
setElectricBorderMode(mode); // used by ::electricBorderMaximizeGeometry(.)
// restore from maximized so that it is possible to tile maximized windows with one hit or by dragging
if (maximizeMode() != MaximizeRestore) {
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry|TabGroup::Maximized);
if (mode != QuickTileMode(QuickTileFlag::None)) {
// decorations may turn off some borders when tiled
const ForceGeometry_t geom_mode = isDecorated() ? ForceGeometrySet : NormalGeometrySet;
m_quickTileMode = int(QuickTileFlag::None); // Temporary, so the maximize code doesn't get all confused
setMaximize(false, false);
setGeometry(electricBorderMaximizeGeometry(keyboard ? geometry().center() : Cursor::pos(), desktop()), geom_mode);
// Store the mode change
m_quickTileMode = mode;
} else {
m_quickTileMode = mode;
setMaximize(false, false);
}
emit quickTileModeChanged();
return;
}
if (mode != QuickTileMode(QuickTileFlag::None)) {
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry);
QPoint whichScreen = keyboard ? geometry().center() : Cursor::pos();
// If trying to tile to the side that the window is already tiled to move the window to the next
// screen if it exists, otherwise toggle the mode (set QuickTileFlag::None)
if (quickTileMode() == mode) {
const int numScreens = screens()->count();
const int curScreen = screen();
int nextScreen = curScreen;
QVarLengthArray<QRect> screens(numScreens);
for (int i = 0; i < numScreens; ++i) // Cache
screens[i] = Screens::self()->geometry(i);
for (int i = 0; i < numScreens; ++i) {
if (i == curScreen)
continue;
if (screens[i].bottom() <= screens[curScreen].top() || screens[i].top() >= screens[curScreen].bottom())
continue; // not in horizontal line
const int x = screens[i].center().x();
if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Left)) {
if (x >= screens[curScreen].center().x() || (curScreen != nextScreen && x <= screens[nextScreen].center().x()))
continue; // not left of current or more left then found next
} else if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Right)) {
if (x <= screens[curScreen].center().x() || (curScreen != nextScreen && x >= screens[nextScreen].center().x()))
continue; // not right of current or more right then found next
}
nextScreen = i;
}
if (nextScreen == curScreen) {
mode = QuickTileFlag::None; // No other screens, toggle tiling
} else {
// Move to other screen
setGeometry(geometryRestore().translated(screens[nextScreen].topLeft() - screens[curScreen].topLeft()));
whichScreen = screens[nextScreen].center();
// Swap sides
if (mode & QuickTileFlag::Horizontal) {
mode = (~mode & QuickTileFlag::Horizontal) | (mode & QuickTileFlag::Vertical);
}
}
setElectricBorderMode(mode); // used by ::electricBorderMaximizeGeometry(.)
} else if (quickTileMode() == QuickTileMode(QuickTileFlag::None)) {
// Not coming out of an existing tile, not shifting monitors, we're setting a brand new tile.
// Store geometry first, so we can go out of this tile later.
setGeometryRestore(geometry());
}
if (mode != QuickTileMode(QuickTileFlag::None)) {
m_quickTileMode = mode;
// decorations may turn off some borders when tiled
const ForceGeometry_t geom_mode = isDecorated() ? ForceGeometrySet : NormalGeometrySet;
// Temporary, so the maximize code doesn't get all confused
m_quickTileMode = int(QuickTileFlag::None);
setGeometry(electricBorderMaximizeGeometry(whichScreen, desktop()), geom_mode);
}
// Store the mode change
m_quickTileMode = mode;
}
if (mode == QuickTileMode(QuickTileFlag::None)) {
TabSynchronizer syncer(this, TabGroup::QuickTile|TabGroup::Geometry);
m_quickTileMode = int(QuickTileFlag::None);
// Untiling, so just restore geometry, and we're done.
if (!geometryRestore().isValid()) // invalid if we started maximized and wait for placement
setGeometryRestore(geometry());
// decorations may turn off some borders when tiled
const ForceGeometry_t geom_mode = isDecorated() ? ForceGeometrySet : NormalGeometrySet;
setGeometry(geometryRestore(), geom_mode);
checkWorkspacePosition(); // Just in case it's a different screen
}
emit quickTileModeChanged();
}
void AbstractClient::sendToScreen(int newScreen)
{
newScreen = rules()->checkScreen(newScreen);
if (isActive()) {
screens()->setCurrent(newScreen);
// might impact the layer of a fullscreen window
foreach (AbstractClient *cc, workspace()->allClientList()) {
if (cc->isFullScreen() && cc->screen() == newScreen) {
cc->updateLayer();
}
}
}
if (screen() == newScreen) // Don't use isOnScreen(), that's true even when only partially
return;
GeometryUpdatesBlocker blocker(this);
// operating on the maximized / quicktiled window would leave the old geom_restore behind,
// so we clear the state first
MaximizeMode maxMode = maximizeMode();
QuickTileMode qtMode = quickTileMode();
if (maxMode != MaximizeRestore)
maximize(MaximizeRestore);
if (qtMode != QuickTileMode(QuickTileFlag::None))
setQuickTileMode(QuickTileFlag::None, true);
QRect oldScreenArea = workspace()->clientArea(MaximizeArea, this);
QRect screenArea = workspace()->clientArea(MaximizeArea, newScreen, desktop());
// the window can have its center so that the position correction moves the new center onto
// the old screen, what will tile it where it is. Ie. the screen is not changed
// this happens esp. with electric border quicktiling
if (qtMode != QuickTileMode(QuickTileFlag::None))
keepInArea(oldScreenArea);
QRect oldGeom = geometry();
QRect newGeom = oldGeom;
// move the window to have the same relative position to the center of the screen
// (i.e. one near the middle of the right edge will also end up near the middle of the right edge)
QPoint center = newGeom.center() - oldScreenArea.center();
center.setX(center.x() * screenArea.width() / oldScreenArea.width());
center.setY(center.y() * screenArea.height() / oldScreenArea.height());
center += screenArea.center();
newGeom.moveCenter(center);
setGeometry(newGeom);
// If the window was inside the old screen area, explicitly make sure its inside also the new screen area.
// Calling checkWorkspacePosition() should ensure that, but when moving to a small screen the window could
// be big enough to overlap outside of the new screen area, making struts from other screens come into effect,
// which could alter the resulting geometry.
if (oldScreenArea.contains(oldGeom)) {
keepInArea(screenArea);
}
// align geom_restore - checkWorkspacePosition operates on it
setGeometryRestore(geometry());
checkWorkspacePosition(oldGeom);
// re-align geom_restore to constrained geometry
setGeometryRestore(geometry());
// finally reset special states
// NOTICE that MaximizeRestore/QuickTileFlag::None checks are required.
// eg. setting QuickTileFlag::None would break maximization
if (maxMode != MaximizeRestore)
maximize(maxMode);
if (qtMode != QuickTileMode(QuickTileFlag::None) && qtMode != quickTileMode())
setQuickTileMode(qtMode, true);
auto tso = workspace()->ensureStackingOrder(transients());
for (auto it = tso.constBegin(), end = tso.constEnd(); it != end; ++it)
(*it)->sendToScreen(newScreen);
}
} // namespace
|