swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.77k stars 1.11k forks source link

Lack of gaps between workspace buttons on swaybar #5816

Open themasterg3 opened 4 years ago

themasterg3 commented 4 years ago

The i3bar has small gaps between the workspace buttons but swaybar does not. I think the buttons on swaybar may be one pixel too large.

lovelymono commented 2 years ago

If someone is familiar with swaybar architecture, any suggestions where to look to change it?

lovelymono commented 2 years ago

Kinda hackish, but works:

diff --git a/swaybar/render.c b/swaybar/render.c
index 7e2f97b..222569e 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -649,22 +649,22 @@ static uint32_t render_workspace_button(struct render_context *ctx,
        cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
        cairo_set_source_u32(cairo, box_colors.background);
        ctx->background_color = box_colors.background;
-       cairo_rectangle(cairo, *x, 0, width, height);
+       cairo_rectangle(cairo, *x + 1, 0 + 1, width - 1, height - 1);
        cairo_fill(cairo);

        cairo_set_source_u32(cairo, box_colors.border);
-       cairo_rectangle(cairo, *x, 0, width, border_width);
+       cairo_rectangle(cairo, *x + 1, 0 + 1, width - 1, border_width);
        cairo_fill(cairo);
-       cairo_rectangle(cairo, *x, 0, border_width, height);
+       cairo_rectangle(cairo, *x + 1, 0 + 1, border_width, height - 1);
        cairo_fill(cairo);
-       cairo_rectangle(cairo, *x + width - border_width, 0, border_width, height);
+       cairo_rectangle(cairo, *x + width - border_width, 0 + 1, border_width, height - 1);
        cairo_fill(cairo);
-       cairo_rectangle(cairo, *x, height - border_width, width, border_width);
+       cairo_rectangle(cairo, *x + 1, height - border_width, width - 1, border_width);
        cairo_fill(cairo);

-       double text_y = height / 2.0 - text_height / 2.0;
+       double text_y = (height) / 2.0 - text_height / 2.0;
        cairo_set_source_u32(cairo, box_colors.text);
-       cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y));
+       cairo_move_to(cairo, *x + (width - 1) / 2 - text_width / 2, (int)floor(text_y));
        choose_text_aa_mode(ctx, box_colors.text);
        render_text(cairo, config->font, 1, config->pango_markup,
                        "%s", ws->label);
lovelymono commented 2 years ago

Sorry for the flurry of edits, I don't know Github >w<