From 2b433775647fccd519fb76ead94cb500d1d14c84 Mon Sep 17 00:00:00 2001
From: Fabian Homborg <FHomborg@gmail.com>
Date: Thu, 24 Oct 2013 11:20:33 +0200
Subject: [PATCH] Fix turning off tiling on a desktop and switching away and
 back

---
 contents/code/tiling.js        | 23 ++++++++++++++++-------
 contents/code/tilingmanager.js |  2 +-
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/contents/code/tiling.js b/contents/code/tiling.js
index d5afbd2..27025fb 100644
--- a/contents/code/tiling.js
+++ b/contents/code/tiling.js
@@ -40,6 +40,7 @@ function Tiling(screenRectangle, layoutType, desktop, screen) {
 		 * True if the layout is active.
 		 */
 		this.active = false;
+		this.userActive = true;
 
 		this.screenRectangle = screenRectangle;
 		
@@ -119,13 +120,11 @@ Tiling.prototype.swapTiles = function(tile1, tile2) {
 }
 
 Tiling.prototype.activate = function() {
-    this.active = true;
-    // Resize the tiles like specified by the layout
-    this._updateAllTiles();
-    // If no tile geometry was specified, just restore the saved geometry
-    // TODO
-    // Register callbacks for all tiles
-    // TODO
+	if (this.userActive == true) {
+		this.active = true;
+		// Resize the tiles like specified by the layout
+		this._updateAllTiles();
+	}
 }
 
 Tiling.prototype.deactivate = function() {
@@ -142,6 +141,16 @@ Tiling.prototype.toggleActive = function() {
 	}
 }
 
+Tiling.prototype.toggleUserActive = function() {
+	if (this.userActive == true) {
+		this.userActive = false;
+		this.deactivate();
+	} else {
+		this.userActive = true;
+		this.activate();
+	}
+}
+
 /**
  * Resets tile sizes to their initial size (in case they were resized by the
  * user).
diff --git a/contents/code/tilingmanager.js b/contents/code/tilingmanager.js
index 7d3365b..ca3a94d 100644
--- a/contents/code/tilingmanager.js
+++ b/contents/code/tilingmanager.js
@@ -225,7 +225,7 @@ function TilingManager() {
 					 function() {
 						 var currentScreen = workspace.activeScreen;
 						 var currentDesktop = workspace.currentDesktop - 1;
-						 self.layouts[currentDesktop][currentScreen].toggleActive();
+						 self.layouts[currentDesktop][currentScreen].toggleUserActive();
 					 });
 	registerUserActionsMenu(function(client) {
 		return {
-- 
GitLab