2 * i3bar - an xcb-based status- and ws-bar for i3
4 * © 2010 Axel Wagner and contributors
6 * See file LICNSE for license information
8 * src/xcb.c: Communicating with X
12 #include <xcb/xproto.h>
13 #include <xcb/xcb_atom.h>
25 #include <X11/XKBlib.h>
26 #include <X11/extensions/XKB.h>
30 /* We save the Atoms in an easy to access array, indexed by an enum */
32 #define ATOM_DO(name) name,
33 #include "xcb_atoms.def"
37 xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS];
38 xcb_atom_t atoms[NUM_ATOMS];
40 /* Variables, that are the same for all functions at all times */
41 xcb_connection_t *xcb_connection;
42 xcb_screen_t *xcb_screen;
43 xcb_window_t xcb_root;
46 /* We need to cache some data to speed up text-width-prediction */
47 xcb_query_font_reply_t *font_info;
49 xcb_charinfo_t *font_table;
51 /* These are only relevant for XKB, which we only need for grabbing modifiers */
56 /* Because the statusline is the same on all outputs, we have
57 * global buffer to render it on */
58 xcb_gcontext_t statusline_ctx;
59 xcb_pixmap_t statusline_pm;
60 uint32_t statusline_width;
62 /* Event-Watchers, to interact with the user */
68 /* The parsed colors */
72 uint32_t active_ws_fg;
73 uint32_t active_ws_bg;
74 uint32_t inactive_ws_fg;
75 uint32_t inactive_ws_bg;
76 uint32_t urgent_ws_bg;
77 uint32_t urgent_ws_fg;
79 struct xcb_colors_t colors;
81 /* We define xcb_request_failed as a macro to include the relevant line-number */
82 #define xcb_request_failed(cookie, err_msg) _xcb_request_failed(cookie, err_msg, __LINE__)
83 int _xcb_request_failed(xcb_void_cookie_t cookie, char *err_msg, int line) {
84 xcb_generic_error_t *err;
85 if ((err = xcb_request_check(xcb_connection, cookie)) != NULL) {
86 ELOG("%s. X Error Code: %d\n", err_msg, err->error_code);
87 return err->error_code;
93 * Predicts the length of text based on cached data.
94 * The string has to be encoded in ucs2 and glyph_len has to be the length
95 * of the string (in glyphs).
98 uint32_t predict_text_extents(xcb_char2b_t *text, uint32_t length) {
99 /* If we don't have per-character data, return the maximum width */
100 if (font_table == NULL) {
101 return (font_info->max_bounds.character_width * length);
107 for (i = 0; i < length; i++) {
108 xcb_charinfo_t *info;
109 int row = text[i].byte1;
110 int col = text[i].byte2;
112 if (row < font_info->min_byte1 || row > font_info->max_byte1 ||
113 col < font_info->min_char_or_byte2 || col > font_info->max_char_or_byte2) {
117 /* Don't you ask me, how this one works… */
118 info = &font_table[((row - font_info->min_byte1) *
119 (font_info->max_char_or_byte2 - font_info->min_char_or_byte2 + 1)) +
120 (col - font_info->min_char_or_byte2)];
122 if (info->character_width != 0 ||
123 (info->right_side_bearing |
124 info->left_side_bearing |
126 info->descent) != 0) {
127 width += info->character_width;
135 * Draws text given in UCS-2-encoding to a given drawable and position
138 void draw_text(xcb_drawable_t drawable, xcb_gcontext_t ctx, int16_t x, int16_t y,
139 xcb_char2b_t *text, uint32_t glyph_count) {
142 int16_t font_ascent = font_info->font_ascent;
144 while (glyph_count > 0) {
145 uint8_t chunk_size = MIN(255, glyph_count);
146 uint32_t chunk_width = predict_text_extents(text + offset, chunk_size);
148 xcb_image_text_16(xcb_connection,
152 pos_x, y + font_ascent,
155 offset += chunk_size;
156 pos_x += chunk_width;
157 glyph_count -= chunk_size;
162 * Converts a colorstring to a colorpixel as expected from xcb_change_gc.
163 * s is assumed to be in the format "rrggbb"
166 uint32_t get_colorpixel(const char *s) {
167 char strings[3][3] = { { s[0], s[1], '\0'} ,
168 { s[2], s[3], '\0'} ,
169 { s[4], s[5], '\0'} };
170 uint8_t r = strtol(strings[0], NULL, 16);
171 uint8_t g = strtol(strings[1], NULL, 16);
172 uint8_t b = strtol(strings[2], NULL, 16);
173 return (r << 16 | g << 8 | b);
177 * Redraws the statusline to the buffer
180 void refresh_statusline() {
183 if (statusline == NULL) {
187 xcb_char2b_t *text = (xcb_char2b_t*) convert_utf8_to_ucs2(statusline, &glyph_count);
188 statusline_width = predict_text_extents(text, glyph_count);
190 xcb_clear_area(xcb_connection, 0, statusline_pm, 0, 0, xcb_screen->width_in_pixels, font_height);
191 draw_text(statusline_pm, statusline_ctx, 0, 0, text, glyph_count);
197 * Hides all bars (unmaps them)
201 if (!config.hide_on_modifier) {
206 SLIST_FOREACH(walk, outputs, slist) {
207 xcb_unmap_window(xcb_connection, walk->bar);
213 * Unhides all bars (maps them)
217 if (!config.hide_on_modifier) {
222 xcb_void_cookie_t cookie;
228 SLIST_FOREACH(walk, outputs, slist) {
229 if (walk->bar == XCB_NONE) {
232 mask = XCB_CONFIG_WINDOW_X |
233 XCB_CONFIG_WINDOW_Y |
234 XCB_CONFIG_WINDOW_WIDTH |
235 XCB_CONFIG_WINDOW_HEIGHT |
236 XCB_CONFIG_WINDOW_STACK_MODE;
237 values[0] = walk->rect.x;
238 values[1] = walk->rect.y + walk->rect.h - font_height - 6;
239 values[2] = walk->rect.w;
240 values[3] = font_height + 6;
241 values[4] = XCB_STACK_MODE_ABOVE;
242 DLOG("Reconfiguring Window for output %s to %d,%d\n", walk->name, values[0], values[1]);
243 cookie = xcb_configure_window_checked(xcb_connection,
248 if (xcb_request_failed(cookie, "Could not reconfigure window")) {
251 xcb_map_window(xcb_connection, walk->bar);
256 * Parse the colors into a format that we can use
259 void init_colors(const struct xcb_color_strings_t *new_colors) {
260 #define PARSE_COLOR(name, def) \
262 colors.name = get_colorpixel(new_colors->name ? new_colors->name : def); \
264 PARSE_COLOR(bar_fg, "FFFFFF");
265 PARSE_COLOR(bar_bg, "000000");
266 PARSE_COLOR(active_ws_fg, "FFFFFF");
267 PARSE_COLOR(active_ws_bg, "480000");
268 PARSE_COLOR(inactive_ws_fg, "FFFFFF");
269 PARSE_COLOR(inactive_ws_bg, "240000");
270 PARSE_COLOR(urgent_ws_fg, "FFFFFF");
271 PARSE_COLOR(urgent_ws_bg, "002400");
276 * Handle a button-press-event (i.c. a mouse click on one of our bars).
277 * We determine, wether the click occured on a ws-button or if the scroll-
278 * wheel was used and change the workspace appropriately
281 void handle_button(xcb_button_press_event_t *event) {
284 /* Determine, which bar was clicked */
286 xcb_window_t bar = event->event;
287 SLIST_FOREACH(walk, outputs, slist) {
288 if (walk->bar == bar) {
294 DLOG("Unknown Bar klicked!\n");
298 /* TODO: Move this to extern get_ws_for_output() */
299 TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) {
300 if (cur_ws->visible) {
305 if (cur_ws == NULL) {
306 DLOG("No Workspace active?\n");
310 int32_t x = event->event_x;
312 DLOG("Got Button %d\n", event->detail);
314 switch (event->detail) {
316 /* Left Mousbutton. We determine, which button was clicked
317 * and set cur_ws accordingly */
318 TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) {
320 if (x < cur_ws->name_width + 10) {
323 x -= cur_ws->name_width + 10;
325 if (cur_ws == NULL) {
330 /* Mouse wheel down. We select the next ws */
331 if (cur_ws == TAILQ_FIRST(walk->workspaces)) {
332 cur_ws = TAILQ_LAST(walk->workspaces, ws_head);
334 cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq);
338 /* Mouse wheel up. We select the previos ws */
339 if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) {
340 cur_ws = TAILQ_FIRST(walk->workspaces);
342 cur_ws = TAILQ_NEXT(cur_ws, tailq);
347 char buffer[strlen(cur_ws->name) + 11];
348 snprintf(buffer, 50, "workspace %s", cur_ws->name);
349 i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer);
353 * This function is called immediately bevor the main loop locks. We flush xcb
354 * then (and only then)
357 void xcb_prep_cb(struct ev_loop *loop, ev_prepare *watcher, int revents) {
358 xcb_flush(xcb_connection);
362 * This function is called immediately after the main loop locks, so when one
363 * of the watchers registered an event.
364 * We check wether an X-Event arrived and handle it.
367 void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) {
368 xcb_generic_event_t *event;
369 while ((event = xcb_poll_for_event(xcb_connection)) == NULL) {
373 switch (event->response_type & ~0x80) {
375 /* Expose-events happen, when the window needs to be redrawn */
378 case XCB_BUTTON_PRESS:
379 /* Button-press-events are mouse-buttons clicked on one of our bars */
380 handle_button((xcb_button_press_event_t*) event);
387 * Dummy Callback. We only need this, so that the Prepare- and Check-Watchers
391 void xcb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
395 * We need to bind to the modifier per XKB. Sadly, XCB does not implement this
398 void xkb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
402 DLOG("Got XKB-Event!\n");
404 while (XPending(xkb_dpy)) {
405 XNextEvent(xkb_dpy, (XEvent*)&ev);
407 if (ev.type != xkb_event_base) {
408 ELOG("No Xkb-Event!\n");
412 if (ev.any.xkb_type != XkbStateNotify) {
413 ELOG("No State Notify!\n");
417 unsigned int mods = ev.state.mods;
418 modstate = mods & Mod4Mask;
421 if (modstate != mod_pressed) {
423 DLOG("Mod4 got released!\n");
426 DLOG("Mod4 got pressed!\n");
429 mod_pressed = modstate;
434 * Initialize xcb and use the specified fontname for text-rendering
437 char *init_xcb(char *fontname) {
438 /* FIXME: xcb_connect leaks Memory */
439 xcb_connection = xcb_connect(NULL, NULL);
440 if (xcb_connection_has_error(xcb_connection)) {
441 ELOG("Cannot open display\n");
444 DLOG("Connected to xcb\n");
446 /* We have to request the atoms we need */
447 #define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name);
448 #include "xcb_atoms.def"
450 xcb_screen = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data;
451 xcb_root = xcb_screen->root;
453 /* We load and allocate the font */
454 xcb_font = xcb_generate_id(xcb_connection);
455 xcb_void_cookie_t open_font_cookie;
456 open_font_cookie = xcb_open_font_checked(xcb_connection,
461 /* We need to save info about the font, because we need the fonts height and
462 * information about the width of characters */
463 xcb_query_font_cookie_t query_font_cookie;
464 query_font_cookie = xcb_query_font(xcb_connection,
467 /* To grab modifiers without blocking other applications from receiving key-events
468 * involving that modifier, we sadly have to use xkb which is not yet fully supported
470 if (config.hide_on_modifier) {
471 int xkb_major, xkb_minor, xkb_errbase, xkb_err;
472 xkb_major = XkbMajorVersion;
473 xkb_minor = XkbMinorVersion;
475 char *dispname = getenv("DISPLAY");
476 if (dispname == NULL) {
479 xkb_dpy = XkbOpenDisplay(dispname,
486 if (xkb_dpy == NULL) {
491 if (fcntl(ConnectionNumber(xkb_dpy), F_SETFD, FD_CLOEXEC) == -1) {
492 ELOG("Could not set FD_CLOEXEC on xkbdpy: %s\n", strerror(errno));
497 if (!XkbQueryExtension(xkb_dpy, &i1, &xkb_event_base, &xkb_errbase, &xkb_major, &xkb_minor)) {
498 ELOG("XKB not supported by X-server!\n");
502 if (!XkbSelectEvents(xkb_dpy, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask)) {
503 ELOG("Could not grab Key!\n");
507 xkb_io = malloc(sizeof(ev_io));
508 ev_io_init(xkb_io, &xkb_io_cb, ConnectionNumber(xkb_dpy), EV_READ);
509 ev_io_start(main_loop, xkb_io);
513 /* We draw the statusline to a seperate pixmap, because it looks the same on all bars and
514 * this way, we can choose to crop it */
515 statusline_ctx = xcb_generate_id(xcb_connection);
516 uint32_t mask = XCB_GC_FOREGROUND |
519 uint32_t vals[3] = { colors.bar_fg, colors.bar_bg, xcb_font };
521 xcb_void_cookie_t sl_ctx_cookie = xcb_create_gc_checked(xcb_connection,
527 statusline_pm = xcb_generate_id(xcb_connection);
528 xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
529 xcb_screen->root_depth,
532 xcb_screen->width_in_pixels,
533 xcb_screen->height_in_pixels);
536 /* The varios Watchers to communicate with xcb */
537 xcb_io = malloc(sizeof(ev_io));
538 xcb_prep = malloc(sizeof(ev_prepare));
539 xcb_chk = malloc(sizeof(ev_check));
541 ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
542 ev_prepare_init(xcb_prep, &xcb_prep_cb);
543 ev_check_init(xcb_chk, &xcb_chk_cb);
545 ev_io_start(main_loop, xcb_io);
546 ev_prepare_start(main_loop, xcb_prep);
547 ev_check_start(main_loop, xcb_chk);
549 /* Now we get the atoms and save them in a nice data-structure */
552 xcb_get_property_cookie_t path_cookie;
553 path_cookie = xcb_get_property_unchecked(xcb_connection,
556 atoms[I3_SOCKET_PATH],
557 XCB_GET_PROPERTY_TYPE_ANY,
560 /* We check, if i3 set it's socket-path */
561 xcb_get_property_reply_t *path_reply = xcb_get_property_reply(xcb_connection,
566 int len = xcb_get_property_value_length(path_reply);
568 path = strndup(xcb_get_property_value(path_reply), len);
572 /* Now we save the font-infos */
573 font_info = xcb_query_font_reply(xcb_connection,
577 if (xcb_request_failed(open_font_cookie, "Could not open font")) {
581 font_height = font_info->font_ascent + font_info->font_descent;
583 if (xcb_query_font_char_infos_length(font_info) == 0) {
586 font_table = xcb_query_font_char_infos(font_info);
589 DLOG("Calculated Font-height: %d\n", font_height);
591 if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline-buffer")) {
595 if (xcb_request_failed(sl_ctx_cookie, "Could not create context for statusline")) {
603 * Cleanup the xcb-stuff.
604 * Called once, before the program terminates.
610 SLIST_FOREACH(o_walk, outputs, slist) {
611 destroy_window(o_walk);
612 FREE(o_walk->workspaces);
615 FREE_SLIST(outputs, i3_output);
618 xcb_disconnect(xcb_connection);
620 ev_check_stop(main_loop, xcb_chk);
621 ev_prepare_stop(main_loop, xcb_prep);
622 ev_io_stop(main_loop, xcb_io);
631 * Get the earlier requested atoms and save them in the prepared data-structure
635 xcb_intern_atom_reply_t *reply;
636 #define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \
637 if (reply == NULL) { \
638 ELOG("Could not get atom %s\n", #name); \
639 exit(EXIT_FAILURE); \
641 atoms[name] = reply->atom; \
644 #include "xcb_atoms.def"
649 * Destroy the bar of the specified output
652 void destroy_window(i3_output *output) {
653 if (output == NULL) {
656 if (output->bar == XCB_NONE) {
659 xcb_destroy_window(xcb_connection, output->bar);
660 output->bar = XCB_NONE;
664 * Reallocate the statusline-buffer
667 void realloc_sl_buffer() {
668 xcb_free_pixmap(xcb_connection, statusline_pm);
669 statusline_pm = xcb_generate_id(xcb_connection);
670 xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
671 xcb_screen->root_depth,
674 xcb_screen->width_in_pixels,
675 xcb_screen->height_in_pixels);
676 if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline-buffer")) {
683 * Reconfigure all bars and create new for newly activated outputs
686 void reconfig_windows() {
691 SLIST_FOREACH(walk, outputs, slist) {
693 /* If an output is not active, we destroy it's bar */
694 /* FIXME: Maybe we rather want to unmap? */
695 DLOG("Destroying window for output %s\n", walk->name);
696 destroy_window(walk);
699 if (walk->bar == XCB_NONE) {
700 DLOG("Creating Window for output %s\n", walk->name);
702 walk->bar = xcb_generate_id(xcb_connection);
703 walk->buffer = xcb_generate_id(xcb_connection);
704 mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
705 /* Black background */
706 values[0] = colors.bar_bg;
707 /* If hide_on_modifier is set, i3 is not supposed to manage our bar-windows */
708 values[1] = config.hide_on_modifier;
709 /* The events we want to receive */
710 values[2] = XCB_EVENT_MASK_EXPOSURE |
711 XCB_EVENT_MASK_BUTTON_PRESS;
712 xcb_void_cookie_t win_cookie = xcb_create_window_checked(xcb_connection,
713 xcb_screen->root_depth,
716 walk->rect.x, walk->rect.y + walk->rect.h - font_height - 6,
717 walk->rect.w, font_height + 6,
719 XCB_WINDOW_CLASS_INPUT_OUTPUT,
720 xcb_screen->root_visual,
724 /* The double-buffer we use to render stuff off-screen */
725 xcb_void_cookie_t pm_cookie = xcb_create_pixmap_checked(xcb_connection,
726 xcb_screen->root_depth,
732 /* We want dock-windows (for now). When override_redirect is set, i3 is ignoring
734 xcb_void_cookie_t dock_cookie = xcb_change_property(xcb_connection,
735 XCB_PROP_MODE_REPLACE,
737 atoms[_NET_WM_WINDOW_TYPE],
741 (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
743 /* We need to tell i3, where to reserve space for i3bar */
744 /* left, right, top, bottom, left_start_y, left_end_y,
745 * right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x,
747 /* A local struct to save the strut_partial property */
753 uint32_t left_start_y;
755 uint32_t right_start_y;
756 uint32_t right_end_y;
757 uint32_t top_start_x;
759 uint32_t bottom_start_x;
760 uint32_t bottom_end_x;
761 } __attribute__((__packed__)) strut_partial = {0,};
762 switch (config.dockpos) {
766 strut_partial.top = font_height + 6;
767 strut_partial.top_start_x = walk->rect.x;
768 strut_partial.top_end_x = walk->rect.x + walk->rect.w;
771 strut_partial.bottom = font_height + 6;
772 strut_partial.bottom_start_x = walk->rect.x;
773 strut_partial.bottom_end_x = walk->rect.x + walk->rect.w;
776 xcb_void_cookie_t strut_cookie = xcb_change_property(xcb_connection,
777 XCB_PROP_MODE_REPLACE,
779 atoms[_NET_WM_STRUT_PARTIAL],
785 /* We also want a graphics-context for the bars (it defines the properties
786 * with which we draw to them) */
787 walk->bargc = xcb_generate_id(xcb_connection);
789 values[0] = xcb_font;
790 xcb_void_cookie_t gc_cookie = xcb_create_gc_checked(xcb_connection,
796 /* We finally map the bar (display it on screen), unless the modifier-switch is on */
797 xcb_void_cookie_t map_cookie;
798 if (!config.hide_on_modifier) {
799 map_cookie = xcb_map_window_checked(xcb_connection, walk->bar);
802 if (xcb_request_failed(win_cookie, "Could not create window") ||
803 xcb_request_failed(pm_cookie, "Could not create pixmap") ||
804 xcb_request_failed(dock_cookie, "Could not set dock mode") ||
805 xcb_request_failed(strut_cookie, "Could not set strut") ||
806 xcb_request_failed(gc_cookie, "Could not create graphical context") ||
807 (!config.hide_on_modifier && xcb_request_failed(map_cookie, "Could not map window"))) {
811 /* We already have a bar, so we just reconfigure it */
812 mask = XCB_CONFIG_WINDOW_X |
813 XCB_CONFIG_WINDOW_Y |
814 XCB_CONFIG_WINDOW_WIDTH |
815 XCB_CONFIG_WINDOW_HEIGHT |
816 XCB_CONFIG_WINDOW_STACK_MODE;
817 values[0] = walk->rect.x;
818 values[1] = walk->rect.y + walk->rect.h - font_height - 6;
819 values[2] = walk->rect.w;
820 values[3] = font_height + 6;
821 values[4] = XCB_STACK_MODE_ABOVE;
823 DLOG("Destroying buffer for output %s", walk->name);
824 xcb_free_pixmap(xcb_connection, walk->buffer);
826 DLOG("Reconfiguring Window for output %s to %d,%d\n", walk->name, values[0], values[1]);
827 xcb_void_cookie_t cfg_cookie = xcb_configure_window_checked(xcb_connection,
832 DLOG("Recreating buffer for output %s", walk->name);
833 xcb_void_cookie_t pm_cookie = xcb_create_pixmap_checked(xcb_connection,
834 xcb_screen->root_depth,
840 if (xcb_request_failed(cfg_cookie, "Could not reconfigure window")) {
843 if (xcb_request_failed(pm_cookie, "Could not create pixmap")) {
851 * Render the bars, with buttons and statusline
855 DLOG("Drawing Bars...\n");
858 refresh_statusline();
860 i3_output *outputs_walk;
861 SLIST_FOREACH(outputs_walk, outputs, slist) {
862 if (!outputs_walk->active) {
863 DLOG("Output %s inactive, skipping...\n", outputs_walk->name);
866 if (outputs_walk->bar == XCB_NONE) {
867 /* Oh shit, an active output without an own bar. Create it now! */
870 /* First things first: clear the backbuffer */
871 uint32_t color = colors.bar_bg;
872 xcb_change_gc(xcb_connection,
876 xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, font_height + 6 };
877 xcb_poly_fill_rectangle(xcb_connection,
878 outputs_walk->buffer,
883 if (statusline != NULL) {
884 DLOG("Printing statusline!\n");
886 /* Luckily we already prepared a seperate pixmap containing the rendered
887 * statusline, we just have to copy the relevant parts to the relevant
889 xcb_copy_area(xcb_connection,
891 outputs_walk->buffer,
893 MAX(0, (int16_t)(statusline_width - outputs_walk->rect.w + 4)), 0,
894 MAX(0, (int16_t)(outputs_walk->rect.w - statusline_width - 4)), 3,
895 MIN(outputs_walk->rect.w - 4, statusline_width), font_height);
899 TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
900 DLOG("Drawing Button for WS %s at x = %d\n", ws_walk->name, i);
901 uint32_t fg_color = colors.inactive_ws_fg;
902 uint32_t bg_color = colors.inactive_ws_bg;
903 if (ws_walk->visible) {
904 fg_color = colors.active_ws_fg;
905 bg_color = colors.active_ws_bg;
907 if (ws_walk->urgent) {
908 DLOG("WS %s is urgent!\n", ws_walk->name);
909 fg_color = colors.urgent_ws_fg;
910 bg_color = colors.urgent_ws_bg;
911 /* The urgent-hint should get noticed, so we unhide the bars shortly */
914 xcb_change_gc(xcb_connection,
918 xcb_change_gc(xcb_connection,
922 xcb_rectangle_t rect = { i + 1, 1, ws_walk->name_width + 8, font_height + 4 };
923 xcb_poly_fill_rectangle(xcb_connection,
924 outputs_walk->buffer,
928 xcb_change_gc(xcb_connection,
932 xcb_image_text_16(xcb_connection,
933 ws_walk->name_glyphs,
934 outputs_walk->buffer,
936 i + 5, font_info->font_ascent + 2,
938 i += 10 + ws_walk->name_width;
948 * Redraw the bars, i.e. simply copy the buffer to the barwindow
952 i3_output *outputs_walk;
953 SLIST_FOREACH(outputs_walk, outputs, slist) {
954 xcb_copy_area(xcb_connection,
955 outputs_walk->buffer,
960 outputs_walk->rect.w,
961 outputs_walk->rect.h);
962 xcb_flush(xcb_connection);