Skip to content

Commit f293418

Browse files
Nefsen402emersion
authored andcommitted
swaybar: Handle opaque region properly
The background color can be set individually for the different elements of the bar. If any of the backgrounds have transparency, we have to bail out from advertising an opaque surface.
1 parent 4eb86fc commit f293418

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

swaybar/render.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct render_context {
2929
cairo_font_options_t *textaa_sharp;
3030
cairo_font_options_t *textaa_safe;
3131
uint32_t background_color;
32+
bool has_transparency;
3233
};
3334

3435
static void choose_text_aa_mode(struct render_context *ctx, uint32_t fontcolor) {
@@ -265,6 +266,7 @@ static uint32_t render_status_block(struct render_context *ctx,
265266

266267
uint32_t bg_color = block->urgent
267268
? config->colors.urgent_workspace.background : block->background;
269+
ctx->has_transparency |= (bg_color & 0xFF) != 0xFF;
268270
if (bg_color) {
269271
render_sharp_rectangle(cairo, bg_color, x_pos, y_pos,
270272
block_width, render_height);
@@ -574,6 +576,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,
574576
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
575577
cairo_set_source_u32(cairo, config->colors.binding_mode.background);
576578
ctx->background_color = config->colors.binding_mode.background;
579+
ctx->has_transparency |= (config->colors.binding_mode.background & 0xFF) != 0xFF;
577580
cairo_rectangle(cairo, x, 0, width, height);
578581
cairo_fill(cairo);
579582

@@ -653,6 +656,7 @@ static uint32_t render_workspace_button(struct render_context *ctx,
653656
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
654657
cairo_set_source_u32(cairo, box_colors.background);
655658
ctx->background_color = box_colors.background;
659+
ctx->has_transparency |= (box_colors.background & 0xFF) != 0xFF;
656660
cairo_rectangle(cairo, *x, 0, width, height);
657661
cairo_fill(cairo);
658662

@@ -760,10 +764,12 @@ void render_frame(struct swaybar_output *output) {
760764
background_color = output->bar->config->colors.background;
761765
}
762766

763-
struct render_context ctx = { 0 };
764-
ctx.output = output;
765-
// initial background color used for deciding the best way to antialias text
766-
ctx.background_color = background_color;
767+
struct render_context ctx = {
768+
.output = output,
769+
// initial background color used for deciding the best way to antialias text
770+
.background_color = background_color,
771+
.has_transparency = (background_color & 0xFF) != 0xFF,
772+
};
767773

768774
cairo_surface_t *recorder = cairo_recording_surface_create(
769775
CAIRO_CONTENT_COLOR_ALPHA, NULL);
@@ -834,8 +840,7 @@ void render_frame(struct swaybar_output *output) {
834840
wl_surface_damage(output->surface, 0, 0,
835841
output->width, output->height);
836842

837-
uint32_t bg_alpha = background_color & 0xFF;
838-
if (bg_alpha == 0xFF) {
843+
if (!ctx.has_transparency) {
839844
struct wl_region *region =
840845
wl_compositor_create_region(output->bar->compositor);
841846
wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);

0 commit comments

Comments
 (0)