aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index a878805e..879a4e42 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 1#include <assert.h>
3#include <linux/input-event-codes.h> 2#include <linux/input-event-codes.h>
4#include <limits.h> 3#include <limits.h>
@@ -160,7 +159,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
160 159
161static enum hotspot_event_handling block_hotspot_callback( 160static enum hotspot_event_handling block_hotspot_callback(
162 struct swaybar_output *output, struct swaybar_hotspot *hotspot, 161 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
163 double x, double y, uint32_t button, void *data) { 162 double x, double y, uint32_t button, bool released, void *data) {
164 struct i3bar_block *block = data; 163 struct i3bar_block *block = data;
165 struct status_line *status = output->bar->status; 164 struct status_line *status = output->bar->status;
166 return i3bar_block_send_click(status, block, x, y, 165 return i3bar_block_send_click(status, block, x, y,
@@ -168,7 +167,7 @@ static enum hotspot_event_handling block_hotspot_callback(
168 y - (double)hotspot->y, 167 y - (double)hotspot->y,
169 (double)hotspot->width, 168 (double)hotspot->width,
170 (double)hotspot->height, 169 (double)hotspot->height,
171 output->scale, button); 170 output->scale, button, released);
172} 171}
173 172
174static void i3bar_block_unref_callback(void *data) { 173static void i3bar_block_unref_callback(void *data) {
@@ -292,7 +291,7 @@ static uint32_t render_status_block(struct render_context *ctx,
292 } 291 }
293 292
294 double offset = 0; 293 double offset = 0;
295 if (strncmp(block->align, "left", 5) == 0) { 294 if (strncmp(block->align, "left", 4) == 0) {
296 offset = x_pos; 295 offset = x_pos;
297 } else if (strncmp(block->align, "right", 5) == 0) { 296 } else if (strncmp(block->align, "right", 5) == 0) {
298 offset = x_pos + width - text_width; 297 offset = x_pos + width - text_width;
@@ -599,10 +598,15 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,
599 598
600static enum hotspot_event_handling workspace_hotspot_callback( 599static enum hotspot_event_handling workspace_hotspot_callback(
601 struct swaybar_output *output, struct swaybar_hotspot *hotspot, 600 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
602 double x, double y, uint32_t button, void *data) { 601 double x, double y, uint32_t button, bool released, void *data) {
603 if (button != BTN_LEFT) { 602 if (button != BTN_LEFT) {
604 return HOTSPOT_PROCESS; 603 return HOTSPOT_PROCESS;
605 } 604 }
605 if (released) {
606 // Since we handle the pressed event, also handle the released event
607 // to block it from falling through to a binding in the bar
608 return HOTSPOT_IGNORE;
609 }
606 ipc_send_workspace_command(output->bar, (const char *)data); 610 ipc_send_workspace_command(output->bar, (const char *)data);
607 return HOTSPOT_IGNORE; 611 return HOTSPOT_IGNORE;
608} 612}
@@ -688,15 +692,6 @@ static uint32_t render_to_cairo(struct render_context *ctx) {
688 struct swaybar_output *output = ctx->output; 692 struct swaybar_output *output = ctx->output;
689 struct swaybar *bar = output->bar; 693 struct swaybar *bar = output->bar;
690 struct swaybar_config *config = bar->config; 694 struct swaybar_config *config = bar->config;
691 cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
692 if (output->focused) {
693 ctx->background_color = config->colors.focused_background;
694 } else {
695 ctx->background_color = config->colors.background;
696 }
697
698 cairo_set_source_u32(cairo, ctx->background_color);
699 cairo_paint(cairo);
700 695
701 int th; 696 int th;
702 get_text_size(cairo, config->font_description, NULL, &th, NULL, 1, false, ""); 697 get_text_size(cairo, config->font_description, NULL, &th, NULL, 1, false, "");
@@ -758,8 +753,17 @@ void render_frame(struct swaybar_output *output) {
758 753
759 free_hotspots(&output->hotspots); 754 free_hotspots(&output->hotspots);
760 755
756 uint32_t background_color;
757 if (output->focused) {
758 background_color = output->bar->config->colors.focused_background;
759 } else {
760 background_color = output->bar->config->colors.background;
761 }
762
761 struct render_context ctx = { 0 }; 763 struct render_context ctx = { 0 };
762 ctx.output = output; 764 ctx.output = output;
765 // initial background color used for deciding the best way to antialias text
766 ctx.background_color = background_color;
763 767
764 cairo_surface_t *recorder = cairo_recording_surface_create( 768 cairo_surface_t *recorder = cairo_recording_surface_create(
765 CAIRO_CONTENT_COLOR_ALPHA, NULL); 769 CAIRO_CONTENT_COLOR_ALPHA, NULL);
@@ -769,24 +773,23 @@ void render_frame(struct swaybar_output *output) {
769 ctx.cairo = cairo; 773 ctx.cairo = cairo;
770 774
771 cairo_font_options_t *fo = cairo_font_options_create(); 775 cairo_font_options_t *fo = cairo_font_options_create();
772 cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL);
773 cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_GRAY); 776 cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_GRAY);
774 ctx.textaa_safe = fo; 777 ctx.textaa_safe = fo;
775 if (output->subpixel == WL_OUTPUT_SUBPIXEL_NONE) { 778 if (output->subpixel == WL_OUTPUT_SUBPIXEL_NONE) {
776 ctx.textaa_sharp = ctx.textaa_safe; 779 ctx.textaa_sharp = ctx.textaa_safe;
777 } else { 780 } else {
778 fo = cairo_font_options_create(); 781 fo = cairo_font_options_create();
779 cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL);
780 cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); 782 cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL);
781 cairo_font_options_set_subpixel_order(fo, 783 cairo_font_options_set_subpixel_order(fo,
782 to_cairo_subpixel_order(output->subpixel)); 784 to_cairo_subpixel_order(output->subpixel));
783 ctx.textaa_sharp = fo; 785 ctx.textaa_sharp = fo;
784 } 786 }
785 787
786 cairo_save(cairo); 788
787 cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); 789 cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
790 cairo_set_source_u32(cairo, background_color);
788 cairo_paint(cairo); 791 cairo_paint(cairo);
789 cairo_restore(cairo); 792
790 uint32_t height = render_to_cairo(&ctx); 793 uint32_t height = render_to_cairo(&ctx);
791 int config_height = output->bar->config->height; 794 int config_height = output->bar->config->height;
792 if (config_height > 0) { 795 if (config_height > 0) {
@@ -831,13 +834,15 @@ void render_frame(struct swaybar_output *output) {
831 wl_surface_damage(output->surface, 0, 0, 834 wl_surface_damage(output->surface, 0, 0,
832 output->width, output->height); 835 output->width, output->height);
833 836
834 uint32_t bg_alpha = ctx.background_color & 0xFF; 837 uint32_t bg_alpha = background_color & 0xFF;
835 if (bg_alpha == 0xFF) { 838 if (bg_alpha == 0xFF) {
836 struct wl_region *region = 839 struct wl_region *region =
837 wl_compositor_create_region(output->bar->compositor); 840 wl_compositor_create_region(output->bar->compositor);
838 wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); 841 wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
839 wl_surface_set_opaque_region(output->surface, region); 842 wl_surface_set_opaque_region(output->surface, region);
840 wl_region_destroy(region); 843 wl_region_destroy(region);
844 } else {
845 wl_surface_set_opaque_region(output->surface, NULL);
841 } 846 }
842 847
843 struct wl_callback *frame_callback = wl_surface_frame(output->surface); 848 struct wl_callback *frame_callback = wl_surface_frame(output->surface);