From b15f88cb59fc9db001f905ef8729e608abb4c0cb Mon Sep 17 00:00:00 2001 From: Fabian Homborg <FHomborg@gmail.com> Date: Sat, 10 Aug 2013 00:17:41 +0200 Subject: [PATCH] Move deactivation (i.e. floating "layout") to tiling.js This is much cleaner than the hodgepodge we had before and also means e.g. desktopswitching can be handled correctly. It is now effectively a layout. This requires a semantics change: addClient can now also deal with already managed clients. --- contents/code/tilelist.js | 22 ++++++++++----------- contents/code/tiling.js | 35 ++++++++++++++++++++++------------ contents/code/tilingmanager.js | 30 ++++++++++++----------------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/contents/code/tilelist.js b/contents/code/tilelist.js index 57982e0..5492ffc 100644 --- a/contents/code/tilelist.js +++ b/contents/code/tilelist.js @@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. * @class */ function TileList() { - this.active = true; /** * List of currently existing tiles. */ @@ -44,12 +43,9 @@ function TileList() { // new/deleted tiles var self = this; workspace.clientAdded.connect(function(client) { - if (self.active == true) { - self._onClientAdded(client); - } + self._onClientAdded(client); }); workspace.clientRemoved.connect(function(client) { - // Even if we aren't active, we need to delete empty tiles self._onClientRemoved(client); }); } @@ -121,7 +117,16 @@ 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) { - this.tiles[tileIndex].clients.push(client); + 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].clients.push(client); + } } else { // If not, create a new tile this._addTile(client); @@ -135,7 +140,6 @@ TileList.prototype.retile = function() { existingClients.forEach(function(client) { var tileIndex = client.tiling_tileIndex; if (tileIndex >= 0 && tileIndex < self.tiles.length) { - self._onClientRemoved(client); self.addClient(client); } }); @@ -267,9 +271,5 @@ TileList._isIgnored = function(client) { print("Client is special"); return true; } - if (this.active == false) { - print("Tiling not active"); - return true; - } return false; }; diff --git a/contents/code/tiling.js b/contents/code/tiling.js index 8e4b677..85fdd5e 100644 --- a/contents/code/tiling.js +++ b/contents/code/tiling.js @@ -65,7 +65,6 @@ Tiling.prototype.addTile = function(tile, x, y) { } else { this.tiles.push(tile); } - // TODO: Set "below all" state if (this.active) { this._updateAllTiles(); // TODO: Register tile callbacks @@ -76,10 +75,8 @@ Tiling.prototype.removeTile = function(tile) { var tileIndex = this.tiles.indexOf(tile); this.tiles.splice(tileIndex, 1); this.layout.removeTile(tileIndex); - if (this.active) { - // TODO: Unregister tile callbacks - this._updateAllTiles(); - } + // TODO: Unregister tile callbacks + this._updateAllTiles(); } Tiling.prototype.swapTiles = function(tile1, tile2) { @@ -108,6 +105,14 @@ Tiling.prototype.deactivate = function() { // TODO } +Tiling.prototype.toggleActive = function() { + if (this.active) { + this.deactivate(); + } else { + this.activate(); + } +} + /** * Resets tile sizes to their initial size (in case they were resized by the * user). @@ -173,14 +178,20 @@ Tiling.prototype.getAdjacentTile = function(from, direction, directOnly) { Tiling.prototype._updateAllTiles = function() { // Set the position/size of all tiles - for (var i = 0; i < this.layout.tiles.length; i++) { - var currentRect = this.tiles[i].clients[0].geometry; - var newRect = this.layout.tiles[i].rectangle; - if (currentRect.x != newRect.x + if (this.active) { + for (var i = 0; i < this.layout.tiles.length; i++) { + var currentRect = this.tiles[i].clients[0].geometry; + var newRect = this.layout.tiles[i].rectangle; + if (! newRect) { + return; + } + // Is this necessary? + if (currentRect.x != newRect.x || currentRect.y != newRect.y || currentRect.width != newRect.width || currentRect.height != newRect.height) { - this.tiles[i].setGeometry(newRect); - } - } + this.tiles[i].setGeometry(newRect); + } + } + } } diff --git a/contents/code/tilingmanager.js b/contents/code/tilingmanager.js index 347eedb..7b349a0 100644 --- a/contents/code/tilingmanager.js +++ b/contents/code/tilingmanager.js @@ -232,22 +232,9 @@ function TilingManager() { "Toggle Tiling", "Meta+Shift+f11", function() { - // FIXME: This moves clients when deactivating tiling - self.active = !self.active; - self.tiles.active = self.active; - print("Tiling: ", self.active); - var existingClients = workspace.clientList(); - if (self.active == false) { - existingClients.forEach(function(client) { - self.tiles._onClientRemoved(client); - client.tiling_tileIndex = -1; - }); - } else { - existingClients.forEach(function(client) { - self.tiles.addClient(client); - self.tiles.retile(); - }); - } + var currentScreen = workspace.activeScreen; + var currentDesktop = workspace.currentDesktop - 1; + self.layouts[currentDesktop][currentScreen].toggleActive(); }); } @@ -453,9 +440,16 @@ TilingManager.prototype._changeTileLayouts = TilingManager.prototype._onCurrentDesktopChanged = function() { // TODO: This is wrong, we need to activate *all* visible layouts - this.layouts[this._currentDesktop][this._currentScreen].deactivate(); + if (this.layouts[this._currentDesktop][this._currentScreen].active) { + this.layouts[this._currentDesktop][this._currentScreen].deactivate(); + } + if (this._currentDesktop === workspace.currentDesktop -1) { + return; + } this._currentDesktop = workspace.currentDesktop - 1; - this.layouts[this._currentDesktop][this._currentScreen].activate(); + if (! this.layouts[this._currentDesktop][this._currentScreen].active) { + this.layouts[this._currentDesktop][this._currentScreen].activate(); + } }; TilingManager.prototype._switchLayout = function(desktop, screen, layoutIndex) { -- GitLab