diff options
author | emersion <contact@emersion.fr> | 2018-04-08 13:49:11 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-04-08 13:49:11 -0400 |
commit | 16e363e3e23e11674d06324efb4374320de40e63 (patch) | |
tree | 6a51c4cf7910b4a8c08c4c132d314bcec2ddef7b /swaybar | |
parent | Merge pull request #1777 from emersion/unmanaged-cursor-input (diff) | |
download | sway-16e363e3e23e11674d06324efb4374320de40e63.tar.gz sway-16e363e3e23e11674d06324efb4374320de40e63.tar.zst sway-16e363e3e23e11674d06324efb4374320de40e63.zip |
Fix swaybar HiDPI rounding issue
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/render.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/swaybar/render.c b/swaybar/render.c index d2175f0a..28296f31 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -37,8 +37,9 @@ 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) { | 40 | uint32_t ideal_surface_height = ideal_height / output->scale; |
41 | return ideal_height / output->scale; | 41 | if (surface_height < ideal_surface_height) { |
42 | return ideal_surface_height; | ||
42 | } | 43 | } |
43 | *x -= text_width + margin; | 44 | *x -= text_width + margin; |
44 | 45 | ||
@@ -46,7 +47,7 @@ static uint32_t render_status_line_error(cairo_t *cairo, | |||
46 | cairo_move_to(cairo, *x, (int)floor(text_y)); | 47 | cairo_move_to(cairo, *x, (int)floor(text_y)); |
47 | pango_printf(cairo, config->font, output->scale, false, "%s", error); | 48 | pango_printf(cairo, config->font, output->scale, false, "%s", error); |
48 | *x -= margin; | 49 | *x -= margin; |
49 | return ideal_height / output->scale; | 50 | return surface_height; |
50 | } | 51 | } |
51 | 52 | ||
52 | static uint32_t render_status_line_text(cairo_t *cairo, | 53 | static uint32_t render_status_line_text(cairo_t *cairo, |
@@ -69,8 +70,9 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
69 | int margin = 3 * output->scale; | 70 | int margin = 3 * output->scale; |
70 | 71 | ||
71 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 72 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
72 | if (height < ideal_height) { | 73 | uint32_t ideal_surface_height = ideal_height / output->scale; |
73 | return ideal_height / output->scale; | 74 | if (surface_height < ideal_surface_height) { |
75 | return ideal_surface_height; | ||
74 | } | 76 | } |
75 | 77 | ||
76 | *x -= text_width + margin; | 78 | *x -= text_width + margin; |
@@ -79,7 +81,7 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
79 | pango_printf(cairo, config->font, output->scale, | 81 | pango_printf(cairo, config->font, output->scale, |
80 | config->pango_markup, "%s", text); | 82 | config->pango_markup, "%s", text); |
81 | *x -= margin; | 83 | *x -= margin; |
82 | return ideal_height / output->scale; | 84 | return surface_height; |
83 | } | 85 | } |
84 | 86 | ||
85 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | 87 | static void render_sharp_line(cairo_t *cairo, uint32_t color, |
@@ -137,8 +139,9 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
137 | 139 | ||
138 | double block_width = width; | 140 | double block_width = width; |
139 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 141 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
140 | if (height < ideal_height) { | 142 | uint32_t ideal_surface_height = ideal_height / output->scale; |
141 | return ideal_height / output->scale; | 143 | if (surface_height < ideal_surface_height) { |
144 | return ideal_surface_height; | ||
142 | } | 145 | } |
143 | 146 | ||
144 | *x -= width; | 147 | *x -= width; |
@@ -249,7 +252,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
249 | cairo_stroke(cairo); | 252 | cairo_stroke(cairo); |
250 | } | 253 | } |
251 | } | 254 | } |
252 | return ideal_height / output->scale; | 255 | return surface_height; |
253 | } | 256 | } |
254 | 257 | ||
255 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 258 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
@@ -291,7 +294,6 @@ static uint32_t render_status_line(cairo_t *cairo, | |||
291 | static uint32_t render_binding_mode_indicator(cairo_t *cairo, | 294 | static uint32_t render_binding_mode_indicator(cairo_t *cairo, |
292 | struct swaybar_output *output, struct swaybar_config *config, | 295 | struct swaybar_output *output, struct swaybar_config *config, |
293 | const char *mode, double x, uint32_t surface_height) { | 296 | const char *mode, double x, uint32_t surface_height) { |
294 | |||
295 | uint32_t height = surface_height * output->scale; | 297 | uint32_t height = surface_height * output->scale; |
296 | 298 | ||
297 | int text_width, text_height; | 299 | int text_width, text_height; |
@@ -304,8 +306,9 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
304 | 306 | ||
305 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 | 307 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 |
306 | + border_width * 2; | 308 | + border_width * 2; |
307 | if (height < ideal_height) { | 309 | uint32_t ideal_surface_height = ideal_height / output->scale; |
308 | return ideal_height / output->scale; | 310 | if (surface_height < ideal_surface_height) { |
311 | return ideal_surface_height; | ||
309 | } | 312 | } |
310 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; | 313 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
311 | 314 | ||
@@ -327,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
327 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); | 330 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); |
328 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); | 331 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); |
329 | pango_printf(cairo, config->font, output->scale, true, "%s", mode); | 332 | pango_printf(cairo, config->font, output->scale, true, "%s", mode); |
330 | return ideal_height / output->scale; | 333 | return surface_height; |
331 | } | 334 | } |
332 | 335 | ||
333 | static const char *strip_workspace_number(const char *ws_name) { | 336 | static const char *strip_workspace_number(const char *ws_name) { |
@@ -379,8 +382,9 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
379 | 382 | ||
380 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height | 383 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height |
381 | + border_width * 2; | 384 | + border_width * 2; |
382 | if (height < ideal_height) { | 385 | uint32_t ideal_surface_height = ideal_height / output->scale; |
383 | return ideal_height / output->scale; | 386 | if (surface_height < ideal_surface_height) { |
387 | return ideal_surface_height; | ||
384 | } | 388 | } |
385 | 389 | ||
386 | uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2; | 390 | uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2; |
@@ -415,7 +419,7 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
415 | wl_list_insert(&output->hotspots, &hotspot->link); | 419 | wl_list_insert(&output->hotspots, &hotspot->link); |
416 | 420 | ||
417 | *x += width; | 421 | *x += width; |
418 | return height / output->scale; | 422 | return surface_height; |
419 | } | 423 | } |
420 | 424 | ||
421 | static uint32_t render_to_cairo(cairo_t *cairo, | 425 | static uint32_t render_to_cairo(cairo_t *cairo, |
@@ -484,8 +488,7 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) { | |||
484 | } | 488 | } |
485 | if (height != output->height) { | 489 | if (height != output->height) { |
486 | // Reconfigure surface | 490 | // Reconfigure surface |
487 | zwlr_layer_surface_v1_set_size( | 491 | zwlr_layer_surface_v1_set_size(output->layer_surface, 0, height); |
488 | output->layer_surface, 0, height); | ||
489 | zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height); | 492 | zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height); |
490 | // TODO: this could infinite loop if the compositor assigns us a | 493 | // TODO: this could infinite loop if the compositor assigns us a |
491 | // different height than what we asked for | 494 | // different height than what we asked for |