aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 11:58:54 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commit1e8faeec0263a7da311a13c56a0de34e47e66fa6 (patch)
tree5d66afa22b48864f5a362971348aa0379ef248c6 /swaybar/render.c
parentAdd binding mode indicator (diff)
downloadsway-1e8faeec0263a7da311a13c56a0de34e47e66fa6.tar.gz
sway-1e8faeec0263a7da311a13c56a0de34e47e66fa6.tar.zst
sway-1e8faeec0263a7da311a13c56a0de34e47e66fa6.zip
Pixel-perfect rendering
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index beb4de40..ba22e9d4 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -13,33 +13,39 @@
13 13
14static const int ws_horizontal_padding = 5; 14static const int ws_horizontal_padding = 5;
15static const double ws_vertical_padding = 1.5; 15static const double ws_vertical_padding = 1.5;
16static const int ws_spacing = 1; 16static const double border_width = 1;
17 17
18static uint32_t render_binding_mode_indicator(cairo_t *cairo, 18static uint32_t render_binding_mode_indicator(cairo_t *cairo,
19 struct swaybar_config *config, const char *mode, double x, 19 struct swaybar_config *config, const char *mode, double x,
20 uint32_t height) { 20 uint32_t height) {
21 int text_width, text_height; 21 int text_width, text_height;
22 get_text_size(cairo, config->font, &text_width, &text_height, 22 get_text_size(cairo, config->font, &text_width, &text_height,
23 1, true, "⚡ %s", mode); 23 1, true, "%s", mode);
24 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 24 uint32_t ideal_height = text_height + ws_vertical_padding * 2
25 + border_width * 2;
25 if (height < ideal_height) { 26 if (height < ideal_height) {
26 height = ideal_height; 27 height = ideal_height;
27 } 28 }
29 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
28 30
29 cairo_set_source_u32(cairo, config->colors.binding_mode.background); 31 cairo_set_source_u32(cairo, config->colors.binding_mode.background);
30 cairo_rectangle(cairo, x, 0, text_width + ws_horizontal_padding * 2 - 1, 32 cairo_rectangle(cairo, x, 0, width, height);
31 height + ws_vertical_padding * 2);
32 cairo_fill(cairo); 33 cairo_fill(cairo);
33 34
34 cairo_set_source_u32(cairo, config->colors.binding_mode.border); 35 cairo_set_source_u32(cairo, config->colors.binding_mode.border);
35 cairo_rectangle(cairo, x, 0, text_width + ws_horizontal_padding * 2 - 1, 36 cairo_rectangle(cairo, x, 0, width, border_width);
36 height + ws_vertical_padding * 2); 37 cairo_fill(cairo);
37 cairo_stroke(cairo); 38 cairo_rectangle(cairo, x, 0, border_width, height);
39 cairo_fill(cairo);
40 cairo_rectangle(cairo, x + width - border_width, 0, border_width, height);
41 cairo_fill(cairo);
42 cairo_rectangle(cairo, x, height - border_width, width, border_width);
43 cairo_fill(cairo);
38 44
39 double text_y = height / 2.0 - text_height / 2.0; 45 double text_y = height / 2.0 - text_height / 2.0;
40 cairo_set_source_u32(cairo, config->colors.binding_mode.text); 46 cairo_set_source_u32(cairo, config->colors.binding_mode.text);
41 cairo_move_to(cairo, (int)x + ws_horizontal_padding, (int)floor(text_y)); 47 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
42 pango_printf(cairo, config->font, 1, true, "%s", mode); 48 pango_printf(cairo, config->font, 1, true, "%s", mode);
43 return ideal_height; 49 return ideal_height;
44} 50}
45 51
@@ -78,26 +84,33 @@ static uint32_t render_workspace_button(cairo_t *cairo,
78 int text_width, text_height; 84 int text_width, text_height;
79 get_text_size(cairo, config->font, &text_width, &text_height, 85 get_text_size(cairo, config->font, &text_width, &text_height,
80 1, true, "%s", name); 86 1, true, "%s", name);
81 uint32_t ideal_height = ws_vertical_padding * 2 + text_height; 87 uint32_t ideal_height = ws_vertical_padding * 2 + text_height
88 + border_width * 2;
82 if (height < ideal_height) { 89 if (height < ideal_height) {
83 height = ideal_height; 90 height = ideal_height;
84 } 91 }
85 uint32_t width = ws_horizontal_padding * 2 + text_width; 92 uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2;
86 93
87 cairo_set_source_u32(cairo, box_colors.background); 94 cairo_set_source_u32(cairo, box_colors.background);
88 cairo_rectangle(cairo, *x, 0, width - 1, height); 95 cairo_rectangle(cairo, *x, 0, width, height);
89 cairo_fill(cairo); 96 cairo_fill(cairo);
90 97
91 cairo_set_source_u32(cairo, box_colors.border); 98 cairo_set_source_u32(cairo, box_colors.border);
92 cairo_rectangle(cairo, *x, 0, width - 1, height); 99 cairo_rectangle(cairo, *x, 0, width, border_width);
93 cairo_stroke(cairo); 100 cairo_fill(cairo);
101 cairo_rectangle(cairo, *x, 0, border_width, height);
102 cairo_fill(cairo);
103 cairo_rectangle(cairo, *x + width - border_width, 0, border_width, height);
104 cairo_fill(cairo);
105 cairo_rectangle(cairo, *x, height - border_width, width, border_width);
106 cairo_fill(cairo);
94 107
95 double text_y = height / 2.0 - text_height / 2.0; 108 double text_y = height / 2.0 - text_height / 2.0;
96 cairo_set_source_u32(cairo, box_colors.text); 109 cairo_set_source_u32(cairo, box_colors.text);
97 cairo_move_to(cairo, (int)*x + ws_horizontal_padding, (int)floor(text_y)); 110 cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y));
98 pango_printf(cairo, config->font, 1, true, "%s", name); 111 pango_printf(cairo, config->font, 1, true, "%s", name);
99 112
100 *x += width + ws_spacing; 113 *x += width;
101 return ideal_height; 114 return ideal_height;
102} 115}
103 116
@@ -167,6 +180,7 @@ void render_frame(struct swaybar *bar,
167 180
168 cairo_set_source_surface(shm, recorder, 0.0, 0.0); 181 cairo_set_source_surface(shm, recorder, 0.0, 0.0);
169 cairo_paint(shm); 182 cairo_paint(shm);
183
170 wl_surface_attach(output->surface, 184 wl_surface_attach(output->surface,
171 output->current_buffer->buffer, 0, 0); 185 output->current_buffer->buffer, 0, 0);
172 wl_surface_damage(output->surface, 0, 0, output->width, output->height); 186 wl_surface_damage(output->surface, 0, 0, output->width, output->height);