(direction, backDirection, options = {})
| 2623 | } |
| 2624 | |
| 2625 | swapMonitor(direction, backDirection, options = {}) { |
| 2626 | const checkIfLast = options.checkIfLast ?? true; |
| 2627 | const warpIfLast = options.warpIfLast ?? true; |
| 2628 | |
| 2629 | const monitor = focusMonitor(); |
| 2630 | const i = display.get_monitor_neighbor_index(monitor.index, direction); |
| 2631 | if (i === -1) |
| 2632 | return; |
| 2633 | |
| 2634 | if (this.lteSpacesThanMonitors( |
| 2635 | (s, m) => Main.notify( |
| 2636 | `PaperWM (cannot swap workspaces)`, |
| 2637 | `You need at least ${m + 1} workspaces to complete this operation.` |
| 2638 | ) |
| 2639 | )) { |
| 2640 | return; |
| 2641 | } |
| 2642 | |
| 2643 | if (checkIfLast) { |
| 2644 | // check how many spaces are on this monitor |
| 2645 | const numSpaces = [...this].filter(([_monitor, space]) => space?.monitor === monitor).length; |
| 2646 | // if last space on this monitor, then swap |
| 2647 | if (numSpaces <= 1) { |
| 2648 | // focus other monitor for a switchback |
| 2649 | this.switchMonitor(direction, false, false); |
| 2650 | this.swapMonitor(backDirection, direction, { |
| 2651 | checkIfLast: false, |
| 2652 | warpIfLast: false, |
| 2653 | }); |
| 2654 | |
| 2655 | // now switch monitor with warp since we back-flipped |
| 2656 | this.switchMonitor(direction, false, true); |
| 2657 | return; |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | let navFinish = () => Navigator.getNavigator().finish(); |
| 2662 | // action on current monitor |
| 2663 | this.selectStackSpace(Meta.MotionDirection.DOWN); |
| 2664 | navFinish(); |
| 2665 | // switch to target monitor and action mru |
| 2666 | this.switchMonitor(direction, false, false); |
| 2667 | this.selectStackSpace(Meta.MotionDirection.DOWN); |
| 2668 | navFinish(); |
| 2669 | // switch back to orig monitor and action mru |
| 2670 | this.switchMonitor(backDirection, false, false); |
| 2671 | this.selectStackSpace(Meta.MotionDirection.DOWN); |
| 2672 | navFinish(); |
| 2673 | // final switch with warp |
| 2674 | this.switchMonitor(direction, false, warpIfLast); |
| 2675 | |
| 2676 | // /** |
| 2677 | // * Fullscreen monitor workaround. |
| 2678 | // * see https://github.com/paperwm/PaperWM/issues/638 |
| 2679 | // */ |
| 2680 | // this.forEach(space => { |
| 2681 | // space.getWindows().filter(w => w.fullscreen).forEach(w => { |
| 2682 | // animateWindow(w); |
no test coverage detected