From 5d7344af8af0fe06fa3d07e25daa0c3577e881f9 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Sun, 14 Nov 2010 18:52:40 +0100
Subject: [PATCH] resize/unmap container x11 windows on demand (makes
 background images visible again)

---
 src/x.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/x.c b/src/x.c
index fe7ce8e0..41707bf7 100644
--- a/src/x.c
+++ b/src/x.c
@@ -372,6 +372,7 @@ void x_draw_decoration(Con *con) {
 static void x_push_node(Con *con) {
     Con *current;
     con_state *state;
+    Rect rect = con->rect;
 
     LOG("Pushing changes for node %p / %s\n", con, con->name);
     state = state_for_frame(con->frame);
@@ -384,6 +385,28 @@ static void x_push_node(Con *con) {
         FREE(state->name);
     }
 
+    if (con->window == NULL) {
+        /* Calculate the height of all window decorations which will be drawn on to
+         * this frame. */
+        uint32_t max_y = 0, max_height = 0;
+        TAILQ_FOREACH(current, &(con->nodes_head), nodes) {
+            DLOG("Child's decoration is %d x %d, from (%d, %d)\n",
+                    current->deco_rect.width, current->deco_rect.height,
+                    current->deco_rect.x, current->deco_rect.y);
+            Rect *dr = &(current->deco_rect);
+            if (dr->y >= max_y && dr->height >= max_height) {
+                max_y = dr->y;
+                max_height = dr->height;
+            }
+        }
+        DLOG("bottom of decorations is %d\n", max_y + max_height);
+        rect.height = max_y + max_height;
+        if (rect.height == 0) {
+            DLOG("Unmapping container because it does not contain anything atm.\n");
+            con->mapped = false;
+        }
+    }
+
     /* reparent the child window (when the window was moved due to a sticky
      * container) */
     if (state->need_reparent && con->window != NULL) {
@@ -452,10 +475,10 @@ static void x_push_node(Con *con) {
 
     bool fake_notify = false;
     /* set new position if rect changed */
-    if (memcmp(&(state->rect), &(con->rect), sizeof(Rect)) != 0) {
-        LOG("setting rect (%d, %d, %d, %d)\n", con->rect.x, con->rect.y, con->rect.width, con->rect.height);
-        xcb_set_window_rect(conn, con->frame, con->rect);
-        memcpy(&(state->rect), &(con->rect), sizeof(Rect));
+    if (memcmp(&(state->rect), &rect, sizeof(Rect)) != 0) {
+        LOG("setting rect (%d, %d, %d, %d)\n", rect.x, rect.y, rect.width, rect.height);
+        xcb_set_window_rect(conn, con->frame, rect);
+        memcpy(&(state->rect), &rect, sizeof(Rect));
         fake_notify = true;
     }