Skip to content
Snippets Groups Projects
Commit 32d1cd95 authored by Fabian Homborg's avatar Fabian Homborg
Browse files

Put windows that reappear (e.g. unminimize) in the same tile

This appears to crash kwin quite a bit
parent 5d33dfb5
No related branches found
No related tags found
No related merge requests found
......@@ -285,3 +285,7 @@ Tile.prototype.addClient = function(client) {
print(err, "in Tile.addClient");
}
}
Tile.prototype.hasClient = function(client) {
return (this.clients.indexOf(client) > -1);
}
......@@ -87,7 +87,7 @@ TileList.prototype.connectSignals = function(client) {
// We also have to connect other client signals here instead of in Tile
// because the tile of a client might change over time
var getTile = function(client) {
return self.tiles[client.tiling_tileIndex];
return self.getTile(client);
};
client.geometryShapeChanged.connect(function() {
var tile = getTile(client);
......@@ -156,6 +156,7 @@ TileList.prototype.addClient = function(client) {
}
if (TileList._isIgnored(client)) {
client.tiling_tileIndex = -1;
client.tiling_floating = true;
return;
}
......@@ -177,34 +178,17 @@ TileList.prototype.addClient = function(client) {
}
// Check whether the client is part of an existing tile
var tileIndex = client.tiling_tileIndex;
if (tileIndex >= 0 && tileIndex < this.tiles.length) {
var notInTiles = true;
for (var i=0; i< this.tiles.length; i++) {
if (this.tiles[i] === client) {
notInTiles = false;
break;
}
}
if (notInTiles) {
this.tiles[tileIndex].addClient(client);
}
} else {
// If not, create a new tile
if (this._indexWithClient(client) == -1) {
this._addTile(client);
}
}
client.tiling_floating = false;
assert(client.tiling_tileIndex >= 0, "Client added with invalid tileIndex");
};
TileList.prototype.retile = function() {
var existingClients = workspace.clientList();
var self = this;
existingClients.forEach(function(client) {
var tileIndex = client.tiling_tileIndex;
if (tileIndex >= 0 && tileIndex < self.tiles.length) {
self.addClient(client);
}
self.addClient(client);
});
};
......@@ -215,16 +199,14 @@ TileList.prototype.retile = function() {
* @return Tile in which the client is located.
*/
TileList.prototype.getTile = function(client) {
var tileIndex = client.tiling_tileIndex;
if (tileIndex >= 0 && tileIndex < this.tiles.length) {
return this.tiles[tileIndex];
} else {
return null;
}
var index = this._indexWithClient(client);
if (index > -1) {
return this.tiles[index];
}
return null;
};
TileList.prototype._onClientAdded = function(client) {
this._identifyNewTiles();
this.addClient(client);
};
......@@ -237,22 +219,23 @@ TileList.prototype._onClientRemoved = function(client) {
}
}
try {
var tileIndex = client.tiling_tileIndex;
if (!(tileIndex >= 0 && tileIndex < this.tiles.length)) {
return;
}
// Unset keepBelow because we set it when tiling
client.keepBelow = false;
// Remove the client from its tile
var tileIndex = this._indexWithClient(client);
var tile = this.tiles[tileIndex];
if (tile.clients.length == 1) {
// Remove the tile if this was the last client in it
this._removeTile(tileIndex);
} else {
// Remove the client from its tile
tile.removeClient(client);
if (tile != null) {
if (tile.clients.length == 1) {
// Remove the tile if this was the last client in it
this._removeTile(tileIndex);
} else {
// Remove the client from its tile
tile.removeClient(client);
}
}
client.tiling_tileIndex = - 1;
// Don't remove tileIndex, so we can move the window to its position in case it comes back (after minimize etc)
//client.tiling_tileIndex = - 1;
if (client.tiling_floating == true) {
client.noBorder = false;
if (cactive == true) {
......@@ -277,43 +260,28 @@ TileList.prototype._onClientTabGroupChanged = function(client) {
};
TileList.prototype._addTile = function(client) {
var newTile = new Tile(client, this.tiles.length)
var tileIndex = this.tiles.length;
if (client.tiling_tileIndex > -1) {
tileIndex = client.tiling_tileIndex;
}
var newTile = new Tile(client, tileIndex);
this.tiles.push(newTile);
this.tileAdded.emit(newTile);
};
TileList.prototype._removeTile = function(tileIndex) {
try {
// Remove the tile if this was the last client in it
// Don't modify tileIndex here - this is a list of _all_ tiles, while tileIndex is the index on the desktop
var tile = this.tiles[tileIndex];
if (tileIndex < this.tiles.length - 1) {
this.tiles[tileIndex] = this.tiles[this.tiles.length - 1];
this.tiles[tileIndex].tileIndex = tileIndex;
this.tiles[tileIndex].syncCustomProperties();
if (tileIndex > -1) {
this.tiles.splice(tileIndex, 1);
}
this.tileRemoved.emit(tile);
this.tiles.length--;
} catch(err) {
print(err, "in TileList._removeTile");
}
};
/**
* Updates the tile index on all clients in all existing tiles by synchronizing
* the tiling_tileIndex property of the group. Clients which do not belong to
* any existing tile will have this property set to null afterwards, while
* clients which belong to a tile have the correct tile index.
*
* This can only detect clients which are not in any tile, it does not detect
* client tab group changes! These shall be handled by removing the client from
* any tile in _onClientTabGroupChanged() first.
*/
TileList.prototype._identifyNewTiles = function() {
this.tiles.forEach(function(tile) {
tile.syncCustomProperties();
});
};
/**
* Returns true for clients which shall not be handled by the tiling script at
* all, e.g. the panel.
......@@ -329,17 +297,17 @@ TileList._isIgnored = function(client) {
client.syncTabGroupFor("kwin_tiling_floats", true);
return true;
}
if (client.dialog) {
return true;
}
if (client.splash) {
return true;
}
if (client.dock) {
return true;
}
if (client.specialWindow == true) {
return true;
}
return false;
};
TileList.prototype._indexWithClient = function(client) {
for (i = 0; i < this.tiles.length; i++) {
if (this.tiles[i].hasClient(client)) {
return i;
}
}
return -1;
}
......@@ -85,7 +85,16 @@ Tiling.prototype.addTile = function(tile, x, y) {
this.tiles.splice(index, 0, tile);
}
} else {
this.tiles.push(tile);
if (tile.tileIndex > -1) {
this.tiles.splice(tile.tileIndex, 0, tile);
for (i = 0; i < this.tiles.length; i++) {
this.tiles[i].tileIndex = i;
this.tiles[i].syncCustomProperties();
}
} else {
tile.tileIndex = this.tiles.length;
this.tiles.push(tile);
}
}
this._updateAllTiles();
// TODO: Register tile callbacks
......@@ -99,6 +108,11 @@ Tiling.prototype.removeTile = function(tile) {
var tileIndex = this.tiles.indexOf(tile);
this.tiles.splice(tileIndex, 1);
this.layout.removeTile(tileIndex);
// Correct tileIndex
for(i = 0; i < this.tiles.length; i++) {
this.tiles[i].tileIndex = i;
this.tiles[i].syncCustomProperties();
}
// TODO: Unregister tile callbacks
this._updateAllTiles();
} catch(err) {
......@@ -114,6 +128,10 @@ Tiling.prototype.swapTiles = function(tile1, tile2) {
var index2 = this.tiles.indexOf(tile2);
this.tiles[index1] = tile2;
this.tiles[index2] = tile1;
this.tiles[index1].tileIndex = index1;
this.tiles[index2].tileIndex = index2;
this.tiles[index1].syncCustomProperties();
this.tiles[index2].syncCustomProperties();
this._updateAllTiles();
} else if (tile1._moving == false) {
this._updateAllTiles();
......@@ -237,7 +255,7 @@ Tiling.prototype.getAdjacentTile = function(from, direction, directOnly) {
Tiling.prototype.resizeTile = function(tile){
try {
if (tile != null) {
var tileIndex = this.tiles.indexOf(tile);
var tileIndex = tile.tileIndex;
var client = tile.clients[0];
this.layout.resizeTile(tileIndex, client.geometry);
this._updateAllTiles();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment