Skip to content

Commit

Permalink
Added switch-global-* actions (#775)
Browse files Browse the repository at this point in the history
This pull request is to add four new actions that complement
`switch-right`, `switch-left`, `switch-up` and `switch-down` with
*global* versions that change window regardless of monitor boundaries.
This means the action will not respect the current monitor boundaries
and will select a window on the adjacent monitor if the previous
selection was at a boundary. For example, `switch-global-right` when the
selected window is the rightmost of a *space* will move to the monitor
on the right and select the first window. While within monitor
boundaries, the behavior is exactly the same as `switch-*`.

1. It doesn't change other actions, you can always keep on changing
monitors with `<Super><Shift><right/left/up/down>`, which preserves the
last selected window on each *space* when moving back and forth, while
`switch-global-*` actions don't (they move to the *"closest"* window).
2. There are no default key bindings for these actions. For example, I
have replaced the ones for `switch-*` with the actions
`switch-global-*`, but by default, the change doesn't do anything.

The pull request is backwards compatible, transparent, and needs the
user to enable the behavior knowingly; it doesn't add any key bindings
by default.
  • Loading branch information
jtaala authored Feb 8, 2024
2 parents b91c743 + c0c9b75 commit 1cc567e
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
5 changes: 5 additions & 0 deletions keybindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ export function setupActions(settings) {
registerMinimapAction("switch-up", (mw, space) => space.switchUp());
registerMinimapAction("switch-down", (mw, space) => space.switchDown());

registerMinimapAction("switch-global-right", (mw, space) => space.switchGlobalRight());
registerMinimapAction("switch-global-left", (mw, space) => space.switchGlobalLeft());
registerMinimapAction("switch-global-up", (mw, space) => space.switchGlobalUp());
registerMinimapAction("switch-global-down", (mw, space) => space.switchGlobalDown());

registerMinimapAction("move-left",
(mw, space) => space.swap(Meta.MotionDirection.LEFT));
registerMinimapAction("move-right",
Expand Down
4 changes: 2 additions & 2 deletions navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ActionDispatcher {
}

if (!Tiling.inGrab && action.options.opensMinimap) {
nav._showMinimap(space);
nav.showMinimap(space);
}
action.handler(metaWindow, space, { navigator: this.navigator });
if (space !== Tiling.spaces.selectedSpace) {
Expand Down Expand Up @@ -286,7 +286,7 @@ class NavigatorClass {
this.space.startAnimate();
}

_showMinimap(space) {
showMinimap(space) {
let minimap = this.minimaps.get(space);
if (!minimap) {
let minimapId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 200, () => {
Expand Down
4 changes: 4 additions & 0 deletions prefsKeybinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const actions = {
'switch-right',
'switch-up',
'switch-down',
'switch-global-left',
'switch-global-right',
'switch-global-up',
'switch-global-down',
'switch-first',
'switch-last',
'live-alt-tab',
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
17 changes: 17 additions & 0 deletions schemas/org.gnome.shell.extensions.paperwm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@
<summary>Switch to the below window</summary>
</key>

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

<key type="as" name="switch-first">
<default><![CDATA[['<Super>Home']]]></default>
<summary>Switch to the first window</summary>
Expand Down
78 changes: 78 additions & 0 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,84 @@ export class Space extends Array {
ensureViewport(metaWindow, space);
}

switchGlobalLeft() { this.switchGlobal(Meta.MotionDirection.LEFT); }
switchGlobalRight() { this.switchGlobal(Meta.MotionDirection.RIGHT); }
switchGlobalUp() { this.switchGlobal(Meta.MotionDirection.UP); }
switchGlobalDown() { this.switchGlobal(Meta.MotionDirection.DOWN); }
switchGlobal(direction) {
let space = this;
let index = space.selectedIndex();
if (index === -1) {
return;
}
let row = space[index].indexOf(space.selectedWindow);

switch (direction) {
case Meta.MotionDirection.RIGHT:
index++;
break;
case Meta.MotionDirection.LEFT:
index--;
}
if (index < 0 || index >= space.length) {
let monitor = focusMonitor();
let dir = index < 0
? Meta.DisplayDirection.LEFT : Meta.DisplayDirection.RIGHT;
let i = display.get_monitor_neighbor_index(monitor.index, dir);
if (i === -1)
return;

let newMonitor = Main.layoutManager.monitors[i];
space = spaces.monitors.get(newMonitor);
if (dir === Meta.DisplayDirection.LEFT) {
index = space.length - 1;
} else {
index = 0;
}
if (space[index].length <= row)
row = space[index].length - 1;
space.activate(false, false);
Navigator.finishNavigation();
Navigator.getNavigator().showMinimap(space);
}

let column = space[index];
if (column.length <= row)
row = column.length - 1;

switch (direction) {
case Meta.MotionDirection.UP:
row--;
break;
case Meta.MotionDirection.DOWN:
row++;
}
if (row < 0 || row >= column.length) {
let monitor = focusMonitor();
let dir = row < 0
? Meta.DisplayDirection.UP : Meta.DisplayDirection.DOWN;
let i = display.get_monitor_neighbor_index(monitor.index, dir);
if (i === -1)
return;

let newMonitor = Main.layoutManager.monitors[i];
space = spaces.monitors.get(newMonitor);
if (space.length <= index)
index = space.length - 1;
if (dir === Meta.DisplayDirection.UP) {
row = space[index].length - 1;
} else {
row = 0;
}
space.activate(false, false);
Navigator.finishNavigation();
Navigator.getNavigator().showMinimap(space);
}

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

/**
* Return the x position of the visible element of this window.
*/
Expand Down

0 comments on commit 1cc567e

Please sign in to comment.