4 * i3 - an improved dynamic tiling window manager
6 * (c) 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
23 /* All functions handling layout/drawing of window decorations */
26 * (Re-)draws window decorations for a given Client
29 void decorate_window(xcb_connection_t *conn, Client *client) {
32 i3Font *font = load_font(conn, pattern);
33 uint32_t background_color,
37 if (client->container->currently_focused == client) {
38 background_color = get_colorpixel(conn, client->frame, "#285577");
39 text_color = get_colorpixel(conn, client->frame, "#ffffff");
40 border_color = get_colorpixel(conn, client->frame, "#4c7899");
42 background_color = get_colorpixel(conn, client->frame, "#222222");
43 text_color = get_colorpixel(conn, client->frame, "#888888");
44 border_color = get_colorpixel(conn, client->frame, "#333333");
47 /* Our plan is the following:
48 - Draw a rect around the whole client in background_color
49 - Draw two lines in a lighter color
50 - Draw the window’s title
52 Note that xcb_image_text apparently adds 1xp border around the font? Can anyone confirm this?
55 /* Draw a green rectangle around the window */
56 mask = XCB_GC_FOREGROUND;
57 values[0] = background_color;
58 xcb_change_gc(conn, client->titlegc, mask, values);
60 xcb_rectangle_t rect = {0, 0, client->width, client->height};
61 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &rect);
64 /* TODO: this needs to be more beautiful somewhen. maybe stdarg + change_gc(gc, ...) ? */
65 #define DRAW_LINE(colorpixel, x, y, to_x, to_y) { \
66 uint32_t draw_values[1]; \
67 draw_values[0] = colorpixel; \
68 xcb_change_gc(conn, client->titlegc, XCB_GC_FOREGROUND, draw_values); \
69 xcb_point_t points[] = {{x, y}, {to_x, to_y}}; \
70 xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, client->frame, client->titlegc, 2, points); \
73 DRAW_LINE(border_color, 2, 0, client->width, 0);
74 DRAW_LINE(border_color, 2, font->height + 3, 2 + client->width, font->height + 3);
77 mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
79 values[0] = text_color;
80 values[1] = background_color;
83 xcb_change_gc(conn, client->titlegc, mask, values);
87 asprintf(&label, "(%08x) %.*s", client->frame, client->name_len, client->name);
88 xcb_void_cookie_t text_cookie = xcb_image_text_8_checked(conn, strlen(label), client->frame,
89 client->titlegc, 3 /* X */, font->height /* Y = baseline of font */, label);
90 check_error(conn, text_cookie, "Could not draw client's title");
94 static void render_container(xcb_connection_t *connection, Container *container) {
96 i3Font *font = load_font(connection, pattern);
98 if (container->mode == MODE_DEFAULT) {
100 CIRCLEQ_FOREACH(client, &(container->clients), clients)
102 printf("got %d clients in this default container.\n", num_clients);
104 int current_client = 0;
105 CIRCLEQ_FOREACH(client, &(container->clients), clients) {
106 /* TODO: at the moment, every column/row is screen / num_cols. This
107 * needs to be changed to "percentage of the screen" by
108 * default and adjustable by the user if necessary.
111 /* Check if we changed client->x or client->y by updating it…
112 * Note the bitwise OR instead of logical OR to force evaluation of both statements */
113 if ((client->x != (client->x = container->x + (container->col * container->width))) |
114 (client->y != (client->y = container->y + (container->row * container->height +
115 (container->height / num_clients) * current_client)))) {
116 printf("frame needs to be pushed to %dx%d\n", client->x, client->y);
117 /* Note: We can use a pointer to client->x like an array of uint32_ts
118 because it is followed by client->y by definition */
119 xcb_configure_window(connection, client->frame,
120 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, &(client->x));
123 /* TODO: vertical default layout */
124 if ((client->width != (client->width = container->width)) |
125 (client->height != (client->height = container->height / num_clients))) {
126 xcb_configure_window(connection, client->frame,
127 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
130 /* Adjust the position of the child inside its frame.
131 * The coordinates of the child are relative to its frame, we
132 * add a border of 2 pixel to each value */
133 uint32_t mask = XCB_CONFIG_WINDOW_X |
134 XCB_CONFIG_WINDOW_Y |
135 XCB_CONFIG_WINDOW_WIDTH |
136 XCB_CONFIG_WINDOW_HEIGHT;
137 uint32_t values[4] = {2, /* x */
138 font->height + 2 + 2, /* y */
139 client->width - (2 + 2), /* width */
140 client->height - ((font->height + 2 + 2) + 2)}; /* height */
142 printf("child itself will be at %dx%d with size %dx%d\n",
143 values[0], values[1], values[2], values[3]);
145 xcb_configure_window(connection, client->child, mask, values);
148 decorate_window(connection, client);
152 /* TODO: Implement stacking */
156 void render_layout(xcb_connection_t *conn) {
159 for (screen = 0; screen < num_screens; screen++) {
160 printf("Rendering screen %d\n", screen);
161 /* TODO: get the workspace which is active on the screen */
162 int width = workspaces[screen].width;
163 int height = workspaces[screen].height;
165 printf("got %d rows and %d cols\n", c_ws->rows, c_ws->cols);
166 printf("each of them therefore is %d px width and %d px height\n",
167 width / c_ws->cols, height / c_ws->rows);
169 /* Go through the whole table and render what’s necessary */
170 for (cols = 0; cols < c_ws->cols; cols++)
171 for (rows = 0; rows < c_ws->rows; rows++) {
172 Container *con = CUR_TABLE[cols][rows];
173 printf("container has %d colspan, %d rowspan\n",
174 con->colspan, con->rowspan);
175 /* Update position of the container */
178 con->x = workspaces[screen].x;
179 con->y = workspaces[screen].y;
180 con->width = (width / c_ws->cols) * con->colspan;
181 con->height = (height / c_ws->rows) * con->rowspan;
184 render_container(conn, CUR_TABLE[cols][rows]);