4 * i3 - an improved dynamic tiling window manager
6 * © 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
10 * layout.c: Functions handling layout/drawing of window decorations
30 #include "workspace.h"
33 * Updates *destination with new_value and returns true if it was changed or false
37 static bool update_if_necessary(uint32_t *destination, const uint32_t new_value) {
38 uint32_t old_value = *destination;
40 return ((*destination = new_value) != old_value);
44 * Gets the unoccupied space (= space which is available for windows which were resized by the user)
45 * for the given row. This is necessary to render both, customly resized windows and never touched
46 * windows correctly, meaning that the aspect ratio will be maintained when opening new windows.
49 int get_unoccupied_x(Workspace *workspace) {
50 int unoccupied = workspace->rect.width;
51 float default_factor = ((float)workspace->rect.width / workspace->cols) / workspace->rect.width;
53 LOG("get_unoccupied_x(), starting with %d, default_factor = %f\n", unoccupied, default_factor);
55 for (int cols = 0; cols < workspace->cols; cols++) {
56 LOG("width_factor[%d] = %f\n", cols, workspace->width_factor[cols]);
58 if (workspace->width_factor[cols] == 0)
59 unoccupied -= workspace->rect.width * default_factor;
62 LOG("unoccupied space: %d\n", unoccupied);
66 /* See get_unoccupied_x() */
67 int get_unoccupied_y(Workspace *workspace) {
68 int height = workspace->rect.height;
69 i3Font *font = load_font(global_conn, config.font);
71 /* Reserve space for dock clients */
73 SLIST_FOREACH(client, &(workspace->screen->dock_clients), dock_clients)
74 height -= client->desired_height;
76 /* Space for the internal bar */
77 height -= (font->height + 6);
79 int unoccupied = height;
80 float default_factor = ((float)height / workspace->rows) / height;
82 LOG("get_unoccupied_y(), starting with %d, default_factor = %f\n", unoccupied, default_factor);
84 for (int rows = 0; rows < workspace->rows; rows++) {
85 LOG("height_factor[%d] = %f\n", rows, workspace->height_factor[rows]);
86 if (workspace->height_factor[rows] == 0)
87 unoccupied -= height * default_factor;
90 LOG("unoccupied space: %d\n", unoccupied);
95 * Redecorates the given client correctly by checking if it’s in a stacking container and
96 * re-rendering the stack window or just calling decorate_window if it’s not in a stacking
100 void redecorate_window(xcb_connection_t *conn, Client *client) {
101 if (client->container != NULL &&
102 (client->container->mode == MODE_STACK ||
103 client->container->mode == MODE_TABBED)) {
104 render_container(conn, client->container);
105 /* We clear the frame to generate exposure events, because the color used
106 in drawing may be different */
107 xcb_clear_area(conn, true, client->frame, 0, 0, client->rect.width, client->rect.height);
108 } else decorate_window(conn, client, client->frame, client->titlegc, 0, 0);
113 * (Re-)draws window decorations for a given Client onto the given drawable/graphic context.
114 * When in stacking mode, the window decorations are drawn onto an own window.
117 void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t drawable,
118 xcb_gcontext_t gc, int offset_x, int offset_y) {
119 i3Font *font = load_font(conn, config.font);
120 int decoration_height = font->height + 2 + 2;
121 struct Colortriple *color;
122 Client *last_focused;
124 /* Clients without a container (docks) won’t get decorated */
128 last_focused = SLIST_FIRST(&(client->workspace->focus_stack));
129 /* Is the window urgent? */
131 color = &(config.client.urgent);
133 if (client_is_floating(client)) {
134 if (last_focused == client)
135 color = &(config.client.focused);
136 else color = &(config.client.unfocused);
138 if (client->container->currently_focused == client) {
139 /* Distinguish if the window is currently focused… */
140 if (last_focused == client && c_ws == client->workspace)
141 color = &(config.client.focused);
142 /* …or if it is the focused window in a not focused container */
143 else color = &(config.client.focused_inactive);
144 } else color = &(config.client.unfocused);
148 /* Our plan is the following:
149 - Draw a rect around the whole client in color->background
150 - Draw two lines in a lighter color
151 - Draw the window’s title
154 /* Draw a rectangle in background color around the window */
155 if (client->borderless && (client->container == NULL ||
156 (client->container->mode != MODE_STACK &&
157 client->container->mode != MODE_TABBED)))
158 xcb_change_gc_single(conn, gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
159 else xcb_change_gc_single(conn, gc, XCB_GC_FOREGROUND, color->background);
161 /* In stacking mode, we only render the rect for this specific decoration */
162 if (client->container != NULL && (client->container->mode == MODE_STACK || client->container->mode == MODE_TABBED)) {
163 /* We need to use the container’s width because it is the more recent value - when
164 in stacking mode, clients get reconfigured only on demand (the not active client
165 is not reconfigured), so the client’s rect.width would be wrong */
166 xcb_rectangle_t rect = {offset_x, offset_y,
167 offset_x + client->container->width,
168 offset_y + decoration_height };
169 xcb_poly_fill_rectangle(conn, drawable, gc, 1, &rect);
171 xcb_rectangle_t rect = {0, 0, client->rect.width, client->rect.height};
172 xcb_poly_fill_rectangle(conn, drawable, gc, 1, &rect);
174 /* Draw the inner background to have a black frame around clients (such as mplayer)
175 which cannot be resized exactly in our frames and therefore are centered */
176 xcb_change_gc_single(conn, client->titlegc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
177 xcb_rectangle_t crect = {2, decoration_height,
178 client->rect.width - (2 + 2), client->rect.height - 2 - decoration_height};
179 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
182 if (client->titlebar_position != TITLEBAR_OFF) {
184 xcb_draw_line(conn, drawable, gc, color->border, offset_x, offset_y, offset_x + client->rect.width, offset_y);
185 if ((client->container == NULL ||
186 (client->container->mode != MODE_STACK &&
187 client->container->mode != MODE_TABBED) ||
188 CIRCLEQ_NEXT_OR_NULL(&(client->container->clients), client, clients) == NULL))
189 xcb_draw_line(conn, drawable, gc, color->border,
190 offset_x + 2, /* x */
191 offset_y + font->height + 3, /* y */
192 offset_x + client->rect.width - 3, /* to_x */
193 offset_y + font->height + 3 /* to_y */);
196 /* If the client has a title, we draw it */
197 if (client->name != NULL) {
199 uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
200 uint32_t values[] = { color->text, color->background, font->id };
201 xcb_change_gc(conn, gc, mask, values);
203 /* name_len == -1 means this is a legacy application which does not specify _NET_WM_NAME,
204 and we don’t handle the old window name (COMPOUND_TEXT) but only _NET_WM_NAME, which
206 if (client->name_len == -1)
207 xcb_image_text_8(conn, strlen(client->name), drawable, gc, offset_x + 3 /* X */,
208 offset_y + font->height /* Y = baseline of font */, client->name);
210 xcb_image_text_16(conn, client->name_len, drawable, gc, offset_x + 3 /* X */,
211 offset_y + font->height /* Y = baseline of font */, (xcb_char2b_t*)client->name);
216 * Pushes the client’s x and y coordinates to X11
219 void reposition_client(xcb_connection_t *conn, Client *client) {
222 LOG("frame 0x%08x needs to be pushed to %dx%d\n", client->frame, client->rect.x, client->rect.y);
223 /* Note: We can use a pointer to client->x like an array of uint32_ts
224 because it is followed by client->y by definition */
225 xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, &(client->rect.x));
227 if (!client_is_floating(client))
230 /* If the client is floating, we need to check if we moved it to a different workspace */
231 if (client->workspace->screen == (screen = get_screen_containing(client->rect.x, client->rect.y)))
234 if (screen == NULL) {
235 LOG("Boundary checking disabled, no screen found for (%d, %d)\n", client->rect.x, client->rect.y);
239 LOG("Client is on workspace %p with screen %p\n", client->workspace, client->workspace->screen);
240 LOG("but screen at %d, %d is %p\n", client->rect.x, client->rect.y, screen);
241 floating_assign_to_workspace(client, workspace_get(screen->current_workspace));
245 * Pushes the client’s width/height to X11 and resizes the child window. This
246 * function also updates the client’s position, so if you work on tiling clients
247 * only, you can use this function instead of separate calls to reposition_client
248 * and resize_client to reduce flickering.
251 void resize_client(xcb_connection_t *conn, Client *client) {
252 i3Font *font = load_font(conn, config.font);
254 LOG("frame 0x%08x needs to be pushed to %dx%d\n", client->frame, client->rect.x, client->rect.y);
255 LOG("resizing client 0x%08x to %d x %d\n", client->frame, client->rect.width, client->rect.height);
256 xcb_configure_window(conn, client->frame,
257 XCB_CONFIG_WINDOW_X |
258 XCB_CONFIG_WINDOW_Y |
259 XCB_CONFIG_WINDOW_WIDTH |
260 XCB_CONFIG_WINDOW_HEIGHT,
263 /* Adjust the position of the child inside its frame.
264 * The coordinates of the child are relative to its frame, we
265 * add a border of 2 pixel to each value */
266 uint32_t mask = XCB_CONFIG_WINDOW_X |
267 XCB_CONFIG_WINDOW_Y |
268 XCB_CONFIG_WINDOW_WIDTH |
269 XCB_CONFIG_WINDOW_HEIGHT;
270 Rect *rect = &(client->child_rect);
271 switch ((client->container != NULL ? client->container->mode : MODE_DEFAULT)) {
276 rect->width = client->rect.width - (2 + 2);
277 rect->height = client->rect.height - 2;
280 if (client->titlebar_position == TITLEBAR_OFF && client->borderless) {
283 rect->width = client->rect.width;
284 rect->height = client->rect.height;
285 } else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless) {
288 rect->width = client->rect.width - 1 - 1;
289 rect->height = client->rect.height - 1 - 1;
292 rect->y = font->height + 2 + 2;
293 rect->width = client->rect.width - (2 + 2);
294 rect->height = client->rect.height - ((font->height + 2 + 2) + 2);
299 rect->width -= (2 * client->border_width);
300 rect->height -= (2 * client->border_width);
302 /* Obey the ratio, if any */
303 if (client->proportional_height != 0 &&
304 client->proportional_width != 0) {
305 LOG("proportional height = %d, width = %d\n", client->proportional_height, client->proportional_width);
306 double new_height = rect->height + 1;
307 int new_width = rect->width;
309 while (new_height > rect->height) {
310 new_height = ((double)client->proportional_height / client->proportional_width) * new_width;
312 if (new_height > rect->height)
315 /* Center the window */
316 rect->y += ceil(rect->height / 2) - floor(new_height / 2);
317 rect->x += ceil(rect->width / 2) - floor(new_width / 2);
319 rect->height = new_height;
320 rect->width = new_width;
321 LOG("new_height = %f, new_width = %d\n", new_height, new_width);
324 if (client->height_increment > 1) {
325 int old_height = rect->height;
326 rect->height -= (rect->height - client->base_height) % client->height_increment;
327 LOG("Lost %d pixel due to client's height_increment (%d px)\n",
328 old_height - rect->height, client->height_increment);
331 if (client->width_increment > 1) {
332 int old_width = rect->width;
333 rect->width -= (rect->width - client->base_width) % client->width_increment;
334 LOG("Lost %d pixel due to client's width_increment (%d px)\n",
335 old_width - rect->width, client->width_increment);
338 LOG("child will be at %dx%d with size %dx%d\n", rect->x, rect->y, rect->width, rect->height);
340 xcb_configure_window(conn, client->child, mask, &(rect->x));
342 /* After configuring a child window we need to fake a configure_notify_event (see ICCCM 4.2.3).
343 * This is necessary to inform the client of its position relative to the root window,
344 * not relative to its frame (as done in the configure_notify_event by the x server). */
345 fake_absolute_configure_notify(conn, client);
347 /* Force redrawing after resizing the window because any now lost
348 * pixels could contain old garbage. */
349 xcb_expose_event_t generated;
350 generated.window = client->frame;
352 handle_expose_event(NULL, conn, &generated);
356 * Renders the given container. Is called by render_layout() or individually (for example
357 * when focus changes in a stacking container)
360 void render_container(xcb_connection_t *conn, Container *container) {
362 int num_clients = 0, current_client = 0;
364 CIRCLEQ_FOREACH(client, &(container->clients), clients)
367 if (container->mode == MODE_DEFAULT) {
368 CIRCLEQ_FOREACH(client, &(container->clients), clients) {
369 /* If the client is in fullscreen mode, it does not get reconfigured */
370 if (container->workspace->fullscreen_client == client) {
375 /* Check if we changed client->x or client->y by updating it.
376 * Note the bitwise OR instead of logical OR to force evaluation of both statements */
377 if (client->force_reconfigure |
378 update_if_necessary(&(client->rect.x), container->x) |
379 update_if_necessary(&(client->rect.y), container->y +
380 (container->height / num_clients) * current_client) |
381 update_if_necessary(&(client->rect.width), container->width) |
382 update_if_necessary(&(client->rect.height), container->height / num_clients))
383 resize_client(conn, client);
385 /* TODO: vertical default layout */
387 client->force_reconfigure = false;
392 i3Font *font = load_font(conn, config.font);
393 int decoration_height = (font->height + 2 + 2);
394 struct Stack_Window *stack_win = &(container->stack_win);
395 /* The size for each tab (width), necessary as a separate variable
396 * because num_clients gets fixed to 1 in tabbed mode. */
397 int size_each = (num_clients == 0 ? container->width : container->width / num_clients);
398 int stack_lines = num_clients;
400 /* Check if we need to remap our stack title window, it gets unmapped when the container
401 is empty in src/handlers.c:unmap_notify() */
402 if (stack_win->rect.height == 0 && num_clients > 0) {
403 LOG("remapping stack win\n");
404 xcb_map_window(conn, stack_win->window);
405 } else LOG("not remapping stackwin, height = %d, num_clients = %d\n",
406 stack_win->rect.height, num_clients);
408 if (container->mode == MODE_TABBED) {
409 /* By setting num_clients to 1 we force that the stack window will be only one line
410 * high. The rest of the code is useful in both cases. */
411 LOG("tabbed mode, setting num_clients = 1\n");
416 if (container->stack_limit == STACK_LIMIT_COLS) {
417 stack_lines = ceil((float)num_clients / container->stack_limit_value);
418 } else if (container->stack_limit == STACK_LIMIT_ROWS) {
419 stack_lines = min(num_clients, container->stack_limit_value);
422 /* Check if we need to reconfigure our stack title window */
423 if (update_if_necessary(&(stack_win->rect.x), container->x) |
424 update_if_necessary(&(stack_win->rect.y), container->y) |
425 update_if_necessary(&(stack_win->rect.width), container->width) |
426 update_if_necessary(&(stack_win->rect.height), decoration_height * stack_lines)) {
428 /* Configuration can happen in two slightly different ways:
430 If there is no client in fullscreen mode, 5 parameters are passed
431 (x, y, width, height, stack mode is set to above which means top-most position).
433 If there is a fullscreen client, the fourth parameter is set to to the
434 fullscreen window as sibling and the stack mode is set to below, which means
435 that the stack_window will be placed just below the sibling, that is, under
436 the fullscreen window.
438 uint32_t values[] = { stack_win->rect.x, stack_win->rect.y,
439 stack_win->rect.width, stack_win->rect.height,
440 XCB_STACK_MODE_ABOVE, XCB_STACK_MODE_BELOW };
441 uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
442 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
443 XCB_CONFIG_WINDOW_STACK_MODE;
445 /* Raise the stack window, but keep it below the first floating client
446 * and below the fullscreen client (if any) */
447 Client *first_floating = TAILQ_FIRST(&(container->workspace->floating_clients));
448 if (first_floating != TAILQ_END(&(container->workspace->floating_clients))) {
449 mask |= XCB_CONFIG_WINDOW_SIBLING;
450 values[4] = first_floating->frame;
451 } else if (container->workspace->fullscreen_client != NULL) {
452 mask |= XCB_CONFIG_WINDOW_SIBLING;
453 values[4] = container->workspace->fullscreen_client->frame;
456 xcb_configure_window(conn, stack_win->window, mask, values);
459 /* Prepare the pixmap for usage */
460 cached_pixmap_prepare(conn, &(stack_win->pixmap));
462 int current_row = 0, current_col = 0;
465 if (container->stack_limit == STACK_LIMIT_COLS) {
466 /* wrap stores the number of rows after which we will
467 * wrap to a new column. */
468 wrap = ceil((float)num_clients / container->stack_limit_value);
469 } else if (container->stack_limit == STACK_LIMIT_ROWS) {
470 /* When limiting rows, the wrap variable serves a
471 * slightly different purpose: it holds the number of
472 * pixels which each client will get. This is constant
473 * during the following loop, so it saves us some
474 * divisions and ceil()ing. */
475 wrap = (stack_win->rect.width / ceil((float)num_clients / container->stack_limit_value));
478 /* Render the decorations of all clients */
479 CIRCLEQ_FOREACH(client, &(container->clients), clients) {
480 /* If the client is in fullscreen mode, it does not get reconfigured */
481 if (container->workspace->fullscreen_client == client) {
486 /* Check if we changed client->x or client->y by updating it.
487 * Note the bitwise OR instead of logical OR to force evaluation of all statements */
488 if (client->force_reconfigure |
489 update_if_necessary(&(client->rect.x), container->x) |
490 update_if_necessary(&(client->rect.y), container->y + (decoration_height * stack_lines)) |
491 update_if_necessary(&(client->rect.width), container->width) |
492 update_if_necessary(&(client->rect.height), container->height - (decoration_height * stack_lines)))
493 resize_client(conn, client);
495 client->force_reconfigure = false;
499 if (container->mode == MODE_STACK) {
500 if (container->stack_limit == STACK_LIMIT_COLS) {
501 offset_x = current_col * (stack_win->rect.width / container->stack_limit_value);
502 offset_y = current_row * decoration_height;
504 if ((current_row % wrap) == 0) {
508 } else if (container->stack_limit == STACK_LIMIT_ROWS) {
509 offset_x = current_col * wrap;
510 offset_y = current_row * decoration_height;
512 if ((current_row % container->stack_limit_value) == 0) {
517 offset_y = current_client * decoration_height;
520 } else if (container->mode == MODE_TABBED)
521 offset_x = current_client++ * size_each;
522 decorate_window(conn, client, stack_win->pixmap.id, stack_win->pixmap.gc,
526 /* Check if we need to fill one column because of an uneven
527 * amount of windows */
528 if (container->mode == MODE_STACK) {
529 if (container->stack_limit == STACK_LIMIT_COLS && (current_col % 2) != 0) {
530 xcb_change_gc_single(conn, stack_win->pixmap.gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
532 int offset_x = current_col * (stack_win->rect.width / container->stack_limit_value);
533 int offset_y = current_row * decoration_height;
534 xcb_rectangle_t rect = {offset_x, offset_y,
535 offset_x + container->width,
536 offset_y + decoration_height };
537 xcb_poly_fill_rectangle(conn, stack_win->pixmap.id, stack_win->pixmap.gc, 1, &rect);
538 } else if (container->stack_limit == STACK_LIMIT_ROWS && (current_row % 2) != 0) {
539 xcb_change_gc_single(conn, stack_win->pixmap.gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
541 int offset_x = current_col * wrap;
542 int offset_y = current_row * decoration_height;
543 xcb_rectangle_t rect = {offset_x, offset_y,
544 offset_x + container->width,
545 offset_y + decoration_height };
546 xcb_poly_fill_rectangle(conn, stack_win->pixmap.id, stack_win->pixmap.gc, 1, &rect);
550 xcb_copy_area(conn, stack_win->pixmap.id, stack_win->window, stack_win->pixmap.gc,
551 0, 0, 0, 0, stack_win->rect.width, stack_win->rect.height);
555 static void render_bars(xcb_connection_t *conn, Workspace *r_ws, int width, int *height) {
557 SLIST_FOREACH(client, &(r_ws->screen->dock_clients), dock_clients) {
558 LOG("client is at %d, should be at %d\n", client->rect.y, *height);
559 if (client->force_reconfigure |
560 update_if_necessary(&(client->rect.x), r_ws->rect.x) |
561 update_if_necessary(&(client->rect.y), *height))
562 reposition_client(conn, client);
564 if (client->force_reconfigure |
565 update_if_necessary(&(client->rect.width), width) |
566 update_if_necessary(&(client->rect.height), client->desired_height))
567 resize_client(conn, client);
569 client->force_reconfigure = false;
570 LOG("desired_height = %d\n", client->desired_height);
571 *height += client->desired_height;
575 static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int width, int height) {
576 i3Font *font = load_font(conn, config.font);
577 i3Screen *screen = r_ws->screen;
578 enum { SET_NORMAL = 0, SET_FOCUSED = 1 };
580 /* Fill the whole bar in black */
581 xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
582 xcb_rectangle_t rect = {0, 0, width, height};
583 xcb_poly_fill_rectangle(conn, screen->bar, screen->bargc, 1, &rect);
586 xcb_change_gc_single(conn, screen->bargc, XCB_GC_FONT, font->id);
589 for (int c = 0; c < num_workspaces; c++) {
590 if (workspaces[c].screen != screen)
593 struct Colortriple *color;
594 Workspace *ws = &workspaces[c];
596 if (screen->current_workspace == c)
597 color = &(config.bar.focused);
599 color = &(config.bar.urgent);
600 else color = &(config.bar.unfocused);
602 /* Draw the outer rect */
603 xcb_draw_rect(conn, screen->bar, screen->bargc, color->border,
606 ws->text_width + 5 + 5, /* width = text width + 5 px left + 5px right */
607 height - 2 /* height = max. height - 1 px upper and 1 px bottom border */);
609 /* Draw the background of this rect */
610 xcb_draw_rect(conn, screen->bar, screen->bargc, color->background,
613 ws->text_width + 4 + 4,
616 xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, color->text);
617 xcb_change_gc_single(conn, screen->bargc, XCB_GC_BACKGROUND, color->background);
618 xcb_image_text_16(conn, ws->name_len, screen->bar, screen->bargc, drawn + 5 /* X */,
619 font->height + 1 /* Y = baseline of font */,
620 (xcb_char2b_t*)ws->name);
621 drawn += ws->text_width + 12;
626 * Modifies the event mask of all clients on the given workspace to either ignore or to handle
627 * enter notifies. It is handy to ignore notifies because they will be sent when a window is mapped
628 * under the cursor, thus when the user didn’t enter the window actively at all.
631 void ignore_enter_notify_forall(xcb_connection_t *conn, Workspace *workspace, bool ignore_enter_notify) {
636 CIRCLEQ_FOREACH(client, &(workspace->table[cols][rows]->clients), clients) {
637 /* Change event mask for the decorations */
638 values[0] = FRAME_EVENT_MASK;
639 if (ignore_enter_notify)
640 values[0] &= ~(XCB_EVENT_MASK_ENTER_WINDOW);
641 xcb_change_window_attributes(conn, client->frame, XCB_CW_EVENT_MASK, values);
643 /* Change event mask for the child itself */
644 values[0] = CHILD_EVENT_MASK;
645 if (ignore_enter_notify)
646 values[0] &= ~(XCB_EVENT_MASK_ENTER_WINDOW);
647 xcb_change_window_attributes(conn, client->child, XCB_CW_EVENT_MASK, values);
652 * Renders the given workspace on the given screen
655 void render_workspace(xcb_connection_t *conn, i3Screen *screen, Workspace *r_ws) {
656 i3Font *font = load_font(conn, config.font);
657 int width = r_ws->rect.width;
658 int height = r_ws->rect.height;
660 /* Reserve space for dock clients */
662 SLIST_FOREACH(client, &(screen->dock_clients), dock_clients)
663 height -= client->desired_height;
665 /* Space for the internal bar */
666 height -= (font->height + 6);
668 int xoffset[r_ws->rows];
669 int yoffset[r_ws->cols];
670 /* Initialize offsets */
671 for (int cols = 0; cols < r_ws->cols; cols++)
672 yoffset[cols] = r_ws->rect.y;
673 for (int rows = 0; rows < r_ws->rows; rows++)
674 xoffset[rows] = r_ws->rect.x;
676 ignore_enter_notify_forall(conn, r_ws, true);
678 /* Go through the whole table and render what’s necessary */
680 Container *container = r_ws->table[cols][rows];
681 int single_width = -1, single_height = -1;
682 /* Update position of the container */
683 container->row = rows;
684 container->col = cols;
685 container->x = xoffset[rows];
686 container->y = yoffset[cols];
687 container->width = 0;
689 for (int c = 0; c < container->colspan; c++) {
690 if (r_ws->width_factor[cols+c] == 0)
691 container->width += (width / r_ws->cols);
692 else container->width += get_unoccupied_x(r_ws) * r_ws->width_factor[cols+c];
694 if (single_width == -1)
695 single_width = container->width;
698 LOG("height is %d\n", height);
700 container->height = 0;
702 for (int c = 0; c < container->rowspan; c++) {
703 if (r_ws->height_factor[rows+c] == 0)
704 container->height += (height / r_ws->rows);
705 else container->height += get_unoccupied_y(r_ws) * r_ws->height_factor[rows+c];
707 if (single_height == -1)
708 single_height = container->height;
711 /* Render the container if it is not empty */
712 render_container(conn, container);
714 xoffset[rows] += single_width;
715 yoffset[cols] += single_height;
718 ignore_enter_notify_forall(conn, r_ws, false);
720 render_bars(conn, r_ws, width, &height);
721 render_internal_bar(conn, r_ws, width, font->height + 6);
725 * Renders the whole layout, that is: Go through each screen, each workspace, each container
726 * and render each client. This also renders the bars.
728 * If you don’t need to render *everything*, you should call render_container on the container
729 * you want to refresh.
732 void render_layout(xcb_connection_t *conn) {
735 if (virtual_screens == NULL)
738 TAILQ_FOREACH(screen, virtual_screens, screens)
739 render_workspace(conn, screen, &(workspaces[screen->current_workspace]));