]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Insert the new client after the currently active one, not always at the end
authorMichael Stapelberg <michael+git@stapelberg.de>
Sat, 28 Feb 2009 01:24:38 +0000 (02:24 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Sat, 28 Feb 2009 01:24:38 +0000 (02:24 +0100)
src/mainx.c

index 114e471fee17544697122bc095b23aaa48f08638..5083f7018e3ab36fb5ff726e16d5c77e551f2dbf 100644 (file)
@@ -119,7 +119,7 @@ out:
  * reparent_window() gets called when a new window was opened and becomes a child of the root
  * window, or it gets called by us when we manage the already existing windows at startup.
  *
- * Essentially, this is the point, where we take over control.
+ * Essentially, this is the point where we take over control.
  *
  */
 void reparent_window(xcb_connection_t *conn, xcb_window_t child,
@@ -143,6 +143,7 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
         uint32_t values[3];
 
         /* Update the data structures */
+        Client *old_focused = CUR_CELL->currently_focused;
         CUR_CELL->currently_focused = new;
         new->container = CUR_CELL;
 
@@ -238,8 +239,13 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
         }
 
         /* Insert into the currently active container, if it’s not a dock window */
-        if (!new->dock)
-                CIRCLEQ_INSERT_TAIL(&(CUR_CELL->clients), new, clients);
+        if (!new->dock) {
+                /* Insert after the old active client, if existing. If it does not exist, the
+                   container is empty and it does not matter, where we insert it */
+                if (old_focused != NULL)
+                        CIRCLEQ_INSERT_AFTER(&(CUR_CELL->clients), old_focused, new, clients);
+                else CIRCLEQ_INSERT_TAIL(&(CUR_CELL->clients), new, clients);
+        }
 
         render_layout(conn);
 }