+/*
+ * Switches the layout of the given container taking care of the necessary house-keeping
+ *
+ */
+void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode) {
+ if (mode == MODE_STACK) {
+ /* When entering stacking mode, we need to open a window on which we can draw the
+ title bars of the clients, it has height 1 because we don’t bother here with
+ calculating the correct height - it will be adjusted when rendering anyways. */
+ Rect rect = {container->x, container->y, container->width, 1 };
+
+ uint32_t mask = 0;
+ uint32_t values[2];
+
+ /* Don’t generate events for our new window, it should *not* be managed */
+ mask |= XCB_CW_OVERRIDE_REDIRECT;
+ values[0] = 1;
+
+ /* We want to know when… */
+ mask |= XCB_CW_EVENT_MASK;
+ values[1] = XCB_EVENT_MASK_BUTTON_PRESS | /* …mouse is pressed */
+ XCB_EVENT_MASK_EXPOSURE; /* …our window needs to be redrawn */
+
+ struct Stack_Window *stack_win = &(container->stack_win);
+ stack_win->window = create_window(conn, rect, XCB_WINDOW_CLASS_INPUT_OUTPUT, mask, values);
+
+ /* Generate a graphics context for the titlebar */
+ stack_win->gc = xcb_generate_id(conn);
+ xcb_create_gc(conn, stack_win->gc, stack_win->window, 0, 0);
+
+ stack_win->container = container;
+
+ SLIST_INSERT_HEAD(&stack_wins, stack_win, stack_windows);
+ } else {
+ if (container->mode == MODE_STACK) {
+ /* 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->gc);
+ xcb_destroy_window(conn, stack_win->window);
+
+ stack_win->width = -1;
+ stack_win->height = -1;
+ }
+ }
+ container->mode = mode;
+
+ /* Force reconfiguration of each client */
+ Client *client;
+
+ CIRCLEQ_FOREACH(client, &(container->clients), clients)
+ client->force_reconfigure = true;
+
+ render_layout(conn);
+}
+
+/*
+ * Warps the pointer into the given client (in the middle of it, to be specific), therefore
+ * selecting it
+ *
+ */
+void warp_pointer_into(xcb_connection_t *connection, Client *client) {
+ int mid_x = client->rect.width / 2,
+ mid_y = client->rect.height / 2;
+ xcb_warp_pointer(connection, XCB_NONE, client->child, 0, 0, 0, 0, mid_x, mid_y);
+}
+