diff options
Diffstat (limited to 'swaybar/main.c')
-rw-r--r-- | swaybar/main.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/swaybar/main.c b/swaybar/main.c index 243ef2a9..5b8ba45d 100644 --- a/swaybar/main.c +++ b/swaybar/main.c | |||
@@ -18,8 +18,6 @@ | |||
18 | #include "stringop.h" | 18 | #include "stringop.h" |
19 | #include "log.h" | 19 | #include "log.h" |
20 | 20 | ||
21 | #define MARGIN 5 | ||
22 | |||
23 | struct box_colors { | 21 | struct box_colors { |
24 | uint32_t border; | 22 | uint32_t border; |
25 | uint32_t background; | 23 | uint32_t background; |
@@ -188,6 +186,11 @@ uint32_t parse_position(const char *position) { | |||
188 | } | 186 | } |
189 | } | 187 | } |
190 | 188 | ||
189 | static int margin = 3; | ||
190 | static const int ws_hor_padding = 5; | ||
191 | static double ws_ver_padding = 1.5; | ||
192 | static const int ws_spacing = 1; | ||
193 | |||
191 | void bar_ipc_init(int outputi, const char *bar_id) { | 194 | void bar_ipc_init(int outputi, const char *bar_id) { |
192 | uint32_t len = 0; | 195 | uint32_t len = 0; |
193 | char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len); | 196 | char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len); |
@@ -229,6 +232,17 @@ void bar_ipc_init(int outputi, const char *bar_id) { | |||
229 | desktop_shell_set_panel_position(registry->desktop_shell, parse_position(json_object_get_string(position))); | 232 | desktop_shell_set_panel_position(registry->desktop_shell, parse_position(json_object_get_string(position))); |
230 | } | 233 | } |
231 | 234 | ||
235 | if (bar_height) { | ||
236 | int width, height; | ||
237 | get_text_size(window, &width, &height, "Test string for measuring purposes"); | ||
238 | int bar_height_value = json_object_get_int(bar_height); | ||
239 | if (bar_height_value > 0) { | ||
240 | margin = (bar_height_value - height) / 2; | ||
241 | ws_ver_padding = margin - 1.5; | ||
242 | } | ||
243 | window->height = height + margin * 2; | ||
244 | } | ||
245 | |||
232 | if (_colors) { | 246 | if (_colors) { |
233 | json_object *background, *statusline, *separator; | 247 | json_object *background, *statusline, *separator; |
234 | json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text; | 248 | json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text; |
@@ -321,12 +335,12 @@ void render() { | |||
321 | int width, height; | 335 | int width, height; |
322 | get_text_size(window, &width, &height, "%s", line); | 336 | get_text_size(window, &width, &height, "%s", line); |
323 | 337 | ||
324 | cairo_move_to(window->cairo, window->width - MARGIN - width, MARGIN); | 338 | cairo_move_to(window->cairo, window->width - margin - width, margin); |
325 | pango_printf(window, "%s", line); | 339 | pango_printf(window, "%s", line); |
326 | 340 | ||
327 | // Workspaces | 341 | // Workspaces |
328 | cairo_set_line_width(window->cairo, 2.0); | 342 | cairo_set_line_width(window->cairo, 1.0); |
329 | int x = 1; | 343 | double x = 0.5; |
330 | int i; | 344 | int i; |
331 | for (i = 0; i < workspaces->length; ++i) { | 345 | for (i = 0; i < workspaces->length; ++i) { |
332 | struct workspace *ws = workspaces->items[i]; | 346 | struct workspace *ws = workspaces->items[i]; |
@@ -341,19 +355,20 @@ void render() { | |||
341 | } else { | 355 | } else { |
342 | box_colors = colors.inactive_workspace; | 356 | box_colors = colors.inactive_workspace; |
343 | } | 357 | } |
358 | |||
344 | cairo_set_source_u32(window->cairo, box_colors.background); | 359 | cairo_set_source_u32(window->cairo, box_colors.background); |
345 | cairo_rectangle(window->cairo, x, 0, width + MARGIN * 2, window->height); | 360 | cairo_rectangle(window->cairo, x, 1.5, width + ws_hor_padding * 2 - 1, height + ws_ver_padding * 2); |
346 | cairo_fill(window->cairo); | 361 | cairo_fill(window->cairo); |
347 | 362 | ||
348 | cairo_set_source_u32(window->cairo, box_colors.border); | 363 | cairo_set_source_u32(window->cairo, box_colors.border); |
349 | cairo_rectangle(window->cairo, x, 2, width + MARGIN * 2, window->height - 4); | 364 | cairo_rectangle(window->cairo, x, 1.5, width + ws_hor_padding * 2 - 1, height + ws_ver_padding * 2); |
350 | cairo_stroke(window->cairo); | 365 | cairo_stroke(window->cairo); |
351 | 366 | ||
352 | cairo_set_source_u32(window->cairo, box_colors.text); | 367 | cairo_set_source_u32(window->cairo, box_colors.text); |
353 | cairo_move_to(window->cairo, x + MARGIN, MARGIN); | 368 | cairo_move_to(window->cairo, (int)x + ws_hor_padding, margin); |
354 | pango_printf(window, "%s", ws->name); | 369 | pango_printf(window, "%s", ws->name); |
355 | 370 | ||
356 | x += width + MARGIN * 2 + MARGIN; | 371 | x += width + ws_hor_padding * 2 + ws_spacing; |
357 | } | 372 | } |
358 | } | 373 | } |
359 | 374 | ||
@@ -467,6 +482,12 @@ int main(int argc, char **argv) { | |||
467 | int desired_output = atoi(argv[optind]); | 482 | int desired_output = atoi(argv[optind]); |
468 | struct output_state *output = registry->outputs->items[desired_output]; | 483 | struct output_state *output = registry->outputs->items[desired_output]; |
469 | 484 | ||
485 | window = window_setup(registry, output->width, 30, false); | ||
486 | if (!window) { | ||
487 | sway_abort("Failed to create window."); | ||
488 | } | ||
489 | desktop_shell_set_panel(registry->desktop_shell, output->output, window->surface); | ||
490 | |||
470 | bar_ipc_init(desired_output, bar_id); | 491 | bar_ipc_init(desired_output, bar_id); |
471 | 492 | ||
472 | if (status_command) { | 493 | if (status_command) { |
@@ -491,16 +512,6 @@ int main(int argc, char **argv) { | |||
491 | line[0] = '\0'; | 512 | line[0] = '\0'; |
492 | } | 513 | } |
493 | 514 | ||
494 | window = window_setup(registry, output->width, 30, false); | ||
495 | if (!window) { | ||
496 | sway_abort("Failed to create window."); | ||
497 | } | ||
498 | desktop_shell_set_panel(registry->desktop_shell, output->output, window->surface); | ||
499 | |||
500 | int width, height; | ||
501 | get_text_size(window, &width, &height, "Test string for measuring purposes"); | ||
502 | window->height = height + MARGIN * 2; | ||
503 | |||
504 | poll_for_update(); | 515 | poll_for_update(); |
505 | 516 | ||
506 | window_teardown(window); | 517 | window_teardown(window); |