6 #include <xcb/xcb_event.h>
14 void die(const char *errstr, ...) {
17 vfprintf(stderr, errstr, ap);
22 window_location_t locate_window(xcb_window_t w)
25 desktop_t *d = desk_head;
26 window_location_t l = {NULL, NULL};
32 n = first_extrema(d->root);
34 if (n->client->window == w) {
47 bool is_managed(xcb_window_t w)
49 window_location_t l = locate_window(w);
50 return (l.desktop != NULL && l.node != NULL);
53 uint32_t color_pixel(char *hex)
55 char strgroups[3][3] = {{hex[1], hex[2], '\0'}, {hex[3], hex[4], '\0'}, {hex[5], hex[6], '\0'}};
56 uint16_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)), (strtol(strgroups[1], NULL, 16)), (strtol(strgroups[2], NULL, 16))};
57 return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
60 uint32_t get_color(char *col)
62 xcb_colormap_t map = screen->default_colormap;
63 xcb_alloc_color_reply_t *rpl;
64 xcb_alloc_named_color_reply_t *rpln;
69 rgb = color_pixel(col);
73 rpl = xcb_alloc_color_reply(dpy, xcb_alloc_color(dpy, map, r * 257, g * 257, b * 257), NULL);
79 rpln = xcb_alloc_named_color_reply(dpy, xcb_alloc_named_color(dpy, map, strlen(col), col), NULL);
87 /* die("error: cannot allocate color '%s'\n", col); */
92 void draw_triple_border(node_t *n, uint32_t main_border_color_pxl)
97 xcb_window_t win = n->client->window;
98 xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, win), NULL);
100 uint16_t width = geom->width;
101 uint16_t height = geom->height;
103 uint8_t depth = geom->depth;
105 uint16_t full_width = width + 2 * border_width;
106 uint16_t full_height = height + 2 * border_width;
110 xcb_rectangle_t inner_rectangles[] =
112 { width, 0, 2 * border_width, height + 2 * border_width },
113 { 0, height, width + 2 * border_width, 2 * border_width }
116 xcb_rectangle_t main_rectangles[] =
118 { width + inner_border_width, 0, 2 * (main_border_width + outer_border_width), height + 2 * border_width },
119 { 0, height + inner_border_width, width + 2 * border_width, 2 * (main_border_width + outer_border_width) }
122 xcb_rectangle_t outer_rectangles[] =
124 { width + inner_border_width + main_border_width, 0, 2 * outer_border_width, height + 2 * border_width },
125 { 0, height + inner_border_width + main_border_width, width + 2 * border_width, 2 * outer_border_width }
128 xcb_rectangle_t *presel_rectangles;
130 xcb_pixmap_t pix = xcb_generate_id(dpy);
131 xcb_create_pixmap(dpy, depth, pix, win, full_width, full_height);
133 xcb_gcontext_t gc = xcb_generate_id(dpy);
134 xcb_create_gc(dpy, gc, pix, 0, NULL);
137 if (inner_border_width > 0) {
138 xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &inner_border_color_pxl);
139 xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(inner_rectangles), inner_rectangles);
143 if (main_border_width > 0) {
144 xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &main_border_color_pxl);
145 xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(main_rectangles), main_rectangles);
149 if (outer_border_width > 0) {
150 xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &outer_border_color_pxl);
151 xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(outer_rectangles), outer_rectangles);
154 if (split_mode == MODE_MANUAL) {
155 split_pos = (int16_t) n->split_ratio * ((split_dir == DIR_UP || split_dir == DIR_DOWN) ? height : width);
156 printf("%i\n", split_pos);
157 presel_rectangles = malloc(2 * sizeof(xcb_rectangle_t));
160 presel_rectangles[0] = (xcb_rectangle_t) {width, 0, 2 * border_width, split_pos};
161 presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
164 presel_rectangles[0] = (xcb_rectangle_t) {width, split_pos + 1, 2 * border_width, height + border_width - (split_pos + 1)};
165 presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
168 presel_rectangles[0] = (xcb_rectangle_t) {0, height, split_pos, 2 * border_width};
169 presel_rectangles[1] = (xcb_rectangle_t) {width + border_width, 0, border_width, full_height};
172 presel_rectangles[0] = (xcb_rectangle_t) {split_pos + 1, height, width + border_width - (split_pos + 1), 2 * border_width};
173 presel_rectangles[1] = (xcb_rectangle_t) {width, 0, border_width, full_height};
176 xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
177 xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(presel_rectangles), presel_rectangles);
178 free(presel_rectangles);
182 /* apply border pixmap */
183 xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXMAP, &pix);
186 xcb_free_gc(dpy, gc);
187 xcb_free_pixmap(dpy, pix);
190 void toggle_fullscreen(node_t *n)