Skip to content

Commit

Permalink
swaybar: Handle opaque region properly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Nefsen402 authored and emersion committed Dec 8, 2024
1 parent 4eb86fc commit f293418
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions swaybar/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct render_context {
cairo_font_options_t *textaa_sharp;
cairo_font_options_t *textaa_safe;
uint32_t background_color;
bool has_transparency;
};

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

uint32_t bg_color = block->urgent
? config->colors.urgent_workspace.background : block->background;
ctx->has_transparency |= (bg_color & 0xFF) != 0xFF;
if (bg_color) {
render_sharp_rectangle(cairo, bg_color, x_pos, y_pos,
block_width, render_height);
Expand Down Expand Up @@ -574,6 +576,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
cairo_set_source_u32(cairo, config->colors.binding_mode.background);
ctx->background_color = config->colors.binding_mode.background;
ctx->has_transparency |= (config->colors.binding_mode.background & 0xFF) != 0xFF;
cairo_rectangle(cairo, x, 0, width, height);
cairo_fill(cairo);

Expand Down Expand Up @@ -653,6 +656,7 @@ 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;
ctx->has_transparency |= (box_colors.background & 0xFF) != 0xFF;
cairo_rectangle(cairo, *x, 0, width, height);
cairo_fill(cairo);

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

struct render_context ctx = { 0 };
ctx.output = output;
// initial background color used for deciding the best way to antialias text
ctx.background_color = background_color;
struct render_context ctx = {
.output = output,
// initial background color used for deciding the best way to antialias text
.background_color = background_color,
.has_transparency = (background_color & 0xFF) != 0xFF,
};

cairo_surface_t *recorder = cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, NULL);
Expand Down Expand Up @@ -834,8 +840,7 @@ void render_frame(struct swaybar_output *output) {
wl_surface_damage(output->surface, 0, 0,
output->width, output->height);

uint32_t bg_alpha = background_color & 0xFF;
if (bg_alpha == 0xFF) {
if (!ctx.has_transparency) {
struct wl_region *region =
wl_compositor_create_region(output->bar->compositor);
wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
Expand Down

0 comments on commit f293418

Please sign in to comment.