- /* Draw a green rectangle around the window */
- xcb_change_gc_single(conn, gc, XCB_GC_FOREGROUND, background_color);
-
- xcb_rectangle_t rect = {0, offset, client->rect.width, offset + client->rect.height};
- xcb_poly_fill_rectangle(conn, drawable, gc, 1, &rect);
-
- /* Draw the lines */
- xcb_draw_line(conn, drawable, gc, border_color, 2, offset, client->rect.width, offset);
- xcb_draw_line(conn, drawable, gc, border_color, 2, offset + font->height + 3,
- 2 + client->rect.width, offset + font->height + 3);
-
- /* Draw the font */
- uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
- uint32_t values[] = { text_color, background_color, font->id };
- xcb_change_gc(conn, gc, mask, values);
-
- /* TODO: utf8? */
- char *label;
- asprintf(&label, "(%08x) %.*s", client->frame, client->name_len, client->name);
- xcb_void_cookie_t text_cookie = xcb_image_text_8_checked(conn, strlen(label), drawable,
- gc, 3 /* X */, offset + font->height /* Y = baseline of font */, label);
- check_error(conn, text_cookie, "Could not draw client's title");
- free(label);
+ /* Draw a rectangle in background color around the window */
+ if (client->borderless)
+ xcb_change_gc_single(conn, gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
+ else xcb_change_gc_single(conn, gc, XCB_GC_FOREGROUND, color->background);
+
+ /* In stacking mode, we only render the rect for this specific decoration */
+ if (client->container != NULL && client->container->mode == MODE_STACK) {
+ /* We need to use the container’s width because it is the more recent value - when
+ in stacking mode, clients get reconfigured only on demand (the not active client
+ is not reconfigured), so the client’s rect.width would be wrong */
+ xcb_rectangle_t rect = {0, offset, client->container->width, offset + decoration_height };
+ xcb_poly_fill_rectangle(conn, drawable, gc, 1, &rect);
+ } else {
+ xcb_rectangle_t rect = {0, 0, client->rect.width, client->rect.height};
+ xcb_poly_fill_rectangle(conn, drawable, gc, 1, &rect);
+
+ /* Draw the inner background to have a black frame around clients (such as mplayer)
+ which cannot be resized exactly in our frames and therefore are centered */
+ xcb_change_gc_single(conn, client->titlegc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
+ xcb_rectangle_t crect = {2, decoration_height,
+ client->rect.width - (2 + 2), client->rect.height - 2 - decoration_height};
+ xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
+ }
+
+ if (client->titlebar_position != TITLEBAR_OFF) {
+ /* Draw the lines */
+ xcb_draw_line(conn, drawable, gc, color->border, 0, offset, client->rect.width, offset);
+ if ((client->container == NULL ||
+ client->container->mode != MODE_STACK ||
+ CIRCLEQ_NEXT_OR_NULL(&(client->container->clients), client, clients) == NULL))
+ xcb_draw_line(conn, drawable, gc, color->border, 2, offset + font->height + 3,
+ client->rect.width - 3, offset + font->height + 3);
+ }
+
+ /* If the client has a title, we draw it */
+ if (client->name != NULL) {
+ /* Draw the font */
+ uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
+ uint32_t values[] = { color->text, color->background, font->id };
+ xcb_change_gc(conn, gc, mask, values);
+
+ /* name_len == -1 means this is a legacy application which does not specify _NET_WM_NAME,
+ and we don’t handle the old window name (COMPOUND_TEXT) but only _NET_WM_NAME, which
+ is UTF-8 */
+ if (client->name_len == -1)
+ xcb_image_text_8(conn, strlen(client->name), drawable, gc, 3 /* X */,
+ offset + font->height /* Y = baseline of font */, client->name);
+ else
+ xcb_image_text_16(conn, client->name_len, drawable, gc, 3 /* X */,
+ offset + font->height /* Y = baseline of font */, (xcb_char2b_t*)client->name);
+ }