mirror of
https://github.com/gosticks/PaperWM.git
synced 2026-10-06 20:07:02 +00:00
Move _reorder to Space.swap(direction, window)
Emit `Space::swapped`
This commit is contained in:
+8
-15
@@ -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)
|
||||
|
||||
+4
-66
@@ -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')) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user