diff options
Diffstat (limited to 'swaybar/render.c')
-rw-r--r-- | swaybar/render.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/swaybar/render.c b/swaybar/render.c index 1e1554c5..9ac0c766 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -8,6 +8,13 @@ | |||
8 | #include "status_line.h" | 8 | #include "status_line.h" |
9 | #include "render.h" | 9 | #include "render.h" |
10 | 10 | ||
11 | |||
12 | /* internal spacing */ | ||
13 | static int margin = 3; | ||
14 | static int ws_horizontal_padding = 5; | ||
15 | static double ws_vertical_padding = 1.5; | ||
16 | static int ws_spacing = 1; | ||
17 | |||
11 | static void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { | 18 | static void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { |
12 | cairo_set_source_rgba(cairo, | 19 | cairo_set_source_rgba(cairo, |
13 | ((color & 0xFF000000) >> 24) / 256.0, | 20 | ((color & 0xFF000000) >> 24) / 256.0, |
@@ -62,13 +69,13 @@ static void render_block(struct window *window, struct swaybar_config *config, s | |||
62 | *x -= width; | 69 | *x -= width; |
63 | 70 | ||
64 | if (block->border != 0 && block->border_left > 0) { | 71 | if (block->border != 0 && block->border_left > 0) { |
65 | *x -= (block->border_left + config->margin); | 72 | *x -= (block->border_left + margin); |
66 | block_width += block->border_left + config->margin; | 73 | block_width += block->border_left + margin; |
67 | } | 74 | } |
68 | 75 | ||
69 | if (block->border != 0 && block->border_right > 0) { | 76 | if (block->border != 0 && block->border_right > 0) { |
70 | *x -= (block->border_right + config->margin); | 77 | *x -= (block->border_right + margin); |
71 | block_width += block->border_right + config->margin; | 78 | block_width += block->border_right + margin; |
72 | } | 79 | } |
73 | 80 | ||
74 | // Add separator | 81 | // Add separator |
@@ -76,13 +83,13 @@ static void render_block(struct window *window, struct swaybar_config *config, s | |||
76 | if (config->sep_symbol) { | 83 | if (config->sep_symbol) { |
77 | get_text_size(window, &sep_width, &height, "%s", config->sep_symbol); | 84 | get_text_size(window, &sep_width, &height, "%s", config->sep_symbol); |
78 | if (sep_width > block->separator_block_width) { | 85 | if (sep_width > block->separator_block_width) { |
79 | block->separator_block_width = sep_width + config->margin * 2; | 86 | block->separator_block_width = sep_width + margin * 2; |
80 | } | 87 | } |
81 | } | 88 | } |
82 | 89 | ||
83 | *x -= block->separator_block_width; | 90 | *x -= block->separator_block_width; |
84 | } else { | 91 | } else { |
85 | *x -= config->margin; | 92 | *x -= margin; |
86 | } | 93 | } |
87 | 94 | ||
88 | double pos = *x; | 95 | double pos = *x; |
@@ -120,7 +127,7 @@ static void render_block(struct window *window, struct swaybar_config *config, s | |||
120 | block->border_left, | 127 | block->border_left, |
121 | window->height - 2); | 128 | window->height - 2); |
122 | 129 | ||
123 | pos += block->border_left + config->margin; | 130 | pos += block->border_left + margin; |
124 | } | 131 | } |
125 | 132 | ||
126 | // render text | 133 | // render text |
@@ -134,7 +141,7 @@ static void render_block(struct window *window, struct swaybar_config *config, s | |||
134 | offset = pos + (width - textwidth) / 2; | 141 | offset = pos + (width - textwidth) / 2; |
135 | } | 142 | } |
136 | 143 | ||
137 | cairo_move_to(window->cairo, offset, config->margin); | 144 | cairo_move_to(window->cairo, offset, margin); |
138 | cairo_set_source_u32(window->cairo, block->color); | 145 | cairo_set_source_u32(window->cairo, block->color); |
139 | pango_printf(window, "%s", block->full_text); | 146 | pango_printf(window, "%s", block->full_text); |
140 | 147 | ||
@@ -142,7 +149,7 @@ static void render_block(struct window *window, struct swaybar_config *config, s | |||
142 | 149 | ||
143 | // render right border | 150 | // render right border |
144 | if (block->border != 0 && block->border_right > 0) { | 151 | if (block->border != 0 && block->border_right > 0) { |
145 | pos += config->margin; | 152 | pos += margin; |
146 | 153 | ||
147 | render_sharp_line(window->cairo, block->border, | 154 | render_sharp_line(window->cairo, block->border, |
148 | pos - 0.5, | 155 | pos - 0.5, |
@@ -158,14 +165,14 @@ static void render_block(struct window *window, struct swaybar_config *config, s | |||
158 | cairo_set_source_u32(window->cairo, config->colors.separator); | 165 | cairo_set_source_u32(window->cairo, config->colors.separator); |
159 | if (config->sep_symbol) { | 166 | if (config->sep_symbol) { |
160 | offset = pos + (block->separator_block_width - sep_width) / 2; | 167 | offset = pos + (block->separator_block_width - sep_width) / 2; |
161 | cairo_move_to(window->cairo, offset, config->margin); | 168 | cairo_move_to(window->cairo, offset, margin); |
162 | pango_printf(window, "%s", config->sep_symbol); | 169 | pango_printf(window, "%s", config->sep_symbol); |
163 | } else { | 170 | } else { |
164 | cairo_set_line_width(window->cairo, 1); | 171 | cairo_set_line_width(window->cairo, 1); |
165 | cairo_move_to(window->cairo, pos + block->separator_block_width/2, | 172 | cairo_move_to(window->cairo, pos + block->separator_block_width/2, |
166 | config->margin); | 173 | margin); |
167 | cairo_line_to(window->cairo, pos + block->separator_block_width/2, | 174 | cairo_line_to(window->cairo, pos + block->separator_block_width/2, |
168 | window->height - config->margin); | 175 | window->height - margin); |
169 | cairo_stroke(window->cairo); | 176 | cairo_stroke(window->cairo); |
170 | } | 177 | } |
171 | } | 178 | } |
@@ -215,22 +222,22 @@ static void render_workspace_button(struct window *window, struct swaybar_config | |||
215 | 222 | ||
216 | // background | 223 | // background |
217 | cairo_set_source_u32(window->cairo, box_colors.background); | 224 | cairo_set_source_u32(window->cairo, box_colors.background); |
218 | cairo_rectangle(window->cairo, *x, 1.5, width + config->ws_horizontal_padding * 2 - 1, | 225 | cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1, |
219 | height + config->ws_vertical_padding * 2); | 226 | height + ws_vertical_padding * 2); |
220 | cairo_fill(window->cairo); | 227 | cairo_fill(window->cairo); |
221 | 228 | ||
222 | // border | 229 | // border |
223 | cairo_set_source_u32(window->cairo, box_colors.border); | 230 | cairo_set_source_u32(window->cairo, box_colors.border); |
224 | cairo_rectangle(window->cairo, *x, 1.5, width + config->ws_horizontal_padding * 2 - 1, | 231 | cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1, |
225 | height + config->ws_vertical_padding * 2); | 232 | height + ws_vertical_padding * 2); |
226 | cairo_stroke(window->cairo); | 233 | cairo_stroke(window->cairo); |
227 | 234 | ||
228 | // text | 235 | // text |
229 | cairo_set_source_u32(window->cairo, box_colors.text); | 236 | cairo_set_source_u32(window->cairo, box_colors.text); |
230 | cairo_move_to(window->cairo, (int)*x + config->ws_horizontal_padding, config->margin); | 237 | cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin); |
231 | pango_printf(window, "%s", name); | 238 | pango_printf(window, "%s", name); |
232 | 239 | ||
233 | *x += width + config->ws_horizontal_padding * 2 + config->ws_spacing; | 240 | *x += width + ws_horizontal_padding * 2 + ws_spacing; |
234 | 241 | ||
235 | free(name); | 242 | free(name); |
236 | } | 243 | } |
@@ -241,19 +248,19 @@ static void render_binding_mode_indicator(struct window *window, struct swaybar_ | |||
241 | 248 | ||
242 | // background | 249 | // background |
243 | cairo_set_source_u32(window->cairo, config->colors.binding_mode.background); | 250 | cairo_set_source_u32(window->cairo, config->colors.binding_mode.background); |
244 | cairo_rectangle(window->cairo, pos, 1.5, width + config->ws_horizontal_padding * 2 - 1, | 251 | cairo_rectangle(window->cairo, pos, 1.5, width + ws_horizontal_padding * 2 - 1, |
245 | height + config->ws_vertical_padding * 2); | 252 | height + ws_vertical_padding * 2); |
246 | cairo_fill(window->cairo); | 253 | cairo_fill(window->cairo); |
247 | 254 | ||
248 | // border | 255 | // border |
249 | cairo_set_source_u32(window->cairo, config->colors.binding_mode.border); | 256 | cairo_set_source_u32(window->cairo, config->colors.binding_mode.border); |
250 | cairo_rectangle(window->cairo, pos, 1.5, width + config->ws_horizontal_padding * 2 - 1, | 257 | cairo_rectangle(window->cairo, pos, 1.5, width + ws_horizontal_padding * 2 - 1, |
251 | height + config->ws_vertical_padding * 2); | 258 | height + ws_vertical_padding * 2); |
252 | cairo_stroke(window->cairo); | 259 | cairo_stroke(window->cairo); |
253 | 260 | ||
254 | // text | 261 | // text |
255 | cairo_set_source_u32(window->cairo, config->colors.binding_mode.text); | 262 | cairo_set_source_u32(window->cairo, config->colors.binding_mode.text); |
256 | cairo_move_to(window->cairo, (int)pos + config->ws_horizontal_padding, config->margin); | 263 | cairo_move_to(window->cairo, (int)pos + ws_horizontal_padding, margin); |
257 | pango_printf(window, "%s", config->mode); | 264 | pango_printf(window, "%s", config->mode); |
258 | } | 265 | } |
259 | 266 | ||
@@ -279,7 +286,7 @@ void render(struct output *output, struct swaybar_config *config, struct status_ | |||
279 | 286 | ||
280 | if (line->protocol == TEXT) { | 287 | if (line->protocol == TEXT) { |
281 | get_text_size(window, &width, &height, "%s", line->text_line); | 288 | get_text_size(window, &width, &height, "%s", line->text_line); |
282 | cairo_move_to(cairo, window->width - config->margin - width, config->margin); | 289 | cairo_move_to(cairo, window->width - margin - width, margin); |
283 | pango_printf(window, "%s", line); | 290 | pango_printf(window, "%s", line); |
284 | } else if (line->protocol == I3BAR && line->block_line) { | 291 | } else if (line->protocol == I3BAR && line->block_line) { |
285 | double pos = window->width - 0.5; | 292 | double pos = window->width - 0.5; |
@@ -309,3 +316,13 @@ void render(struct output *output, struct swaybar_config *config, struct status_ | |||
309 | render_binding_mode_indicator(window, config, x); | 316 | render_binding_mode_indicator(window, config, x); |
310 | } | 317 | } |
311 | } | 318 | } |
319 | |||
320 | void set_window_height(struct window *window, int height) { | ||
321 | int text_width, text_height; | ||
322 | get_text_size(window, &text_width, &text_height, "Test string for measuring purposes"); | ||
323 | if (height > 0) { | ||
324 | margin = (height - text_height) / 2; | ||
325 | ws_vertical_padding = margin - 1.5; | ||
326 | } | ||
327 | window->height = text_height + margin * 2; | ||
328 | } | ||