Skip to content

Commit

Permalink
Add commands switch-(up/down)-or-else-workspace (#850)
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.

Issue #847
  • Loading branch information
jtaala authored May 7, 2024
2 parents 8ee58d3 + 204e86f commit c497307
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 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.
28 changes: 18 additions & 10 deletions schemas/org.gnome.shell.extensions.paperwm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,45 +198,53 @@
</key>

<key type="as" name="switch-next-loop">
<default><![CDATA[['']]]></default>
<default><![CDATA[[]]]></default>
<summary>Switch to the next window (with wrap-around)</summary>
</key>
<key type="as" name="switch-previous-loop">
<default><![CDATA[['']]]></default>
<default><![CDATA[[]]]></default>
<summary>Switch to the previous window (with wrap-around)</summary>
</key>
<key type="as" name="switch-right-loop">
<default><![CDATA[['']]]></default>
<default><![CDATA[[]]]></default>
<summary>Switch to the right window (with wrap-around)</summary>
</key>
<key type="as" name="switch-left-loop">
<default><![CDATA[['']]]></default>
<default><![CDATA[[]]]></default>
<summary>Switch to the left window (with wrap-around)</summary>
</key>
<key type="as" name="switch-up-loop">
<default><![CDATA[['']]]></default>
<default><![CDATA[[]]]></default>
<summary>Switch to the window above (with wrap-around)</summary>
</key>
<key type="as" name="switch-down-loop">
<default><![CDATA[['']]]></default>
<default><![CDATA[[]]]></default>
<summary>Switch to the window below (with wrap-around)</summary>
</key>

<key type="as" name="switch-global-right">
<default><![CDATA[[]]]></default>
<summary>Switch to the right window (no monitor boundary)</summary>
<summary>Switch to window or monitor to the right</summary>
</key>
<key type="as" name="switch-global-left">
<default><![CDATA[[]]]></default>
<summary>Switch to the left window (no monitor boundary)</summary>
<summary>Switch to window or monitor to the left</summary>
</key>
<key type="as" name="switch-global-up">
<default><![CDATA[[]]]></default>
<summary>Switch to the above window (no monitor boundary)</summary>
<summary>Switch to window or monitor above</summary>
</key>
<key type="as" name="switch-global-down">
<default><![CDATA[[]]]></default>
<summary>Switch to the below window (no monitor boundary)</summary>
<summary>Switch to window or monitor below</summary>
</key>
<key type="as" name="switch-up-or-else-workspace">
<default><![CDATA[[]]]></default>
<summary>Switch window or workspace above</summary>
</key>
<key type="as" name="switch-down-or-else-workspace">
<default><![CDATA[[]]]></default>
<summary>Switch to window or workspace below</summary>
</key>

<key type="as" name="switch-first">
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 c497307

Please sign in to comment.