diff options
Diffstat (limited to 'swaybar/render.c')
-rw-r--r-- | swaybar/render.c | 117 |
1 files changed, 64 insertions, 53 deletions
diff --git a/swaybar/render.c b/swaybar/render.c index 9fe4ee9c..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; |
@@ -44,7 +45,8 @@ static uint32_t render_status_line_error(cairo_t *cairo, | |||
44 | 45 | ||
45 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 46 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
46 | uint32_t ideal_surface_height = ideal_height / output->scale; | 47 | uint32_t ideal_surface_height = ideal_height / output->scale; |
47 | if (output->height < ideal_surface_height) { | 48 | if (!output->bar->config->height && |
49 | output->height < ideal_surface_height) { | ||
48 | return ideal_surface_height; | 50 | return ideal_surface_height; |
49 | } | 51 | } |
50 | *x -= text_width + margin; | 52 | *x -= text_width + margin; |
@@ -71,12 +73,13 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
71 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, | 73 | get_text_size(cairo, config->font, &text_width, &text_height, NULL, |
72 | output->scale, config->pango_markup, "%s", text); | 74 | output->scale, config->pango_markup, "%s", text); |
73 | 75 | ||
74 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 76 | double ws_vertical_padding = config->status_padding * output->scale; |
75 | int margin = 3 * output->scale; | 77 | int margin = 3 * output->scale; |
76 | 78 | ||
77 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 79 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
78 | uint32_t ideal_surface_height = ideal_height / output->scale; | 80 | uint32_t ideal_surface_height = ideal_height / output->scale; |
79 | if (output->height < ideal_surface_height) { | 81 | if (!output->bar->config->height && |
82 | output->height < ideal_surface_height) { | ||
80 | return ideal_surface_height; | 83 | return ideal_surface_height; |
81 | } | 84 | } |
82 | 85 | ||
@@ -90,13 +93,24 @@ static uint32_t render_status_line_text(cairo_t *cairo, | |||
90 | return output->height; | 93 | return output->height; |
91 | } | 94 | } |
92 | 95 | ||
93 | static void render_sharp_line(cairo_t *cairo, uint32_t color, | 96 | static void render_sharp_rectangle(cairo_t *cairo, uint32_t color, |
94 | double x, double y, double width, double height) { | 97 | double x, double y, double width, double height) { |
98 | cairo_save(cairo); | ||
95 | 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) { | ||
96 | if (width > 1 && height > 1) { | 108 | if (width > 1 && height > 1) { |
97 | cairo_rectangle(cairo, x, y, width, height); | 109 | render_sharp_rectangle(cairo, color, x, y, width, height); |
98 | cairo_fill(cairo); | ||
99 | } else { | 110 | } else { |
111 | cairo_save(cairo); | ||
112 | cairo_set_source_u32(cairo, color); | ||
113 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_NONE); | ||
100 | if (width == 1) { | 114 | if (width == 1) { |
101 | x += 0.5; | 115 | x += 0.5; |
102 | height += y; | 116 | height += y; |
@@ -111,6 +125,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, | |||
111 | cairo_set_line_width(cairo, 1.0); | 125 | cairo_set_line_width(cairo, 1.0); |
112 | cairo_line_to(cairo, width, height); | 126 | cairo_line_to(cairo, width, height); |
113 | cairo_stroke(cairo); | 127 | cairo_stroke(cairo); |
128 | cairo_restore(cairo); | ||
114 | } | 129 | } |
115 | } | 130 | } |
116 | 131 | ||
@@ -141,7 +156,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
141 | output->scale, block->markup, "%s", block->full_text); | 156 | output->scale, block->markup, "%s", block->full_text); |
142 | 157 | ||
143 | int margin = 3 * output->scale; | 158 | int margin = 3 * output->scale; |
144 | int ws_vertical_padding = WS_VERTICAL_PADDING * 2; | 159 | double ws_vertical_padding = config->status_padding * output->scale; |
145 | 160 | ||
146 | int width = text_width; | 161 | int width = text_width; |
147 | if (width < block->min_width) { | 162 | if (width < block->min_width) { |
@@ -151,18 +166,19 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
151 | double block_width = width; | 166 | double block_width = width; |
152 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; | 167 | uint32_t ideal_height = text_height + ws_vertical_padding * 2; |
153 | uint32_t ideal_surface_height = ideal_height / output->scale; | 168 | uint32_t ideal_surface_height = ideal_height / output->scale; |
154 | if (output->height < ideal_surface_height) { | 169 | if (!output->bar->config->height && |
170 | output->height < ideal_surface_height) { | ||
155 | return ideal_surface_height; | 171 | return ideal_surface_height; |
156 | } | 172 | } |
157 | 173 | ||
158 | *x -= width; | 174 | *x -= width; |
159 | if ((block->border || block->urgent) && block->border_left > 0) { | 175 | if ((block->border || block->urgent) && block->border_left > 0) { |
160 | *x -= (block->border_left + margin); | 176 | *x -= (block->border_left * output->scale + margin); |
161 | block_width += block->border_left + margin; | 177 | block_width += block->border_left * output->scale + margin; |
162 | } | 178 | } |
163 | if ((block->border || block->urgent) && block->border_right > 0) { | 179 | if ((block->border || block->urgent) && block->border_right > 0) { |
164 | *x -= (block->border_right + margin); | 180 | *x -= (block->border_right * output->scale + margin); |
165 | block_width += block->border_right + margin; | 181 | block_width += block->border_right * output->scale + margin; |
166 | } | 182 | } |
167 | 183 | ||
168 | int sep_width, sep_height; | 184 | int sep_width, sep_height; |
@@ -173,7 +189,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
173 | output->scale, false, "%s", config->sep_symbol); | 189 | output->scale, false, "%s", config->sep_symbol); |
174 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; | 190 | uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; |
175 | uint32_t _ideal_surface_height = _ideal_height / output->scale; | 191 | uint32_t _ideal_surface_height = _ideal_height / output->scale; |
176 | if (output->height < _ideal_surface_height) { | 192 | if (!output->bar->config->height && |
193 | output->height < _ideal_surface_height) { | ||
177 | return _ideal_surface_height; | 194 | return _ideal_surface_height; |
178 | } | 195 | } |
179 | if (sep_width > sep_block_width) { | 196 | if (sep_width > sep_block_width) { |
@@ -181,8 +198,8 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
181 | } | 198 | } |
182 | } | 199 | } |
183 | *x -= sep_block_width; | 200 | *x -= sep_block_width; |
184 | } else { | 201 | } else if (config->status_edge_padding) { |
185 | *x -= margin; | 202 | *x -= config->status_edge_padding * output->scale; |
186 | } | 203 | } |
187 | 204 | ||
188 | uint32_t height = output->height * output->scale; | 205 | uint32_t height = output->height * output->scale; |
@@ -199,48 +216,41 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
199 | wl_list_insert(&output->hotspots, &hotspot->link); | 216 | wl_list_insert(&output->hotspots, &hotspot->link); |
200 | } | 217 | } |
201 | 218 | ||
202 | double pos = *x; | 219 | double x_pos = *x; |
220 | double y_pos = ws_vertical_padding; | ||
221 | double render_height = height - ws_vertical_padding * 2; | ||
203 | 222 | ||
204 | uint32_t bg_color = block->urgent | 223 | uint32_t bg_color = block->urgent |
205 | ? config->colors.urgent_workspace.background : block->background; | 224 | ? config->colors.urgent_workspace.background : block->background; |
206 | if (bg_color) { | 225 | if (bg_color) { |
207 | cairo_set_source_u32(cairo, bg_color); | 226 | render_sharp_rectangle(cairo, bg_color, x_pos, y_pos, |
208 | cairo_rectangle(cairo, pos - 0.5 * output->scale, | 227 | block_width, render_height); |
209 | output->scale, width, height); | ||
210 | cairo_fill(cairo); | ||
211 | } | 228 | } |
212 | 229 | ||
213 | uint32_t border_color = block->urgent | 230 | uint32_t border_color = block->urgent |
214 | ? config->colors.urgent_workspace.border : block->border; | 231 | ? config->colors.urgent_workspace.border : block->border; |
215 | if (border_color && block->border_top > 0) { | 232 | if (border_color && block->border_top > 0) { |
216 | render_sharp_line(cairo, border_color, | 233 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
217 | pos - 0.5 * output->scale, output->scale, | 234 | block_width, block->border_top * output->scale); |
218 | text_width, block->border_top); | ||
219 | } | 235 | } |
220 | if (border_color && block->border_bottom > 0) { | 236 | if (border_color && block->border_bottom > 0) { |
221 | render_sharp_line(cairo, border_color, | 237 | render_sharp_line(cairo, border_color, x_pos, |
222 | pos - 0.5 * output->scale, | 238 | y_pos + render_height - block->border_bottom * output->scale, |
223 | height - output->scale - block->border_bottom, | 239 | 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 | } | 240 | } |
231 | if (border_color != 0 && block->border_right > 0) { | 241 | if (border_color && block->border_left > 0) { |
232 | render_sharp_line(cairo, border_color, | 242 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
233 | pos - 0.5 * output->scale + text_width, output->scale, | 243 | block->border_left * output->scale, render_height); |
234 | block->border_right, height); | 244 | x_pos += block->border_left * output->scale + margin; |
235 | } | 245 | } |
236 | 246 | ||
237 | double offset = 0; | 247 | double offset = 0; |
238 | if (strncmp(block->align, "left", 5) == 0) { | 248 | if (strncmp(block->align, "left", 5) == 0) { |
239 | offset = pos; | 249 | offset = x_pos; |
240 | } else if (strncmp(block->align, "right", 5) == 0) { | 250 | } else if (strncmp(block->align, "right", 5) == 0) { |
241 | offset = pos + width - text_width; | 251 | offset = x_pos + width - text_width; |
242 | } else if (strncmp(block->align, "center", 6) == 0) { | 252 | } else if (strncmp(block->align, "center", 6) == 0) { |
243 | offset = pos + (width - text_width) / 2; | 253 | offset = x_pos + (width - text_width) / 2; |
244 | } | 254 | } |
245 | 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); |
246 | uint32_t color = block->color ? *block->color : config->colors.statusline; | 256 | uint32_t color = block->color ? *block->color : config->colors.statusline; |
@@ -248,14 +258,13 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
248 | cairo_set_source_u32(cairo, color); | 258 | cairo_set_source_u32(cairo, color); |
249 | pango_printf(cairo, config->font, output->scale, | 259 | pango_printf(cairo, config->font, output->scale, |
250 | block->markup, "%s", block->full_text); | 260 | block->markup, "%s", block->full_text); |
251 | pos += width; | 261 | x_pos += width; |
252 | 262 | ||
253 | if (block->border && block->border_right > 0) { | 263 | if (block->border && block->border_right > 0) { |
254 | pos += margin; | 264 | x_pos += margin; |
255 | render_sharp_line(cairo, block->border, | 265 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
256 | pos - 0.5 * output->scale, output->scale, | 266 | block->border_right * output->scale, render_height); |
257 | block->border_right, height); | 267 | x_pos += block->border_right * output->scale; |
258 | pos += block->border_right; | ||
259 | } | 268 | } |
260 | 269 | ||
261 | if (!edge && block->separator) { | 270 | if (!edge && block->separator) { |
@@ -265,14 +274,14 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
265 | cairo_set_source_u32(cairo, config->colors.separator); | 274 | cairo_set_source_u32(cairo, config->colors.separator); |
266 | } | 275 | } |
267 | if (config->sep_symbol) { | 276 | if (config->sep_symbol) { |
268 | offset = pos + (sep_block_width - sep_width) / 2; | 277 | offset = x_pos + (sep_block_width - sep_width) / 2; |
269 | 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); |
270 | pango_printf(cairo, config->font, output->scale, false, | 279 | pango_printf(cairo, config->font, output->scale, false, |
271 | "%s", config->sep_symbol); | 280 | "%s", config->sep_symbol); |
272 | } else { | 281 | } else { |
273 | cairo_set_line_width(cairo, 1); | 282 | cairo_set_line_width(cairo, 1); |
274 | cairo_move_to(cairo, pos + sep_block_width / 2, margin); | 283 | cairo_move_to(cairo, x_pos + sep_block_width / 2, margin); |
275 | cairo_line_to(cairo, pos + sep_block_width / 2, height - margin); | 284 | cairo_line_to(cairo, x_pos + sep_block_width / 2, height - margin); |
276 | cairo_stroke(cairo); | 285 | cairo_stroke(cairo); |
277 | } | 286 | } |
278 | } | 287 | } |
@@ -282,7 +291,7 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
282 | static uint32_t render_status_line_i3bar(cairo_t *cairo, | 291 | static uint32_t render_status_line_i3bar(cairo_t *cairo, |
283 | struct swaybar_output *output, double *x) { | 292 | struct swaybar_output *output, double *x) { |
284 | uint32_t max_height = 0; | 293 | uint32_t max_height = 0; |
285 | bool edge = true; | 294 | bool edge = *x == output->width * output->scale; |
286 | struct i3bar_block *block; | 295 | struct i3bar_block *block; |
287 | wl_list_for_each(block, &output->bar->status->blocks, link) { | 296 | wl_list_for_each(block, &output->bar->status->blocks, link) { |
288 | uint32_t h = render_status_block(cairo, output, block, x, edge); | 297 | uint32_t h = render_status_block(cairo, output, block, x, edge); |
@@ -328,7 +337,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
328 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 | 337 | uint32_t ideal_height = text_height + ws_vertical_padding * 2 |
329 | + border_width * 2; | 338 | + border_width * 2; |
330 | uint32_t ideal_surface_height = ideal_height / output->scale; | 339 | uint32_t ideal_surface_height = ideal_height / output->scale; |
331 | if (output->height < ideal_surface_height) { | 340 | if (!output->bar->config->height && |
341 | output->height < ideal_surface_height) { | ||
332 | return ideal_surface_height; | 342 | return ideal_surface_height; |
333 | } | 343 | } |
334 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; | 344 | uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; |
@@ -394,7 +404,8 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
394 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height | 404 | uint32_t ideal_height = ws_vertical_padding * 2 + text_height |
395 | + border_width * 2; | 405 | + border_width * 2; |
396 | uint32_t ideal_surface_height = ideal_height / output->scale; | 406 | uint32_t ideal_surface_height = ideal_height / output->scale; |
397 | if (output->height < ideal_surface_height) { | 407 | if (!output->bar->config->height && |
408 | output->height < ideal_surface_height) { | ||
398 | return ideal_surface_height; | 409 | return ideal_surface_height; |
399 | } | 410 | } |
400 | 411 | ||
@@ -521,7 +532,7 @@ void render_frame(struct swaybar_output *output) { | |||
521 | cairo_restore(cairo); | 532 | cairo_restore(cairo); |
522 | uint32_t height = render_to_cairo(cairo, output); | 533 | uint32_t height = render_to_cairo(cairo, output); |
523 | int config_height = output->bar->config->height; | 534 | int config_height = output->bar->config->height; |
524 | if (config_height >= 0 && height < (uint32_t)config_height) { | 535 | if (config_height > 0) { |
525 | height = config_height; | 536 | height = config_height; |
526 | } | 537 | } |
527 | if (height != output->height || output->width == 0) { | 538 | if (height != output->height || output->width == 0) { |