aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-09 20:28:30 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-09 20:28:30 -0500
commit39873bc1f0c3fbd5f1ac0526d29324befad29f2d (patch)
treeed5f3318cc4ad80645e201d6c2235f4300cff34e /swaybar
parentReset container dimensions when moving into workspace from direction (diff)
downloadsway-39873bc1f0c3fbd5f1ac0526d29324befad29f2d.tar.gz
sway-39873bc1f0c3fbd5f1ac0526d29324befad29f2d.tar.zst
sway-39873bc1f0c3fbd5f1ac0526d29324befad29f2d.zip
swaybar: fix rendering of border and background
This fixes the rendering of borders and backgrounds for blocks. This also makes the following changes: * both borders and padding are scaled with the output * both lines and rectangles are rendered without an antialiasing to avoid bleeding outside the desired area
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/render.c86
1 files changed, 45 insertions, 41 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index 9fe4ee9c..7cbcea07 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -90,13 +90,24 @@ static uint32_t render_status_line_text(cairo_t *cairo,
90 return output->height; 90 return output->height;
91} 91}
92 92
93static void render_sharp_line(cairo_t *cairo, uint32_t color, 93static void render_sharp_rectangle(cairo_t *cairo, uint32_t color,
94 double x, double y, double width, double height) { 94 double x, double y, double width, double height) {
95 cairo_save(cairo);
95 cairo_set_source_u32(cairo, color); 96 cairo_set_source_u32(cairo, color);
97 cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE);
98 cairo_rectangle(cairo, x, y, width, height);
99 cairo_fill(cairo);
100 cairo_restore(cairo);
101}
102
103static void render_sharp_line(cairo_t *cairo, uint32_t color,
104 double x, double y, double width, double height) {
96 if (width > 1 && height > 1) { 105 if (width > 1 && height > 1) {
97 cairo_rectangle(cairo, x, y, width, height); 106 render_sharp_rectangle(cairo, color, x, y, width, height);
98 cairo_fill(cairo);
99 } else { 107 } else {
108 cairo_save(cairo);
109 cairo_set_source_u32(cairo, color);
110 cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE);
100 if (width == 1) { 111 if (width == 1) {
101 x += 0.5; 112 x += 0.5;
102 height += y; 113 height += y;
@@ -111,6 +122,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
111 cairo_set_line_width(cairo, 1.0); 122 cairo_set_line_width(cairo, 1.0);
112 cairo_line_to(cairo, width, height); 123 cairo_line_to(cairo, width, height);
113 cairo_stroke(cairo); 124 cairo_stroke(cairo);
125 cairo_restore(cairo);
114 } 126 }
115} 127}
116 128
@@ -141,7 +153,7 @@ static uint32_t render_status_block(cairo_t *cairo,
141 output->scale, block->markup, "%s", block->full_text); 153 output->scale, block->markup, "%s", block->full_text);
142 154
143 int margin = 3 * output->scale; 155 int margin = 3 * output->scale;
144 int ws_vertical_padding = WS_VERTICAL_PADDING * 2; 156 double ws_vertical_padding = WS_VERTICAL_PADDING * 2 * output->scale;
145 157
146 int width = text_width; 158 int width = text_width;
147 if (width < block->min_width) { 159 if (width < block->min_width) {
@@ -157,12 +169,12 @@ static uint32_t render_status_block(cairo_t *cairo,
157 169
158 *x -= width; 170 *x -= width;
159 if ((block->border || block->urgent) && block->border_left > 0) { 171 if ((block->border || block->urgent) && block->border_left > 0) {
160 *x -= (block->border_left + margin); 172 *x -= (block->border_left * output->scale + margin);
161 block_width += block->border_left + margin; 173 block_width += block->border_left * output->scale + margin;
162 } 174 }
163 if ((block->border || block->urgent) && block->border_right > 0) { 175 if ((block->border || block->urgent) && block->border_right > 0) {
164 *x -= (block->border_right + margin); 176 *x -= (block->border_right * output->scale + margin);
165 block_width += block->border_right + margin; 177 block_width += block->border_right * output->scale + margin;
166 } 178 }
167 179
168 int sep_width, sep_height; 180 int sep_width, sep_height;
@@ -199,48 +211,41 @@ static uint32_t render_status_block(cairo_t *cairo,
199 wl_list_insert(&output->hotspots, &hotspot->link); 211 wl_list_insert(&output->hotspots, &hotspot->link);
200 } 212 }
201 213
202 double pos = *x; 214 double x_pos = *x;
215 double y_pos = WS_VERTICAL_PADDING * output->scale;
216 double render_height = height - ws_vertical_padding + output->scale;
203 217
204 uint32_t bg_color = block->urgent 218 uint32_t bg_color = block->urgent
205 ? config->colors.urgent_workspace.background : block->background; 219 ? config->colors.urgent_workspace.background : block->background;
206 if (bg_color) { 220 if (bg_color) {
207 cairo_set_source_u32(cairo, bg_color); 221 render_sharp_rectangle(cairo, bg_color, x_pos, y_pos,
208 cairo_rectangle(cairo, pos - 0.5 * output->scale, 222 block_width, render_height);
209 output->scale, width, height);
210 cairo_fill(cairo);
211 } 223 }
212 224
213 uint32_t border_color = block->urgent 225 uint32_t border_color = block->urgent
214 ? config->colors.urgent_workspace.border : block->border; 226 ? config->colors.urgent_workspace.border : block->border;
215 if (border_color && block->border_top > 0) { 227 if (border_color && block->border_top > 0) {
216 render_sharp_line(cairo, border_color, 228 render_sharp_line(cairo, border_color, x_pos, y_pos,
217 pos - 0.5 * output->scale, output->scale, 229 block_width, block->border_top * output->scale);
218 text_width, block->border_top);
219 } 230 }
220 if (border_color && block->border_bottom > 0) { 231 if (border_color && block->border_bottom > 0) {
221 render_sharp_line(cairo, border_color, 232 render_sharp_line(cairo, border_color, x_pos,
222 pos - 0.5 * output->scale, 233 y_pos + render_height - block->border_bottom * output->scale,
223 height - output->scale - block->border_bottom, 234 block_width, block->border_bottom * output->scale);
224 text_width, block->border_bottom);
225 }
226 if (border_color != 0 && block->border_left > 0) {
227 render_sharp_line(cairo, border_color,
228 pos - 0.5 * output->scale, output->scale,
229 block->border_left, height);
230 } 235 }
231 if (border_color != 0 && block->border_right > 0) { 236 if (border_color && block->border_left > 0) {
232 render_sharp_line(cairo, border_color, 237 render_sharp_line(cairo, border_color, x_pos, y_pos,
233 pos - 0.5 * output->scale + text_width, output->scale, 238 block->border_left * output->scale, render_height);
234 block->border_right, height); 239 x_pos += block->border_left * output->scale + margin;
235 } 240 }
236 241
237 double offset = 0; 242 double offset = 0;
238 if (strncmp(block->align, "left", 5) == 0) { 243 if (strncmp(block->align, "left", 5) == 0) {
239 offset = pos; 244 offset = x_pos;
240 } else if (strncmp(block->align, "right", 5) == 0) { 245 } else if (strncmp(block->align, "right", 5) == 0) {
241 offset = pos + width - text_width; 246 offset = x_pos + width - text_width;
242 } else if (strncmp(block->align, "center", 6) == 0) { 247 } else if (strncmp(block->align, "center", 6) == 0) {
243 offset = pos + (width - text_width) / 2; 248 offset = x_pos + (width - text_width) / 2;
244 } 249 }
245 cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); 250 cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0);
246 uint32_t color = block->color ? *block->color : config->colors.statusline; 251 uint32_t color = block->color ? *block->color : config->colors.statusline;
@@ -248,14 +253,13 @@ static uint32_t render_status_block(cairo_t *cairo,
248 cairo_set_source_u32(cairo, color); 253 cairo_set_source_u32(cairo, color);
249 pango_printf(cairo, config->font, output->scale, 254 pango_printf(cairo, config->font, output->scale,
250 block->markup, "%s", block->full_text); 255 block->markup, "%s", block->full_text);
251 pos += width; 256 x_pos += width;
252 257
253 if (block->border && block->border_right > 0) { 258 if (block->border && block->border_right > 0) {
254 pos += margin; 259 x_pos += margin;
255 render_sharp_line(cairo, block->border, 260 render_sharp_line(cairo, border_color, x_pos, y_pos,
256 pos - 0.5 * output->scale, output->scale, 261 block->border_right * output->scale, render_height);
257 block->border_right, height); 262 x_pos += block->border_right * output->scale;
258 pos += block->border_right;
259 } 263 }
260 264
261 if (!edge && block->separator) { 265 if (!edge && block->separator) {
@@ -265,14 +269,14 @@ static uint32_t render_status_block(cairo_t *cairo,
265 cairo_set_source_u32(cairo, config->colors.separator); 269 cairo_set_source_u32(cairo, config->colors.separator);
266 } 270 }
267 if (config->sep_symbol) { 271 if (config->sep_symbol) {
268 offset = pos + (sep_block_width - sep_width) / 2; 272 offset = x_pos + (sep_block_width - sep_width) / 2;
269 cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0); 273 cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0);
270 pango_printf(cairo, config->font, output->scale, false, 274 pango_printf(cairo, config->font, output->scale, false,
271 "%s", config->sep_symbol); 275 "%s", config->sep_symbol);
272 } else { 276 } else {
273 cairo_set_line_width(cairo, 1); 277 cairo_set_line_width(cairo, 1);
274 cairo_move_to(cairo, pos + sep_block_width / 2, margin); 278 cairo_move_to(cairo, x_pos + sep_block_width / 2, margin);
275 cairo_line_to(cairo, pos + sep_block_width / 2, height - margin); 279 cairo_line_to(cairo, x_pos + sep_block_width / 2, height - margin);
276 cairo_stroke(cairo); 280 cairo_stroke(cairo);
277 } 281 }
278 } 282 }