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
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Params = imports.misc.params;
const Main = imports.ui.main;
const AppDisplay = imports.ui.appDisplay;
const Dash = imports.ui.dash;
const Environment = imports.ui.environment;
const IconGrid = imports.ui.iconGrid;
const Overview = imports.ui.overview;
const OverviewControls = imports.ui.overviewControls;
const PointerWatcher = imports.ui.pointerWatcher;
const Signals = imports.signals;
const SearchController = imports.ui.searchController;
const WorkspaceSwitcherPopup= imports.ui.workspaceSwitcherPopup;
const Layout = imports.ui.layout;
const LayoutManager = imports.ui.main.layoutManager;
const Workspace = imports.ui.workspace;
const WorkspacesView = imports.ui.workspacesView;
const WorkspaceThumbnail = imports.ui.workspaceThumbnail;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const AppSpread = Me.imports.appSpread;
const Utils = Me.imports.utils;
const Intellihide = Me.imports.intellihide;
const Theming = Me.imports.theming;
const DockDash = Me.imports.dash;
const Locations = Me.imports.locations;
const LauncherAPI = Me.imports.launcherAPI;
const FileManager1API = Me.imports.fileManager1API;
const DesktopIconsIntegration = Me.imports.desktopIconsIntegration;
const DOCK_DWELL_CHECK_INTERVAL = 100;
const ICON_ANIMATOR_DURATION = 3000;
var State = {
HIDDEN: 0,
SHOWING: 1,
SHOWN: 2,
HIDING: 3
};
const scrollAction = {
DO_NOTHING: 0,
CYCLE_WINDOWS: 1,
SWITCH_WORKSPACE: 2
};
const Labels = Object.freeze({
INITIALIZE: Symbol('initialize'),
ISOLATION: Symbol('isolation'),
LOCATIONS: Symbol('locations'),
MAIN_DASH: Symbol('main-dash'),
OLD_DASH_CHANGES: Symbol('old-dash-changes'),
SETTINGS: Symbol('settings'),
STARTUP_ANIMATION: Symbol('startup-animation'),
WORKSPACE_SWITCH_SCROLL: Symbol('workspace-switch-scroll'),
});
/**
* A simple St.Widget with one child whose allocation takes into account the
* slide out of its child via the slide-x property ([0:1]).
*
* Required since I want to track the input region of this container which is
* based on its allocation even if the child overlows the parent actor. By doing
* this the region of the dash that is slideout is not steling anymore the input
* regions making the extesion usable when the primary monitor is the right one.
*
* The slide-x parameter can be used to directly animate the sliding. The parent
* must have a WEST (SOUTH) anchor_point to achieve the sliding to the RIGHT (BOTTOM)
* side.
*/
var DashSlideContainer = GObject.registerClass({
Properties: {
'monitor-index': GObject.ParamSpec.uint(
'monitor-index', 'monitor-index', 'monitor-index',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
0, GLib.MAXUINT32, 0),
'side': GObject.ParamSpec.enum(
'side', 'side', 'side',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
St.Side, St.Side.LEFT),
'slide-x': GObject.ParamSpec.double(
'slide-x', 'slide-x', 'slide-x',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
0, 1, 1),
}
}, class DashSlideContainer extends St.Bin {
_init(params = {}) {
super._init(params);
this._slideoutSize = 0; // minimum size when slided out
this.connect('notify::slide-x', () => this.queue_relayout());
if (this.side == St.Side.TOP && DockManager.settings.dockFixed) {
this._signalsHandler = new Utils.GlobalSignalsHandler(this);
this._signalsHandler.add(Main.panel, 'notify::height',
() => this.queue_relayout());
}
}
vfunc_allocate(box) {
let contentBox = this.get_theme_node().get_content_box(box);
this.set_allocation(box);
if (this.child == null)
return;
let availWidth = contentBox.x2 - contentBox.x1;
let availHeight = contentBox.y2 - contentBox.y1;
let [, , natChildWidth, natChildHeight] =
this.child.get_preferred_size();
let childWidth = natChildWidth;
let childHeight = natChildHeight;
let childBox = new Clutter.ActorBox();
let slideoutSize = this._slideoutSize;
if (this.side == St.Side.LEFT) {
childBox.x1 = (this.slideX -1) * (childWidth - slideoutSize);
childBox.x2 = slideoutSize + this.slideX * (childWidth - slideoutSize);
childBox.y1 = 0;
childBox.y2 = childBox.y1 + childHeight;
}
else if ((this.side == St.Side.RIGHT) || (this.side == St.Side.BOTTOM)) {
childBox.x1 = 0;
childBox.x2 = childWidth;
childBox.y1 = 0;
childBox.y2 = childBox.y1 + childHeight;
}
else if (this.side == St.Side.TOP) {
const monitor = Main.layoutManager.monitors[this.monitorIndex];
let yOffset = 0;
if (Main.panel.x === monitor.x && Main.panel.y === monitor.y &&
DockManager.settings.dockFixed)
yOffset = Main.panel.height;
childBox.x1 = 0;
childBox.x2 = childWidth;
childBox.y1 = (this.slideX - 1) * (childHeight - slideoutSize) + yOffset;
childBox.y2 = slideoutSize + this.slideX * (childHeight - slideoutSize) + yOffset;
availHeight += yOffset;
}
this.child.allocate(childBox);
this.child.set_clip(-childBox.x1, -childBox.y1,
-childBox.x1+availWidth, -childBox.y1 + availHeight);
}
/**
* Just the child width but taking into account the slided out part
*/
vfunc_get_preferred_width(forHeight) {
let [minWidth, natWidth] = super.vfunc_get_preferred_width((forHeight || 0));
if ((this.side == St.Side.LEFT) || (this.side == St.Side.RIGHT)) {
minWidth = (minWidth - this._slideoutSize) * this.slideX + this._slideoutSize;
natWidth = (natWidth - this._slideoutSize) * this.slideX + this._slideoutSize;
}
return [minWidth, natWidth];
}
/**
* Just the child height but taking into account the slided out part
*/
vfunc_get_preferred_height(forWidth) {
let [minHeight, natHeight] = super.vfunc_get_preferred_height((forWidth || 0));
if ((this.side == St.Side.TOP) || (this.side == St.Side.BOTTOM)) {
minHeight = (minHeight - this._slideoutSize) * this.slideX + this._slideoutSize;
natHeight = (natHeight - this._slideoutSize) * this.slideX + this._slideoutSize;
if (this.side == St.Side.TOP && DockManager.settings.dockFixed) {
const monitor = Main.layoutManager.monitors[this.monitorIndex];
if (Main.panel.x === monitor.x && Main.panel.y === monitor.y) {
minHeight += Main.panel.height;
natHeight += Main.panel.height;
}
}
}
return [minHeight, natHeight];
}
});
var DockedDash = GObject.registerClass({
Properties: {
'is-main': GObject.ParamSpec.boolean(
'is-main', 'is-main', 'is-main',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
false),
'monitor-index': GObject.ParamSpec.uint(
'monitor-index', 'monitor-index', 'monitor-index',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
0, GLib.MAXUINT32, 0),
},
Signals: {
'showing': {},
'hiding': {},
}
}, class DashToDock extends St.Bin {
_init(params) {
this._position = Utils.getPosition();
// This is the centering actor
super._init({
...params,
name: 'dashtodockContainer',
reactive: false,
style_class: Theming.PositionStyleClass[this._position],
});
if (this.monitorIndex === undefined) {
// Hello turkish locale, gjs has instead defined this.monitorİndex
// See: https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/742
this.monitorIndex = this.monitor_index;
}
this._rtl = (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL);
// Load settings
let settings = DockManager.settings;
this._isHorizontal = ((this._position == St.Side.TOP) || (this._position == St.Side.BOTTOM));
// Temporary ignore hover events linked to autohide for whatever reason
this._ignoreHover = false;
this._oldignoreHover = null;
// This variables are linked to the settings regardles of autohide or intellihide
// being temporary disable. Get set by _updateVisibilityMode;
this._autohideIsEnabled = null;
this._intellihideIsEnabled = null;
// Create intellihide object to monitor windows overlapping
this._intellihide = new Intellihide.Intellihide(this.monitorIndex);
// initialize dock state
this._dockState = State.HIDDEN;
// Put dock on the required monitor
this._monitor = Main.layoutManager.monitors[this.monitorIndex];
// this store size and the position where the dash is shown;
// used by intellihide module to check window overlap.
this.staticBox = new Clutter.ActorBox();
// Initialize pressure barrier variables
this._canUsePressure = false;
this._pressureBarrier = null;
this._barrier = null;
this._removeBarrierTimeoutId = 0;
// Initialize dwelling system variables
this._dockDwelling = false;
this._dockWatch = null;
this._dockDwellUserTime = 0;
this._dockDwellTimeoutId = 0
// Create a new dash object
this.dash = new DockDash.DockDash(this.monitorIndex);
if (Main.overview.isDummy || !settings.showShowAppsButton)
this.dash.hideShowAppsButton();
// Create the containers for sliding in and out and
// centering, turn on track hover
// This is the sliding actor whose allocation is to be tracked for input regions
this._slider = new DashSlideContainer({
monitor_index: this._monitor.index,
side: this._position,
slide_x: Main.layoutManager._startingUp ? 0 : 1,
...(this._isHorizontal ? {
x_align: Clutter.ActorAlign.CENTER,
} : {
y_align: Clutter.ActorAlign.CENTER,
})
});
// This is the actor whose hover status us tracked for autohide
this._box = new St.BoxLayout({
name: 'dashtodockBox',
reactive: true,
track_hover: true
});
this._box.connect('notify::hover', this._hoverChanged.bind(this));
// Connect global signals
this._signalsHandler = new Utils.GlobalSignalsHandler(this);
this._bindSettingsChanges();
this._signalsHandler.add([
// update when workarea changes, for instance if other extensions modify the struts
//(like moving th panel at the bottom)
global.display,
'workareas-changed',
this._resetPosition.bind(this)
], [
global.display,
'in-fullscreen-changed',
this._updateBarrier.bind(this)
], [
// Monitor windows overlapping
this._intellihide,
'status-changed',
this._updateDashVisibility.bind(this)
], [
this.dash,
'menu-opened',
() => { this._onMenuOpened() }
], [
// sync hover after a popupmenu is closed
this.dash,
'menu-closed',
() => { this._onMenuClosed() }
], [
this.dash,
'notify::requires-visibility',
() => this._updateDashVisibility(),
]);
if (!Main.overview.isDummy) {
this._signalsHandler.add([
Main.overview,
'item-drag-begin',
this._onDragStart.bind(this)
], [
Main.overview,
'item-drag-end',
this._onDragEnd.bind(this)
], [
Main.overview,
'item-drag-cancelled',
this._onDragEnd.bind(this)
], [
Main.overview,
'showing',
this._onOverviewShowing.bind(this)
], [
Main.overview,
'hiding',
this._onOverviewHiding.bind(this)
],
[
Main.overview,
'hidden',
this._onOverviewHidden.bind(this)
]);
}
this._themeManager = new Theming.ThemeManager(this);
this._signalsHandler.add(this._themeManager, 'updated',
() => this.dash.resetAppIcons());
this._signalsHandler.add(DockManager.iconTheme, 'changed',
() => this.dash.resetAppIcons());
// Since the actor is not a topLevel child and its parent is now not added to the Chrome,
// the allocation change of the parent container (slide in and slideout) doesn't trigger
// anymore an update of the input regions. Force the update manually.
this.connect('notify::allocation',
Main.layoutManager._queueUpdateRegions.bind(Main.layoutManager));
// Since Clutter has no longer ClutterAllocationFlags,
// "allocation-changed" signal has been removed. MR !1245
this.dash._container.connect('notify::allocation', this._updateStaticBox.bind(this));
this._slider.connect(this._isHorizontal ? 'notify::x' : 'notify::y', this._updateStaticBox.bind(this));
// Load optional features that need to be activated for one dock only
if (this.isMain)
this._enableExtraFeatures();
// Load optional features that need to be activated once per dock
this._optionalScrollWorkspaceSwitch();
// Delay operations that require the shell to be fully loaded and with
// user theme applied.
this._signalsHandler.addWithLabel(Labels.INITIALIZE, global.stage,
'after-paint', () => this._initialize());
// Add dash container actor and the container to the Chrome.
this.set_child(this._slider);
this._slider.set_child(this._box);
this._box.add_actor(this.dash);
// Add aligning container without tracking it for input region
Main.uiGroup.add_child(this);
if (Main.uiGroup.contains(global.top_window_group))
Main.uiGroup.set_child_below_sibling(this, global.top_window_group);
if (settings.dockFixed) {
// Note: tracking the fullscreen directly on the slider actor causes some hiccups when fullscreening
// windows of certain applications
Main.layoutManager._trackActor(this, {affectsInputRegion: false, trackFullscreen: true});
Main.layoutManager._trackActor(this._slider, {affectsStruts: true});
}
else
Main.layoutManager._trackActor(this._slider);
// Create and apply height/width constraint to the dash.
if (this._isHorizontal) {
this.connect('notify::width', () => {
this.dash.setMaxSize(this.width, this.height);
});
} else {
this.connect('notify::height', () => {
this.dash.setMaxSize(this.width, this.height)
});
}
if (this._position == St.Side.RIGHT)
this.connect('notify::width', () => this.translation_x = -this.width);
else if (this._position == St.Side.BOTTOM)
this.connect('notify::height', () => this.translation_y = -this.height);
// Set initial position
this._resetPosition();
this.connect('destroy', this._onDestroy.bind(this));
}
get position() {
return this._position;
}
get isHorizontal() {
return this._isHorizontal;
}
_untrackDock() {
Main.layoutManager._untrackActor(this);
Main.layoutManager._untrackActor(this._slider);
}
_trackDock() {
if (DockManager.settings.dockFixed) {
if (Main.layoutManager._findActor(this) == -1)
Main.layoutManager._trackActor(this, { affectsInputRegion: false, trackFullscreen: true });
if (Main.layoutManager._findActor(this._slider) == -1)
Main.layoutManager._trackActor(this._slider, { affectsStruts: true });
} else {
if (Main.layoutManager._findActor(this._slider) == -1)
Main.layoutManager._trackActor(this._slider);
}
}
_initialize() {
this._signalsHandler.removeWithLabel(Labels.INITIALIZE);
// Apply custome css class according to the settings
this._themeManager.updateCustomTheme();
this._updateVisibilityMode();
// In case we are already inside the overview when the extension is loaded,
// for instance on unlocking the screen if it was locked with the overview open.
if (Main.overview.visibleTarget) {
this._onOverviewShowing();
}
this._updateAutoHideBarriers();
}
_onDestroy() {
// The dash, intellihide and themeManager have global signals as well internally
this.dash.destroy();
this._intellihide.destroy();
this._themeManager.destroy();
if (this._marginLater) {
Meta.later_remove(this._marginLater);
delete this._marginLater;
}
// Remove barrier timeout
if (this._removeBarrierTimeoutId > 0)
GLib.source_remove(this._removeBarrierTimeoutId);
// Remove existing barrier
this._removeBarrier();
// Remove pointer watcher
if (this._dockWatch) {
PointerWatcher.getPointerWatcher()._removeWatch(this._dockWatch);
this._dockWatch = null;
}
}
_updateAutoHideBarriers() {
// Remove pointer watcher
if (this._dockWatch) {
PointerWatcher.getPointerWatcher()._removeWatch(this._dockWatch);
this._dockWatch = null;
}
// Setup pressure barrier (GS38+ only)
this._updatePressureBarrier();
this._updateBarrier();
// setup dwelling system if pressure barriers are not available
this._setupDockDwellIfNeeded();
}
_bindSettingsChanges() {
let settings = DockManager.settings;
this._signalsHandler.add([
settings,
'changed::scroll-action',
() => { this._optionalScrollWorkspaceSwitch(); }
], [
settings,
'changed::dash-max-icon-size',
() => { this.dash.setIconSize(settings.dashMaxIconSize); }
], [
settings,
'changed::icon-size-fixed',
() => { this.dash.setIconSize(settings.dashMaxIconSize); }
], [
settings,
'changed::show-favorites',
() => { this.dash.resetAppIcons(); }
], [
settings,
'changed::show-trash',
() => { this.dash.resetAppIcons(); },
Utils.SignalsHandlerFlags.CONNECT_AFTER,
], [
settings,
'changed::show-mounts',
() => { this.dash.resetAppIcons(); },
Utils.SignalsHandlerFlags.CONNECT_AFTER
], [
settings,
'changed::isolate-locations',
() => this.dash.resetAppIcons(),
Utils.SignalsHandlerFlags.CONNECT_AFTER
], [
settings,
'changed::show-running',
() => { this.dash.resetAppIcons(); }
], [
settings,
'changed::show-apps-at-top',
() => { this.dash.updateShowAppsButton(); }
], [
settings,
'changed::show-show-apps-button',
() => {
if (!Main.overview.isDummy &&
settings.showShowAppsButton)
this.dash.showShowAppsButton();
else
this.dash.hideShowAppsButton();
}
], [
settings,
'changed::dock-fixed',
() => {
this._untrackDock();
this._trackDock();
this._resetPosition();
this._updateAutoHideBarriers();
this._updateVisibilityMode();
}
], [
settings,
'changed::manualhide',
() => {
this._updateVisibilityMode();
}
], [
settings,
'changed::intellihide',
() => {
this._updateVisibilityMode();
this._updateVisibleDesktop();
}
], [
settings,
'changed::intellihide-mode',
() => { this._intellihide.forceUpdate(); }
], [
settings,
'changed::autohide',
() => {
this._updateVisibilityMode();
this._updateAutoHideBarriers();
}
], [
settings,
'changed::autohide-in-fullscreen',
this._updateBarrier.bind(this)
], [
settings,
'changed::show-dock-urgent-notify',
() => {
this.dash.resetAppIcons(); }
],
[
settings,
'changed::extend-height',
this._resetPosition.bind(this)
], [
settings,
'changed::height-fraction',
this._resetPosition.bind(this)
], [
settings,
'changed::require-pressure-to-show',
() => this._updateAutoHideBarriers(),
], [
settings,
'changed::pressure-threshold',
() => {
this._updatePressureBarrier();
this._updateBarrier();
}
]);
}
/**
* This is call when visibility settings change
*/
_updateVisibilityMode() {
let settings = DockManager.settings;
if (DockManager.settings.dockFixed || DockManager.settings.manualhide) {
this._autohideIsEnabled = false;
this._intellihideIsEnabled = false;
}
else {
this._autohideIsEnabled = settings.autohide
this._intellihideIsEnabled = settings.intellihide
}
if (this._autohideIsEnabled)
this.add_style_class_name('autohide');
else
this.remove_style_class_name('autohide');
if (this._intellihideIsEnabled)
this._intellihide.enable();
else
this._intellihide.disable();
this._updateDashVisibility();
}
/**
* Show/hide dash based on, in order of priority:
* overview visibility
* fixed mode
* intellihide
* autohide
* overview visibility
*/
_updateDashVisibility() {
if (DockManager.settings.manualhide) {
this._ignoreHover = true;
this._removeAnimations();
this._animateOut(0, 0);
return;
}
if (Main.overview.visibleTarget)
return;
let settings = DockManager.settings;
if (DockManager.settings.dockFixed) {
this._removeAnimations();
this._animateIn(settings.animationTime, 0);
}
else if (this._intellihideIsEnabled) {
if (!this.dash.requiresVisibility && this._intellihide.getOverlapStatus()) {
this._ignoreHover = false;
// Do not hide if autohide is enabled and mouse is hover
if (!this._box.hover || !this._autohideIsEnabled)
this._animateOut(settings.animationTime, 0);
}
else {
this._ignoreHover = true;
this._removeAnimations();
this._animateIn(settings.animationTime, 0);
}
}
else {
if (this._autohideIsEnabled) {
this._ignoreHover = false;
if (this._box.hover || this.dash.requiresVisibility)
this._animateIn(settings.animationTime, 0);
else
this._animateOut(settings.animationTime, 0);
}
else
this._animateOut(settings.animationTime, 0);
}
}
_onOverviewShowing() {
this.add_style_class_name('overview');
this._ignoreHover = true;
this._intellihide.disable();
this._removeAnimations();
this._animateIn(DockManager.settings.animationTime, 0);
}
_onOverviewHiding() {
this._intellihide.enable();
this._updateDashVisibility();
}
_onOverviewHidden() {
this.remove_style_class_name('overview');
}
_onMenuOpened() {
this._ignoreHover = true;
}
_onMenuClosed() {
this._ignoreHover = false;
this._box.sync_hover();
this._updateDashVisibility();
}
_hoverChanged() {
if (!this._ignoreHover) {
// Skip if dock is not in autohide mode for instance because it is shown
// by intellihide.
if (this._autohideIsEnabled) {
if (this._box.hover || Main.overview.visible)
this._show();
else
this._hide();
}
}
}
getDockState() {
return this._dockState;
}
_show() {
this._delayedHide = false;
if ((this._dockState == State.HIDDEN) || (this._dockState == State.HIDING)) {
if (this._dockState == State.HIDING)
// suppress all potential queued transitions - i.e. added but not started,
// always give priority to show
this._removeAnimations();
this.emit('showing');
this._animateIn(DockManager.settings.animationTime, 0);
}
}
_hide() {
// If no hiding animation is running or queued
if ((this._dockState == State.SHOWN) || (this._dockState == State.SHOWING)) {
let settings = DockManager.settings;
let delay = settings.hideDelay;
if (this._dockState == State.SHOWING) {
// if a show already started, let it finish; queue hide without removing the show.
// to obtain this, we wait for the animateIn animation to be completed
this._delayedHide = true;
return;
}
this.emit('hiding');
this._animateOut(settings.animationTime, delay);
}
}
_animateIn(time, delay) {
this._dockState = State.SHOWING;
this.dash.iconAnimator.start();
this._delayedHide = false;
this._slider.ease_property('slide-x', 1, {
duration: time * 1000,
delay: delay * 1000,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._dockState = State.SHOWN;
// Remove barrier so that mouse pointer is released and can access monitors on other side of dock
// NOTE: Delay needed to keep mouse from moving past dock and re-hiding dock immediately. This
// gives users an opportunity to hover over the dock
if (this._removeBarrierTimeoutId > 0)
GLib.source_remove(this._removeBarrierTimeoutId);
if (!this._delayedHide) {
this._removeBarrierTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT, 100, this._removeBarrier.bind(this));
} else {
this._hide();
}
}
});
}
_animateOut(time, delay) {
this._dockState = State.HIDING;
this._slider.ease_property('slide-x', 0, {
duration: time * 1000,
delay: delay * 1000,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._dockState = State.HIDDEN;
// Remove queued barried removal if any
if (this._removeBarrierTimeoutId > 0)
GLib.source_remove(this._removeBarrierTimeoutId);
this._updateBarrier();
this.dash.iconAnimator.pause();
}
});
}
/**
* Dwelling system based on the GNOME Shell 3.14 messageTray code.
*/
_setupDockDwellIfNeeded() {
// If we don't have extended barrier features, then we need
// to support the old tray dwelling mechanism.
if (this._autohideIsEnabled &&
(!global.display.supports_extended_barriers() ||
!DockManager.settings.requirePressureToShow)) {
let pointerWatcher = PointerWatcher.getPointerWatcher();
this._dockWatch = pointerWatcher.addWatch(DOCK_DWELL_CHECK_INTERVAL, this._checkDockDwell.bind(this));
this._dockDwelling = false;
this._dockDwellUserTime = 0;
}
}
_checkDockDwell(x, y) {
let workArea = Main.layoutManager.getWorkAreaForMonitor(this._monitor.index)
let shouldDwell;
// Check for the correct screen edge, extending the sensitive area to the whole workarea,
// minus 1 px to avoid conflicting with other active corners.
if (this._position == St.Side.LEFT)
shouldDwell = (x == this._monitor.x) && (y > workArea.y) && (y < workArea.y + workArea.height);
else if (this._position == St.Side.RIGHT)
shouldDwell = (x == this._monitor.x + this._monitor.width - 1) && (y > workArea.y) && (y < workArea.y + workArea.height);
else if (this._position == St.Side.TOP)
shouldDwell = (y == this._monitor.y) && (x > workArea.x) && (x < workArea.x + workArea.width);
else if (this._position == St.Side.BOTTOM)
shouldDwell = (y == this._monitor.y + this._monitor.height - 1) && (x > workArea.x) && (x < workArea.x + workArea.width);
if (shouldDwell) {
// We only set up dwell timeout when the user is not hovering over the dock
// already (!this._box.hover).
// The _dockDwelling variable is used so that we only try to
// fire off one dock dwell - if it fails (because, say, the user has the mouse down),
// we don't try again until the user moves the mouse up and down again.
if (!this._dockDwelling && !this._box.hover && (this._dockDwellTimeoutId == 0)) {
// Save the interaction timestamp so we can detect user input
let focusWindow = global.display.focus_window;
this._dockDwellUserTime = focusWindow ? focusWindow.user_time : 0;
this._dockDwellTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
DockManager.settings.showDelay * 1000,
this._dockDwellTimeout.bind(this));
GLib.Source.set_name_by_id(this._dockDwellTimeoutId, '[dash-to-dock] this._dockDwellTimeout');
}
this._dockDwelling = true;
}
else {
this._cancelDockDwell();
this._dockDwelling = false;
}
}
_cancelDockDwell() {
if (this._dockDwellTimeoutId != 0) {
GLib.source_remove(this._dockDwellTimeoutId);
this._dockDwellTimeoutId = 0;
}
}
_dockDwellTimeout() {
this._dockDwellTimeoutId = 0;
if (!DockManager.settings.autohideInFullscreen &&
this._monitor.inFullscreen)
return GLib.SOURCE_REMOVE;
// We don't want to open the tray when a modal dialog
// is up, so we check the modal count for that. When we are in the
// overview we have to take the overview's modal push into account
if (Main.modalCount > (Main.overview.visible ? 1 : 0))
return GLib.SOURCE_REMOVE;
// If the user interacted with the focus window since we started the tray
// dwell (by clicking or typing), don't activate the message tray
let focusWindow = global.display.focus_window;
let currentUserTime = focusWindow ? focusWindow.user_time : 0;
if (currentUserTime != this._dockDwellUserTime)
return GLib.SOURCE_REMOVE;
// Reuse the pressure version function, the logic is the same
this._onPressureSensed();
return GLib.SOURCE_REMOVE;
}
_updatePressureBarrier() {
let settings = DockManager.settings;
this._canUsePressure = global.display.supports_extended_barriers();
let pressureThreshold = settings.pressureThreshold;
// Remove existing pressure barrier
if (this._pressureBarrier) {
this._pressureBarrier.destroy();
this._pressureBarrier = null;
}
if (this._barrier) {
this._barrier.destroy();
this._barrier = null;
}
// Create new pressure barrier based on pressure threshold setting
if (this._canUsePressure && this._autohideIsEnabled &&
DockManager.settings.requirePressureToShow) {
this._pressureBarrier = new Layout.PressureBarrier(pressureThreshold, settings.showDelay*1000,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW);
this._pressureBarrier.connect('trigger', (barrier) => {
if (!settings.autohideInFullscreen && this._monitor.inFullscreen)
return;
this._onPressureSensed();
});
}
}
/**
* handler for mouse pressure sensed
*/
_onPressureSensed() {
if (Main.overview.visibleTarget)
return;
// In case the mouse move away from the dock area before hovering it, in such case the leave event
// would never be triggered and the dock would stay visible forever.
let triggerTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 250, () => {
triggerTimeoutId = 0;
let [x, y, mods] = global.get_pointer();
let shouldHide = true;
switch (this._position) {
case St.Side.LEFT:
if (x <= this.staticBox.x2 &&
x >= this._monitor.x &&
y >= this._monitor.y &&
y <= this._monitor.y + this._monitor.height) {
shouldHide = false;
}
break;
case St.Side.RIGHT:
if (x >= this.staticBox.x1 &&
x <= this._monitor.x + this._monitor.width &&
y >= this._monitor.y &&
y <= this._monitor.y + this._monitor.height) {
shouldHide = false;
}
break;
case St.Side.TOP:
if (x >= this._monitor.x &&
x <= this._monitor.x + this._monitor.width &&
y <= this.staticBox.y2 &&
y >= this._monitor.y) {
shouldHide = false;
}
break;
case St.Side.BOTTOM:
if (x >= this._monitor.x &&
x <= this._monitor.x + this._monitor.width &&
y >= this.staticBox.y1 &&
y <= this._monitor.y + this._monitor.height) {
shouldHide = false;
}
}
if (shouldHide) {
this._hoverChanged();
return GLib.SOURCE_REMOVE;
}
else {
return GLib.SOURCE_CONTINUE;
}
});
this._show();
}
/**
* Remove pressure barrier
*/
_removeBarrier() {
if (this._barrier) {
if (this._pressureBarrier)
this._pressureBarrier.removeBarrier(this._barrier);
this._barrier.destroy();
this._barrier = null;
}
this._removeBarrierTimeoutId = 0;
return false;
}
/**
* Update pressure barrier size
*/
_updateBarrier() {
// Remove existing barrier
this._removeBarrier();
// The barrier needs to be removed in fullscreen with autohide disabled, otherwise the mouse can
// get trapped on monitor.
if (this._monitor.inFullscreen &&
!DockManager.settings.autohideInFullscreen)
return
// Manually reset pressure barrier
// This is necessary because we remove the pressure barrier when it is triggered to show the dock
if (this._pressureBarrier) {
this._pressureBarrier._reset();
this._pressureBarrier._isTriggered = false;
}
// Create new barrier
// The barrier extends to the whole workarea, minus 1 px to avoid conflicting with other active corners
// Note: dash in fixed position doesn't use pressure barrier.
if (this._canUsePressure && this._autohideIsEnabled &&
DockManager.settings.requirePressureToShow) {
let x1, x2, y1, y2, direction;
let workArea = Main.layoutManager.getWorkAreaForMonitor(this._monitor.index)
if (this._position == St.Side.LEFT) {
x1 = this._monitor.x + 1;
x2 = x1;
y1 = workArea.y + 1;
y2 = workArea.y + workArea.height - 1;
direction = Meta.BarrierDirection.POSITIVE_X;
}
else if (this._position == St.Side.RIGHT) {
x1 = this._monitor.x + this._monitor.width - 1;
x2 = x1;
y1 = workArea.y + 1;
y2 = workArea.y + workArea.height - 1;
direction = Meta.BarrierDirection.NEGATIVE_X;
}
else if (this._position == St.Side.TOP) {
x1 = workArea.x + 1;
x2 = workArea.x + workArea.width - 1;
y1 = this._monitor.y;
y2 = y1;
direction = Meta.BarrierDirection.POSITIVE_Y;
}
else if (this._position == St.Side.BOTTOM) {
x1 = workArea.x + 1;
x2 = workArea.x + workArea.width - 1;
y1 = this._monitor.y + this._monitor.height;
y2 = y1;
direction = Meta.BarrierDirection.NEGATIVE_Y;
}
if (this._pressureBarrier && this._dockState == State.HIDDEN) {
this._barrier = new Meta.Barrier({
display: global.display,
x1: x1,
x2: x2,
y1: y1,
y2: y2,
directions: direction
});
this._pressureBarrier.addBarrier(this._barrier);
}
}
}
_isPrimaryMonitor() {
return (this.monitorIndex === Main.layoutManager.primaryIndex);
}
_resetPosition() {
// Ensure variables linked to settings are updated.
this._updateVisibilityMode();
const { dockFixed: fixedIsEnabled, dockExtended: extendHeight } = DockManager.settings;
if (fixedIsEnabled) {
this.add_style_class_name('fixed');
} else {
this.remove_style_class_name('fixed');
}
// Note: do not use the workarea coordinates in the direction on which the dock is placed,
// to avoid a loop [position change -> workArea change -> position change] with
// fixed dock.
let workArea = Main.layoutManager.getWorkAreaForMonitor(this.monitorIndex);
let fraction = DockManager.settings.heightFraction;
if (extendHeight)
fraction = 1;
else if ((fraction < 0) || (fraction > 1))
fraction = 0.95;
if (this._isHorizontal) {
this.width = Math.round(fraction * workArea.width);
let pos_y = this._monitor.y;
if (this._position == St.Side.BOTTOM)
pos_y += this._monitor.height;
this.x = workArea.x + Math.round((1 - fraction) / 2 * workArea.width);
this.y = pos_y;
if (extendHeight) {
this.dash._container.set_width(this.width);
this.add_style_class_name('extended');
} else {
this.dash._container.set_width(-1);
this.remove_style_class_name('extended');
}
} else {
this.height = Math.round(fraction * workArea.height);
let pos_x = this._monitor.x;
if (this._position == St.Side.RIGHT)
pos_x += this._monitor.width;
this.x = pos_x;
this.y = workArea.y + Math.round((1 - fraction) / 2 * workArea.height);
if (extendHeight) {
this.dash._container.set_height(this.height);
this.add_style_class_name('extended');
} else {
this.dash._container.set_height(-1);
this.remove_style_class_name('extended');
}
}
}
_updateVisibleDesktop() {
if (!this._intellihideIsEnabled)
return;
const { desktopIconsUsableArea } = DockManager.getDefault();
if (this._position === St.Side.BOTTOM)
desktopIconsUsableArea.setMargins(this.monitorIndex, 0, this._box.height, 0, 0);
else if (this._position === St.Side.TOP)
desktopIconsUsableArea.setMargins(this.monitorIndex, this._box.height, 0, 0, 0);
else if (this._position === St.Side.RIGHT)
desktopIconsUsableArea.setMargins(this.monitorIndex, 0, 0, 0, this._box.width);
else if (this._position === St.Side.LEFT)
desktopIconsUsableArea.setMargins(this.monitorIndex, 0, 0, this._box.width, 0);
}
_updateStaticBox() {
this.staticBox.init_rect(
this.x + this._slider.x - (this._position == St.Side.RIGHT ? this._box.width : 0),
this.y + this._slider.y - (this._position == St.Side.BOTTOM ? this._box.height : 0),
this._box.width,
this._box.height
);
this._intellihide.updateTargetBox(this.staticBox);
this._updateVisibleDesktop();
}
_removeAnimations() {
this._slider.remove_all_transitions();
}
_onDragStart() {
this._oldignoreHover = this._ignoreHover;
this._ignoreHover = true;
this._animateIn(DockManager.settings.animationTime, 0);
}
_onDragEnd() {
if (this._oldignoreHover !== null)
this._ignoreHover = this._oldignoreHover;
this._oldignoreHover = null;
this._box.sync_hover();
}
/**
* Show dock and give key focus to it
*/
_onAccessibilityFocus() {
this._box.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
this._animateIn(DockManager.settings.animationTime, 0);
}
// Optional features to be enabled only for the main Dock
_enableExtraFeatures() {
// Restore dash accessibility
Main.ctrlAltTabManager.addGroup(
this.dash, _('Dash'), 'user-bookmarks-symbolic',
{focusCallback: this._onAccessibilityFocus.bind(this)});
}
/**
* Switch workspace by scrolling over the dock
*/
_optionalScrollWorkspaceSwitch() {
function isEnabled() {
return DockManager.settings.scrollAction === scrollAction.SWITCH_WORKSPACE;
}
DockManager.settings.connect('changed::scroll-action', () => {
if (isEnabled.bind(this)())
enable.bind(this)();
else
disable.bind(this)();
});
if (isEnabled.bind(this)())
enable.bind(this)();
function enable() {
this._signalsHandler.removeWithLabel(Labels.WORKSPACE_SWITCH_SCROLL);
this._signalsHandler.addWithLabel(Labels.WORKSPACE_SWITCH_SCROLL,
this._box,
'scroll-event',
onScrollEvent.bind(this));
}
function disable() {
this._signalsHandler.removeWithLabel(Labels.WORKSPACE_SWITCH_SCROLL);
if (this._optionalScrollWorkspaceSwitchDeadTimeId) {
GLib.source_remove(this._optionalScrollWorkspaceSwitchDeadTimeId);
this._optionalScrollWorkspaceSwitchDeadTimeId = 0;
}
}
// This was inspired to desktop-scroller@obsidien.github.com
function onScrollEvent(actor, event) {
// When in overview change workspace only in windows view
if (Main.overview.visible)
return false;
let activeWs = global.workspace_manager.get_active_workspace();
let direction = null;
let prev_direction, next_direction;
if (global.workspace_manager.layout_columns > global.workspace_manager.layout_rows) {
prev_direction = Meta.MotionDirection.UP;
next_direction = Meta.MotionDirection.DOWN;
} else {
prev_direction = Meta.MotionDirection.LEFT;
next_direction = Meta.MotionDirection.RIGHT;
}
switch (event.get_scroll_direction()) {
case Clutter.ScrollDirection.UP:
direction = prev_direction;
break;
case Clutter.ScrollDirection.DOWN:
direction = next_direction;
break;
case Clutter.ScrollDirection.SMOOTH: {
let [dx, dy] = event.get_scroll_delta();
if (dy < 0)
direction = prev_direction;
else if (dy > 0)
direction = next_direction;
}
break;
}
if (direction !== null) {
// Prevent scroll events from triggering too many workspace switches
// by adding a 250ms deadtime between each scroll event.
// Usefull on laptops when using a touchpad.
// During the deadtime do nothing
if (this._optionalScrollWorkspaceSwitchDeadTimeId)
return false;
else
this._optionalScrollWorkspaceSwitchDeadTimeId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT, 250, () => {
this._optionalScrollWorkspaceSwitchDeadTimeId = 0;
});
let ws;
ws = activeWs.get_neighbor(direction)
if (Main.wm._workspaceSwitcherPopup == null)
// Support Workspace Grid extension showing their custom Grid Workspace Switcher
if (global.workspace_manager.workspace_grid !== undefined) {
Main.wm._workspaceSwitcherPopup =
global.workspace_manager.workspace_grid.getWorkspaceSwitcherPopup();
} else {
Main.wm._workspaceSwitcherPopup = new WorkspaceSwitcherPopup.WorkspaceSwitcherPopup();
}
// Set the actor non reactive, so that it doesn't prevent the
// clicks events from reaching the dash actor. I can't see a reason
// why it should be reactive.
Main.wm._workspaceSwitcherPopup.reactive = false;
Main.wm._workspaceSwitcherPopup.connect('destroy', function() {
Main.wm._workspaceSwitcherPopup = null;
});
// If Workspace Grid is installed, let them handle the scroll behaviour.
if (global.workspace_manager.workspace_grid !== undefined)
ws = global.workspace_manager.workspace_grid.actionMoveWorkspace(direction);
else
Main.wm.actionMoveWorkspace(ws);
// Do not show workspaceSwitcher in overview
if (!Main.overview.visible)
Main.wm._workspaceSwitcherPopup.display(direction, ws.index());
return true;
}
else
return false;
}
}
_activateApp(appIndex) {
let children = this.dash._box.get_children().filter(function(actor) {
return actor.child &&
actor.child.app;
});
// Apps currently in the dash
let apps = children.map(function(actor) {
return actor.child;
});
// Activate with button = 1, i.e. same as left click
let button = 1;
if (appIndex < apps.length)
apps[appIndex].activate(button);
}
});
/*
* Handle keybaord shortcuts
*/
const DashToDock_KeyboardShortcuts_NUM_HOTKEYS = 10;
var KeyboardShortcuts = class DashToDock_KeyboardShortcuts {
constructor() {
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._hotKeysEnabled = false;
if (DockManager.settings.hotKeys)
this._enableHotKeys();
this._signalsHandler.add([
DockManager.settings,
'changed::hot-keys',
() => {
if (DockManager.settings.hotKeys)
this._enableHotKeys.bind(this)();
else
this._disableHotKeys.bind(this)();
}
]);
this._optionalNumberOverlay();
}
destroy() {
DockManager.allDocks.forEach(dock => {
if (dock._numberOverlayTimeoutId) {
GLib.source_remove(dock._numberOverlayTimeoutId);
dock._numberOverlayTimeoutId = 0;
}
});
// Remove keybindings
this._disableHotKeys();
this._disableExtraShortcut();
this._signalsHandler.destroy();
}
_enableHotKeys() {
if (this._hotKeysEnabled)
return;
// Setup keyboard bindings for dash elements
let keys = ['app-hotkey-', 'app-shift-hotkey-', 'app-ctrl-hotkey-'];
keys.forEach( function(key) {
for (let i = 0; i < DashToDock_KeyboardShortcuts_NUM_HOTKEYS; i++) {
let appNum = i;
Main.wm.addKeybinding(key + (i + 1), DockManager.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
() => {
DockManager.getDefault().mainDock._activateApp(appNum);
this._showOverlay();
});
}
}, this);
this._hotKeysEnabled = true;
}
_disableHotKeys() {
if (!this._hotKeysEnabled)
return;
let keys = ['app-hotkey-', 'app-shift-hotkey-', 'app-ctrl-hotkey-'];
keys.forEach( function(key) {
for (let i = 0; i < DashToDock_KeyboardShortcuts_NUM_HOTKEYS; i++)
Main.wm.removeKeybinding(key + (i + 1));
}, this);
this._hotKeysEnabled = false;
}
_optionalNumberOverlay() {
let settings = DockManager.settings;
this._shortcutIsSet = false;
// Enable extra shortcut if either 'overlay' or 'show-dock' are true
if (settings.hotKeys &&
(settings.hotkeysOverlay || settings.hotkeysShowDock))
this._enableExtraShortcut();
this._signalsHandler.add([
settings,
'changed::hot-keys',
this._checkHotkeysOptions.bind(this)
], [
settings,
'changed::hotkeys-overlay',
this._checkHotkeysOptions.bind(this)
], [
settings,
'changed::hotkeys-show-dock',
this._checkHotkeysOptions.bind(this)
]);
}
_checkHotkeysOptions() {
let settings = DockManager.settings;
if (settings.hotKeys &&
(settings.hotkeysOverlay || settings.hotkeysShowDock))
this._enableExtraShortcut();
else
this._disableExtraShortcut();
}
_enableExtraShortcut() {
if (!this._shortcutIsSet) {
Main.wm.addKeybinding('shortcut', DockManager.settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._showOverlay.bind(this));
this._shortcutIsSet = true;
}
}
_disableExtraShortcut() {
if (this._shortcutIsSet) {
Main.wm.removeKeybinding('shortcut');
this._shortcutIsSet = false;
}
}
_showOverlay() {
for (let dock of DockManager.allDocks) {
if (DockManager.settings.hotkeysOverlay)
dock.dash.toggleNumberOverlay(true);
// Restart the counting if the shortcut is pressed again
if (dock._numberOverlayTimeoutId) {
GLib.source_remove(dock._numberOverlayTimeoutId);
dock._numberOverlayTimeoutId = 0;
}
// Hide the overlay/dock after the timeout
let timeout = DockManager.settings.shortcutTimeout * 1000;
dock._numberOverlayTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT, timeout, () => {
dock._numberOverlayTimeoutId = 0;
dock.dash.toggleNumberOverlay(false);
// Hide the dock again if necessary
dock._updateDashVisibility();
});
// Show the dock if it is hidden
if (DockManager.settings.hotkeysShowDock) {
let showDock = (dock._intellihideIsEnabled || dock._autohideIsEnabled);
if (showDock)
dock._show();
}
}
}
};
/**
* Isolate overview to open new windows for inactive apps
* Note: the future implementaion is not fully contained here. Some bits are around in other methods of other classes.
* This class just take care of enabling/disabling the option.
*/
var WorkspaceIsolation = class DashToDock_WorkspaceIsolation {
constructor() {
let settings = DockManager.settings;
this._signalsHandler = new Utils.GlobalSignalsHandler();
this._injectionsHandler = new Utils.InjectionsHandler();
const updateAllDocks = () => {
DockManager.allDocks.forEach((dock) =>
dock.dash.resetAppIcons());
if (settings.isolateWorkspaces ||
settings.isolateMonitors)
this._enable.bind(this)();
else
this._disable.bind(this)();
};
this._signalsHandler.add(
[ settings, 'changed::isolate-workspaces', updateAllDocks ],
[ settings, 'changed::workspace-agnostic-urgent-windows', updateAllDocks ],
[ settings, 'changed::isolate-monitors', updateAllDocks ]
);
if (settings.isolateWorkspaces ||
settings.isolateMonitors)
this._enable();
}
_enable() {
// ensure I never double-register/inject
// although it should never happen
this._disable();
DockManager.allDocks.forEach((dock) => {
this._signalsHandler.addWithLabel(
Labels.ISOLATION,
[ global.display, 'restacked', () => dock.dash._queueRedisplay() ],
[ global.display, 'window-marked-urgent', () => dock.dash._queueRedisplay() ],
[ global.display, 'window-demands-attention', () => dock.dash._queueRedisplay() ],
[ global.window_manager, 'switch-workspace', () => dock.dash._queueRedisplay() ]
);
// This last signal is only needed for monitor isolation, as windows
// might migrate from one monitor to another without triggering 'restacked'
if (DockManager.settings.isolateMonitors)
this._signalsHandler.addWithLabel(Labels.ISOLATION,
global.display,
'window-entered-monitor',
dock.dash._queueRedisplay.bind(dock.dash));
}, this);
// here this is the Shell.App
function IsolatedOverview() {
// These lines take care of Nautilus for icons on Desktop
const activeWorkspaceIndex =
global.workspaceManager.get_active_workspace_index();
const windows = this.get_windows().filter(w =>
!w.skipTaskbar && w.get_workspace().index() === activeWorkspaceIndex);
if (windows.length)
return Main.activateWindow(windows[0]);
return this.open_new_window(-1);
}
this._injectionsHandler.addWithLabel(Labels.ISOLATION,
Shell.App.prototype,
'activate',
IsolatedOverview);
}
_disable () {
this._signalsHandler.removeWithLabel(Labels.ISOLATION);
this._injectionsHandler.removeWithLabel(Labels.ISOLATION);
}
destroy() {
this._signalsHandler.destroy();
this._injectionsHandler.destroy();
}
};
var DockManager = class DashToDock_DockManager {
constructor() {
if (Me.imports.extension.dockManager)
throw new Error('DashToDock has been already initialized');
Me.imports.extension.dockManager = this;
this._iconTheme = new Utils.IconTheme();
this._remoteModel = new LauncherAPI.LauncherEntryRemoteModel();
this._signalsHandler = new Utils.GlobalSignalsHandler(this);
this._methodInjections = new Utils.InjectionsHandler(this);
this._vfuncInjections = new Utils.VFuncInjectionsHandler(this);
this._propertyInjections = new Utils.PropertyInjectionsHandler(this);
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.dash-to-dock');
this._appSwitcherSettings = new Gio.Settings({ schema_id: 'org.gnome.shell.app-switcher' });
this._desktopIconsUsableArea = new DesktopIconsIntegration.DesktopIconsUsableAreaClass();
this._oldDash = Main.overview.isDummy ? null : Main.overview.dash;
this._discreteGpuAvailable = AppDisplay.discreteGpuAvailable;
this._appSpread = new AppSpread.AppSpread();
if (this._discreteGpuAvailable === undefined) {
const updateDiscreteGpuAvailable = () => {
const switcherooProxy = global.get_switcheroo_control();
if (switcherooProxy) {
const prop = switcherooProxy.get_cached_property('HasDualGpu');
this._discreteGpuAvailable = prop?.unpack() ?? false;
} else {
this._discreteGpuAvailable = false;
}
}
this._signalsHandler.add(global, 'notify::switcheroo-control',
() => updateDiscreteGpuAvailable());
updateDiscreteGpuAvailable();
}
// Connect relevant signals to the toggling function
this._bindSettingsChanges();
this._ensureLocations();
/* Array of all the docks created */
this._allDocks = [];
this._createDocks();
// status variable: true when the overview is shown through the dash
// applications button.
this._forcedOverview = false;
}
static getDefault() {
return Me.imports.extension.dockManager
}
static get allDocks() {
return DockManager.getDefault()._allDocks;
}
static get settings() {
return DockManager.getDefault().settings;
}
get settings() {
return this._settings;
}
static get iconTheme() {
return DockManager.getDefault().iconTheme;
}
get settings() { // eslint-disable-line no-dupe-class-members
return this._settings;
}
get iconTheme() {
return this._iconTheme.iconTheme;
}
get fm1Client() {
return this._fm1Client;
}
get remoteModel() {
return this._remoteModel;
}
get mainDock() {
return this._allDocks.length ? this._allDocks[0] : null;
}
get removables() {
return this._removables;
}
get trash() {
return this._trash;
}
get desktopIconsUsableArea() {
return this._desktopIconsUsableArea;
}
get discreteGpuAvailable() {
return AppDisplay.discreteGpuAvailable || this._discreteGpuAvailable;
}
get appSpread() {
return this._appSpread;
}
getDockByMonitor(monitorIndex) {
return this._allDocks.find(d => (d.monitorIndex === monitorIndex));
}
_ensureLocations() {
const { showMounts, showTrash } = this.settings;
if (showTrash || showMounts) {
if (!this._fm1Client)
this._fm1Client = new FileManager1API.FileManager1Client();
} else if (this._fm1Client) {
this._fm1Client.destroy();
this._fm1Client = null;
}
if (showMounts && !this._removables) {
this._removables = new Locations.Removables();
} else if (!showMounts && this._removables) {
this._removables.destroy();
this._removables = null;
}
if (showTrash && !this._trash) {
this._trash = new Locations.Trash();
} else if (!showTrash && this._trash) {
this._trash.destroy();
this._trash = null;
}
Locations.unWrapFileManagerApp();
[this._methodInjections, this._propertyInjections].forEach(
injections => injections.removeWithLabel(Labels.LOCATIONS));
if (showMounts || showTrash) {
if (this.settings.isolateLocations) {
const fileManagerApp = Locations.wrapFileManagerApp();
this._methodInjections.addWithLabel(Labels.LOCATIONS, [
Shell.AppSystem.prototype, 'get_running',
function (originalMethod, ...args) {
const runningApps = originalMethod.call(this, ...args);
const locationApps = Locations.getRunningApps();
if (!locationApps.length)
return runningApps;
const fileManagerIdx = runningApps.indexOf(fileManagerApp);
if (fileManagerIdx > -1 && fileManagerApp?.state !== Shell.AppState.RUNNING)
runningApps.splice(fileManagerIdx, 1);
return [...runningApps, ...locationApps].sort(Utils.shellAppCompare);
}
],
[
Shell.WindowTracker.prototype, 'get_window_app',
function (originalMethod, window) {
const locationApp = Locations.getRunningApps().find(a =>
a.get_windows().includes(window));
return locationApp ?? originalMethod.call(this, window);
}
],
[
Shell.WindowTracker.prototype, 'get_app_from_pid',
function (originalMethod, pid) {
const locationApp = Locations.getRunningApps().find(a =>
a.get_pids().includes(pid));
return locationApp ?? originalMethod.call(this, pid);
}
]);
const { get: defaultFocusAppGetter } = Object.getOwnPropertyDescriptor(
Shell.WindowTracker.prototype, 'focus_app');
this._propertyInjections.addWithLabel(Labels.LOCATIONS,
Shell.WindowTracker.prototype, 'focus_app', {
get: function () {
const locationApp = Locations.getRunningApps().find(a => a.isFocused);
return locationApp ?? defaultFocusAppGetter.call(this);
}
});
}
}
}
_toggle() {
if (this._toggleLater)
return;
this._toggleLater = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
delete this._toggleLater;
this._restoreDash();
this._deleteDocks();
this._createDocks();
this.emit('toggled');
});
}
_mapExternalSetting(settings, key, mappedKey, mapValueFunction) {
const camelMappedKey = mappedKey.replace(/-([a-z\d])/g, k => k[1].toUpperCase());
const dockPropertyDesc = Object.getOwnPropertyDescriptor(this.settings, camelMappedKey);
if (!dockPropertyDesc)
throw new Error('Setting %s not found in dock'.format(mappedKey));
const mappedValue = () => mapValueFunction(settings.get_value(key).recursiveUnpack());
Object.defineProperty(this.settings, camelMappedKey, {
get: () => mappedValue() ?? dockPropertyDesc.value,
set: (value) => { mappedValue() ?? (dockPropertyDesc.value = value) },
});
this._signalsHandler.addWithLabel(Labels.SETTINGS, settings,
'changed::%s'.format(key), () => {
this._signalsHandler.blockWithLabel(Labels.SETTINGS);
this.settings.emit('changed::%s'.format(mappedKey), mappedKey);
this._signalsHandler.unblockWithLabel(Labels.SETTINGS);
});
}
_bindSettingsChanges() {
this.settings.settingsSchema.list_keys().forEach(key => {
const camelKey = key.replace(/-([a-z\d])/g, k => k[1].toUpperCase());
const updateSetting = () => {
const schemaKey = this.settings.settingsSchema.get_key(key);
if (schemaKey.get_range().deepUnpack()[0] === 'enum')
this.settings[camelKey] = this.settings.get_enum(key);
else
this.settings[camelKey] = this.settings.get_value(key).recursiveUnpack();
};
updateSetting();
this._signalsHandler.addWithLabel(Labels.SETTINGS, this.settings,
`changed::${key}`, updateSetting);
if (key != camelKey) {
Object.defineProperty(this.settings, key,
{ get: () => this.settings[camelKey] });
}
});
Object.defineProperties(this.settings, {
dockExtended: { get: () => this.settings.extendHeight },
});
// Connect relevant signals to the toggling function
this._signalsHandler.addWithLabel(Labels.SETTINGS, [
Meta.MonitorManager.get(),
'monitors-changed',
this._toggle.bind(this)
], [
Main.sessionMode,
'updated',
this._toggle.bind(this)
], [
this._settings,
'changed::multi-monitor',
this._toggle.bind(this)
], [
this._settings,
'changed::preferred-monitor',
this._toggle.bind(this)
], [
this._settings,
'changed::preferred-monitor-by-connector',
this._toggle.bind(this)
], [
this._settings,
'changed::dock-position',
this._toggle.bind(this)
], [
this._settings,
'changed::extend-height',
() => this._adjustPanelCorners()
], [
this._settings,
'changed::dock-fixed',
() => this._adjustPanelCorners()
], [
this._settings,
'changed::show-trash',
() => this._ensureLocations()
], [
this._settings,
'changed::show-mounts',
() => this._ensureLocations()
], [
this._settings,
'changed::isolate-locations',
() => this._ensureLocations()
], [
this._settings,
'changed::intellihide',
() => {
if (!this._settings.intellihide)
this._desktopIconsUsableArea.resetMargins();
}
]);
this._mapExternalSetting(this._appSwitcherSettings, 'current-workspace-only',
'isolate-workspaces', value => value || undefined);
}
_createDocks() {
// If there are no monitors (headless configurations, but it can also happen temporary while disconnecting
// and reconnecting monitors), just do nothing. When a monitor will be connected we we'll be notified and
// and thus create the docks. This prevents pointing trying to access monitors throughout the code, were we
// are assuming that at least the primary monitor is present.
if (Main.layoutManager.monitors.length <= 0) {
return;
}
this._preferredMonitorIndex = this.settings.preferredMonitor;
if (this._preferredMonitorIndex === -2) {
const monitorManager = Meta.MonitorManager.get();
this._preferredMonitorIndex = monitorManager.get_monitor_for_connector(
this.settings.preferredMonitorByConnector);
} else if (this._preferredMonitorIndex >= 0) {
// Primary monitor used to be always 0 in Gdk, but the shell has a different
// concept (where the order depends on mutter order).
// So even if now the extension settings may use the same logic of the shell
// we prefer not to break the previously configured systems, and so we still
// assume that the gsettings monitor numbering follows the old strategy.
// This ensure the indexing in the settings and in the shell are matched,
// i.e. that we start counting from the primaryMonitorIndex
this._preferredMonitorIndex = (Main.layoutManager.primaryIndex + this._preferredMonitorIndex) % Main.layoutManager.monitors.length ;
}
// In case of multi-monitor, we consider the dock on the primary monitor
// to be the preferred (main) one regardless of the settings the dock
// goes on the primary monitor also if the settings are inconsistent
// (e.g. desired monitor not connected).
if (this.settings.multiMonitor ||
this._preferredMonitorIndex < 0 ||
this._preferredMonitorIndex > Main.layoutManager.monitors.length - 1) {
this._preferredMonitorIndex = Main.layoutManager.primaryIndex;
}
// First we create the main Dock, to get the extra features to bind to this one
let dock = new DockedDash({
monitorIndex: this._preferredMonitorIndex,
isMain: true,
});
this._allDocks.push(dock);
// connect app icon into the view selector
dock.dash.showAppsButton.connect('notify::checked', this._onShowAppsButtonToggled.bind(this));
// Make the necessary changes to Main.overview.dash
this._prepareMainDash();
// Adjust corners if necessary
this._adjustPanelCorners();
if (this.settings.multiMonitor) {
let nMon = Main.layoutManager.monitors.length;
for (let iMon = 0; iMon < nMon; iMon++) {
if (iMon == this._preferredMonitorIndex)
continue;
dock = new DockedDash({ monitorIndex: iMon });
this._allDocks.push(dock);
// connect app icon into the view selector
dock.dash.showAppsButton.connect('notify::checked', this._onShowAppsButtonToggled.bind(this));
}
}
// Load optional features. We load *after* the docks are created, since
// we need to connect the signals to all dock instances.
this._workspaceIsolation = new WorkspaceIsolation();
this._keyboardShortcuts = new KeyboardShortcuts();
this.emit('docks-ready');
}
_prepareStartupAnimation(callback) {
DockManager.allDocks.forEach(dock => {
const { dash } = dock;
dock.opacity = 255;
dash.set({
opacity: 0,
translation_x: 0,
translation_y: 0,
});
});
// We need to ensure that if docks are destroyed before animation is
// completed, then we still ensure the animation runs anyways.
const label = Labels.STARTUP_ANIMATION;
this._signalsHandler.removeWithLabel(label);
// This shouldn't really ever happen, but in theory the manager
// could be destroyed at any time, in such case complete the animation
this._signalsHandler.addWithLabel(label, this, 'destroy', () =>
Main.overview.runStartupAnimation(callback));
const waitForDocksReady = () => {
global.window_group.remove_clip();
this._signalsHandler.addWithLabel(label, this, 'docks-ready', () => {
this._signalsHandler.removeWithLabel(label);
Main.overview.runStartupAnimation(callback);
});
};
if (this._allDocks.length) {
this._signalsHandler.addWithLabel(label, this, 'docks-destroyed',
() => waitForDocksReady());
} else {
waitForDocksReady();
}
}
_runStartupAnimation(callback) {
const { STARTUP_ANIMATION_TIME } = Layout;
DockManager.allDocks.forEach(dock => {
const { dash } = dock;
switch (dock.position) {
case St.Side.LEFT:
dash.translation_x = -dash.width;
break;
case St.Side.RIGHT:
dash.translation_x = dash.width;
break;
case St.Side.BOTTOM:
dash.translation_y = dash.height;
break;
case St.Side.TOP:
dash.translation_y = -dash.height;
break;
}
const mainDockProperties = {};
if (dock === this.mainDock) {
mainDockProperties.onComplete = () => {
this._signalsHandler.removeWithLabel(Labels.STARTUP_ANIMATION);
if (callback)
callback();
};
}
dash.ease({
opacity: 255,
translation_x: 0,
translation_y: 0,
delay: STARTUP_ANIMATION_TIME,
duration: STARTUP_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
...mainDockProperties,
});
});
}
_prepareMainDash() {
// Ensure Main.overview.dash is set to our dash in dummy mode
// while just use the default getter otherwise.
// The getter must be dynamic and not set only when we've a dummy
// overview because the mode can change dynamically.
this._propertyInjections.removeWithLabel(Labels.MAIN_DASH);
let defaultDashGetter = Object.getOwnPropertyDescriptor(
Main.overview.constructor.prototype, 'dash').get;
this._propertyInjections.addWithLabel(Labels.MAIN_DASH, Main.overview, 'dash', {
get: () => Main.overview.isDummy ?
this.mainDock.dash : defaultDashGetter.call(Main.overview),
});
if (Main.overview.isDummy)
return;
// Hide usual Dash
this._oldDash.hide();
// Also set dash width to 1, so it's almost not taken into account by code
// calculaing the reserved space in the overview. The reason to keep it at 1 is
// to allow its visibility change to trigger an allocaion of the appGrid which
// in turn is triggergin the appsIcon spring animation, required when no other
// actors has this effect, i.e in horizontal mode and without the workspaceThumnails
// 1 static workspace only)
this._oldDash.set_height(1);
this._signalsHandler.addWithLabel(Labels.OLD_DASH_CHANGES, [
this._oldDash,
'notify::visible',
() => this._oldDash.hide()
], [
this._oldDash,
'notify::height',
() => this._oldDash.set_height(1)
]);
// Pretend I'm the dash: meant to make appgrid swarm animation come from
// the right position of the appShowButton.
this.overviewControls.dash = this.mainDock.dash;
this.searchController._showAppsButton = this.mainDock.dash.showAppsButton;
// We also need to ignore max-size changes
this._methodInjections.addWithLabel(Labels.MAIN_DASH, this._oldDash,
'setMaxSize', () => {});
this._methodInjections.addWithLabel(Labels.MAIN_DASH, this._oldDash,
'allocate', () => {});
// And to return the preferred height depending on the state
this._methodInjections.addWithLabel(Labels.MAIN_DASH, this._oldDash,
'get_preferred_height', (_originalMethod, ...args) => {
if (this.mainDock.isHorizontal && !this.settings.dockFixed)
return this.mainDock.get_preferred_height(...args);
return [0, 0];
});
const { ControlsManager, ControlsManagerLayout } = OverviewControls;
this._methodInjections.addWithLabel(Labels.MAIN_DASH, ControlsManager.prototype,
'runStartupAnimation', async function (originalMethod, callback) {
try {
const injections = new Utils.InjectionsHandler();
const dockManager = DockManager.getDefault();
dockManager._prepareStartupAnimation(callback);
injections.add(dockManager.mainDock.dash, 'ease', () => {});
let callbackArgs = [];
const ret = await originalMethod.call(this,
(...args) => (callbackArgs = [...args]));
injections.destroy();
const onComplete = () => callback(...callbackArgs);
dockManager._prepareStartupAnimation(onComplete);
dockManager._runStartupAnimation(onComplete);
return ret;
} catch (e) {
logError(e);
}
});
const maybeAdjustBoxToDock = (state, box, spacing) => {
const initialRatio = box.get_width() / box.get_height();
if (state === OverviewControls.ControlsState.WINDOW_PICKER) {
const searchBox = this.overviewControls._searchEntry.get_allocation_box();
const { shouldShow: wsThumbnails } = this.overviewControls._thumbnailsBox;
if (!wsThumbnails)
box.y1 += spacing;
box.y2 -= searchBox.get_height() + spacing;
if (!wsThumbnails && this.mainDock.position === St.Side.BOTTOM)
box.y2 -= spacing;
}
if (this.mainDock.isHorizontal || this.settings.dockFixed)
return box;
let [, preferredWidth] = this.mainDock.get_preferred_width(box.get_height());
// For some reason we need to use an even value for the box area
// or we may end up in allocation issues:
// https://github.com/micheleg/dash-to-dock/issues/1612
preferredWidth = Math.floor(preferredWidth / 2.0) * 2
box.x2 -= preferredWidth;
if (this.mainDock.position === St.Side.LEFT)
box.set_origin(box.x1 + preferredWidth, box.y1);
// Reduce the box height too, to keep the initial proportions
const heightAdjustment = (preferredWidth / initialRatio) / 2;
box.y1 += heightAdjustment;
box.y2 -= heightAdjustment;
return box;
}
this._vfuncInjections.addWithLabel(Labels.MAIN_DASH, ControlsManagerLayout.prototype,
'allocate', function (container) {
const oldPostAllocation = this._runPostAllocation;
this._runPostAllocation = () => {};
const monitor = Main.layoutManager.findMonitorForActor(this._container);
const workArea = Main.layoutManager.getWorkAreaForMonitor(monitor.index);
const startX = workArea.x - monitor.x;
const startY = workArea.y - monitor.y;
const workAreaBox = new Clutter.ActorBox();
workAreaBox.set_origin(startX, startY);
workAreaBox.set_size(workArea.width, workArea.height);
const propertyInjections = new Utils.PropertyInjectionsHandler();
propertyInjections.add(Main.layoutManager.panelBox, 'height', { value: workAreaBox.y1 });
if (Main.layoutManager.panelBox.y === Main.layoutManager.primaryMonitor.y)
workAreaBox.y1 -= startY;
this.vfunc_allocate(container, workAreaBox);
propertyInjections.destroy();
workAreaBox.y1 = startY;
maybeAdjustBoxToDock(undefined, workAreaBox, this.spacing);
const adjustActorHorizontalAllocation = actor => {
if (!actor.visible || !workAreaBox.x1)
return;
const contentBox = actor.get_allocation_box();
contentBox.set_size(workAreaBox.get_width(), contentBox.get_height());
contentBox.set_origin(workAreaBox.x1, contentBox.y1);
actor.allocate(contentBox);
};
[this._searchEntry, this._workspacesThumbnails, this._searchController].forEach(
actor => adjustActorHorizontalAllocation(actor));
this._runPostAllocation = oldPostAllocation;
this._runPostAllocation();
});
// This can be removed or bypassed when GNOME/gnome-shell!1892 will be merged
function workspaceBoxOriginFixer(originalFunction, state, workAreaBox, ...args) {
const workspaceBox = originalFunction.call(this, state, workAreaBox, ...args);
workspaceBox.set_origin(workAreaBox.x1, workspaceBox.y1);
return workspaceBox;
}
this._methodInjections.addWithLabel(Labels.MAIN_DASH, [
ControlsManagerLayout.prototype,
'_computeWorkspacesBoxForState',
function (originalFunction, state, ...args) {
const box = workspaceBoxOriginFixer.call(this, originalFunction, state, ...args);
if (state !== OverviewControls.ControlsState.HIDDEN)
maybeAdjustBoxToDock(state, box, this.spacing);
return box;
}
], [
ControlsManagerLayout.prototype,
'_getAppDisplayBoxForState',
function (originalFunction, state, ...args) {
const { spacing } = this;
const box = workspaceBoxOriginFixer.call(this, originalFunction, state, ...args);
return maybeAdjustBoxToDock(state, box, spacing);
}
]);
this._vfuncInjections.addWithLabel(Labels.MAIN_DASH, Workspace.WorkspaceBackground.prototype,
'allocate', function (box) {
this.vfunc_allocate(box);
// This code has been submitted upstream via GNOME/gnome-shell!1892
// so can be removed when that gets merged (or bypassed on newer shell
// versions).
const monitor = Main.layoutManager.monitors[this._monitorIndex];
const [contentWidth, contentHeight] = this._bin.get_content_box().get_size();
const [mX1, mX2] = [monitor.x, monitor.x + monitor.width];
const [mY1, mY2] = [monitor.y, monitor.y + monitor.height];
const [wX1, wX2] = [this._workarea.x, this._workarea.x + this._workarea.width];
const [wY1, wY2] = [this._workarea.y, this._workarea.y + this._workarea.height];
const xScale = contentWidth / this._workarea.width;
const yScale = contentHeight / this._workarea.height;
const leftOffset = wX1 - mX1;
const topOffset = wY1 - mY1;
const rightOffset = mX2 - wX2;
const bottomOffset = mY2 - wY2;
const contentBox = new Clutter.ActorBox();
contentBox.set_origin(-leftOffset * xScale, -topOffset * yScale);
contentBox.set_size(
contentWidth + (leftOffset + rightOffset) * xScale,
contentHeight + (topOffset + bottomOffset) * yScale);
this._backgroundGroup.allocate(contentBox);
});
// Reduce the space that the workspaces can use in secondary monitors
this._methodInjections.addWithLabel(Labels.MAIN_DASH, WorkspacesView.WorkspacesView.prototype,
'_getFirstFitAllWorkspaceBox', function (originalFunction, ...args) {
const box = originalFunction.call(this, ...args);
if (DockManager.settings.dockFixed ||
this._monitorIndex === Main.layoutManager.primaryIndex)
return box;
const dock = DockManager.getDefault().getDockByMonitor(this._monitorIndex);
if (!dock)
return box;
if (dock.isHorizontal) {
const [, preferredHeight] = dock.get_preferred_height(box.get_width());
box.y2 -= preferredHeight;
if (dock.position === St.Side.TOP)
box.set_origin(box.x1, box.y1 + preferredHeight);
} else {
const [, preferredWidth] = dock.get_preferred_width(box.get_height());
box.x2 -= preferredWidth / 2;
if (dock.position === St.Side.LEFT)
box.set_origin(box.x1 + preferredWidth, box.y1);
}
return box;
});
if (AppDisplay.BaseAppView?.prototype?._pageForCoords) {
// Ensure we handle Dnd events happening on the dock when we're dragging from AppDisplay
// Remove when merged https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2002
this._methodInjections.addWithLabel(Labels.MAIN_DASH,
AppDisplay.BaseAppView.prototype,
'_pageForCoords', function (originalFunction, ...args) {
if (!this._scrollView.has_pointer)
return AppDisplay.SidePages.NONE;
return originalFunction.call(this, ...args);
});
}
if (Main.layoutManager._startingUp && Main.sessionMode.hasOverview &&
this._settings.disableOverviewOnStartup) {
this._methodInjections.addWithLabel(Labels.MAIN_DASH,
Overview.Overview.prototype,
'runStartupAnimation', (_originalFunction, callback) => {
const monitor = Main.layoutManager.primaryMonitor;
const x = monitor.x + monitor.width / 2.0;
const y = monitor.y + monitor.height / 2.0;
const { STARTUP_ANIMATION_TIME } = Layout;
this._prepareStartupAnimation(callback);
Main.uiGroup.set_pivot_point(
x / global.screen_width,
y / global.screen_height);
Main.uiGroup.set({
scale_x: 0.75,
scale_y: 0.75,
opacity: 0,
});
Main.uiGroup.ease({
scale_x: 1,
scale_y: 1,
opacity: 255,
duration: STARTUP_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: callback,
});
this._runStartupAnimation();
});
}
}
_deleteDocks() {
if (!this._allDocks.length)
return;
// Remove extra features
this._workspaceIsolation.destroy();
this._keyboardShortcuts.destroy();
this._desktopIconsUsableArea.resetMargins();
// Delete all docks
this._allDocks.forEach(d => d.destroy());
this._allDocks = [];
this.emit('docks-destroyed');
}
_restoreDash() {
if (!this._oldDash)
return;
this._signalsHandler.removeWithLabel(Labels.OLD_DASH_CHANGES);
[this._methodInjections, this._vfuncInjections, this._propertyInjections].forEach(
injections => injections.removeWithLabel(Labels.MAIN_DASH));
this.overviewControls.layout_manager._dash = this._oldDash;
this.overviewControls.dash = this._oldDash;
this.searchController._showAppsButton = this._oldDash.showAppsButton;
Main.overview.dash.show();
Main.overview.dash.set_height(-1); // reset default dash size
// This force the recalculation of the icon size
Main.overview.dash._maxHeight = -1;
}
get overviewControls() {
return Main.overview._overview.controls;
}
get searchController() {
return this.overviewControls._searchController;
}
_onShowAppsButtonToggled(button) {
const { checked } = button;
const { overviewControls } = this;
if (!Main.overview.visible) {
this.mainDock.dash.showAppsButton._fromDesktop = true;
if (this._settings.animateShowApps) {
Main.overview.show(OverviewControls.ControlsState.APP_GRID);
} else {
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
const oldAnimationTime = OverviewControls.SIDE_CONTROLS_ANIMATION_TIME;
Overview.ANIMATION_TIME = 1;
const id = Main.overview.connect('shown', () => {
Overview.ANIMATION_TIME = oldAnimationTime;
Main.overview.disconnect(id);
});
Main.overview.show(OverviewControls.ControlsState.APP_GRID);
return GLib.SOURCE_REMOVE;
});
}
} else {
if (!checked && this.mainDock.dash.showAppsButton._fromDesktop) {
if (this._settings.animateShowApps) {
Main.overview.hide();
this.mainDock.dash.showAppsButton._fromDesktop = false;
} else {
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
const oldAnimationTime = Overview.ANIMATION_TIME;
Overview.ANIMATION_TIME = 1;
const id = Main.overview.connect('hidden', () => {
Overview.ANIMATION_TIME = oldAnimationTime;
Main.overview.disconnect(id);
});
Main.overview.hide();
this.mainDock.dash.showAppsButton._fromDesktop = false;
return GLib.SOURCE_REMOVE;
});
}
} else {
// TODO: I'm not sure how reliable this is, we might need to move the
// _onShowAppsButtonToggled logic into the extension.
if (!checked) {
this.mainDock.dash.showAppsButton._fromDesktop = false;
}
// Instead of "syncing" the stock button, let's call its callback directly.
overviewControls._onShowAppsButtonToggled.call(overviewControls);
}
}
// Because we "disconnected" from the search controller, we have to manage its state.
this.searchController._setSearchActive(false);
}
destroy() {
this.emit('destroy');
if (this._toggleLater) {
Meta.later_remove(this._toggleLater);
delete this._toggleLater;
}
this._restoreDash();
this._deleteDocks();
this._revertPanelCorners();
if (this._oldSelectorMargin)
this.searchController.margin_bottom = this._oldSelectorMargin;
if (this._fm1Client) {
this._fm1Client.destroy();
this._fm1Client = null;
}
this._appSpread.destroy();
this._trash?.destroy();
this._trash = null;
Locations.unWrapFileManagerApp();
this._removables?.destroy();
this._removables = null;
this._iconTheme.destroy();
this._remoteModel.destroy();
this._settings.run_dispose();
this._settings = null;
this._appSwitcherSettings = null;
this._oldDash = null;
this._desktopIconsUsableArea.destroy();
this._desktopIconsUsableArea = null;
Me.imports.extension.dockManager = null;
}
/**
* Adjust Panel corners, remove this when 41 won't be supported anymore
*/
_adjustPanelCorners() {
if (!this._hasPanelCorners())
return;
let position = Utils.getPosition();
let isHorizontal = ((position == St.Side.TOP) || (position == St.Side.BOTTOM));
let dockOnPrimary = this._settings.multiMonitor ||
this._preferredMonitorIndex == Main.layoutManager.primaryIndex;
if (!isHorizontal && dockOnPrimary && this.settings.dockExtended && this.settings.dockFixed) {
Main.panel._rightCorner.hide();
Main.panel._leftCorner.hide();
}
else
this._revertPanelCorners();
}
_revertPanelCorners() {
if (!this._hasPanelCorners())
return;
Main.panel._leftCorner.show();
Main.panel._rightCorner.show();
}
_hasPanelCorners() {
return !!Main.panel?._rightCorner && !!Main.panel?._leftCorner;
}
};
Signals.addSignalMethods(DockManager.prototype);
// This class drives long-running icon animations, to keep them running in sync
// with each other, and to save CPU by pausing them when the dock is hidden.
var IconAnimator = class DashToDock_IconAnimator {
constructor(actor) {
this._count = 0;
this._started = false;
this._animations = {
dance: [],
};
this._timeline = new Clutter.Timeline({
duration: Environment.adjustAnimationTime(ICON_ANIMATOR_DURATION),
repeat_count: -1,
actor
});
this._updateSettings();
this._settingsChangedId = St.Settings.get().connect('notify',
() => this._updateSettings());
this._timeline.connect('new-frame', () => {
const progress = this._timeline.get_progress();
const danceRotation = progress < 1/6 ? 15*Math.sin(progress*24*Math.PI) : 0;
const dancers = this._animations.dance;
for (let i = 0, iMax = dancers.length; i < iMax; i++) {
dancers[i].target.rotation_angle_z = danceRotation;
}
});
}
_updateSettings() {
this._timeline.set_duration(Environment.adjustAnimationTime(ICON_ANIMATOR_DURATION));
}
destroy() {
St.Settings.get().disconnect(this._settingsChangedId);
this._timeline.stop();
this._timeline = null;
for (const name in this._animations) {
const pairs = this._animations[name];
for (let i = 0, iMax = pairs.length; i < iMax; i++) {
const pair = pairs[i];
pair.target.disconnect(pair.targetDestroyId);
}
}
this._animations = null;
}
pause() {
if (this._started && this._count > 0) {
this._timeline.stop();
}
this._started = false;
}
start() {
if (!this._started && this._count > 0) {
this._timeline.start();
}
this._started = true;
}
addAnimation(target, name) {
const targetDestroyId = target.connect('destroy', () => this.removeAnimation(target, name));
this._animations[name].push({ target, targetDestroyId });
if (this._started && this._count === 0) {
this._timeline.start();
}
this._count++;
}
removeAnimation(target, name) {
const pairs = this._animations[name];
for (let i = 0, iMax = pairs.length; i < iMax; i++) {
const pair = pairs[i];
if (pair.target === target) {
target.disconnect(pair.targetDestroyId);
pairs.splice(i, 1);
this._count--;
if (this._started && this._count === 0) {
this._timeline.stop();
}
return;
}
}
}
};
|