diff --git a/contents/code/tilelist.js b/contents/code/tilelist.js index 57982e0f5c68cc4d9820b338047bb988728df308..5492ffc641c30bc4693dcec5350ebb10c8fa33f4 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 8e4b67762afdf0b8cbb51f92ea92346d21c17dd8..85fdd5e5171eceec72158b73aa27ca1c5196bcc8 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 347eedb6d958af7f53c8e10d5fe93f1601854b67..7b349a097a66fb156d0cc580c2a1f6d3e8793552 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) {