aboutsummaryrefslogtreecommitdiff
path: root/swaybar
diff options
context:
space:
mode:
authorAlexander Orzechowski <orzechowski.alexander@gmail.com>2023-03-27 08:50:44 +0200
committerKenny Levinsen <kl@kl.wtf>2023-04-02 01:58:02 +0200
commit9cf66e8c7cfc06680a1af055bafd7e5cc01d6fe2 (patch)
tree7a0a05ec6e0b94a4eef2b9cf4ac9496ff4768674 /swaybar
parent5d5b21dcce0fa6416a7639a6cc0e3edf4311b0cf (diff)
swaybar: Lift background clearing out of main rendering function
This avoids us from using a bogus background_color value that mutates as swaybar renders things and deciding opacity depending on that. Also remove a redundant full surface clear. Just directly write our desired background color.
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/render.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index a296112a..1113ca44 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -693,15 +693,6 @@ static uint32_t render_to_cairo(struct render_context *ctx) {
struct swaybar_output *output = ctx->output;
struct swaybar *bar = output->bar;
struct swaybar_config *config = bar->config;
- cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
- if (output->focused) {
- ctx->background_color = config->colors.focused_background;
- } else {
- ctx->background_color = config->colors.background;
- }
-
- cairo_set_source_u32(cairo, ctx->background_color);
- cairo_paint(cairo);
int th;
get_text_size(cairo, config->font_description, NULL, &th, NULL, 1, false, "");
@@ -763,8 +754,17 @@ void render_frame(struct swaybar_output *output) {
free_hotspots(&output->hotspots);
+ uint32_t background_color;
+ if (output->focused) {
+ background_color = output->bar->config->colors.focused_background;
+ } else {
+ 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;
cairo_surface_t *recorder = cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, NULL);
@@ -786,10 +786,11 @@ void render_frame(struct swaybar_output *output) {
ctx.textaa_sharp = fo;
}
- cairo_save(cairo);
- cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
+
+ cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_u32(cairo, background_color);
cairo_paint(cairo);
- cairo_restore(cairo);
+
uint32_t height = render_to_cairo(&ctx);
int config_height = output->bar->config->height;
if (config_height > 0) {
@@ -834,7 +835,7 @@ void render_frame(struct swaybar_output *output) {
wl_surface_damage(output->surface, 0, 0,
output->width, output->height);
- uint32_t bg_alpha = ctx.background_color & 0xFF;
+ uint32_t bg_alpha = background_color & 0xFF;
if (bg_alpha == 0xFF) {
struct wl_region *region =
wl_compositor_create_region(output->bar->compositor);