_computeWindowMotion calculate difference between relative positions
https://bugzilla.gnome.org/show_bug.cgi?id=607826
This commit is contained in:
parent
004cf3da5c
commit
8d76e362a0
@ -833,16 +833,15 @@ Workspace.prototype = {
|
|||||||
* Currently this is the square of the distance between the
|
* Currently this is the square of the distance between the
|
||||||
* centers.
|
* centers.
|
||||||
*/
|
*/
|
||||||
_computeWindowMotion: function (metaWindow, slot, slotGeometry) {
|
_computeWindowMotion: function (metaWindow, slot) {
|
||||||
let rect = new Meta.Rectangle();
|
let rect = new Meta.Rectangle();
|
||||||
metaWindow.get_outer_rect(rect);
|
metaWindow.get_outer_rect(rect);
|
||||||
|
|
||||||
let [slotX, slotY, slotWidth, slotHeight] = slotGeometry;
|
let [xCenter, yCenter, fraction] = slot;
|
||||||
let distanceSquared;
|
let xDelta, yDelta, distanceSquared;
|
||||||
let xDelta, yDelta;
|
|
||||||
|
|
||||||
xDelta = (rect.x + rect.width / 2) - (slotX + slotWidth / 2);
|
xDelta = rect.x + rect.width / 2.0 - xCenter * global.screen_width;
|
||||||
yDelta = (rect.y + rect.height / 2) - (slotY + slotHeight / 2);
|
yDelta = rect.y + rect.height / 2.0 - yCenter * global.screen_height;
|
||||||
distanceSquared = xDelta * xDelta + yDelta * yDelta;
|
distanceSquared = xDelta * xDelta + yDelta * yDelta;
|
||||||
|
|
||||||
return distanceSquared;
|
return distanceSquared;
|
||||||
@ -854,7 +853,7 @@ Workspace.prototype = {
|
|||||||
* Iterate over all permutations of the windows, and determine the
|
* Iterate over all permutations of the windows, and determine the
|
||||||
* permutation which has the least total motion.
|
* permutation which has the least total motion.
|
||||||
*/
|
*/
|
||||||
_orderWindowsPermutations: function (clones, slots, slotGeometries) {
|
_orderWindowsPermutations: function (clones, slots) {
|
||||||
let minimumMotionPermutation = null;
|
let minimumMotionPermutation = null;
|
||||||
let minimumMotion = -1;
|
let minimumMotion = -1;
|
||||||
let permIndex = 0;
|
let permIndex = 0;
|
||||||
@ -863,9 +862,8 @@ Workspace.prototype = {
|
|||||||
for (let i = 0; i < permutation.length; i++) {
|
for (let i = 0; i < permutation.length; i++) {
|
||||||
let metaWindow = permutation[i].metaWindow;
|
let metaWindow = permutation[i].metaWindow;
|
||||||
let slot = slots[i];
|
let slot = slots[i];
|
||||||
let slotAbsGeometry = slotGeometries[i];
|
|
||||||
|
|
||||||
let delta = this._computeWindowMotion(metaWindow, slot, slotAbsGeometry);
|
let delta = this._computeWindowMotion(metaWindow, slot);
|
||||||
|
|
||||||
motion += delta;
|
motion += delta;
|
||||||
}
|
}
|
||||||
@ -885,19 +883,18 @@ Workspace.prototype = {
|
|||||||
* Iterate over available slots in order, placing into each one the window
|
* Iterate over available slots in order, placing into each one the window
|
||||||
* we find with the smallest motion to that slot.
|
* we find with the smallest motion to that slot.
|
||||||
*/
|
*/
|
||||||
_orderWindowsGreedy: function(clones, slots, slotGeometries) {
|
_orderWindowsGreedy: function(clones, slots) {
|
||||||
let result = [];
|
let result = [];
|
||||||
let slotIndex = 0;
|
let slotIndex = 0;
|
||||||
// Copy since we mutate below
|
// Copy since we mutate below
|
||||||
let clonesCopy = clones.concat();
|
let clonesCopy = clones.concat();
|
||||||
for (let i = 0; i < slots.length; i++) {
|
for (let i = 0; i < slots.length; i++) {
|
||||||
let slot = slots[i];
|
let slot = slots[i];
|
||||||
let slotGeometry = slotGeometries[i];
|
|
||||||
let minimumMotionIndex = -1;
|
let minimumMotionIndex = -1;
|
||||||
let minimumMotion = -1;
|
let minimumMotion = -1;
|
||||||
for (let j = 0; j < clonesCopy.length; j++) {
|
for (let j = 0; j < clonesCopy.length; j++) {
|
||||||
let metaWindow = clonesCopy[j].metaWindow;
|
let metaWindow = clonesCopy[j].metaWindow;
|
||||||
let delta = this._computeWindowMotion(metaWindow, slot, slotGeometry);
|
let delta = this._computeWindowMotion(metaWindow, slot);
|
||||||
if (minimumMotionIndex == -1 || delta < minimumMotion) {
|
if (minimumMotionIndex == -1 || delta < minimumMotion) {
|
||||||
minimumMotionIndex = j;
|
minimumMotionIndex = j;
|
||||||
minimumMotion = delta;
|
minimumMotion = delta;
|
||||||
@ -922,11 +919,10 @@ Workspace.prototype = {
|
|||||||
clones.sort(function(w1, w2) {
|
clones.sort(function(w1, w2) {
|
||||||
return w2.metaWindow.get_stable_sequence() - w1.metaWindow.get_stable_sequence();
|
return w2.metaWindow.get_stable_sequence() - w1.metaWindow.get_stable_sequence();
|
||||||
});
|
});
|
||||||
let slotGeometries = slots.map(Lang.bind(this, this._getSlotAbsoluteGeometry));
|
|
||||||
if (clones.length <= POSITIONING_PERMUTATIONS_MAX)
|
if (clones.length <= POSITIONING_PERMUTATIONS_MAX)
|
||||||
return this._orderWindowsPermutations(clones, slots, slotGeometries);
|
return this._orderWindowsPermutations(clones, slots);
|
||||||
else
|
else
|
||||||
return this._orderWindowsGreedy(clones, slots, slotGeometries);
|
return this._orderWindowsGreedy(clones, slots);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -948,19 +944,6 @@ Workspace.prototype = {
|
|||||||
return [x, y, width, height];
|
return [x, y, width, height];
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* _getSlotAbsoluteGeometry:
|
|
||||||
* @slot: A layout slot
|
|
||||||
*
|
|
||||||
* Returns: the screen coordiantes [x, y, width, height]
|
|
||||||
* of a given window layout slot.
|
|
||||||
*/
|
|
||||||
_getSlotAbsoluteGeometry: function(slot) {
|
|
||||||
let [x, y, width, height] = this._getSlotRelativeGeometry(slot);
|
|
||||||
return [ this.gridX + x, this.gridY + y,
|
|
||||||
this.scale * width, this.scale * height];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _computeWindowRelativeLayout:
|
* _computeWindowRelativeLayout:
|
||||||
* @metaWindow: A #MetaWindow
|
* @metaWindow: A #MetaWindow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user