aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index 2d848bfa..26db80cb 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -1,4 +1,5 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <assert.h>
2#include <limits.h> 3#include <limits.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <stdint.h> 5#include <stdint.h>
@@ -120,14 +121,14 @@ static void i3bar_block_unref_callback(void *data) {
120} 121}
121 122
122static uint32_t render_status_block(cairo_t *cairo, 123static uint32_t render_status_block(cairo_t *cairo,
123 struct swaybar_config *config, struct swaybar_output *output, 124 struct swaybar_output *output, struct i3bar_block *block, double *x,
124 struct i3bar_block *block, double *x,
125 uint32_t surface_height, bool focused, bool edge) { 125 uint32_t surface_height, bool focused, bool edge) {
126 if (!block->full_text || !*block->full_text) { 126 if (!block->full_text || !*block->full_text) {
127 return 0; 127 return 0;
128 } 128 }
129 129
130 uint32_t height = surface_height * output->scale; 130 uint32_t height = surface_height * output->scale;
131 struct swaybar_config *config = output->bar->config;
131 132
132 int text_width, text_height; 133 int text_width, text_height;
133 get_text_size(cairo, config->font, &text_width, &text_height, NULL, 134 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
@@ -177,16 +178,18 @@ static uint32_t render_status_block(cairo_t *cairo,
177 *x -= margin; 178 *x -= margin;
178 } 179 }
179 180
180 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); 181 if (output->bar->status->click_events) {
181 hotspot->x = *x; 182 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
182 hotspot->y = 0; 183 hotspot->x = *x;
183 hotspot->width = width; 184 hotspot->y = 0;
184 hotspot->height = height; 185 hotspot->width = width;
185 hotspot->callback = block_hotspot_callback; 186 hotspot->height = height;
186 hotspot->destroy = i3bar_block_unref_callback; 187 hotspot->callback = block_hotspot_callback;
187 hotspot->data = block; 188 hotspot->destroy = i3bar_block_unref_callback;
188 block->ref_count++; 189 hotspot->data = block;
189 wl_list_insert(&output->hotspots, &hotspot->link); 190 block->ref_count++;
191 wl_list_insert(&output->hotspots, &hotspot->link);
192 }
190 193
191 double pos = *x; 194 double pos = *x;
192 if (block->background) { 195 if (block->background) {
@@ -268,7 +271,7 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
268 bool edge = true; 271 bool edge = true;
269 struct i3bar_block *block; 272 struct i3bar_block *block;
270 wl_list_for_each(block, &status->blocks, link) { 273 wl_list_for_each(block, &status->blocks, link) {
271 uint32_t h = render_status_block(cairo, config, output, 274 uint32_t h = render_status_block(cairo, output,
272 block, x, surface_height, focused, edge); 275 block, x, surface_height, focused, edge);
273 max_height = h > max_height ? h : max_height; 276 max_height = h > max_height ? h : max_height;
274 edge = false; 277 edge = false;
@@ -478,6 +481,8 @@ static uint32_t render_to_cairo(cairo_t *cairo,
478} 481}
479 482
480void render_frame(struct swaybar *bar, struct swaybar_output *output) { 483void render_frame(struct swaybar *bar, struct swaybar_output *output) {
484 assert(output->surface != NULL);
485
481 struct swaybar_hotspot *hotspot, *tmp; 486 struct swaybar_hotspot *hotspot, *tmp;
482 wl_list_for_each_safe(hotspot, tmp, &output->hotspots, link) { 487 wl_list_for_each_safe(hotspot, tmp, &output->hotspots, link) {
483 if (hotspot->destroy) { 488 if (hotspot->destroy) {
@@ -505,7 +510,6 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
505 // TODO: this could infinite loop if the compositor assigns us a 510 // TODO: this could infinite loop if the compositor assigns us a
506 // different height than what we asked for 511 // different height than what we asked for
507 wl_surface_commit(output->surface); 512 wl_surface_commit(output->surface);
508 wl_display_roundtrip(bar->display);
509 } else if (height > 0) { 513 } else if (height > 0) {
510 // Replay recording into shm and send it off 514 // Replay recording into shm and send it off
511 output->current_buffer = get_next_buffer(bar->shm, 515 output->current_buffer = get_next_buffer(bar->shm,
@@ -531,7 +535,6 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
531 wl_surface_damage(output->surface, 0, 0, 535 wl_surface_damage(output->surface, 0, 0,
532 output->width, output->height); 536 output->width, output->height);
533 wl_surface_commit(output->surface); 537 wl_surface_commit(output->surface);
534 wl_display_roundtrip(bar->display);
535 } 538 }
536 cairo_surface_destroy(recorder); 539 cairo_surface_destroy(recorder);
537 cairo_destroy(cairo); 540 cairo_destroy(cairo);