diff --git a/extension.js b/extension.js index 5e6290e..48b2747 100644 --- a/extension.js +++ b/extension.js @@ -88,8 +88,8 @@ function init() { registerPaperAction('move-previous-workspace', previewNavigate); registerPaperAction('move-previous-workspace-backward', previewNavigate); - registerPaperAction("switch-next", previewNavigate); - registerPaperAction("switch-previous", previewNavigate); + registerNavigatorAction("switch-next", (mw, space) => space.switchLinear(1)); + registerNavigatorAction("switch-previous", (mw, space) => space.switchLinear(-1)); registerPaperAction("switch-first", Tiling.activateFirstWindow); registerPaperAction("switch-last", Tiling.activateLastWindow); diff --git a/navigator.js b/navigator.js index 50b133c..619cf32 100644 --- a/navigator.js +++ b/navigator.js @@ -58,37 +58,6 @@ var PreviewedWindowNavigator = new Lang.Class({ }, - _next: function() { - let index = this.space.selectedIndex(); - let column = this.space[index]; - if (!column) - return false; - let row = column.indexOf(this.space.selectedWindow); - if (row + 1 >= column.length) { - index = Math.min(this.space.length-1, index + 1); - row = 0; - } else { - row++; - } - return [index, row]; - }, - - _previous: function() { - let index = this.space.selectedIndex(); - let column = this.space[index]; - if (!column) - return false; - let row = column.indexOf(this.space.selectedWindow); - if (row - 1 < 0) { - index = Math.max(0, index - 1); - column = this.space[index]; - row = column.length - 1; - } else { - row--; - } - return [index, row]; - }, - _initialSelection: function(backward, actionName) { debug('#preview', '_initialSelection'); TopBar.show(); @@ -280,13 +249,7 @@ var PreviewedWindowNavigator = new Lang.Class({ break; } - if (mutterActionId === Keybindings.idOf("switch-next")) { - this._select(this._next()); - return true; - } else if (mutterActionId === Keybindings.idOf("switch-previous")) { - this._select(this._previous()); - return true; - } else if (mutterActionId + if (mutterActionId === Keybindings.idOf('previous-workspace-backward')) { this.selectSpace(Meta.MotionDirection.UP); return true; diff --git a/tiling.js b/tiling.js index 7c0e59d..ccf723f 100644 --- a/tiling.js +++ b/tiling.js @@ -391,6 +391,29 @@ class Space extends Array { ensureViewport(this.selectedWindow, this, true); } + switchLinear(dir) { + let index = this.selectedIndex(); + let column = this[index]; + if (!column) + return false; + let row = column.indexOf(this.selectedWindow); + if (utils.in_bounds(column, row + dir) == false) { + index += dir; + if (dir === 1) { + if (index < this.length) row = 0; + } else { + if (index >= 0) + row = this[index].length - 1 + } + } else { + row += dir; + } + + let metaWindow = this.getWindow(index, row); + ensureViewport(metaWindow, this); + return true; + } + switchLeft() { this.switch(Meta.MotionDirection.LEFT) } switchRight() { this.switch(Meta.MotionDirection.RIGHT) } switchUp() { this.switch(Meta.MotionDirection.UP) }