Skip to content

Commit 7cc424b

Browse files
committed
Introduce move-global-* actions
Added four new actions that swap windows, but move them across monitor boundaries if the focused window is the first/last window on the current monitor. These actions are supposed to complement the switch-global-* actions, and so the behavior is intended to be similar.
1 parent ad90e0c commit 7cc424b

File tree

5 files changed

+125
-1
lines changed

5 files changed

+125
-1
lines changed

keybindings.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ export function setupActions(settings) {
227227
registerMinimapAction("switch-global-up", (mw, space) => space.switchGlobalUp());
228228
registerMinimapAction("switch-global-down", (mw, space) => space.switchGlobalDown());
229229

230+
registerAction("move-global-right",
231+
(mw, space) => space.moveGlobal(mw, Meta.MotionDirection.RIGHT),
232+
{ settings, mutterFlags: Meta.KeyBindingFlags.PER_WINDOW }
233+
);
234+
registerAction("move-global-left",
235+
(mw, space) => space.moveGlobal(mw, Meta.MotionDirection.LEFT),
236+
{ settings, mutterFlags: Meta.KeyBindingFlags.PER_WINDOW }
237+
);
238+
registerAction("move-global-up",
239+
(mw, space) => space.moveGlobal(mw, Meta.MotionDirection.UP),
240+
{ settings, mutterFlags: Meta.KeyBindingFlags.PER_WINDOW }
241+
);
242+
registerAction("move-global-down",
243+
(mw, space) => space.moveGlobal(mw, Meta.MotionDirection.DO),
244+
{ settings, mutterFlags: Meta.KeyBindingFlags.PER_WINDOW }
245+
);
246+
230247
registerMinimapAction("move-left",
231248
(_mw, space) => space.swap(Meta.MotionDirection.LEFT));
232249
registerMinimapAction("move-right",

prefsKeybinding.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const actions = {
3939
'switch-global-right',
4040
'switch-global-up',
4141
'switch-global-down',
42+
'move-global-left',
43+
'move-global-right',
44+
'move-global-up',
45+
'move-global-down',
4246
'switch-up-or-else-workspace',
4347
'switch-down-or-else-workspace',
4448
'switch-first',

schemas/gschemas.compiled

304 Bytes
Binary file not shown.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@
285285
<default><![CDATA[[]]]></default>
286286
<summary>Switch to window or monitor below</summary>
287287
</key>
288+
<key type="as" name="move-global-right">
289+
<default><![CDATA[[]]]></default>
290+
<summary>Move active window to the next spot or monitor to the right</summary>
291+
</key>
292+
<key type="as" name="move-global-left">
293+
<default><![CDATA[[]]]></default>
294+
<summary>Move active window to the next spot or monitor to the left</summary>
295+
</key>
296+
<key type="as" name="move-global-up">
297+
<default><![CDATA[[]]]></default>
298+
<summary>Move active window to the next spot or monitor above</summary>
299+
</key>
300+
<key type="as" name="move-global-down">
301+
<default><![CDATA[[]]]></default>
302+
<summary>Move active window to the next spot or monitor below</summary>
303+
</key>
288304
<key type="as" name="switch-up-or-else-workspace">
289305
<default><![CDATA[[]]]></default>
290306
<summary>Switch to window or workspace above</summary>

tiling.js

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,33 @@ export class Space extends Array {
10941094
ensureViewport(this.selectedWindow, this, { force: true });
10951095
}
10961096

1097+
moveToStart(metaWindow) {
1098+
metaWindow = metaWindow || this.selectedWindow;
1099+
1100+
let [index, row] = this.positionOf(metaWindow);
1101+
if (index == 0) return;
1102+
1103+
let [it] = this.splice(index, 1);
1104+
this.unshift(it);
1105+
this.layout();
1106+
this.emit("swapped", index, 0, row, row);
1107+
ensureViewport(this.selectedWindow, this, { force: true });
1108+
}
1109+
1110+
moveToEnd(metaWindow) {
1111+
metaWindow = metaWindow || this.selectedWindow;
1112+
1113+
let [index, row] = this.positionOf(metaWindow);
1114+
let targetIndex = this.length-1;
1115+
if (index == targetIndex) return;
1116+
1117+
let [it] = this.splice(index, 1);
1118+
this.push(it);
1119+
this.layout();
1120+
this.emit("swapped", index, 0, row, row);
1121+
ensureViewport(this.selectedWindow, this, { force: true });
1122+
}
1123+
10971124
switchLinear(dir, loop) {
10981125
let index = this.selectedIndex();
10991126
let column = this[index];
@@ -1262,6 +1289,65 @@ export class Space extends Array {
12621289
ensureViewport(metaWindow, space);
12631290
}
12641291

1292+
moveGlobal(metaWindow, direction) {
1293+
let space = this;
1294+
let index = space.selectedIndex();
1295+
if (index === -1) {
1296+
return;
1297+
}
1298+
1299+
let column = space[index];
1300+
let row = column.indexOf(metaWindow);
1301+
if (row === -1) {
1302+
let selected = sortWindows(this, column)[column.length - 1];
1303+
row = column.indexOf(selected);
1304+
}
1305+
1306+
switch (direction) {
1307+
case Meta.MotionDirection.LEFT:
1308+
if (index > 0) {
1309+
space.swap(direction, metaWindow);
1310+
return;
1311+
} else {
1312+
let new_space = spaces.switchMonitor(Meta.DisplayDirection.LEFT, true);
1313+
if (new_space != null) {
1314+
new_space.moveToEnd(metaWindow);
1315+
}
1316+
return;
1317+
}
1318+
1319+
case Meta.MotionDirection.RIGHT:
1320+
if (index < space.length-1) {
1321+
space.swap(direction);
1322+
return;
1323+
} else {
1324+
let new_space = spaces.switchMonitor(Meta.DisplayDirection.RIGHT, true);
1325+
if (new_space != null) {
1326+
new_space.moveToStart(metaWindow);
1327+
}
1328+
return;
1329+
}
1330+
1331+
case Meta.MotionDirection.UP:
1332+
if (row > 0) {
1333+
space.swap(direction);
1334+
return;
1335+
} else {
1336+
spaces.switchMonitor(Meta.DisplayDirection.UP, true);
1337+
return;
1338+
}
1339+
1340+
case Meta.MotionDirection.DOWN:
1341+
if (row < column.length-1) {
1342+
space.swap(direction);
1343+
return;
1344+
} else {
1345+
spaces.switchMonitor(Meta.DisplayDirection.DOWN, true);
1346+
return;
1347+
}
1348+
}
1349+
}
1350+
12651351
_drift(dx) {
12661352
if (dx === 0) {
12671353
return;
@@ -2542,7 +2628,7 @@ export const Spaces = class Spaces extends Map {
25422628
let currentSpace = this.monitors.get(monitor);
25432629
let i = display.get_monitor_neighbor_index(monitor.index, direction);
25442630
if (i === -1)
2545-
return;
2631+
return null;
25462632
let newMonitor = Main.layoutManager.monitors[i];
25472633
if (warp) {
25482634
Utils.warpPointerToMonitor(newMonitor);
@@ -2575,6 +2661,7 @@ export const Spaces = class Spaces extends Map {
25752661
} else {
25762662
space.activate(false, false);
25772663
}
2664+
return space;
25782665
}
25792666

25802667
moveToMonitor(direction, backDirection) {

0 commit comments

Comments
 (0)