From bcee9acfb82c06db7be7283a2e1fc88d39588803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Hedin=20Br=C3=B8nner?= Date: Fri, 29 Jun 2018 00:10:42 +0200 Subject: [PATCH] Move _reorder to Space.swap(direction, window) Emit `Space::swapped` --- minimap.js | 23 ++++++----------- navigator.js | 70 +++------------------------------------------------- tiling.js | 33 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 81 deletions(-) diff --git a/minimap.js b/minimap.js index 473ae10..e41dc94 100644 --- a/minimap.js +++ b/minimap.js @@ -108,6 +108,7 @@ class Minimap { space.connect('select', this.select.bind(this)), space.connect('window-added', this.addWindow.bind(this)), space.connect('window-removed', this.removeWindow.bind(this)), + space.connect('swapped', this.swapped.bind(this)), ]; } @@ -132,6 +133,13 @@ class Minimap { this.container.remove_child(clone); } + swapped(space, index, targetIndex, row, targetRow) { + let column = this.clones[index]; + utils.swap(column, row, targetRow); + utils.swap(this.clones, index, targetIndex); + this.layout(); + } + show() { this.space.actor.add_actor(this.actor); this.clones = this.createClones(); @@ -194,21 +202,6 @@ class Minimap { .forEach(c => this.container.add_actor(c)); } - reorder(index, targetIndex) { - // targetX is the destination of the moving window in viewport - // coordinates - - let movingClone = this.clones[index]; - let next = this.clones[targetIndex]; - - let temp = this.clones[index]; - this.clones[index] = this.clones[targetIndex]; - this.clones[targetIndex] = temp; - - this.layout(false); - this.select(targetIndex); - } - select() { let position = this.space.positionOf(); if (!position) diff --git a/navigator.js b/navigator.js index 94953ad..db00485 100644 --- a/navigator.js +++ b/navigator.js @@ -128,68 +128,6 @@ var PreviewedWindowNavigator = new Lang.Class({ this._doAction(actionId); }, - _reorder: function (direction) { - function swapArray(array, i, j) { - let temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - - let metaWindow = this.space.selectedWindow; - let index = this.space.indexOf(metaWindow); - let targetIndex = index; - switch (direction) { - case Meta.MotionDirection.LEFT: - targetIndex--; - break; - case Meta.MotionDirection.RIGHT: - targetIndex++; - break; - } - - if (targetIndex < 0 || targetIndex >= this.space.length) - return; - - this.space[index].forEach(w => w.clone.raise_top()); - - swapArray(this.space, index, targetIndex); - - Tiling.ensureViewport(metaWindow, this.space, true); - this.minimap.reorder(index, targetIndex); - }, - - _reorderColumn(direction) { - function swapArray(array, i, j) { - let temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - - let space = this.space; - let metaWindow = space.selectedWindow; - let index = space.indexOf(metaWindow); - let column = space[index]; - let row = column.indexOf(metaWindow); - let targetRow = row; - - switch (direction) { - case Meta.MotionDirection.DOWN: - targetRow++; - break; - case Meta.MotionDirection.UP: - targetRow--; - break; - } - if (targetRow < 0 || targetRow >= column.length) - return; - - metaWindow.clone.raise_top(); - - swapArray(column, row, targetRow); - this.minimap.show(); - Tiling.ensureViewport(metaWindow, space, true); - }, - _initSpaceMru(move) { let heights = [0].concat(this._yPositions.slice(1)); let minimap = this.minimap; @@ -371,16 +309,16 @@ var PreviewedWindowNavigator = new Lang.Class({ this._switch(Meta.MotionDirection.DOWN); return true; } else if (mutterActionId === paperActions.idOf("move-left")) { - this._reorder(Meta.MotionDirection.LEFT); + this.space.swap(Meta.MotionDirection.LEFT); return true; } else if (mutterActionId === paperActions.idOf("move-right")) { - this._reorder(Meta.MotionDirection.RIGHT); + this.space.swap(Meta.MotionDirection.RIGHT); return true; } else if (mutterActionId === paperActions.idOf("move-up")) { - this._reorderColumn(Meta.MotionDirection.UP); + this.space.swap(Meta.MotionDirection.UP); return true; } else if (mutterActionId === paperActions.idOf("move-down")) { - this._reorderColumn(Meta.MotionDirection.DOWN); + this.space.swap(Meta.MotionDirection.DOWN); return true; } else if (mutterActionId === paperActions.idOf('previous-workspace-backward')) { diff --git a/tiling.js b/tiling.js index 773857d..7a6232f 100644 --- a/tiling.js +++ b/tiling.js @@ -192,6 +192,39 @@ class Space extends Array { return true; } + swap(direction, metaWindow) { + metaWindow = metaWindow || this.selectedWindow; + + let [index, row] = this.positionOf(metaWindow); + let targetIndex = index; + let targetRow = row; + switch (direction) { + case Meta.MotionDirection.LEFT: + targetIndex--; + break; + case Meta.MotionDirection.RIGHT: + targetIndex++; + break; + case Meta.MotionDirection.DOWN: + targetRow++; + break; + case Meta.MotionDirection.UP: + targetRow--; + break; + } + let column = this[index]; + if (targetIndex < 0 || targetIndex >= this.length + || targetRow < 0 || targetRow >= column.length) + return; + + utils.swap(this[index], row, targetRow); + utils.swap(this, index, targetIndex); + metaWindow.clone.raise_top(); + + this.emit('swapped', index, targetIndex, row, targetRow); + ensureViewport(this.selectedWindow, this, true); + } + positionOf(metaWindow) { metaWindow = metaWindow || this.selectedWindow; let index, row;