Skip to content

Commit f8e982c

Browse files
authored
actions: add "loop" variants of "switch-{next,previous,left,right,up,down}" (#787)
The "switch-next", "switch-prev" and related actions currently do nothing once they reach the last window in the action's direction. Add "loop" variants of these actions that loop around when the last window is reached. The new actions are "switch-previous-loop", "switch-next-loop", "switch-left-loop", "switch-right-loop", "switch-up-loop" and "switch-down-loop".
2 parents ac04118 + 7c72fa5 commit f8e982c

5 files changed

Lines changed: 78 additions & 20 deletions

File tree

keybindings.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,24 @@ export function setupActions(settings) {
161161

162162
registerNavigatorAction('take-window', Tiling.takeWindow);
163163

164-
registerMinimapAction("switch-next", (mw, space) => space.switchLinear(1));
165-
registerMinimapAction("switch-previous", (mw, space) => space.switchLinear(-1));
164+
registerMinimapAction("switch-next", (mw, space) => space.switchLinear(1, false));
165+
registerMinimapAction("switch-previous", (mw, space) => space.switchLinear(-1, false));
166+
registerMinimapAction("switch-next-loop", (mw, space) => space.switchLinear(1, true));
167+
registerMinimapAction("switch-previous-loop", (mw, space) => space.switchLinear(-1, true));
168+
169+
registerMinimapAction("switch-right", (mw, space) => space.switchRight(false));
170+
registerMinimapAction("switch-left", (mw, space) => space.switchLeft(false));
171+
registerMinimapAction("switch-up", (mw, space) => space.switchUp(false));
172+
registerMinimapAction("switch-down", (mw, space) => space.switchDown(false));
173+
174+
registerMinimapAction("switch-right-loop", (mw, space) => space.switchRight(true));
175+
registerMinimapAction("switch-left-loop", (mw, space) => space.switchLeft(true));
176+
registerMinimapAction("switch-up-loop", (mw, space) => space.switchUp(true));
177+
registerMinimapAction("switch-down-loop", (mw, space) => space.switchDown(true));
166178

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

170-
registerMinimapAction("switch-right", (mw, space) => space.switchRight());
171-
registerMinimapAction("switch-left", (mw, space) => space.switchLeft());
172-
registerMinimapAction("switch-up", (mw, space) => space.switchUp());
173-
registerMinimapAction("switch-down", (mw, space) => space.switchDown());
174-
175182
registerMinimapAction("switch-global-right", (mw, space) => space.switchGlobalRight());
176183
registerMinimapAction("switch-global-left", (mw, space) => space.switchGlobalLeft());
177184
registerMinimapAction("switch-global-up", (mw, space) => space.switchGlobalUp());

prefsKeybinding.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const actions = {
2727
'switch-right',
2828
'switch-up',
2929
'switch-down',
30+
'switch-next-loop',
31+
'switch-previous-loop',
32+
'switch-left-loop',
33+
'switch-right-loop',
34+
'switch-up-loop',
35+
'switch-down-loop',
3036
'switch-global-left',
3137
'switch-global-right',
3238
'switch-global-up',

schemas/gschemas.compiled

360 Bytes
Binary file not shown.

schemas/org.gnome.shell.extensions.paperwm.gschema.xml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
<default><![CDATA[['<Super>comma']]]></default>
159159
<summary>Switch to the previous window</summary>
160160
</key>
161-
162161
<key type="as" name="switch-right">
163162
<default><![CDATA[['<Super>Right']]]></default>
164163
<summary>Switch to the right window</summary>
@@ -169,11 +168,36 @@
169168
</key>
170169
<key type="as" name="switch-up">
171170
<default><![CDATA[['<Super>Up']]]></default>
172-
<summary>Switch to the above window</summary>
171+
<summary>Switch to the window above</summary>
173172
</key>
174173
<key type="as" name="switch-down">
175174
<default><![CDATA[['<Super>Down']]]></default>
176-
<summary>Switch to the below window</summary>
175+
<summary>Switch to the window below</summary>
176+
</key>
177+
178+
<key type="as" name="switch-next-loop">
179+
<default><![CDATA[['']]]></default>
180+
<summary>Switch to the next window (with wrap-around)</summary>
181+
</key>
182+
<key type="as" name="switch-previous-loop">
183+
<default><![CDATA[['']]]></default>
184+
<summary>Switch to the previous window (with wrap-around)</summary>
185+
</key>
186+
<key type="as" name="switch-right-loop">
187+
<default><![CDATA[['']]]></default>
188+
<summary>Switch to the right window (with wrap-around)</summary>
189+
</key>
190+
<key type="as" name="switch-left-loop">
191+
<default><![CDATA[['']]]></default>
192+
<summary>Switch to the left window (with wrap-around)</summary>
193+
</key>
194+
<key type="as" name="switch-up-loop">
195+
<default><![CDATA[['']]]></default>
196+
<summary>Switch to the window above (with wrap-around)</summary>
197+
</key>
198+
<key type="as" name="switch-down-loop">
199+
<default><![CDATA[['']]]></default>
200+
<summary>Switch to the window below (with wrap-around)</summary>
177201
</key>
178202

179203
<key type="as" name="switch-global-right">

tiling.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,21 @@ export class Space extends Array {
10041004
ensureViewport(this.selectedWindow, this, { force: true });
10051005
}
10061006

1007-
switchLinear(dir) {
1007+
switchLinear(dir, loop) {
10081008
let index = this.selectedIndex();
10091009
let column = this[index];
10101010
if (!column)
10111011
return false;
10121012
let row = column.indexOf(this.selectedWindow);
10131013
if (Lib.in_bounds(column, row + dir) === false) {
10141014
index += dir;
1015+
if (loop) {
1016+
if (index >= this.length) {
1017+
index = 0;
1018+
} else if (index < 0) {
1019+
index = this.length - 1;
1020+
}
1021+
}
10151022
if (dir === 1) {
10161023
if (index < this.length)
10171024
row = 0;
@@ -1026,11 +1033,11 @@ export class Space extends Array {
10261033
return true;
10271034
}
10281035

1029-
switchLeft() { this.switch(Meta.MotionDirection.LEFT); }
1030-
switchRight() { this.switch(Meta.MotionDirection.RIGHT); }
1031-
switchUp() { this.switch(Meta.MotionDirection.UP); }
1032-
switchDown() { this.switch(Meta.MotionDirection.DOWN); }
1033-
switch(direction) {
1036+
switchLeft(loop) { this.switch(Meta.MotionDirection.LEFT, loop); }
1037+
switchRight(loop) { this.switch(Meta.MotionDirection.RIGHT, loop); }
1038+
switchUp(loop) { this.switch(Meta.MotionDirection.UP, loop); }
1039+
switchDown(loop) { this.switch(Meta.MotionDirection.DOWN, loop); }
1040+
switch(direction, loop) {
10341041
let space = this;
10351042
let index = space.selectedIndex();
10361043
if (index === -1) {
@@ -1046,8 +1053,15 @@ export class Space extends Array {
10461053
index--;
10471054
row = -1;
10481055
}
1049-
if (index < 0 || index >= space.length)
1056+
if (loop) {
1057+
if (index < 0) {
1058+
index = space.length - 1;
1059+
} else if (index >= space.length) {
1060+
index = 0;
1061+
}
1062+
} else if (index < 0 || index >= space.length) {
10501063
return;
1064+
}
10511065

10521066
let column = space[index];
10531067

@@ -1064,8 +1078,15 @@ export class Space extends Array {
10641078
case Meta.MotionDirection.DOWN:
10651079
row++;
10661080
}
1067-
if (row < 0 || row >= column.length)
1081+
if (loop) {
1082+
if (row < 0) {
1083+
row = column.length - 1;
1084+
} else if (row >= column.length) {
1085+
row = 0;
1086+
}
1087+
} else if (row < 0 || row >= column.length) {
10681088
return;
1089+
}
10691090

10701091
let metaWindow = space.getWindow(index, row);
10711092
ensureViewport(metaWindow, space);
@@ -1766,11 +1787,11 @@ border-radius: ${borderWidth}px;
17661787
switch (dir) {
17671788
case Clutter.ScrollDirection.LEFT:
17681789
case Clutter.ScrollDirection.UP:
1769-
this.switchLeft();
1790+
this.switchLeft(false);
17701791
break;
17711792
case Clutter.ScrollDirection.RIGHT:
17721793
case Clutter.ScrollDirection.DOWN:
1773-
this.switchRight();
1794+
this.switchRight(false);
17741795
break;
17751796
}
17761797
});

0 commit comments

Comments
 (0)