aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-09-28 14:09:33 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-09-28 14:09:33 +0100
commit25e1f327386c5c8d0b2839d03e2d833e71dc9e61 (patch)
tree9e9da5790b1fd66f13ab89b70570750081b36c45 /swaybar/render.c
parentswaybar: move i3bar definitions into separate file (diff)
downloadsway-25e1f327386c5c8d0b2839d03e2d833e71dc9e61.tar.gz
sway-25e1f327386c5c8d0b2839d03e2d833e71dc9e61.tar.zst
sway-25e1f327386c5c8d0b2839d03e2d833e71dc9e61.zip
swaybar: trim function prototypes
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c109
1 files changed, 51 insertions, 58 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index 035be0b1..90e5bac7 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -21,47 +21,47 @@ static const double WS_VERTICAL_PADDING = 1.5;
21static const double BORDER_WIDTH = 1; 21static const double BORDER_WIDTH = 1;
22 22
23static uint32_t render_status_line_error(cairo_t *cairo, 23static uint32_t render_status_line_error(cairo_t *cairo,
24 struct swaybar_output *output, struct swaybar_config *config, 24 struct swaybar_output *output, double *x) {
25 const char *error, double *x, uint32_t surface_height) { 25 const char *error = output->bar->status->text;
26 if (!error) { 26 if (!error) {
27 return 0; 27 return 0;
28 } 28 }
29 29
30 uint32_t height = surface_height * output->scale; 30 uint32_t height = output->height * output->scale;
31 31
32 cairo_set_source_u32(cairo, 0xFF0000FF); 32 cairo_set_source_u32(cairo, 0xFF0000FF);
33 33
34 int margin = 3 * output->scale; 34 int margin = 3 * output->scale;
35 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; 35 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
36 36
37 char *font = output->bar->config->font;
37 int text_width, text_height; 38 int text_width, text_height;
38 get_text_size(cairo, config->font, &text_width, &text_height, NULL, 39 get_text_size(cairo, font, &text_width, &text_height, NULL,
39 output->scale, false, "%s", error); 40 output->scale, false, "%s", error);
40 41
41 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 42 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
42 uint32_t ideal_surface_height = ideal_height / output->scale; 43 uint32_t ideal_surface_height = ideal_height / output->scale;
43 if (surface_height < ideal_surface_height) { 44 if (output->height < ideal_surface_height) {
44 return ideal_surface_height; 45 return ideal_surface_height;
45 } 46 }
46 *x -= text_width + margin; 47 *x -= text_width + margin;
47 48
48 double text_y = height / 2.0 - text_height / 2.0; 49 double text_y = height / 2.0 - text_height / 2.0;
49 cairo_move_to(cairo, *x, (int)floor(text_y)); 50 cairo_move_to(cairo, *x, (int)floor(text_y));
50 pango_printf(cairo, config->font, output->scale, false, "%s", error); 51 pango_printf(cairo, font, output->scale, false, "%s", error);
51 *x -= margin; 52 *x -= margin;
52 return surface_height; 53 return output->height;
53} 54}
54 55
55static uint32_t render_status_line_text(cairo_t *cairo, 56static uint32_t render_status_line_text(cairo_t *cairo,
56 struct swaybar_output *output, struct swaybar_config *config, 57 struct swaybar_output *output, double *x) {
57 const char *text, bool focused, double *x, uint32_t surface_height) { 58 const char *text = output->bar->status->text;
58 if (!text) { 59 if (!text) {
59 return 0; 60 return 0;
60 } 61 }
61 62
62 uint32_t height = surface_height * output->scale; 63 struct swaybar_config *config = output->bar->config;
63 64 cairo_set_source_u32(cairo, output->focused ?
64 cairo_set_source_u32(cairo, focused ?
65 config->colors.focused_statusline : config->colors.statusline); 65 config->colors.focused_statusline : config->colors.statusline);
66 66
67 int text_width, text_height; 67 int text_width, text_height;
@@ -73,17 +73,18 @@ static uint32_t render_status_line_text(cairo_t *cairo,
73 73
74 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 74 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
75 uint32_t ideal_surface_height = ideal_height / output->scale; 75 uint32_t ideal_surface_height = ideal_height / output->scale;
76 if (surface_height < ideal_surface_height) { 76 if (output->height < ideal_surface_height) {
77 return ideal_surface_height; 77 return ideal_surface_height;
78 } 78 }
79 79
80 *x -= text_width + margin; 80 *x -= text_width + margin;
81 uint32_t height = output->height * output->scale;
81 double text_y = height / 2.0 - text_height / 2.0; 82 double text_y = height / 2.0 - text_height / 2.0;
82 cairo_move_to(cairo, *x, (int)floor(text_y)); 83 cairo_move_to(cairo, *x, (int)floor(text_y));
83 pango_printf(cairo, config->font, output->scale, 84 pango_printf(cairo, config->font, output->scale,
84 config->pango_markup, "%s", text); 85 config->pango_markup, "%s", text);
85 *x -= margin; 86 *x -= margin;
86 return surface_height; 87 return output->height;
87} 88}
88 89
89static void render_sharp_line(cairo_t *cairo, uint32_t color, 90static void render_sharp_line(cairo_t *cairo, uint32_t color,
@@ -123,12 +124,11 @@ static void i3bar_block_unref_callback(void *data) {
123 124
124static uint32_t render_status_block(cairo_t *cairo, 125static uint32_t render_status_block(cairo_t *cairo,
125 struct swaybar_output *output, struct i3bar_block *block, double *x, 126 struct swaybar_output *output, struct i3bar_block *block, double *x,
126 uint32_t surface_height, bool focused, bool edge) { 127 bool edge) {
127 if (!block->full_text || !*block->full_text) { 128 if (!block->full_text || !*block->full_text) {
128 return 0; 129 return 0;
129 } 130 }
130 131
131 uint32_t height = surface_height * output->scale;
132 struct swaybar_config *config = output->bar->config; 132 struct swaybar_config *config = output->bar->config;
133 133
134 int text_width, text_height; 134 int text_width, text_height;
@@ -146,7 +146,7 @@ static uint32_t render_status_block(cairo_t *cairo,
146 double block_width = width; 146 double block_width = width;
147 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 147 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
148 uint32_t ideal_surface_height = ideal_height / output->scale; 148 uint32_t ideal_surface_height = ideal_height / output->scale;
149 if (surface_height < ideal_surface_height) { 149 if (output->height < ideal_surface_height) {
150 return ideal_surface_height; 150 return ideal_surface_height;
151 } 151 }
152 152
@@ -167,7 +167,7 @@ static uint32_t render_status_block(cairo_t *cairo,
167 output->scale, false, "%s", config->sep_symbol); 167 output->scale, false, "%s", config->sep_symbol);
168 uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; 168 uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
169 uint32_t _ideal_surface_height = _ideal_height / output->scale; 169 uint32_t _ideal_surface_height = _ideal_height / output->scale;
170 if (surface_height < _ideal_surface_height) { 170 if (output->height < _ideal_surface_height) {
171 return _ideal_surface_height; 171 return _ideal_surface_height;
172 } 172 }
173 if (sep_width > block->separator_block_width) { 173 if (sep_width > block->separator_block_width) {
@@ -179,6 +179,7 @@ static uint32_t render_status_block(cairo_t *cairo,
179 *x -= margin; 179 *x -= margin;
180 } 180 }
181 181
182 uint32_t height = output->height * output->scale;
182 if (output->bar->status->click_events) { 183 if (output->bar->status->click_events) {
183 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); 184 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
184 hotspot->x = *x; 185 hotspot->x = *x;
@@ -242,7 +243,7 @@ static uint32_t render_status_block(cairo_t *cairo,
242 } 243 }
243 244
244 if (!edge && block->separator) { 245 if (!edge && block->separator) {
245 if (focused) { 246 if (output->focused) {
246 cairo_set_source_u32(cairo, config->colors.focused_separator); 247 cairo_set_source_u32(cairo, config->colors.focused_separator);
247 } else { 248 } else {
248 cairo_set_source_u32(cairo, config->colors.separator); 249 cairo_set_source_u32(cairo, config->colors.separator);
@@ -261,19 +262,16 @@ static uint32_t render_status_block(cairo_t *cairo,
261 cairo_stroke(cairo); 262 cairo_stroke(cairo);
262 } 263 }
263 } 264 }
264 return surface_height; 265 return output->height;
265} 266}
266 267
267static uint32_t render_status_line_i3bar(cairo_t *cairo, 268static uint32_t render_status_line_i3bar(cairo_t *cairo,
268 struct swaybar_config *config, struct swaybar_output *output, 269 struct swaybar_output *output, double *x) {
269 struct status_line *status, bool focused,
270 double *x, uint32_t surface_height) {
271 uint32_t max_height = 0; 270 uint32_t max_height = 0;
272 bool edge = true; 271 bool edge = true;
273 struct i3bar_block *block; 272 struct i3bar_block *block;
274 wl_list_for_each(block, &status->blocks, link) { 273 wl_list_for_each(block, &output->bar->status->blocks, link) {
275 uint32_t h = render_status_block(cairo, output, 274 uint32_t h = render_status_block(cairo, output, block, x, edge);
276 block, x, surface_height, focused, edge);
277 max_height = h > max_height ? h : max_height; 275 max_height = h > max_height ? h : max_height;
278 edge = false; 276 edge = false;
279 } 277 }
@@ -281,19 +279,15 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
281} 279}
282 280
283static uint32_t render_status_line(cairo_t *cairo, 281static uint32_t render_status_line(cairo_t *cairo,
284 struct swaybar_config *config, struct swaybar_output *output, 282 struct swaybar_output *output, double *x) {
285 struct status_line *status, bool focused, 283 struct status_line *status = output->bar->status;
286 double *x, uint32_t surface_height) {
287 switch (status->protocol) { 284 switch (status->protocol) {
288 case PROTOCOL_ERROR: 285 case PROTOCOL_ERROR:
289 return render_status_line_error(cairo, output, config, 286 return render_status_line_error(cairo, output, x);
290 status->text, x, surface_height);
291 case PROTOCOL_TEXT: 287 case PROTOCOL_TEXT:
292 return render_status_line_text(cairo, output, config, 288 return render_status_line_text(cairo, output, x);
293 status->text, focused, x, surface_height);
294 case PROTOCOL_I3BAR: 289 case PROTOCOL_I3BAR:
295 return render_status_line_i3bar(cairo, config, output, 290 return render_status_line_i3bar(cairo, output, x);
296 status, focused, x, surface_height);
297 case PROTOCOL_UNDEF: 291 case PROTOCOL_UNDEF:
298 return 0; 292 return 0;
299 } 293 }
@@ -301,10 +295,9 @@ static uint32_t render_status_line(cairo_t *cairo,
301} 295}
302 296
303static uint32_t render_binding_mode_indicator(cairo_t *cairo, 297static uint32_t render_binding_mode_indicator(cairo_t *cairo,
304 struct swaybar_output *output, struct swaybar_config *config, 298 struct swaybar_output *output, double x) {
305 const char *mode, double x, uint32_t surface_height) { 299 struct swaybar_config *config = output->bar->config;
306 uint32_t height = surface_height * output->scale; 300 const char *mode = config->mode;
307
308 int text_width, text_height; 301 int text_width, text_height;
309 get_text_size(cairo, config->font, &text_width, &text_height, NULL, 302 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
310 output->scale, config->mode_pango_markup, 303 output->scale, config->mode_pango_markup,
@@ -317,11 +310,12 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
317 uint32_t ideal_height = text_height + ws_vertical_padding * 2 310 uint32_t ideal_height = text_height + ws_vertical_padding * 2
318 + border_width * 2; 311 + border_width * 2;
319 uint32_t ideal_surface_height = ideal_height / output->scale; 312 uint32_t ideal_surface_height = ideal_height / output->scale;
320 if (surface_height < ideal_surface_height) { 313 if (output->height < ideal_surface_height) {
321 return ideal_surface_height; 314 return ideal_surface_height;
322 } 315 }
323 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; 316 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
324 317
318 uint32_t height = output->height * output->scale;
325 cairo_set_source_u32(cairo, config->colors.binding_mode.background); 319 cairo_set_source_u32(cairo, config->colors.binding_mode.background);
326 cairo_rectangle(cairo, x, 0, width, height); 320 cairo_rectangle(cairo, x, 0, width, height);
327 cairo_fill(cairo); 321 cairo_fill(cairo);
@@ -341,7 +335,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
341 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); 335 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
342 pango_printf(cairo, config->font, output->scale, config->mode_pango_markup, 336 pango_printf(cairo, config->font, output->scale, config->mode_pango_markup,
343 "%s", mode); 337 "%s", mode);
344 return surface_height; 338 return output->height;
345} 339}
346 340
347static const char *strip_workspace_number(const char *ws_name) { 341static const char *strip_workspace_number(const char *ws_name) {
@@ -367,8 +361,9 @@ static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_out
367} 361}
368 362
369static uint32_t render_workspace_button(cairo_t *cairo, 363static uint32_t render_workspace_button(cairo_t *cairo,
370 struct swaybar_output *output, struct swaybar_config *config, 364 struct swaybar_output *output,
371 struct swaybar_workspace *ws, double *x, uint32_t surface_height) { 365 struct swaybar_workspace *ws, double *x) {
366 struct swaybar_config *config = output->bar->config;
372 const char *name = ws->name; 367 const char *name = ws->name;
373 if (config->strip_workspace_numbers) { 368 if (config->strip_workspace_numbers) {
374 name = strip_workspace_number(ws->name); 369 name = strip_workspace_number(ws->name);
@@ -385,7 +380,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
385 box_colors = config->colors.inactive_workspace; 380 box_colors = config->colors.inactive_workspace;
386 } 381 }
387 382
388 uint32_t height = surface_height * output->scale; 383 uint32_t height = output->height * output->scale;
389 384
390 int text_width, text_height; 385 int text_width, text_height;
391 get_text_size(cairo, config->font, &text_width, &text_height, NULL, 386 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
@@ -398,7 +393,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
398 uint32_t ideal_height = ws_vertical_padding * 2 + text_height 393 uint32_t ideal_height = ws_vertical_padding * 2 + text_height
399 + border_width * 2; 394 + border_width * 2;
400 uint32_t ideal_surface_height = ideal_height / output->scale; 395 uint32_t ideal_surface_height = ideal_height / output->scale;
401 if (surface_height < ideal_surface_height) { 396 if (output->height < ideal_surface_height) {
402 return ideal_surface_height; 397 return ideal_surface_height;
403 } 398 }
404 399
@@ -435,11 +430,11 @@ static uint32_t render_workspace_button(cairo_t *cairo,
435 wl_list_insert(&output->hotspots, &hotspot->link); 430 wl_list_insert(&output->hotspots, &hotspot->link);
436 431
437 *x += width; 432 *x += width;
438 return surface_height; 433 return output->height;
439} 434}
440 435
441static uint32_t render_to_cairo(cairo_t *cairo, 436static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) {
442 struct swaybar *bar, struct swaybar_output *output) { 437 struct swaybar *bar = output->bar;
443 struct swaybar_config *config = bar->config; 438 struct swaybar_config *config = bar->config;
444 cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); 439 cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
445 if (output->focused) { 440 if (output->focused) {
@@ -459,22 +454,19 @@ static uint32_t render_to_cairo(cairo_t *cairo,
459 */ 454 */
460 double x = output->width * output->scale; 455 double x = output->width * output->scale;
461 if (bar->status) { 456 if (bar->status) {
462 uint32_t h = render_status_line(cairo, config, output, 457 uint32_t h = render_status_line(cairo, output, &x);
463 bar->status, output->focused, &x, output->height);
464 max_height = h > max_height ? h : max_height; 458 max_height = h > max_height ? h : max_height;
465 } 459 }
466 x = 0; 460 x = 0;
467 if (config->workspace_buttons) { 461 if (config->workspace_buttons) {
468 struct swaybar_workspace *ws; 462 struct swaybar_workspace *ws;
469 wl_list_for_each_reverse(ws, &output->workspaces, link) { 463 wl_list_for_each_reverse(ws, &output->workspaces, link) {
470 uint32_t h = render_workspace_button(cairo, 464 uint32_t h = render_workspace_button(cairo, output, ws, &x);
471 output, config, ws, &x, output->height);
472 max_height = h > max_height ? h : max_height; 465 max_height = h > max_height ? h : max_height;
473 } 466 }
474 } 467 }
475 if (config->binding_mode_indicator && config->mode) { 468 if (config->binding_mode_indicator && config->mode) {
476 uint32_t h = render_binding_mode_indicator(cairo, 469 uint32_t h = render_binding_mode_indicator(cairo, output, x);
477 output, config, config->mode, x, output->height);
478 max_height = h > max_height ? h : max_height; 470 max_height = h > max_height ? h : max_height;
479 } 471 }
480 472
@@ -507,9 +499,10 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
507 cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); 499 cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
508 cairo_paint(cairo); 500 cairo_paint(cairo);
509 cairo_restore(cairo); 501 cairo_restore(cairo);
510 uint32_t height = render_to_cairo(cairo, bar, output); 502 uint32_t height = render_to_cairo(cairo, output);
511 if (bar->config->height >= 0 && height < (uint32_t)bar->config->height) { 503 int config_height = output->bar->config->height;
512 height = bar->config->height; 504 if (config_height >= 0 && height < (uint32_t)config_height) {
505 height = config_height;
513 } 506 }
514 if (height != output->height) { 507 if (height != output->height) {
515 // Reconfigure surface 508 // Reconfigure surface
@@ -520,7 +513,7 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
520 wl_surface_commit(output->surface); 513 wl_surface_commit(output->surface);
521 } else if (height > 0) { 514 } else if (height > 0) {
522 // Replay recording into shm and send it off 515 // Replay recording into shm and send it off
523 output->current_buffer = get_next_buffer(bar->shm, 516 output->current_buffer = get_next_buffer(output->bar->shm,
524 output->buffers, 517 output->buffers,
525 output->width * output->scale, 518 output->width * output->scale,
526 output->height * output->scale); 519 output->height * output->scale);