Skip to content

Commit

Permalink
Add commands switch-(up/down)-or-else-workspace
Browse files Browse the repository at this point in the history
Add commands to switch to the window above (or below), but fall back to
switching to the workspace above (or below) if there was no window above
(or below).

Keyboard shortcuts are added as well, but without default keybindings.
  • Loading branch information
gustavcedersjo committed May 5, 2024
1 parent 469dcfd commit 66d7477
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions keybindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ export function setupActions(settings) {
registerMinimapAction("switch-up-loop", (mw, space) => space.switchUp(true));
registerMinimapAction("switch-down-loop", (mw, space) => space.switchDown(true));

registerNavigatorAction("switch-up-or-else-workspace", Tiling.switchUpOrElseWorkspace);
registerNavigatorAction("switch-down-or-else-workspace", Tiling.switchDownOrElseWorkspace);

registerMinimapAction("switch-first", Tiling.activateFirstWindow);
registerMinimapAction("switch-last", Tiling.activateLastWindow);

Expand Down
2 changes: 2 additions & 0 deletions prefsKeybinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const actions = {
'switch-global-right',
'switch-global-up',
'switch-global-down',
'switch-up-or-else-workspace',
'switch-down-or-else-workspace',
'switch-first',
'switch-last',
'live-alt-tab',
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
8 changes: 8 additions & 0 deletions schemas/org.gnome.shell.extensions.paperwm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@
<default><![CDATA[[]]]></default>
<summary>Switch to the below window (no monitor boundary)</summary>
</key>
<key type="as" name="switch-up-or-else-workspace">
<default><![CDATA[['']]]></default>
<summary>Switch to the above window (no workspace boundary)</summary>
</key>
<key type="as" name="switch-down-or-else-workspace">
<default><![CDATA[['']]]></default>
<summary>Switch to the below window (no workspace boundary)</summary>
</key>

<key type="as" name="switch-first">
<default><![CDATA[['<Super>Home']]]></default>
Expand Down
26 changes: 19 additions & 7 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,15 +1058,15 @@ export class Space extends Array {
return true;
}

switchLeft(loop) { this.switch(Meta.MotionDirection.LEFT, loop); }
switchRight(loop) { this.switch(Meta.MotionDirection.RIGHT, loop); }
switchUp(loop) { this.switch(Meta.MotionDirection.UP, loop); }
switchDown(loop) { this.switch(Meta.MotionDirection.DOWN, loop); }
switchLeft(loop) { return this.switch(Meta.MotionDirection.LEFT, loop); }
switchRight(loop) { return this.switch(Meta.MotionDirection.RIGHT, loop); }
switchUp(loop) { return this.switch(Meta.MotionDirection.UP, loop); }
switchDown(loop) { return this.switch(Meta.MotionDirection.DOWN, loop); }
switch(direction, loop) {
let space = this;
let index = space.selectedIndex();
if (index === -1) {
return;
return false;
}
let row = space[index].indexOf(space.selectedWindow);
switch (direction) {
Expand All @@ -1085,7 +1085,7 @@ export class Space extends Array {
index = 0;
}
} else if (index < 0 || index >= space.length) {
return;
return false;
}

let column = space[index];
Expand All @@ -1110,11 +1110,13 @@ export class Space extends Array {
row = 0;
}
} else if (row < 0 || row >= column.length) {
return;
return false;
}

let metaWindow = space.getWindow(index, row);
ensureViewport(metaWindow, space);

return true;
}

switchGlobalLeft() { this.switchGlobal(Meta.MotionDirection.LEFT); }
Expand Down Expand Up @@ -4951,6 +4953,16 @@ export function selectUpSpace(mw, space, fromAllMonitors) {
spaces.selectSequenceSpace(Meta.MotionDirection.UP, false, fromAllMonitors);
}

export function switchDownOrElseWorkspace(mw, space) {
if (!space.switchDown(false))
selectDownSpace(mw, space, false);
}

export function switchUpOrElseWorkspace(mw, space) {
if (!space.switchUp(false))
selectUpSpace(mw, space, false);
}

export function moveDownSpace(_mw, _space) {
spaces.selectSequenceSpace(Meta.MotionDirection.DOWN, true);
}
Expand Down

0 comments on commit 66d7477

Please sign in to comment.