]> git.sur5r.net Git - i3/i3/blobdiff - src/x.c
fix: to always abort we need to assert(false)
[i3/i3] / src / x.c
diff --git a/src/x.c b/src/x.c
index 347b8f7649849934b716552a2869e09dad81a7ad..f0a34d3bf466c3aba5aa803562207f23f8a57c23 100644 (file)
--- a/src/x.c
+++ b/src/x.c
@@ -48,7 +48,7 @@ static con_state *state_for_frame(xcb_window_t window) {
 
     /* TODO: better error handling? */
     ELOG("No state found\n");
-    assert(true);
+    assert(false);
     return NULL;
 }
 
@@ -86,6 +86,25 @@ void x_con_init(Con *con) {
     LOG("adding new state for window id 0x%08x\n", state->id);
 }
 
+/*
+ * Re-initializes the associated X window state for this container. You have
+ * to call this when you assign a client to an empty container to ensure that
+ * its state gets updated correctly.
+ *
+ */
+void x_reinit(Con *con) {
+    struct con_state *state;
+
+    if ((state = state_for_frame(con->frame)) == NULL) {
+        ELOG("window state not found\n");
+        return;
+    }
+
+    LOG("resetting state %p to initial\n", state);
+    state->initial = true;
+    memset(&(state->window_rect), 0, sizeof(Rect));
+}
+
 void x_con_kill(Con *con) {
     con_state *state;
 
@@ -202,8 +221,10 @@ static void x_push_node(Con *con) {
     LOG("Pushing changes for node %p / %s\n", con, con->name);
     state = state_for_frame(con->frame);
 
-    /* map/unmap if map state changed */
-    if (state->mapped != con->mapped) {
+    /* map/unmap if map state changed, also ensure that the child window
+     * is changed if we are mapped *and* in initial state (meaning the
+     * container was empty before, but now got a child) */
+    if (state->mapped != con->mapped || (con->mapped && state->initial)) {
         if (!con->mapped) {
             LOG("unmapping container\n");
             xcb_unmap_window(conn, con->frame);
@@ -218,11 +239,13 @@ static void x_push_node(Con *con) {
         state->mapped = con->mapped;
     }
 
+    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));
+        fake_notify = true;
     }
 
     /* dito, but for child windows */
@@ -231,6 +254,12 @@ static void x_push_node(Con *con) {
             con->window_rect.x, con->window_rect.y, con->window_rect.width, con->window_rect.height);
         xcb_set_window_rect(conn, con->window->id, con->window_rect);
         memcpy(&(state->rect), &(con->rect), sizeof(Rect));
+        fake_notify = true;
+    }
+
+    if (fake_notify) {
+        LOG("Sending fake configure notify\n");
+        fake_absolute_configure_notify(con);
     }
 
     /* handle all children and floating windows of this node */
@@ -255,7 +284,7 @@ void x_push_changes(Con *con) {
     LOG("\n\n PUSHING CHANGES\n\n");
     x_push_node(con);
 
-    LOG("-- PUSHING FOCUS STACK --\n");
+    LOG("-- PUSHING WINDOW STACK --\n");
     /* X11 correctly represents the stack if we push it from bottom to top */
     CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
         LOG("stack: 0x%08x\n", state->id);
@@ -278,7 +307,7 @@ void x_push_changes(Con *con) {
         to_focus = focused->window->id;
 
     if (focused_id != to_focus) {
-        LOG("Updating focus\n");
+        LOG("Updating focus (focused: %p / %s)\n", focused, focused->name);
         xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, to_focus, XCB_CURRENT_TIME);
     }