From 0a1a805553fb3548f8acce46633e2528a88f18ed Mon Sep 17 00:00:00 2001
From: Fabian Homborg <FHomborg@gmail.com>
Date: Thu, 7 Nov 2013 22:39:04 +0100
Subject: [PATCH] Fix graphics bugs

This requires delaying the first resize until after the window is shown

It seems that kwin doesn't create the pixmap early enough so we could
resize before that happens.
---
 contents/code/tile.js          | 19 ++++++++++++++++++-
 contents/code/tilelist.js      | 16 ++++++++++++++--
 contents/code/tilingmanager.js |  1 +
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/contents/code/tile.js b/contents/code/tile.js
index 47b5ef0..cca4fe8 100644
--- a/contents/code/tile.js
+++ b/contents/code/tile.js
@@ -178,6 +178,12 @@ Tile.prototype.onClientGeometryChanged = function(client) {
 		if (client == null) {
 			return;
 		}
+		if (client.deleted == true) {
+			return;
+		}
+		if (client.managed == false) {
+			return;
+		}
 		if (client.tiling_MoveResize == true) {
 			client.tiling_MoveResize = false;
 			return;
@@ -199,16 +205,27 @@ Tile.prototype.onClientGeometryChanged = function(client) {
 		if (this._moving || this._resizing) {
 			return;
 		}
-		if (this.rectangle != null) {
+		if (this.rectangle != null && client.tiling_shown == true) {
 			if (client.geometry.x != this.rectangle.x ||
 				client.geometry.y != this.rectangle.y ||
 				client.geometry.width != this.rectangle.width ||
 				client.geometry.height != this.rectangle.height) {
 				client.tiling_MoveResize = true;
+				/*
+				if (client.minSize.w > this.rectangle.width) {
+					this.rectangle.width = client.minSize.w;
+				}
+				if (client.minSize.h > this.rectangle.height) {
+					this.rectangle.height = client.minSize.h;
+				}
+				*/
 				client.geometry = Qt.rect(this.rectangle.x,
 										  this.rectangle.y,
 										  this.rectangle.width,
 										  this.rectangle.height);
+				// This could take a _lot_ of processing power and battery life
+				// TEST
+				client.addRepaint(this.rectangle);
 			}
 		}
 		this.geometryChanged.emit();
diff --git a/contents/code/tilelist.js b/contents/code/tilelist.js
index f9e755e..10cfdfb 100644
--- a/contents/code/tilelist.js
+++ b/contents/code/tilelist.js
@@ -95,6 +95,18 @@ TileList.prototype.connectSignals = function(client) {
 			tile.onClientGeometryChanged(client);
 		}
     });
+	client.windowShown.connect(function() {
+		// Delay adding until the window is actually shown
+		// This prevents graphics bugs
+		// due to resizing before the pixmap is created (or something like that)
+		if (client.tiling_shown != true) {
+			client.tiling_shown = true;
+			var tile = getTile(client);
+			if (tile != null) {
+				tile.onClientGeometryChanged(client);
+			}
+		}
+	});
     client.clientStartUserMovedResized.connect(function() {
 		var tile = getTile(client);
 		if (tile != null) {
@@ -284,8 +296,8 @@ TileList.prototype._removeTile = function(tileIndex) {
 };
 
 /**
- * Returns true for clients which shall not be handled by the tiling script at
- * all, e.g. the panel.
+ * Returns true for clients which shall never be handled by the tiling script,
+ * e.g. panels, dialogs or the user-defined apps
  */
 TileList._isIgnored = function(client) {
     // Application workarounds should be put here
diff --git a/contents/code/tilingmanager.js b/contents/code/tilingmanager.js
index 0f3c60e..fa01b5a 100644
--- a/contents/code/tilingmanager.js
+++ b/contents/code/tilingmanager.js
@@ -116,6 +116,7 @@ function TilingManager() {
     var existingClients = workspace.clientList();
     existingClients.forEach(function(client) {
 		self.tiles._onClientRemoved(client);
+		client.tiling_shown = true;
 		self.tiles.addClient(client);
 		// Don't reset floating so we don't lose the value over restarts
         //client.tiling_floating = null;
-- 
GitLab