Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: move space to other monitors #825

Merged
merged 9 commits into from
Apr 15, 2024
Prev Previous commit
Next Next commit
Added checkIfLast approach into swapMonitor.
  • Loading branch information
jtaala committed Apr 13, 2024
commit 624035365bff7d60982552b7aa2f69ed8c8e79e7
32 changes: 24 additions & 8 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -2382,12 +2382,7 @@ export const Spaces = class Spaces extends Map {
const numSpaces = [...this].filter(([_monitor, space]) => space?.monitor === monitor).length;
// if last space on this monitor, then swap
if (numSpaces <= 1) {
// focus other monitor and switch back
this.switchMonitor(direction, false, false);
this.swapMonitor(backDirection, direction);

// now switch monitor since we back-flipped
this.switchMonitor(direction, false, true);
this.swapMonitor(direction, backDirection);
return;
}

Expand Down Expand Up @@ -2417,12 +2412,33 @@ export const Spaces = class Spaces extends Map {
this.setSpaceTopbarElementsVisible(true, { force: true });
}

swapMonitor(direction, backDirection) {
swapMonitor(direction, backDirection, options = {}) {
const checkIfLast = options.checkIfLast ?? true;
const warpIfLast = options.warpIfLast ?? true;

const monitor = focusMonitor();
const i = display.get_monitor_neighbor_index(monitor.index, direction);
if (i === -1)
return;

if (checkIfLast) {
// check how many spaces are on this monitor
const numSpaces = [...this].filter(([_monitor, space]) => space?.monitor === monitor).length;
// if last space on this monitor, then swap
if (numSpaces <= 1) {
// focus other monitor for a switchback
this.switchMonitor(direction, false, false);
this.swapMonitor(backDirection, direction, {
checkIfLast: false,
warpIfLast: false,
});

// now switch monitor with warp since we back-flipped
this.switchMonitor(direction, false, true);
return;
}
}

let navFinish = () => Navigator.getNavigator().finish();
// action on current monitor
this.selectStackSpace(Meta.MotionDirection.DOWN);
Expand All @@ -2436,7 +2452,7 @@ export const Spaces = class Spaces extends Map {
this.selectStackSpace(Meta.MotionDirection.DOWN);
navFinish();
// final switch with warp
this.switchMonitor(direction);
this.switchMonitor(direction, false, warpIfLast);

// /**
// * Fullscreen monitor workaround.
Expand Down