]> git.sur5r.net Git - i3/i3/commitdiff
kill placeholder windows when the actual window appears
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 15 Dec 2013 14:00:26 +0000 (15:00 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 22 Dec 2013 20:52:49 +0000 (21:52 +0100)
include/restore_layout.h
src/manage.c
src/restore_layout.c

index a039f92f72a454527662ff44b32e7e851c3a44db..75617410dd608842263b7cc3a73f2bc2f5d6396d 100644 (file)
@@ -29,4 +29,13 @@ void restore_connect(void);
  */
 void restore_open_placeholder_windows(Con *con);
 
+/**
+ * Kill the placeholder window, if placeholder refers to a placeholder window.
+ * This function is called when manage.c puts a window into an existing
+ * container. In order not to leak resources, we need to destroy the window and
+ * all associated X11 objects (pixmap/gc).
+ *
+ */
+bool restore_kill_placeholder(xcb_window_t placeholder);
+
 #endif
index 0eaf35e7ecedd4e9583e4e3c156fddabb3a419b3..d7a28eb140a83a612d7a29d98b6419b61a28c3db 100644 (file)
@@ -327,6 +327,11 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
     }
 
     DLOG("new container = %p\n", nc);
+    if (nc->window != NULL) {
+        if (!restore_kill_placeholder(nc->window->id)) {
+            DLOG("Uh?! Container without a placeholder, but with a window, has swallowed this to-be-managed window?!\n");
+        }
+    }
     nc->window = cwindow;
     x_reinit(nc);
 
index f868cf3e5839adebb94cf6ab3313040b65a3c2b9..319b5505776fad670f52baa6a9d54bbcc34fc370 100644 (file)
@@ -226,6 +226,32 @@ void restore_open_placeholder_windows(Con *parent) {
     xcb_flush(restore_conn);
 }
 
+/*
+ * Kill the placeholder window, if placeholder refers to a placeholder window.
+ * This function is called when manage.c puts a window into an existing
+ * container. In order not to leak resources, we need to destroy the window and
+ * all associated X11 objects (pixmap/gc).
+ *
+ */
+bool restore_kill_placeholder(xcb_window_t placeholder) {
+    placeholder_state *state;
+    TAILQ_FOREACH(state, &state_head, state) {
+        if (state->window != placeholder)
+            continue;
+
+        xcb_destroy_window(restore_conn, state->window);
+        xcb_free_pixmap(restore_conn, state->pixmap);
+        xcb_free_gc(restore_conn, state->gc);
+        TAILQ_REMOVE(&state_head, state, state);
+        free(state);
+        DLOG("placeholder window 0x%08x destroyed.\n", placeholder);
+        return true;
+    }
+
+    DLOG("0x%08x is not a placeholder window, ignoring.\n", placeholder);
+    return false;
+}
+
 static void expose_event(xcb_expose_event_t *event) {
     placeholder_state *state;
     TAILQ_FOREACH(state, &state_head, state) {