diff options
Diffstat (limited to 'swaybar/render.c')
-rw-r--r-- | swaybar/render.c | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/swaybar/render.c b/swaybar/render.c index e149d3a2..12dd3b07 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -35,7 +35,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, | |||
35 | cairo_set_source_u32(cairo, 0xFF0000FF); | 35 | cairo_set_source_u32(cairo, 0xFF0000FF); |
36 | 36 | ||
37 | int margin = 3 * output->scale; | 37 | int margin = 3 * output->scale; |
38 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 38 | double ws_vertical_padding = |
39 | output->bar->config->status_padding * output->scale; | ||
39 | 40 | ||
40 | char *font = output->bar->config->font; | 41 | char *font = output->bar->config->font; |
41 | int text_width, text_height; | 42 | int text_width, text_height; |
@@ -72,7 +73,7 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
72 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 73 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, |
73 | output->scale, config->pango_markup, "%s", text); | 74 | output->scale, config->pango_markup, "%s", text); |
74 | 75 | ||
75 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 76 | double ws_vertical_padding = config->status_padding * output->scale; |
76 | int margin = 3 * output->scale; | 77 | int margin = 3 * output->scale; |
77 | 78 | ||
78 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 79 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
@@ -92,13 +93,24 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
92 | return output->height; | 93 | return output->height; |
93 | } | 94 | } |
94 | 95 | ||
95 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | 96 | static void render_sharp_rectangle(cairo_t *cairo, uint32_t color, |
96 | double x, double y, double width, double height) { | 97 | double x, double y, double width, double height) { |
98 | cairo_save(cairo); | ||
97 | cairo_set_source_u32(cairo, color); | 99 | cairo_set_source_u32(cairo, color); |
100 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); | ||
101 | cairo_rectangle(cairo, x, y, width, height); | ||
102 | cairo_fill(cairo); | ||
103 | cairo_restore(cairo); | ||
104 | } | ||
105 | |||
106 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | ||
107 | double x, double y, double width, double height) { | ||
98 | if (width > 1 && height > 1) { | 108 | if (width > 1 && height > 1) { |
99 | cairo_rectangle(cairo, x, y, width, height); | 109 | render_sharp_rectangle(cairo, color, x, y, width, height); |
100 | cairo_fill(cairo); | ||
101 | } else { | 110 | } else { |
111 | cairo_save(cairo); | ||
112 | cairo_set_source_u32(cairo, color); | ||
113 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); | ||
102 | if (width == 1) { | 114 | if (width == 1) { |
103 | x += 0.5; | 115 | x += 0.5; |
104 | height += y; | 116 | height += y; |
@@ -113,6 +125,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, | |||
113 | cairo_set_line_width(cairo, 1.0); | 125 | cairo_set_line_width(cairo, 1.0); |
114 | cairo_line_to(cairo, width, height); | 126 | cairo_line_to(cairo, width, height); |
115 | cairo_stroke(cairo); | 127 | cairo_stroke(cairo); |
128 | cairo_restore(cairo); | ||
116 | } | 129 | } |
117 | } | 130 | } |
118 | 131 | ||
@@ -143,7 +156,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
143 | output->scale, block->markup, "%s", block->full_text); | 156 | output->scale, block->markup, "%s", block->full_text); |
144 | 157 | ||
145 | int margin = 3 * output->scale; | 158 | int margin = 3 * output->scale; |
146 | int ws_vertical_padding = WS_VERTICAL_PADDING * 2; | 159 | double ws_vertical_padding = config->status_padding * output->scale; |
147 | 160 | ||
148 | int width = text_width; | 161 | int width = text_width; |
149 | if (width < block->min_width) { | 162 | if (width < block->min_width) { |
@@ -160,12 +173,12 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
160 | 173 | ||
161 | *x -= width; | 174 | *x -= width; |
162 | if ((block->border || block->urgent) && block->border_left > 0) { | 175 | if ((block->border || block->urgent) && block->border_left > 0) { |
163 | *x -= (block->border_left + margin); | 176 | *x -= (block->border_left * output->scale + margin); |
164 | block_width += block->border_left + margin; | 177 | block_width += block->border_left * output->scale + margin; |
165 | } | 178 | } |
166 | if ((block->border || block->urgent) && block->border_right > 0) { | 179 | if ((block->border || block->urgent) && block->border_right > 0) { |
167 | *x -= (block->border_right + margin); | 180 | *x -= (block->border_right * output->scale + margin); |
168 | block_width += block->border_right + margin; | 181 | block_width += block->border_right * output->scale + margin; |
169 | } | 182 | } |
170 | 183 | ||
171 | int sep_width, sep_height; | 184 | int sep_width, sep_height; |
@@ -185,8 +198,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
185 | } | 198 | } |
186 | } | 199 | } |
187 | *x -= sep_block_width; | 200 | *x -= sep_block_width; |
188 | } else { | 201 | } else if (config->status_edge_padding) { |
189 | *x -= margin; | 202 | *x -= config->status_edge_padding * output->scale; |
190 | } | 203 | } |
191 | 204 | ||
192 | uint32_t height = output->height * output->scale; | 205 | uint32_t height = output->height * output->scale; |
@@ -203,48 +216,41 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
203 | wl_list_insert(&output->hotspots, &hotspot->link); | 216 | wl_list_insert(&output->hotspots, &hotspot->link); |
204 | } | 217 | } |
205 | 218 | ||
206 | double pos = *x; | 219 | double x_pos = *x; |
220 | double y_pos = ws_vertical_padding; | ||
221 | double render_height = height - ws_vertical_padding * 2; | ||
207 | 222 | ||
208 | uint32_t bg_color = block->urgent | 223 | uint32_t bg_color = block->urgent |
209 | ? config->colors.urgent_workspace.background : block->background; | 224 | ? config->colors.urgent_workspace.background : block->background; |
210 | if (bg_color) { | 225 | if (bg_color) { |
211 | cairo_set_source_u32(cairo, bg_color); | 226 | render_sharp_rectangle(cairo, bg_color, x_pos, y_pos, |
212 | cairo_rectangle(cairo, pos - 0.5 * output->scale, | 227 | block_width, render_height); |
213 | output->scale, width, height); | ||
214 | cairo_fill(cairo); | ||
215 | } | 228 | } |
216 | 229 | ||
217 | uint32_t border_color = block->urgent | 230 | uint32_t border_color = block->urgent |
218 | ? config->colors.urgent_workspace.border : block->border; | 231 | ? config->colors.urgent_workspace.border : block->border; |
219 | if (border_color && block->border_top > 0) { | 232 | if (border_color && block->border_top > 0) { |
220 | render_sharp_line(cairo, border_color, | 233 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
221 | pos - 0.5 * output->scale, output->scale, | 234 | block_width, block->border_top * output->scale); |
222 | text_width, block->border_top); | ||
223 | } | 235 | } |
224 | if (border_color && block->border_bottom > 0) { | 236 | if (border_color && block->border_bottom > 0) { |
225 | render_sharp_line(cairo, border_color, | 237 | render_sharp_line(cairo, border_color, x_pos, |
226 | pos - 0.5 * output->scale, | 238 | y_pos + render_height - block->border_bottom * output->scale, |
227 | height - output->scale - block->border_bottom, | 239 | block_width, block->border_bottom * output->scale); |
228 | text_width, block->border_bottom); | ||
229 | } | ||
230 | if (border_color != 0 && block->border_left > 0) { | ||
231 | render_sharp_line(cairo, border_color, | ||
232 | pos - 0.5 * output->scale, output->scale, | ||
233 | block->border_left, height); | ||
234 | } | 240 | } |
235 | if (border_color != 0 && block->border_right > 0) { | 241 | if (border_color && block->border_left > 0) { |
236 | render_sharp_line(cairo, border_color, | 242 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
237 | pos - 0.5 * output->scale + text_width, output->scale, | 243 | block->border_left * output->scale, render_height); |
238 | block->border_right, height); | 244 | x_pos += block->border_left * output->scale + margin; |
239 | } | 245 | } |
240 | 246 | ||
241 | double offset = 0; | 247 | double offset = 0; |
242 | if (strncmp(block->align, "left", 5) == 0) { | 248 | if (strncmp(block->align, "left", 5) == 0) { |
243 | offset = pos; | 249 | offset = x_pos; |
244 | } else if (strncmp(block->align, "right", 5) == 0) { | 250 | } else if (strncmp(block->align, "right", 5) == 0) { |
245 | offset = pos + width - text_width; | 251 | offset = x_pos + width - text_width; |
246 | } else if (strncmp(block->align, "center", 6) == 0) { | 252 | } else if (strncmp(block->align, "center", 6) == 0) { |
247 | offset = pos + (width - text_width) / 2; | 253 | offset = x_pos + (width - text_width) / 2; |
248 | } | 254 | } |
249 | cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); | 255 | cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0); |
250 | uint32_t color = block->color ? *block->color : config->colors.statusline; | 256 | uint32_t color = block->color ? *block->color : config->colors.statusline; |
@@ -252,14 +258,13 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
252 | cairo_set_source_u32(cairo, color); | 258 | cairo_set_source_u32(cairo, color); |
253 | pango_printf(cairo, config->font, output->scale, | 259 | pango_printf(cairo, config->font, output->scale, |
254 | block->markup, "%s", block->full_text); | 260 | block->markup, "%s", block->full_text); |
255 | pos += width; | 261 | x_pos += width; |
256 | 262 | ||
257 | if (block->border && block->border_right > 0) { | 263 | if (block->border && block->border_right > 0) { |
258 | pos += margin; | 264 | x_pos += margin; |
259 | render_sharp_line(cairo, block->border, | 265 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
260 | pos - 0.5 * output->scale, output->scale, | 266 | block->border_right * output->scale, render_height); |
261 | block->border_right, height); | 267 | x_pos += block->border_right * output->scale; |
262 | pos += block->border_right; | ||
263 | } | 268 | } |
264 | 269 | ||
265 | if (!edge && block->separator) { | 270 | if (!edge && block->separator) { |
@@ -269,14 +274,14 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
269 | cairo_set_source_u32(cairo, config->colors.separator); | 274 | cairo_set_source_u32(cairo, config->colors.separator); |
270 | } | 275 | } |
271 | if (config->sep_symbol) { | 276 | if (config->sep_symbol) { |
272 | offset = pos + (sep_block_width - sep_width) / 2; | 277 | offset = x_pos + (sep_block_width - sep_width) / 2; |
273 | cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0); | 278 | cairo_move_to(cairo, offset, height / 2.0 - sep_height / 2.0); |
274 | pango_printf(cairo, config->font, output->scale, false, | 279 | pango_printf(cairo, config->font, output->scale, false, |
275 | "%s", config->sep_symbol); | 280 | "%s", config->sep_symbol); |
276 | } else { | 281 | } else { |
277 | cairo_set_line_width(cairo, 1); | 282 | cairo_set_line_width(cairo, 1); |
278 | cairo_move_to(cairo, pos + sep_block_width / 2, margin); | 283 | cairo_move_to(cairo, x_pos + sep_block_width / 2, margin); |
279 | cairo_line_to(cairo, pos + sep_block_width / 2, height - margin); | 284 | cairo_line_to(cairo, x_pos + sep_block_width / 2, height - margin); |
280 | cairo_stroke(cairo); | 285 | cairo_stroke(cairo); |
281 | } | 286 | } |
282 | } | 287 | } |
@@ -286,7 +291,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
286 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 291 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
287 | struct swaybar_output *output, double *x) { | 292 | struct swaybar_output *output, double *x) { |
288 | uint32_t max_height = 0; | 293 | uint32_t max_height = 0; |
289 | bool edge = true; | 294 | bool edge = *x == output->width * output->scale; |
290 | struct i3bar_block *block; | 295 | struct i3bar_block *block; |
291 | wl_list_for_each(block, &output->bar->status->blocks, link) { | 296 | wl_list_for_each(block, &output->bar->status->blocks, link) { |
292 | uint32_t h = render_status_block(cairo, output, block, x, edge); | 297 | uint32_t h = render_status_block(cairo, output, block, x, edge); |