+ /* If the last client was a floating client, we need to go to the next
+ * tiling client in stack and re-decorate it. */
+ if (old_client != NULL && client_is_floating(old_client)) {
+ DLOG("Coming from floating client, searching next tiling...\n");
+ Client *current;
+ SLIST_FOREACH(current, &(client->workspace->focus_stack), focus_clients) {
+ if (client_is_floating(current))
+ continue;
+
+ DLOG("Found window: %p / child %p\n", current->frame, current->child);
+ redecorate_window(conn, current);
+ break;
+ }
+ }
+
+ SLIST_REMOVE(&(client->workspace->focus_stack), client, Client, focus_clients);
+ SLIST_INSERT_HEAD(&(client->workspace->focus_stack), client, focus_clients);
+
+ /* Clear the urgency flag if set (necessary when i3 sets the flag, for
+ * example when automatically putting windows on the workspace of their
+ * leader) */
+ client->urgent = false;
+ workspace_update_urgent_flag(client->workspace);
+
+ /* If we’re in stacking mode, this renders the container to update changes in the title
+ bars and to raise the focused client */
+ if ((old_client != NULL) && (old_client != client) && !old_client->dock)
+ redecorate_window(conn, old_client);
+
+ /* redecorate_window flushes, so we don’t need to */
+ redecorate_window(conn, client);
+}
+
+/*
+ * Called when the user switches to another mode or when the container is
+ * destroyed and thus needs to be cleaned up.
+ *
+ */
+void leave_stack_mode(xcb_connection_t *conn, Container *container) {
+ /* When going out of stacking mode, we need to close the window */
+ struct Stack_Window *stack_win = &(container->stack_win);
+
+ SLIST_REMOVE(&stack_wins, stack_win, Stack_Window, stack_windows);
+
+ xcb_free_gc(conn, stack_win->pixmap.gc);
+ xcb_free_pixmap(conn, stack_win->pixmap.id);
+ xcb_destroy_window(conn, stack_win->window);
+
+ stack_win->rect.width = -1;
+ stack_win->rect.height = -1;