aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-03 21:57:47 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-03 21:57:47 -0400
commitc4e92c81f5ce0adbc3320c578dc926a8004d3b75 (patch)
tree3eee82e4666b4d0e15a390fcf16a67eb79734e55 /swaybar
parentDon't use asserts with side-effects (diff)
downloadsway-c4e92c81f5ce0adbc3320c578dc926a8004d3b75.tar.gz
sway-c4e92c81f5ce0adbc3320c578dc926a8004d3b75.tar.zst
sway-c4e92c81f5ce0adbc3320c578dc926a8004d3b75.zip
Adjust height calculation, naming
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/render.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index bf144d5c..1f84fdba 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -20,12 +20,12 @@ static const double BORDER_WIDTH = 1;
20 20
21static uint32_t render_status_line_error(cairo_t *cairo, 21static uint32_t render_status_line_error(cairo_t *cairo,
22 struct swaybar_output *output, struct swaybar_config *config, 22 struct swaybar_output *output, struct swaybar_config *config,
23 const char *error, double *x, uint32_t width, uint32_t height) { 23 const char *error, double *x, uint32_t width, uint32_t surface_height) {
24 if (!error) { 24 if (!error) {
25 return 0; 25 return 0;
26 } 26 }
27 27
28 height *= output->scale; 28 uint32_t height = surface_height * output->scale;
29 29
30 cairo_set_source_u32(cairo, 0xFF0000FF); 30 cairo_set_source_u32(cairo, 0xFF0000FF);
31 31
@@ -37,7 +37,7 @@ static uint32_t render_status_line_error(cairo_t *cairo,
37 &text_width, &text_height, output->scale, false, "%s", error); 37 &text_width, &text_height, output->scale, false, "%s", error);
38 38
39 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 39 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
40 if (height < ideal_height / output->scale) { 40 if (height < ideal_height) {
41 return ideal_height / output->scale; 41 return ideal_height / output->scale;
42 } 42 }
43 *x -= text_width + margin; 43 *x -= text_width + margin;
@@ -52,12 +52,12 @@ static uint32_t render_status_line_error(cairo_t *cairo,
52static uint32_t render_status_line_text(cairo_t *cairo, 52static uint32_t render_status_line_text(cairo_t *cairo,
53 struct swaybar_output *output, struct swaybar_config *config, 53 struct swaybar_output *output, struct swaybar_config *config,
54 const char *text, bool focused, double *x, 54 const char *text, bool focused, double *x,
55 uint32_t width, uint32_t height) { 55 uint32_t width, uint32_t surface_height) {
56 if (!text) { 56 if (!text) {
57 return 0; 57 return 0;
58 } 58 }
59 59
60 height *= output->scale; 60 uint32_t height = surface_height * output->scale;
61 61
62 cairo_set_source_u32(cairo, focused ? 62 cairo_set_source_u32(cairo, focused ?
63 config->colors.focused_statusline : config->colors.statusline); 63 config->colors.focused_statusline : config->colors.statusline);
@@ -70,7 +70,7 @@ static uint32_t render_status_line_text(cairo_t *cairo,
70 int margin = 3 * output->scale; 70 int margin = 3 * output->scale;
71 71
72 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 72 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
73 if (height < ideal_height / output->scale) { 73 if (height < ideal_height) {
74 return ideal_height / output->scale; 74 return ideal_height / output->scale;
75 } 75 }
76 76
@@ -117,12 +117,12 @@ static void block_hotspot_callback(struct swaybar_output *output,
117static uint32_t render_status_block(cairo_t *cairo, 117static uint32_t render_status_block(cairo_t *cairo,
118 struct swaybar_config *config, struct swaybar_output *output, 118 struct swaybar_config *config, struct swaybar_output *output,
119 struct i3bar_block *block, double *x, 119 struct i3bar_block *block, double *x,
120 uint32_t height, bool focused, bool edge) { 120 uint32_t surface_height, bool focused, bool edge) {
121 if (!block->full_text || !*block->full_text) { 121 if (!block->full_text || !*block->full_text) {
122 return 0; 122 return 0;
123 } 123 }
124 124
125 height *= output->scale; 125 uint32_t height = surface_height * output->scale;
126 126
127 int text_width, text_height; 127 int text_width, text_height;
128 get_text_size(cairo, config->font, &text_width, &text_height, 128 get_text_size(cairo, config->font, &text_width, &text_height,
@@ -138,7 +138,7 @@ static uint32_t render_status_block(cairo_t *cairo,
138 138
139 double block_width = width; 139 double block_width = width;
140 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 140 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
141 if (height < ideal_height / output->scale) { 141 if (height < ideal_height) {
142 return ideal_height / output->scale; 142 return ideal_height / output->scale;
143 } 143 }
144 144
@@ -256,13 +256,13 @@ static uint32_t render_status_block(cairo_t *cairo,
256static uint32_t render_status_line_i3bar(cairo_t *cairo, 256static uint32_t render_status_line_i3bar(cairo_t *cairo,
257 struct swaybar_config *config, struct swaybar_output *output, 257 struct swaybar_config *config, struct swaybar_output *output,
258 struct status_line *status, bool focused, 258 struct status_line *status, bool focused,
259 double *x, uint32_t width, uint32_t height) { 259 double *x, uint32_t width, uint32_t surface_height) {
260 uint32_t max_height = 0; 260 uint32_t max_height = 0;
261 bool edge = true; 261 bool edge = true;
262 struct i3bar_block *block; 262 struct i3bar_block *block;
263 wl_list_for_each(block, &status->blocks, link) { 263 wl_list_for_each(block, &status->blocks, link) {
264 uint32_t h = render_status_block(cairo, config, output, 264 uint32_t h = render_status_block(cairo, config, output,
265 block, x, height, focused, edge); 265 block, x, surface_height, focused, edge);
266 max_height = h > max_height ? h : max_height; 266 max_height = h > max_height ? h : max_height;
267 edge = false; 267 edge = false;
268 } 268 }
@@ -272,17 +272,17 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
272static uint32_t render_status_line(cairo_t *cairo, 272static uint32_t render_status_line(cairo_t *cairo,
273 struct swaybar_config *config, struct swaybar_output *output, 273 struct swaybar_config *config, struct swaybar_output *output,
274 struct status_line *status, bool focused, 274 struct status_line *status, bool focused,
275 double *x, uint32_t width, uint32_t height) { 275 double *x, uint32_t width, uint32_t surface_height) {
276 switch (status->protocol) { 276 switch (status->protocol) {
277 case PROTOCOL_ERROR: 277 case PROTOCOL_ERROR:
278 return render_status_line_error(cairo, 278 return render_status_line_error(cairo, output, config,
279 output, config, status->text, x, width, height); 279 status->text, x, width, surface_height);
280 case PROTOCOL_TEXT: 280 case PROTOCOL_TEXT:
281 return render_status_line_text(cairo, 281 return render_status_line_text(cairo, output, config,
282 output, config, status->text, focused, x, width, height); 282 status->text, focused, x, width, surface_height);
283 case PROTOCOL_I3BAR: 283 case PROTOCOL_I3BAR:
284 return render_status_line_i3bar(cairo, config, output, status, 284 return render_status_line_i3bar(cairo, config, output,
285 focused, x, width, height); 285 status, focused, x, width, surface_height);
286 case PROTOCOL_UNDEF: 286 case PROTOCOL_UNDEF:
287 return 0; 287 return 0;
288 } 288 }
@@ -291,9 +291,9 @@ static uint32_t render_status_line(cairo_t *cairo,
291 291
292static uint32_t render_binding_mode_indicator(cairo_t *cairo, 292static uint32_t render_binding_mode_indicator(cairo_t *cairo,
293 struct swaybar_output *output, struct swaybar_config *config, 293 struct swaybar_output *output, struct swaybar_config *config,
294 const char *mode, double x, uint32_t height) { 294 const char *mode, double x, uint32_t surface_height) {
295 295
296 height *= output->scale; 296 uint32_t height = surface_height * output->scale;
297 297
298 int text_width, text_height; 298 int text_width, text_height;
299 get_text_size(cairo, config->font, &text_width, &text_height, 299 get_text_size(cairo, config->font, &text_width, &text_height,
@@ -305,7 +305,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
305 305
306 uint32_t ideal_height = text_height + ws_vertical_padding * 2 306 uint32_t ideal_height = text_height + ws_vertical_padding * 2
307 + border_width * 2; 307 + border_width * 2;
308 if (height < ideal_height / output->scale) { 308 if (height < ideal_height) {
309 return ideal_height / output->scale; 309 return ideal_height / output->scale;
310 } 310 }
311 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; 311 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
@@ -351,7 +351,7 @@ static void workspace_hotspot_callback(struct swaybar_output *output,
351 351
352static uint32_t render_workspace_button(cairo_t *cairo, 352static uint32_t render_workspace_button(cairo_t *cairo,
353 struct swaybar_output *output, struct swaybar_config *config, 353 struct swaybar_output *output, struct swaybar_config *config,
354 struct swaybar_workspace *ws, double *x, uint32_t height) { 354 struct swaybar_workspace *ws, double *x, uint32_t surface_height) {
355 const char *name = ws->name; 355 const char *name = ws->name;
356 if (config->strip_workspace_numbers) { 356 if (config->strip_workspace_numbers) {
357 name = strip_workspace_number(ws->name); 357 name = strip_workspace_number(ws->name);
@@ -368,7 +368,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
368 box_colors = config->colors.inactive_workspace; 368 box_colors = config->colors.inactive_workspace;
369 } 369 }
370 370
371 height *= output->scale; 371 uint32_t height = surface_height *output->scale;
372 372
373 int text_width, text_height; 373 int text_width, text_height;
374 get_text_size(cairo, config->font, &text_width, &text_height, 374 get_text_size(cairo, config->font, &text_width, &text_height,
@@ -380,7 +380,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
380 380
381 uint32_t ideal_height = ws_vertical_padding * 2 + text_height 381 uint32_t ideal_height = ws_vertical_padding * 2 + text_height
382 + border_width * 2; 382 + border_width * 2;
383 if (height < ideal_height / output->scale) { 383 if (height < ideal_height) {
384 return ideal_height / output->scale; 384 return ideal_height / output->scale;
385 } 385 }
386 386