aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-31 14:58:30 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-02 11:09:23 -0400
commit0cbd2a4f492b758f495af9f3ec4899dffe8d57d4 (patch)
tree24818f1a3c3d8c9ffe6bba61c2caa4685b7aba91 /swaybar/render.c
parentRender i3bar blocks (diff)
downloadsway-0cbd2a4f492b758f495af9f3ec4899dffe8d57d4.tar.gz
sway-0cbd2a4f492b758f495af9f3ec4899dffe8d57d4.tar.zst
sway-0cbd2a4f492b758f495af9f3ec4899dffe8d57d4.zip
Send click events for i3bar blocks
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index 3ad6d5d7..a5039a2e 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -89,9 +89,17 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
89 } 89 }
90} 90}
91 91
92static void block_hotspot_callback(struct swaybar_output *output,
93 int x, int y, uint32_t button, void *data) {
94 struct i3bar_block *block = data;
95 struct status_line *status = output->bar->status;
96 i3bar_block_send_click(status, block, x, y, button);
97}
98
92static uint32_t render_status_block(cairo_t *cairo, 99static uint32_t render_status_block(cairo_t *cairo,
93 struct swaybar_config *config, struct i3bar_block *block, 100 struct swaybar_config *config, struct swaybar_output *output,
94 double *x, uint32_t height, bool focused, bool edge) { 101 struct i3bar_block *block, double *x,
102 uint32_t height, bool focused, bool edge) {
95 static const int margin = 3; 103 static const int margin = 3;
96 if (!block->full_text || !*block->full_text) { 104 if (!block->full_text || !*block->full_text) {
97 return 0; 105 return 0;
@@ -139,7 +147,15 @@ static uint32_t render_status_block(cairo_t *cairo,
139 *x -= margin; 147 *x -= margin;
140 } 148 }
141 149
142 // TODO: Create hotspot here 150 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
151 hotspot->x = *x;
152 hotspot->y = 0;
153 hotspot->width = width;
154 hotspot->height = height;
155 hotspot->callback = block_hotspot_callback;
156 hotspot->destroy = free;
157 hotspot->data = block;
158 wl_list_insert(&output->hotspots, &hotspot->link);
143 159
144 double pos = *x; 160 double pos = *x;
145 if (block->background) { 161 if (block->background) {
@@ -208,13 +224,14 @@ static uint32_t render_status_block(cairo_t *cairo,
208} 224}
209 225
210static uint32_t render_status_line_i3bar(cairo_t *cairo, 226static uint32_t render_status_line_i3bar(cairo_t *cairo,
211 struct swaybar_config *config, struct status_line *status, 227 struct swaybar_config *config, struct swaybar_output *output,
212 bool focused, double *x, uint32_t width, uint32_t height) { 228 struct status_line *status, bool focused,
229 double *x, uint32_t width, uint32_t height) {
213 struct i3bar_block *block; 230 struct i3bar_block *block;
214 uint32_t max_height = 0; 231 uint32_t max_height = 0;
215 bool edge = true; 232 bool edge = true;
216 wl_list_for_each_reverse(block, &status->blocks, link) { 233 wl_list_for_each_reverse(block, &status->blocks, link) {
217 uint32_t h = render_status_block(cairo, config, 234 uint32_t h = render_status_block(cairo, config, output,
218 block, x, height, focused, edge); 235 block, x, height, focused, edge);
219 max_height = h > max_height ? h : max_height; 236 max_height = h > max_height ? h : max_height;
220 edge = false; 237 edge = false;
@@ -223,8 +240,9 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
223} 240}
224 241
225static uint32_t render_status_line(cairo_t *cairo, 242static uint32_t render_status_line(cairo_t *cairo,
226 struct swaybar_config *config, struct status_line *status, 243 struct swaybar_config *config, struct swaybar_output *output,
227 bool focused, double *x, uint32_t width, uint32_t height) { 244 struct status_line *status, bool focused,
245 double *x, uint32_t width, uint32_t height) {
228 switch (status->protocol) { 246 switch (status->protocol) {
229 case PROTOCOL_ERROR: 247 case PROTOCOL_ERROR:
230 return render_status_line_error(cairo, 248 return render_status_line_error(cairo,
@@ -233,8 +251,8 @@ static uint32_t render_status_line(cairo_t *cairo,
233 return render_status_line_text(cairo, 251 return render_status_line_text(cairo,
234 config, status->text, focused, x, width, height); 252 config, status->text, focused, x, width, height);
235 case PROTOCOL_I3BAR: 253 case PROTOCOL_I3BAR:
236 return render_status_line_i3bar(cairo, 254 return render_status_line_i3bar(cairo, config, output, status,
237 config, status, focused, x, width, height); 255 focused, x, width, height);
238 case PROTOCOL_UNDEF: 256 case PROTOCOL_UNDEF:
239 return 0; 257 return 0;
240 } 258 }
@@ -344,8 +362,8 @@ static uint32_t render_workspace_button(cairo_t *cairo,
344 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); 362 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
345 hotspot->x = *x; 363 hotspot->x = *x;
346 hotspot->y = 0; 364 hotspot->y = 0;
347 hotspot->height = height;
348 hotspot->width = width; 365 hotspot->width = width;
366 hotspot->height = height;
349 hotspot->callback = workspace_hotspot_callback; 367 hotspot->callback = workspace_hotspot_callback;
350 hotspot->destroy = free; 368 hotspot->destroy = free;
351 hotspot->data = strdup(name); 369 hotspot->data = strdup(name);
@@ -391,7 +409,7 @@ static uint32_t render_to_cairo(cairo_t *cairo,
391 } 409 }
392 x = output->width; 410 x = output->width;
393 if (bar->status) { 411 if (bar->status) {
394 uint32_t h = render_status_line(cairo, config, bar->status, 412 uint32_t h = render_status_line(cairo, config, output, bar->status,
395 output->focused, &x, output->width, output->height); 413 output->focused, &x, output->width, output->height);
396 max_height = h > max_height ? h : max_height; 414 max_height = h > max_height ? h : max_height;
397 } 415 }