From 985d73d92ed8e83c3236054a3c3039a735f1b43b Mon Sep 17 00:00:00 2001 From: Fabian Homborg <FHomborg@gmail.com> Date: Thu, 24 Oct 2013 11:53:49 +0200 Subject: [PATCH] Add more error checking --- contents/code/tile.js | 3 +++ contents/code/tilelist.js | 21 ++++++++++------ contents/code/tilingmanager.js | 46 ++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/contents/code/tile.js b/contents/code/tile.js index ec899cb..9523049 100644 --- a/contents/code/tile.js +++ b/contents/code/tile.js @@ -184,6 +184,9 @@ Tile.prototype.syncCustomProperties = function() { Tile.prototype.onClientGeometryChanged = function(client) { try { + if (client == null) { + return; + } if (!client.isCurrentTab) { return; } diff --git a/contents/code/tilelist.js b/contents/code/tilelist.js index abc523a..fdbf608 100644 --- a/contents/code/tilelist.js +++ b/contents/code/tilelist.js @@ -155,6 +155,9 @@ TileList.prototype.connectSignals = function(client) { * @param client Client which is added to the tile list. */ TileList.prototype.addClient = function(client) { + if (client == null) { + return; + } if (TileList._isIgnored(client)) { client.tileIndex = - 1; return; @@ -300,13 +303,17 @@ TileList.prototype._addTile = function(client) { }; TileList.prototype._removeTile = function(tileIndex) { - // Remove the tile if this was the last client in it - var tile = this.tiles[tileIndex]; - this.tiles[tileIndex] = this.tiles[this.tiles.length - 1]; - this.tiles[tileIndex].tileIndex = tileIndex; - this.tiles[tileIndex].syncCustomProperties(); - this.tileRemoved.emit(tile); - this.tiles.length--; + try { + // Remove the tile if this was the last client in it + var tile = this.tiles[tileIndex]; + this.tiles[tileIndex] = this.tiles[this.tiles.length - 1]; + this.tiles[tileIndex].tileIndex = tileIndex; + this.tiles[tileIndex].syncCustomProperties(); + this.tileRemoved.emit(tile); + this.tiles.length--; + } catch(err) { + print(err, "in TileList._removeTile"); + } }; /** diff --git a/contents/code/tilingmanager.js b/contents/code/tilingmanager.js index ca3a94d..24127b9 100644 --- a/contents/code/tilingmanager.js +++ b/contents/code/tilingmanager.js @@ -386,28 +386,32 @@ TilingManager.prototype._onTileMovingStarted = function(tile) { } TilingManager.prototype._onTileMovingEnded = function(tile) { - var client = tile.clients[0]; - this._moving = false; - var movingEndScreen = client.screen; - var windowRect = client.geometry; - if (client.tiling_tileIndex >= 0) { - if (this._movingStartScreen != movingEndScreen) { - // Transfer the tile from one layout to another layout - var startLayout = - this.layouts[this._currentDesktop][this._movingStartScreen]; - var endLayout = this.layouts[this._currentDesktop][client.screen]; - startLayout.removeTile(tile); - endLayout.addTile(tile, windowRect.x + windowRect.width / 2, - windowRect.y + windowRect.height / 2); - } else { - // Transfer the tile to a different location in the same layout - var layout = this.layouts[this._currentDesktop][client.screen]; - var targetTile = layout.getTile(windowRect.x + windowRect.width / 2, - windowRect.y + windowRect.height / 2); - // swapTiles() works correctly even if tile == targetTile - layout.swapTiles(tile, targetTile); + try { + var client = tile.clients[0]; + this._moving = false; + var movingEndScreen = client.screen; + var windowRect = client.geometry; + if (client.tiling_tileIndex >= 0) { + if (this._movingStartScreen != movingEndScreen) { + // Transfer the tile from one layout to another layout + var startLayout = + this.layouts[this._currentDesktop][this._movingStartScreen]; + var endLayout = this.layouts[this._currentDesktop][client.screen]; + startLayout.removeTile(tile); + endLayout.addTile(tile, windowRect.x + windowRect.width / 2, + windowRect.y + windowRect.height / 2); + } else { + // Transfer the tile to a different location in the same layout + var layout = this.layouts[this._currentDesktop][client.screen]; + var targetTile = layout.getTile(windowRect.x + windowRect.width / 2, + windowRect.y + windowRect.height / 2); + // swapTiles() works correctly even if tile == targetTile + layout.swapTiles(tile, targetTile); + } + workspace.hideOutline(); } - workspace.hideOutline(); + } catch(err) { + print(err, "in TilingManager._onTileMovingEnded"); } } -- GitLab