Add support for workspace_min_width bar option.

This commit is contained in:
Tarmack 2020-10-03 15:45:26 +02:00 committed by Simon Ser
parent 657587964e
commit 989123a2a5
13 changed files with 74 additions and 3 deletions

View file

@ -35,6 +35,7 @@ struct swaybar_config *init_config(void) {
config->binding_mode_indicator = true;
config->wrap_scroll = false;
config->workspace_buttons = true;
config->workspace_min_width = 0;
config->bindings = create_list();
wl_list_init(&config->outputs);
config->status_padding = 1;

View file

@ -270,6 +270,12 @@ static bool ipc_parse_config(
config->workspace_buttons = json_object_get_boolean(workspace_buttons);
}
json_object *workspace_min_width =
json_object_object_get(bar_config, "workspace_min_width");
if (workspace_min_width) {
config->workspace_min_width = json_object_get_int(workspace_min_width);
}
json_object *wrap_scroll = json_object_object_get(bar_config, "wrap_scroll");
if (wrap_scroll) {
config->wrap_scroll = json_object_get_boolean(wrap_scroll);

View file

@ -402,7 +402,11 @@ static uint32_t predict_workspace_button_length(cairo_t *cairo,
return 0;
}
return ws_horizontal_padding * 2 + text_width + border_width * 2;
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
return width;
}
static uint32_t predict_workspace_buttons_length(cairo_t *cairo,
@ -446,7 +450,11 @@ static uint32_t predict_binding_mode_indicator_length(cairo_t *cairo,
output->height < ideal_surface_height) {
return 0;
}
return text_width + ws_horizontal_padding * 2 + border_width * 2;
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
return width;
}
static uint32_t render_status_line_i3bar(cairo_t *cairo,
@ -518,6 +526,9 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
return ideal_surface_height;
}
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
uint32_t height = output->height * output->scale;
cairo_set_source_u32(cairo, config->colors.binding_mode.background);
@ -585,7 +596,10 @@ static uint32_t render_workspace_button(cairo_t *cairo,
return ideal_surface_height;
}
uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2;
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
cairo_set_source_u32(cairo, box_colors.background);
cairo_rectangle(cairo, *x, 0, width, height);