- if (n == NULL || (n->client->border_width < 1 && !n->client->frame)) {
- return;
- }
-
- if (n->client->frame) {
- draw_frame_background(n, focused_window, focused_monitor);
- return;
- }
-
- xcb_window_t win = n->client->window;
- uint32_t border_color_pxl = get_border_color(n->client, focused_window, focused_monitor);
-
- if (n->split_mode == MODE_AUTOMATIC) {
- xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXEL, &border_color_pxl);
- } else {
- unsigned int border_width = n->client->border_width;
- uint32_t presel_border_color_pxl;
- get_color(presel_border_color, win, &presel_border_color_pxl);
-
- xcb_rectangle_t actual_rectangle = get_rectangle(n->client);
-
- uint16_t width = actual_rectangle.width;
- uint16_t height = actual_rectangle.height;
-
- uint16_t full_width = width + 2 * border_width;
- uint16_t full_height = height + 2 * border_width;
-
- xcb_rectangle_t border_rectangles[] =
- {
- { width, 0, 2 * border_width, height + 2 * border_width },
- { 0, height, width + 2 * border_width, 2 * border_width }
- };
-
- xcb_rectangle_t *presel_rectangles;
-
- uint8_t win_depth = root_depth;
- xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, win), NULL);
- if (geo != NULL)
- win_depth = geo->depth;
- free(geo);
-
- xcb_pixmap_t pixmap = xcb_generate_id(dpy);
- xcb_create_pixmap(dpy, win_depth, pixmap, win, full_width, full_height);
-
- xcb_gcontext_t gc = xcb_generate_id(dpy);
- xcb_create_gc(dpy, gc, pixmap, 0, NULL);
-
- xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &border_color_pxl);
- xcb_poly_fill_rectangle(dpy, pixmap, gc, LENGTH(border_rectangles), border_rectangles);
-
- uint16_t fence = (int16_t) (n->split_ratio * ((n->split_dir == DIR_UP || n->split_dir == DIR_DOWN) ? height : width));
- presel_rectangles = malloc(2 * sizeof(xcb_rectangle_t));
- switch (n->split_dir) {
- case DIR_UP:
- presel_rectangles[0] = (xcb_rectangle_t) {width, 0, 2 * border_width, fence};
- presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
- break;
- case DIR_DOWN:
- presel_rectangles[0] = (xcb_rectangle_t) {width, fence + 1, 2 * border_width, height + border_width - (fence + 1)};
- presel_rectangles[1] = (xcb_rectangle_t) {0, height, full_width, border_width};
- break;
- case DIR_LEFT:
- presel_rectangles[0] = (xcb_rectangle_t) {0, height, fence, 2 * border_width};
- presel_rectangles[1] = (xcb_rectangle_t) {width + border_width, 0, border_width, full_height};
- break;
- case DIR_RIGHT:
- presel_rectangles[0] = (xcb_rectangle_t) {fence + 1, height, width + border_width - (fence + 1), 2 * border_width};
- presel_rectangles[1] = (xcb_rectangle_t) {width, 0, border_width, full_height};
- break;
- }
- xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
- xcb_poly_fill_rectangle(dpy, pixmap, gc, 2, presel_rectangles);
- xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXMAP, &pixmap);
- free(presel_rectangles);
- xcb_free_gc(dpy, gc);
- xcb_free_pixmap(dpy, pixmap);
- }
-}
-
-void draw_frame_background(node_t *n, bool focused_window, bool focused_monitor)
-{
- if (n == NULL)
- return;
-
- xcb_window_t win = n->client->window;
- uint32_t border_color_pxl = get_border_color(n->client, focused_window, focused_monitor);
- uint32_t opacity = (focused_window ? (focused_monitor ? focused_frame_opacity : active_frame_opacity) : normal_frame_opacity) * 0xffffffff;
- xcb_change_property(dpy, XCB_PROP_MODE_REPLACE, win, _NET_WM_WINDOW_OPACITY, XCB_ATOM_CARDINAL, 32, 1, &opacity);
- uint8_t win_depth = root_depth;
- xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, win), NULL);
- if (geo != NULL)
- win_depth = geo->depth;
- free(geo);
- xcb_rectangle_t rectangle = get_rectangle(n->client);
- rectangle.x = rectangle.y = 0;
- uint16_t width = rectangle.width;
- uint16_t height = rectangle.height;
- xcb_pixmap_t pixmap = xcb_generate_id(dpy);
- xcb_create_pixmap(dpy, win_depth, pixmap, win, width, height);
- xcb_gcontext_t gc = xcb_generate_id(dpy);
- xcb_create_gc(dpy, gc, pixmap, 0, NULL);
- xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &border_color_pxl);
- xcb_poly_fill_rectangle(dpy, pixmap, gc, 1, &rectangle);
- if (n->split_mode == MODE_MANUAL) {
- xcb_rectangle_t presel_rectangle = rectangle;
- uint32_t presel_border_color_pxl;
- get_color(presel_border_color, win, &presel_border_color_pxl);
- xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
- switch (n->split_dir) {
- case DIR_UP:
- presel_rectangle.height = n->split_ratio * rectangle.height;
- break;
- case DIR_RIGHT:
- presel_rectangle.width = (1 - n->split_ratio) * rectangle.width;
- presel_rectangle.x = rectangle.width - presel_rectangle.width;
- break;
- case DIR_DOWN:
- presel_rectangle.height = (1 - n->split_ratio) * rectangle.height;
- presel_rectangle.y = rectangle.height - presel_rectangle.height;
- break;
- case DIR_LEFT:
- presel_rectangle.width = n->split_ratio * rectangle.width;
- break;
- }
- xcb_poly_fill_rectangle(dpy, pixmap, gc, 1, &presel_rectangle);
- }
- xcb_copy_area(dpy, pixmap, win, gc, 0, 0, 0, 0, width, height);
- xcb_free_gc(dpy, gc);
- xcb_free_pixmap(dpy, pixmap);
+ if (n == NULL || n->client->border_width < 1) {
+ return;
+ }
+
+ xcb_window_t win = n->client->window;
+ uint32_t border_color_pxl = get_border_color(n->client, focused_window, focused_monitor);
+
+ if (n->split_mode == MODE_AUTOMATIC) {
+ xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXEL, &border_color_pxl);
+ } else {
+ unsigned int border_width = n->client->border_width;
+ uint32_t presel_border_color_pxl;
+ get_color(presel_border_color, win, &presel_border_color_pxl);
+
+ xcb_rectangle_t actual_rectangle = get_rectangle(n->client);
+
+ uint16_t width = actual_rectangle.width;
+ uint16_t height = actual_rectangle.height;
+
+ uint16_t full_width = width + 2 * border_width;
+ uint16_t full_height = height + 2 * border_width;
+
+ xcb_rectangle_t border_rectangles[] =
+ {
+ { width, 0, 2 * border_width, height + 2 * border_width },
+ { 0, height, width + 2 * border_width, 2 * border_width }
+ };
+
+ xcb_rectangle_t *presel_rectangles;
+
+ uint8_t win_depth = root_depth;
+ xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, win), NULL);
+ if (geo != NULL)
+ win_depth = geo->depth;
+ free(geo);
+
+ xcb_pixmap_t pixmap = xcb_generate_id(dpy);
+ xcb_create_pixmap(dpy, win_depth, pixmap, win, full_width, full_height);
+
+ xcb_gcontext_t gc = xcb_generate_id(dpy);
+ xcb_create_gc(dpy, gc, pixmap, 0, NULL);
+
+ xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &border_color_pxl);
+ xcb_poly_fill_rectangle(dpy, pixmap, gc, LENGTH(border_rectangles), border_rectangles);
+
+ uint16_t fence = (int16_t) (n->split_ratio * ((n->split_dir == DIR_UP || n->split_dir == DIR_DOWN) ? height : width));
+ presel_rectangles = malloc(2 * sizeof(xcb_rectangle_t));
+ switch (n->split_dir) {
+ case DIR_UP:
+ presel_rectangles[0] = (xcb_rectangle_t) {width, 0, 2 * border_width, fence};
+ presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
+ break;
+ case DIR_DOWN:
+ presel_rectangles[0] = (xcb_rectangle_t) {width, fence + 1, 2 * border_width, height + border_width - (fence + 1)};
+ presel_rectangles[1] = (xcb_rectangle_t) {0, height, full_width, border_width};
+ break;
+ case DIR_LEFT:
+ presel_rectangles[0] = (xcb_rectangle_t) {0, height, fence, 2 * border_width};
+ presel_rectangles[1] = (xcb_rectangle_t) {width + border_width, 0, border_width, full_height};
+ break;
+ case DIR_RIGHT:
+ presel_rectangles[0] = (xcb_rectangle_t) {fence + 1, height, width + border_width - (fence + 1), 2 * border_width};
+ presel_rectangles[1] = (xcb_rectangle_t) {width, 0, border_width, full_height};
+ break;
+ }
+ xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
+ xcb_poly_fill_rectangle(dpy, pixmap, gc, 2, presel_rectangles);
+ xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXMAP, &pixmap);
+ free(presel_rectangles);
+ xcb_free_gc(dpy, gc);
+ xcb_free_pixmap(dpy, pixmap);
+ }