diff options
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 30 | ||||
-rw-r--r-- | swaybar/config.c | 2 | ||||
-rw-r--r-- | swaybar/ipc.c | 11 | ||||
-rw-r--r-- | swaybar/render.c | 117 | ||||
-rw-r--r-- | swaybar/tray/tray.c | 8 |
5 files changed, 106 insertions, 62 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 7aed4dca..d36367fc 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -59,6 +59,7 @@ static void swaybar_output_free(struct swaybar_output *output) { free_workspaces(&output->workspaces); wl_list_remove(&output->link); free(output->name); + free(output->identifier); free(output); } @@ -166,13 +167,15 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) { return visible; } -static bool bar_uses_output(struct swaybar *bar, const char *name) { - if (bar->config->all_outputs) { +static bool bar_uses_output(struct swaybar_output *output) { + if (output->bar->config->all_outputs) { return true; } + char *identifier = output->identifier; struct config_output *coutput; - wl_list_for_each(coutput, &bar->config->outputs, link) { - if (strcmp(coutput->name, name) == 0) { + wl_list_for_each(coutput, &output->bar->config->outputs, link) { + if (strcmp(coutput->name, output->name) == 0 || + (identifier && strcmp(coutput->name, identifier) == 0)) { return true; } } @@ -233,7 +236,7 @@ static void xdg_output_handle_done(void *data, struct swaybar *bar = output->bar; assert(output->name != NULL); - if (!bar_uses_output(bar, output->name)) { + if (!bar_uses_output(output)) { swaybar_output_free(output); return; } @@ -258,7 +261,22 @@ static void xdg_output_handle_name(void *data, static void xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output, const char *description) { - // Who cares + // wlroots currently sets the description to `make model serial (name)` + // If this changes in the future, this will need to be modified. + struct swaybar_output *output = data; + free(output->identifier); + output->identifier = NULL; + char *paren = strrchr(description, '('); + if (paren) { + size_t length = paren - description; + output->identifier = malloc(length); + if (!output->identifier) { + wlr_log(WLR_ERROR, "Failed to allocate output identifier"); + return; + } + strncpy(output->identifier, description, length); + output->identifier[length - 1] = '\0'; + } } struct zxdg_output_v1_listener xdg_output_listener = { diff --git a/swaybar/config.c b/swaybar/config.c index 9cafe061..d4cc9b1a 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -37,6 +37,8 @@ struct swaybar_config *init_config(void) { config->workspace_buttons = true; config->bindings = create_list(); wl_list_init(&config->outputs); + config->status_padding = 1; + config->status_edge_padding = 3; /* height */ config->height = 0; diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 8e7a542e..bc5c28b4 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -157,7 +157,7 @@ static bool ipc_parse_config( json_object *font, *gaps, *bar_height, *wrap_scroll, *workspace_buttons; json_object *strip_workspace_numbers, *strip_workspace_name; json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol; - json_object *outputs, *bindings; + json_object *outputs, *bindings, *status_padding, *status_edge_padding; json_object_object_get_ex(bar_config, "mode", &mode); json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); json_object_object_get_ex(bar_config, "position", &position); @@ -176,6 +176,9 @@ static bool ipc_parse_config( json_object_object_get_ex(bar_config, "outputs", &outputs); json_object_object_get_ex(bar_config, "pango_markup", &markup); json_object_object_get_ex(bar_config, "bindings", &bindings); + json_object_object_get_ex(bar_config, "status_padding", &status_padding); + json_object_object_get_ex(bar_config, "status_edge_padding", + &status_edge_padding); if (status_command) { free(config->status_command); config->status_command = strdup(json_object_get_string(status_command)); @@ -209,6 +212,12 @@ static bool ipc_parse_config( if (bar_height) { config->height = json_object_get_int(bar_height); } + if (status_padding) { + config->status_padding = json_object_get_int(status_padding); + } + if (status_edge_padding) { + config->status_edge_padding = json_object_get_int(status_edge_padding); + } if (gaps) { json_object *top = json_object_object_get(gaps, "top"); if (top) { diff --git a/swaybar/render.c b/swaybar/render.c index 9fe4ee9c..12dd3b07 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -35,7 +35,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, cairo_set_source_u32(cairo, 0xFF0000FF); int margin = 3 * output->scale; - int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; + double ws_vertical_padding = + output->bar->config->status_padding * output->scale; char *font = output->bar->config->font; int text_width, text_height; @@ -44,7 +45,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, uint32_t ideal_height = text_height + ws_vertical_padding * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } *x -= text_width + margin; @@ -71,12 +73,13 @@ static uint32_t render_status_line_text(cairo_t *cairo, get_text_size(cairo, config->font, &text_width, &text_height, NULL, output->scale, config->pango_markup, "%s", text); - int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; + double ws_vertical_padding = config->status_padding * output->scale; int margin = 3 * output->scale; uint32_t ideal_height = text_height + ws_vertical_padding * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } @@ -90,13 +93,24 @@ static uint32_t render_status_line_text(cairo_t *cairo, return output->height; } -static void render_sharp_line(cairo_t *cairo, uint32_t color, +static void render_sharp_rectangle(cairo_t *cairo, uint32_t color, double x, double y, double width, double height) { + cairo_save(cairo); cairo_set_source_u32(cairo, color); + cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); + cairo_rectangle(cairo, x, y, width, height); + cairo_fill(cairo); + cairo_restore(cairo); +} + +static void render_sharp_line(cairo_t *cairo, uint32_t color, + double x, double y, double width, double height) { if (width > 1 && height > 1) { - cairo_rectangle(cairo, x, y, width, height); - cairo_fill(cairo); + render_sharp_rectangle(cairo, color, x, y, width, height); } else { + cairo_save(cairo); + cairo_set_source_u32(cairo, color); + cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); if (width == 1) { x += 0.5; height += y; @@ -111,6 +125,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, cairo_set_line_width(cairo, 1.0); cairo_line_to(cairo, width, height); cairo_stroke(cairo); + cairo_restore(cairo); } } @@ -141,7 +156,7 @@ static uint32_t render_status_block(cairo_t *cairo, output->scale, block->markup, "%s", block->full_text); int margin = 3 * output->scale; - int ws_vertical_padding = WS_VERTICAL_PADDING * 2; + double ws_vertical_padding = config->status_padding * output->scale; int width = text_width; if (width < block->min_width) { @@ -151,18 +166,19 @@ static uint32_t render_status_block(cairo_t *cairo, double block_width = width; uint32_t ideal_height = text_height + ws_vertical_padding * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } *x -= width; if ((block->border || block->urgent) && block->border_left > 0) { - *x -= (block->border_left + margin); - block_width += block->border_left + margin; + *x -= (block->border_left * output->scale + margin); + block_width += block->border_left * output->scale + margin; } if ((block->border || block->urgent) && block->border_right > 0) { - *x -= (block->border_right + margin); - block_width += block->border_right + margin; + *x -= (block->border_right * output->scale + margin); + block_width += block->border_right * output->scale + margin; } int sep_width, sep_height; @@ -173,7 +189,8 @@ static uint32_t render_status_block(cairo_t *cairo, output->scale, false, "%s", config->sep_symbol); uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; uint32_t _ideal_surface_height = _ideal_height / output->scale; - if (output->height < _ideal_surface_height) { + if (!output->bar->config->height && + output->height < _ideal_surface_height) { return _ideal_surface_height; } if (sep_width > sep_block_width) { @@ -181,8 +198,8 @@ static uint32_t render_status_block(cairo_t *cairo, } } *x -= sep_block_width; - } else { - *x -= margin; + } else if (config->status_edge_padding) { + *x -= config->status_edge_padding * output->scale; } uint32_t height = output->height * output->scale; @@ -199,48 +216,41 @@ static uint32_t render_status_block(cairo_t *cairo, wl_list_insert(&output->hotspots, &hotspot->link); } - double pos = *x; + double x_pos = *x; + double y_pos = ws_vertical_padding; + double render_height = height - ws_vertical_padding * 2; uint32_t bg_color = block->urgent ? config->colors.urgent_workspace.background : block->background; if (bg_color) { - cairo_set_source_u32(cairo, bg_color); - cairo_rectangle(cairo, pos - 0.5 * output->scale, - output->scale, width, height); - cairo_fill(cairo); + render_sharp_rectangle(cairo, bg_color, x_pos, y_pos, + block_width, render_height); } uint32_t border_color = block->urgent ? config->colors.urgent_workspace.border : block->border; if (border_color && block->border_top > 0) { - render_sharp_line(cairo, border_color, - pos - 0.5 * output->scale, output->scale, - text_width, block->border_top); + render_sharp_line(cairo, border_color, x_pos, y_pos, + block_width, block->border_top * output->scale); } if (border_color && block->border_bottom > 0) { - render_sharp_line(cairo, border_color, - pos - 0.5 * output->scale, - height - output->scale - block->border_bottom, - text_width, block->border_bottom); - } - if (border_color != 0 && block->border_left > 0) { - render_sharp_line(cairo, border_color, - pos - 0.5 * output->scale, output->scale, - block->border_left, height); + render_sharp_line(cairo, border_color, x_pos, + y_pos + render_height - block->border_bottom * output->scale, + block_width, block->border_bottom * output->scale); } - if (border_color != 0 && block->border_right > 0) { - render_sharp_line(cairo, border_color, - pos - 0.5 * output->scale + text_width, output->scale, - block->border_right, height); + if (border_color && block->border_left > 0) { + render_sharp_line(cairo, border_color, x_pos, y_pos, + block->border_left * output->scale, render_height); + x_pos += block->border_left * output->scale + margin; } double offset = 0; if (strncmp(block->align, "left", 5) == 0) { - offset = pos; + offset = x_pos; } else if (strncmp(block->align, "right", 5) == 0) { - offset = pos + width - text_width; + offset = x_pos + width - text_width; } else if (strncmp(block->align, "center", 6) == 0) { - offset = pos + (width - text_width) / 2; + offset = x_pos + (width - text_width) / 2; } cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); uint32_t color = block->color ? *block->color : config->colors.statusline; @@ -248,14 +258,13 @@ static uint32_t render_status_block(cairo_t *cairo, cairo_set_source_u32(cairo, color); pango_printf(cairo, config->font, output->scale, block->markup, "%s", block->full_text); - pos += width; + x_pos += width; if (block->border && block->border_right > 0) { - pos += margin; - render_sharp_line(cairo, block->border, - pos - 0.5 * output->scale, output->scale, - block->border_right, height); - pos += block->border_right; + x_pos += margin; + render_sharp_line(cairo, border_color, x_pos, y_pos, + block->border_right * output->scale, render_height); + x_pos += block->border_right * output->scale; } if (!edge && block->separator) { @@ -265,14 +274,14 @@ static uint32_t render_status_block(cairo_t *cairo, cairo_set_source_u32(cairo, config->colors.separator); } if (config->sep_symbol) { - offset = pos + (sep_block_width - sep_width) / 2; + offset = x_pos + (sep_block_width - sep_width) / 2; cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0); pango_printf(cairo, config->font, output->scale, false, "%s", config->sep_symbol); } else { cairo_set_line_width(cairo, 1); - cairo_move_to(cairo, pos + sep_block_width / 2, margin); - cairo_line_to(cairo, pos + sep_block_width / 2, height - margin); + cairo_move_to(cairo, x_pos + sep_block_width / 2, margin); + cairo_line_to(cairo, x_pos + sep_block_width / 2, height - margin); cairo_stroke(cairo); } } @@ -282,7 +291,7 @@ static uint32_t render_status_block(cairo_t *cairo, static uint32_t render_status_line_i3bar(cairo_t *cairo, struct swaybar_output *output, double *x) { uint32_t max_height = 0; - bool edge = true; + bool edge = *x == output->width * output->scale; struct i3bar_block *block; wl_list_for_each(block, &output->bar->status->blocks, link) { uint32_t h = render_status_block(cairo, output, block, x, edge); @@ -328,7 +337,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, uint32_t ideal_height = text_height + ws_vertical_padding * 2 + border_width * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; @@ -394,7 +404,8 @@ static uint32_t render_workspace_button(cairo_t *cairo, uint32_t ideal_height = ws_vertical_padding * 2 + text_height + border_width * 2; uint32_t ideal_surface_height = ideal_height / output->scale; - if (output->height < ideal_surface_height) { + if (!output->bar->config->height && + output->height < ideal_surface_height) { return ideal_surface_height; } @@ -521,7 +532,7 @@ void render_frame(struct swaybar_output *output) { cairo_restore(cairo); uint32_t height = render_to_cairo(cairo, output); int config_height = output->bar->config->height; - if (config_height >= 0 && height < (uint32_t)config_height) { + if (config_height > 0) { height = config_height; } if (height != output->height || output->width == 0) { diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index 0c3517cb..d5d0c84e 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -101,13 +101,17 @@ void tray_in(int fd, short mask, void *data) { } static int cmp_output(const void *item, const void *cmp_to) { - return strcmp(item, cmp_to); + const struct swaybar_output *output = cmp_to; + if (output->identifier && strcmp(item, output->identifier) == 0) { + return 0; + } + return strcmp(item, output->name); } uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { struct swaybar_config *config = output->bar->config; if (config->tray_outputs) { - if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) { + if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) { return 0; } } // else display on all |