Merge pull request #2039 from DavidMikeSimon/fix-1824

Use separate buffers for i3bar statusline for each workspace, track short and long renders separately, fixes #1824
This commit is contained in:
Michael Stapelberg 2015-10-26 21:26:53 +01:00
commit d187214562
5 changed files with 156 additions and 135 deletions

View File

@ -31,6 +31,14 @@ typedef enum {
ALIGN_RIGHT ALIGN_RIGHT
} blockalign_t; } blockalign_t;
/* This data structure describes the way a status block should be rendered. These
* variables are updated each time the statusline is re-rendered. */
struct status_block_render_desc {
uint32_t width;
uint32_t x_offset;
uint32_t x_append;
};
/* This data structure represents one JSON dictionary, multiple of these make /* This data structure represents one JSON dictionary, multiple of these make
* up one status line. */ * up one status line. */
struct status_block { struct status_block {
@ -56,11 +64,9 @@ struct status_block {
/* The amount of pixels necessary to render a separater after the block. */ /* The amount of pixels necessary to render a separater after the block. */
uint32_t sep_block_width; uint32_t sep_block_width;
/* The amount of pixels necessary to render this block. These variables are /* Continuously-updated information on how to render this status block. */
* only temporarily used in refresh_statusline(). */ struct status_block_render_desc full_render;
uint32_t width; struct status_block_render_desc short_render;
uint32_t x_offset;
uint32_t x_append;
/* Optional */ /* Optional */
char *name; char *name;

View File

@ -46,8 +46,14 @@ struct i3_output {
int ws; /* The number of the currently visible ws */ int ws; /* The number of the currently visible ws */
rect rect; /* The rect (relative to the root window) */ rect rect; /* The rect (relative to the root window) */
/* Off-screen buffer for preliminary rendering. */ /* Off-screen buffer for preliminary rendering of the bar. */
surface_t buffer; surface_t buffer;
/* Off-screen buffer for pre-rendering the statusline, separated to make clipping easier. */
surface_t statusline_buffer;
/* How much of statusline_buffer's horizontal space was used on last statusline render. */
int statusline_width;
/* Whether statusline block short texts where used on last statusline render. */
bool statusline_short_text;
/* The actual window on which we draw. */ /* The actual window on which we draw. */
surface_t bar; surface_t bar;

View File

@ -63,7 +63,6 @@ void got_output_reply(char *reply) {
DLOG("Parsing outputs JSON...\n"); DLOG("Parsing outputs JSON...\n");
parse_outputs_json(reply); parse_outputs_json(reply);
DLOG("Reconfiguring windows...\n"); DLOG("Reconfiguring windows...\n");
realloc_sl_buffer();
reconfig_windows(false); reconfig_windows(false);
i3_output *o_walk; i3_output *o_walk;
@ -175,7 +174,6 @@ void got_bar_config_update(char *event) {
/* update fonts and colors */ /* update fonts and colors */
init_xcb_late(config.fontname); init_xcb_late(config.fontname);
init_colors(&(config.colors)); init_colors(&(config.colors));
realloc_sl_buffer();
draw_bars(false); draw_bars(false);
} }

View File

@ -144,10 +144,16 @@ static int outputs_start_map_cb(void *params_) {
if (params->cur_key == NULL) { if (params->cur_key == NULL) {
new_output = smalloc(sizeof(i3_output)); new_output = smalloc(sizeof(i3_output));
new_output->name = NULL; new_output->name = NULL;
new_output->active = false;
new_output->primary = false;
new_output->visible = false;
new_output->ws = 0, new_output->ws = 0,
new_output->statusline_width = 0;
new_output->statusline_short_text = false;
memset(&new_output->rect, 0, sizeof(rect)); memset(&new_output->rect, 0, sizeof(rect));
memset(&new_output->bar, 0, sizeof(surface_t)); memset(&new_output->bar, 0, sizeof(surface_t));
memset(&new_output->buffer, 0, sizeof(surface_t)); memset(&new_output->buffer, 0, sizeof(surface_t));
memset(&new_output->statusline_buffer, 0, sizeof(surface_t));
new_output->workspaces = smalloc(sizeof(struct ws_head)); new_output->workspaces = smalloc(sizeof(struct ws_head));
TAILQ_INIT(new_output->workspaces); TAILQ_INIT(new_output->workspaces);

View File

@ -74,11 +74,6 @@ int bar_height;
int xkb_base; int xkb_base;
int mod_pressed = 0; int mod_pressed = 0;
/* Because the statusline is the same on all outputs, we have
* global buffer to render it on */
surface_t statusline_surface;
uint32_t statusline_width;
/* Event watchers, to interact with the user */ /* Event watchers, to interact with the user */
ev_prepare *xcb_prep; ev_prepare *xcb_prep;
ev_check *xcb_chk; ev_check *xcb_chk;
@ -165,7 +160,7 @@ int get_tray_width(struct tc_head *trayclients) {
* Draws a separator for the given block if necessary. * Draws a separator for the given block if necessary.
* *
*/ */
static void draw_separator(uint32_t x, struct status_block *block) { static void draw_separator(i3_output *output, uint32_t x, struct status_block *block) {
uint32_t sep_offset = get_sep_offset(block); uint32_t sep_offset = get_sep_offset(block);
if (TAILQ_NEXT(block, blocks) == NULL || sep_offset == 0) if (TAILQ_NEXT(block, blocks) == NULL || sep_offset == 0)
return; return;
@ -173,7 +168,7 @@ static void draw_separator(uint32_t x, struct status_block *block) {
uint32_t center_x = x - sep_offset; uint32_t center_x = x - sep_offset;
if (config.separator_symbol == NULL) { if (config.separator_symbol == NULL) {
/* Draw a classic one pixel, vertical separator. */ /* Draw a classic one pixel, vertical separator. */
draw_util_rectangle(&statusline_surface, colors.sep_fg, draw_util_rectangle(&output->statusline_buffer, colors.sep_fg,
center_x, center_x,
logical_px(sep_voff_px), logical_px(sep_voff_px),
logical_px(1), logical_px(1),
@ -181,119 +176,138 @@ static void draw_separator(uint32_t x, struct status_block *block) {
} else { } else {
/* Draw a custom separator. */ /* Draw a custom separator. */
uint32_t separator_x = MAX(x - block->sep_block_width, center_x - separator_symbol_width / 2); uint32_t separator_x = MAX(x - block->sep_block_width, center_x - separator_symbol_width / 2);
draw_util_text(config.separator_symbol, &statusline_surface, colors.sep_fg, colors.bar_bg, draw_util_text(config.separator_symbol, &output->statusline_buffer, colors.sep_fg, colors.bar_bg,
separator_x, logical_px(ws_voff_px), x - separator_x); separator_x, logical_px(ws_voff_px), x - separator_x);
} }
} }
/* uint32_t predict_statusline_length(bool use_short_text) {
* Redraws the statusline to the buffer uint32_t width = 0;
*
*/
void refresh_statusline(bool use_short_text) {
struct status_block *block; struct status_block *block;
uint32_t old_statusline_width = statusline_width;
statusline_width = 0;
/* Predict the text width of all blocks (in pixels). */
TAILQ_FOREACH(block, &statusline_head, blocks) { TAILQ_FOREACH(block, &statusline_head, blocks) {
/* Try to use the shorter text if necessary and possible. */ i3String *text = block->full_text;
struct status_block_render_desc *render = &block->full_render;
if (use_short_text && block->short_text != NULL) { if (use_short_text && block->short_text != NULL) {
I3STRING_FREE(block->full_text); text = block->short_text;
block->full_text = i3string_copy(block->short_text); render = &block->short_render;
} }
if (i3string_get_num_bytes(block->full_text) == 0) if (i3string_get_num_bytes(text) == 0)
continue; continue;
block->width = predict_text_width(block->full_text); render->width = predict_text_width(text);
/* Add padding for the border if we have to draw it. */
if (block->border) if (block->border)
block->width += logical_px(2); render->width += logical_px(2);
/* Compute offset and append for text aligment in min_width. */ /* Compute offset and append for text aligment in min_width. */
if (block->min_width <= block->width) { if (block->min_width <= render->width) {
block->x_offset = 0; render->x_offset = 0;
block->x_append = 0; render->x_append = 0;
} else { } else {
uint32_t padding_width = block->min_width - block->width; uint32_t padding_width = block->min_width - render->width;
switch (block->align) { switch (block->align) {
case ALIGN_LEFT: case ALIGN_LEFT:
block->x_append = padding_width; render->x_append = padding_width;
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
block->x_offset = padding_width; render->x_offset = padding_width;
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
block->x_offset = padding_width / 2; render->x_offset = padding_width / 2;
block->x_append = padding_width / 2 + padding_width % 2; render->x_append = padding_width / 2 + padding_width % 2;
break; break;
} }
} }
width += render->width + render->x_offset + render->x_append;
/* If this is not the last block, add some pixels for a separator. */ /* If this is not the last block, add some pixels for a separator. */
if (TAILQ_NEXT(block, blocks) != NULL) if (TAILQ_NEXT(block, blocks) != NULL)
statusline_width += block->sep_block_width; width += block->sep_block_width;
statusline_width += block->width + block->x_offset + block->x_append;
} }
/* If the statusline is bigger than our screen we need to make sure that return width;
* the pixmap provides enough space, so re-allocate if the width grew */ }
if (statusline_width > root_screen->width_in_pixels &&
statusline_width > old_statusline_width)
realloc_sl_buffer();
/* Clear the statusline pixmap. */ /*
draw_util_clear_surface(&statusline_surface, colors.bar_bg); * Redraws the statusline to the output's statusline_buffer
*/
void draw_statusline(i3_output *output, uint32_t clip_left, bool use_short_text) {
struct status_block *block;
/* Draw the text of each block. */ draw_util_clear_surface(&output->statusline_buffer, colors.bar_bg);
uint32_t x = 0;
/* Use unsigned integer wraparound to clip off the left side.
* For example, if clip_left is 75, then x will start at the very large
* number INT_MAX-75, which is way outside the surface dimensions. Drawing
* to that x position is a no-op which XCB and Cairo safely ignore. Once x moves
* up by 75 and goes past INT_MAX, it will wrap around again to 0, and we start
* actually rendering content to the surface. */
uint32_t x = 0 - clip_left;
/* Draw the text of each block */
TAILQ_FOREACH(block, &statusline_head, blocks) { TAILQ_FOREACH(block, &statusline_head, blocks) {
if (i3string_get_num_bytes(block->full_text) == 0) i3String *text = block->full_text;
struct status_block_render_desc *render = &block->full_render;
if (use_short_text && block->short_text != NULL) {
text = block->short_text;
render = &block->short_render;
}
if (i3string_get_num_bytes(text) == 0)
continue; continue;
color_t fg_color = (block->color ? draw_util_hex_to_color(block->color) : colors.bar_fg); color_t fg_color;
int border_width = (block->border) ? logical_px(1) : 0; if (block->urgent) {
if (block->border || block->background || block->urgent) { fg_color = colors.urgent_ws_fg;
if (block->urgent) } else if (block->color) {
fg_color = colors.urgent_ws_fg; fg_color = draw_util_hex_to_color(block->color);
} else {
fg_color = colors.bar_fg;
}
color_t bg_color = colors.bar_bg;
int border_width = (block->border) ? logical_px(1) : 0;
int full_render_width = render->width + render->x_offset + render->x_append;
if (block->border || block->background || block->urgent) {
/* Let's determine the colors first. */ /* Let's determine the colors first. */
color_t border_color = colors.bar_bg; color_t border_color = colors.bar_bg;
color_t bg_color = colors.bar_bg;
if (block->urgent) { if (block->urgent) {
border_color = colors.urgent_ws_border; border_color = colors.urgent_ws_border;
bg_color = colors.urgent_ws_bg; bg_color = colors.urgent_ws_bg;
} else { } else {
if (block->border) if (block->border)
border_color = draw_util_hex_to_color(block->border); border_color = draw_util_hex_to_color(block->border);
if (block->background) if (block->background)
bg_color = draw_util_hex_to_color(block->background); bg_color = draw_util_hex_to_color(block->background);
} }
/* Draw the border. */ /* Draw the border. */
draw_util_rectangle(&statusline_surface, border_color, draw_util_rectangle(&output->statusline_buffer, border_color,
x, logical_px(1), x, logical_px(1),
block->width + block->x_offset + block->x_append, full_render_width,
bar_height - logical_px(2)); bar_height - logical_px(2));
/* Draw the background. */ /* Draw the background. */
draw_util_rectangle(&statusline_surface, bg_color, draw_util_rectangle(&output->statusline_buffer, bg_color,
x + border_width, x + border_width,
logical_px(1) + border_width, logical_px(1) + border_width,
block->width + block->x_offset + block->x_append - 2 * border_width, full_render_width - 2 * border_width,
bar_height - 2 * border_width - logical_px(2)); bar_height - 2 * border_width - logical_px(2));
} }
draw_util_text(block->full_text, &statusline_surface, fg_color, colors.bar_bg, draw_util_text(text, &output->statusline_buffer, fg_color, bg_color,
x + block->x_offset + border_width, logical_px(ws_voff_px), block->width - 2 * border_width); x + render->x_offset + border_width, logical_px(ws_voff_px),
x += block->width + block->sep_block_width + block->x_offset + block->x_append; render->width - 2 * border_width);
x += full_render_width;
/* If this is not the last block, draw a separator. */ /* If this is not the last block, draw a separator. */
draw_separator(x, block); if (TAILQ_NEXT(block, blocks) != NULL) {
x += block->sep_block_width;
draw_separator(output, x, block);
}
} }
} }
@ -426,7 +440,6 @@ void handle_button(xcb_button_press_event_t *event) {
} }
int32_t x = event->event_x >= 0 ? event->event_x : 0; int32_t x = event->event_x >= 0 ? event->event_x : 0;
int32_t original_x = x;
DLOG("Got button %d\n", event->detail); DLOG("Got button %d\n", event->detail);
@ -449,21 +462,28 @@ void handle_button(xcb_button_press_event_t *event) {
* check if a status block has been clicked. */ * check if a status block has been clicked. */
int tray_width = get_tray_width(walk->trayclients); int tray_width = get_tray_width(walk->trayclients);
int block_x = 0, last_block_x; int block_x = 0, last_block_x;
int offset = walk->rect.w - statusline_width - tray_width - logical_px(sb_hoff_px); int offset = walk->rect.w - walk->statusline_width - tray_width - logical_px(sb_hoff_px);
int32_t statusline_x = x - offset;
x = original_x - offset; if (statusline_x >= 0 && statusline_x < walk->statusline_width) {
if (x >= 0 && (size_t)x < statusline_width) {
struct status_block *block; struct status_block *block;
int sep_offset_remainder = 0; int sep_offset_remainder = 0;
TAILQ_FOREACH(block, &statusline_head, blocks) { TAILQ_FOREACH(block, &statusline_head, blocks) {
if (i3string_get_num_bytes(block->full_text) == 0) i3String *text = block->full_text;
struct status_block_render_desc *render = &block->full_render;
if (walk->statusline_short_text && block->short_text != NULL) {
text = block->short_text;
render = &block->short_render;
}
if (i3string_get_num_bytes(text) == 0)
continue; continue;
last_block_x = block_x; last_block_x = block_x;
block_x += block->width + block->x_offset + block->x_append + get_sep_offset(block) + sep_offset_remainder; block_x += render->width + render->x_offset + render->x_append + get_sep_offset(block) + sep_offset_remainder;
if (x <= block_x && x >= last_block_x) { if (statusline_x <= block_x && statusline_x >= last_block_x) {
send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y); send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y);
return; return;
} }
@ -471,7 +491,6 @@ void handle_button(xcb_button_press_event_t *event) {
sep_offset_remainder = block->sep_block_width - get_sep_offset(block); sep_offset_remainder = block->sep_block_width - get_sep_offset(block);
} }
} }
x = original_x;
} }
/* If a custom command was specified for this mouse button, it overrides /* If a custom command was specified for this mouse button, it overrides
@ -1147,17 +1166,6 @@ char *init_xcb_early() {
colormap = root_screen->default_colormap; colormap = root_screen->default_colormap;
visual_type = get_visualtype(root_screen); visual_type = get_visualtype(root_screen);
/* We draw the statusline to a seperate pixmap, because it looks the same on all bars and
* this way, we can choose to crop it */
xcb_pixmap_t statusline_id = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
depth,
statusline_id,
xcb_root,
root_screen->width_in_pixels,
root_screen->height_in_pixels);
draw_util_surface_init(&statusline_surface, statusline_id, root_screen->width_in_pixels, root_screen->height_in_pixels);
/* The various watchers to communicate with xcb */ /* The various watchers to communicate with xcb */
xcb_io = smalloc(sizeof(ev_io)); xcb_io = smalloc(sizeof(ev_io));
xcb_prep = smalloc(sizeof(ev_prepare)); xcb_prep = smalloc(sizeof(ev_prepare));
@ -1176,9 +1184,6 @@ char *init_xcb_early() {
char *path = root_atom_contents("I3_SOCKET_PATH", xcb_connection, screen); char *path = root_atom_contents("I3_SOCKET_PATH", xcb_connection, screen);
if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline buffer"))
exit(EXIT_FAILURE);
return path; return path;
} }
@ -1510,29 +1515,6 @@ void destroy_window(i3_output *output) {
output->bar.id = XCB_NONE; output->bar.id = XCB_NONE;
} }
/*
* Reallocate the statusline buffer
*
*/
void realloc_sl_buffer(void) {
DLOG("Re-allocating statusline buffer, statusline_width = %d, root_screen->width_in_pixels = %d\n",
statusline_width, root_screen->width_in_pixels);
xcb_free_pixmap(xcb_connection, statusline_surface.id);
draw_util_surface_free(&statusline_surface);
xcb_pixmap_t statusline_id = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
depth,
statusline_id,
xcb_root,
MAX(root_screen->width_in_pixels, statusline_width),
bar_height);
draw_util_surface_init(&statusline_surface, statusline_id, root_screen->width_in_pixels, root_screen->height_in_pixels);
if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline buffer"))
exit(EXIT_FAILURE);
}
/* Strut partial tells i3 where to reserve space for i3bar. This is determined /* Strut partial tells i3 where to reserve space for i3bar. This is determined
* by the `position` bar config directive. */ * by the `position` bar config directive. */
xcb_void_cookie_t config_strut_partial(i3_output *output) { xcb_void_cookie_t config_strut_partial(i3_output *output) {
@ -1600,6 +1582,7 @@ void reconfig_windows(bool redraw_bars) {
xcb_window_t bar_id = xcb_generate_id(xcb_connection); xcb_window_t bar_id = xcb_generate_id(xcb_connection);
xcb_pixmap_t buffer_id = xcb_generate_id(xcb_connection); xcb_pixmap_t buffer_id = xcb_generate_id(xcb_connection);
xcb_pixmap_t statusline_buffer_id = xcb_generate_id(xcb_connection);
mask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; mask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
values[0] = colors.bar_bg.colorpixel; values[0] = colors.bar_bg.colorpixel;
@ -1643,6 +1626,14 @@ void reconfig_windows(bool redraw_bars) {
walk->rect.w, walk->rect.w,
bar_height); bar_height);
/* The double-buffer we use to render the statusline before copying to buffer */
xcb_void_cookie_t slpm_cookie = xcb_create_pixmap_checked(xcb_connection,
depth,
statusline_buffer_id,
bar_id,
walk->rect.w,
bar_height);
/* Set the WM_CLASS and WM_NAME (we don't need UTF-8) atoms */ /* Set the WM_CLASS and WM_NAME (we don't need UTF-8) atoms */
xcb_void_cookie_t class_cookie; xcb_void_cookie_t class_cookie;
class_cookie = xcb_change_property(xcb_connection, class_cookie = xcb_change_property(xcb_connection,
@ -1680,6 +1671,7 @@ void reconfig_windows(bool redraw_bars) {
draw_util_surface_init(&walk->bar, bar_id, walk->rect.w, bar_height); draw_util_surface_init(&walk->bar, bar_id, walk->rect.w, bar_height);
draw_util_surface_init(&walk->buffer, buffer_id, walk->rect.w, bar_height); draw_util_surface_init(&walk->buffer, buffer_id, walk->rect.w, bar_height);
draw_util_surface_init(&walk->statusline_buffer, statusline_buffer_id, walk->rect.w, bar_height);
xcb_void_cookie_t strut_cookie = config_strut_partial(walk); xcb_void_cookie_t strut_cookie = config_strut_partial(walk);
@ -1691,6 +1683,7 @@ void reconfig_windows(bool redraw_bars) {
if (xcb_request_failed(win_cookie, "Could not create window") || if (xcb_request_failed(win_cookie, "Could not create window") ||
xcb_request_failed(pm_cookie, "Could not create pixmap") || xcb_request_failed(pm_cookie, "Could not create pixmap") ||
xcb_request_failed(slpm_cookie, "Could not create statusline pixmap") ||
xcb_request_failed(dock_cookie, "Could not set dock mode") || xcb_request_failed(dock_cookie, "Could not set dock mode") ||
xcb_request_failed(class_cookie, "Could not set WM_CLASS") || xcb_request_failed(class_cookie, "Could not set WM_CLASS") ||
xcb_request_failed(name_cookie, "Could not set WM_NAME") || xcb_request_failed(name_cookie, "Could not set WM_NAME") ||
@ -1737,6 +1730,9 @@ void reconfig_windows(bool redraw_bars) {
DLOG("Destroying buffer for output %s\n", walk->name); DLOG("Destroying buffer for output %s\n", walk->name);
xcb_free_pixmap(xcb_connection, walk->buffer.id); xcb_free_pixmap(xcb_connection, walk->buffer.id);
DLOG("Destroying statusline buffer for output %s\n", walk->name);
xcb_free_pixmap(xcb_connection, walk->statusline_buffer.id);
DLOG("Reconfiguring window for output %s to %d,%d\n", walk->name, values[0], values[1]); DLOG("Reconfiguring window for output %s to %d,%d\n", walk->name, values[0], values[1]);
xcb_void_cookie_t cfg_cookie = xcb_configure_window_checked(xcb_connection, xcb_void_cookie_t cfg_cookie = xcb_configure_window_checked(xcb_connection,
walk->bar.id, walk->bar.id,
@ -1759,10 +1755,20 @@ void reconfig_windows(bool redraw_bars) {
walk->rect.w, walk->rect.w,
bar_height); bar_height);
DLOG("Recreating statusline buffer for output %s\n", walk->name);
xcb_void_cookie_t slpm_cookie = xcb_create_pixmap_checked(xcb_connection,
depth,
walk->statusline_buffer.id,
walk->bar.id,
walk->rect.w,
bar_height);
draw_util_surface_free(&(walk->bar)); draw_util_surface_free(&(walk->bar));
draw_util_surface_free(&(walk->buffer)); draw_util_surface_free(&(walk->buffer));
draw_util_surface_free(&(walk->statusline_buffer));
draw_util_surface_init(&(walk->bar), walk->bar.id, walk->rect.w, bar_height); draw_util_surface_init(&(walk->bar), walk->bar.id, walk->rect.w, bar_height);
draw_util_surface_init(&(walk->buffer), walk->buffer.id, walk->rect.w, bar_height); draw_util_surface_init(&(walk->buffer), walk->buffer.id, walk->rect.w, bar_height);
draw_util_surface_init(&(walk->statusline_buffer), walk->statusline_buffer.id, walk->rect.w, bar_height);
xcb_void_cookie_t map_cookie, umap_cookie; xcb_void_cookie_t map_cookie, umap_cookie;
if (redraw_bars) { if (redraw_bars) {
@ -1787,6 +1793,7 @@ void reconfig_windows(bool redraw_bars) {
if (xcb_request_failed(cfg_cookie, "Could not reconfigure window") || if (xcb_request_failed(cfg_cookie, "Could not reconfigure window") ||
xcb_request_failed(chg_cookie, "Could not change window") || xcb_request_failed(chg_cookie, "Could not change window") ||
xcb_request_failed(pm_cookie, "Could not create pixmap") || xcb_request_failed(pm_cookie, "Could not create pixmap") ||
xcb_request_failed(slpm_cookie, "Could not create statusline pixmap") ||
xcb_request_failed(strut_cookie, "Could not set strut") || xcb_request_failed(strut_cookie, "Could not set strut") ||
(redraw_bars && (xcb_request_failed(umap_cookie, "Could not unmap window") || (redraw_bars && (xcb_request_failed(umap_cookie, "Could not unmap window") ||
(config.hide_on_modifier == M_DOCK && xcb_request_failed(map_cookie, "Could not map window"))))) { (config.hide_on_modifier == M_DOCK && xcb_request_failed(map_cookie, "Could not map window"))))) {
@ -1802,14 +1809,14 @@ void reconfig_windows(bool redraw_bars) {
*/ */
void draw_bars(bool unhide) { void draw_bars(bool unhide) {
DLOG("Drawing bars...\n"); DLOG("Drawing bars...\n");
int workspace_width = 0;
/* Is the currently-rendered statusline using short_text items? */
bool rendered_statusline_is_short = false;
refresh_statusline(false); uint32_t full_statusline_width = predict_statusline_length(false);
uint32_t short_statusline_width = predict_statusline_length(true);
i3_output *outputs_walk; i3_output *outputs_walk;
SLIST_FOREACH(outputs_walk, outputs, slist) { SLIST_FOREACH(outputs_walk, outputs, slist) {
int workspace_width = 0;
if (!outputs_walk->active) { if (!outputs_walk->active) {
DLOG("Output %s inactive, skipping...\n", outputs_walk->name); DLOG("Output %s inactive, skipping...\n", outputs_walk->name);
continue; continue;
@ -1906,30 +1913,28 @@ void draw_bars(bool unhide) {
int tray_width = get_tray_width(outputs_walk->trayclients); int tray_width = get_tray_width(outputs_walk->trayclients);
uint32_t max_statusline_width = outputs_walk->rect.w - workspace_width - tray_width - 2 * logical_px(sb_hoff_px); uint32_t max_statusline_width = outputs_walk->rect.w - workspace_width - tray_width - 2 * logical_px(sb_hoff_px);
uint32_t clip_left = 0;
uint32_t statusline_width = full_statusline_width;
bool use_short_text = false;
/* If the statusline is too long, try to use short texts. */
if (statusline_width > max_statusline_width) { if (statusline_width > max_statusline_width) {
/* If the currently rendered statusline is long, render a short status line */ statusline_width = short_statusline_width;
refresh_statusline(true); use_short_text = true;
rendered_statusline_is_short = true; if (statusline_width > max_statusline_width) {
} else if (rendered_statusline_is_short) { clip_left = statusline_width - max_statusline_width;
/* If the currently rendered statusline is short, render a long status line */ }
refresh_statusline(false);
rendered_statusline_is_short = false;
} }
/* Luckily we already prepared a seperate pixmap containing the rendered int16_t visible_statusline_width = MIN(statusline_width, max_statusline_width);
* statusline, we just have to copy the relevant parts to the relevant int x_dest = outputs_walk->rect.w - tray_width - logical_px(sb_hoff_px) - visible_statusline_width;
* position */
int visible_statusline_width = MIN(statusline_width, max_statusline_width);
int x_src = (int16_t)(statusline_width - visible_statusline_width);
int x_dest = (int16_t)(outputs_walk->rect.w - tray_width - logical_px(sb_hoff_px) - visible_statusline_width);
draw_util_copy_surface(&statusline_surface, &(outputs_walk->buffer), x_src, 0, draw_statusline(outputs_walk, clip_left, use_short_text);
x_dest, 0, (int16_t)visible_statusline_width, (int16_t)bar_height); draw_util_copy_surface(&outputs_walk->statusline_buffer, &outputs_walk->buffer, 0, 0,
x_dest, 0, visible_statusline_width, (int16_t)bar_height);
outputs_walk->statusline_width = statusline_width;
outputs_walk->statusline_short_text = use_short_text;
} }
workspace_width = 0;
} }
/* Assure the bar is hidden/unhidden according to the specified hidden_state and mode */ /* Assure the bar is hidden/unhidden according to the specified hidden_state and mode */