diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2015-12-20 17:02:35 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2015-12-20 17:52:33 +0100 |
commit | d373a193acfccf7ce2c4118d0c5a0e91481e680a (patch) | |
tree | 1d7f8f346a9e520ed38781f638ecaa0c27db0916 | |
parent | Update README screenshot (diff) | |
download | sway-d373a193acfccf7ce2c4118d0c5a0e91481e680a.tar.gz sway-d373a193acfccf7ce2c4118d0c5a0e91481e680a.tar.zst sway-d373a193acfccf7ce2c4118d0c5a0e91481e680a.zip |
swaybar: pixel perfect layout
This should make the bar workspace button layout identical to the layout
used in i3.
-rw-r--r-- | swaybar/main.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/swaybar/main.c b/swaybar/main.c index 4d23e087..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); |
@@ -230,14 +233,14 @@ void bar_ipc_init(int outputi, const char *bar_id) { | |||
230 | } | 233 | } |
231 | 234 | ||
232 | if (bar_height) { | 235 | if (bar_height) { |
233 | if (json_object_get_int(bar_height) == -1) { | 236 | int width, height; |
234 | int width, height; | 237 | get_text_size(window, &width, &height, "Test string for measuring purposes"); |
235 | get_text_size(window, &width, &height, "Test string for measuring purposes"); | 238 | int bar_height_value = json_object_get_int(bar_height); |
236 | window->height = height + MARGIN * 2; | 239 | if (bar_height_value > 0) { |
237 | } | 240 | margin = (bar_height_value - height) / 2; |
238 | else { | 241 | ws_ver_padding = margin - 1.5; |
239 | window->height = json_object_get_int(bar_height) + MARGIN * 2; | ||
240 | } | 242 | } |
243 | window->height = height + margin * 2; | ||
241 | } | 244 | } |
242 | 245 | ||
243 | if (_colors) { | 246 | if (_colors) { |
@@ -332,12 +335,12 @@ void render() { | |||
332 | int width, height; | 335 | int width, height; |
333 | get_text_size(window, &width, &height, "%s", line); | 336 | get_text_size(window, &width, &height, "%s", line); |
334 | 337 | ||
335 | cairo_move_to(window->cairo, window->width - MARGIN - width, (window->height - height) / 2 ); | 338 | cairo_move_to(window->cairo, window->width - margin - width, margin); |
336 | pango_printf(window, "%s", line); | 339 | pango_printf(window, "%s", line); |
337 | 340 | ||
338 | // Workspaces | 341 | // Workspaces |
339 | cairo_set_line_width(window->cairo, 2.0); | 342 | cairo_set_line_width(window->cairo, 1.0); |
340 | int x = 1; | 343 | double x = 0.5; |
341 | int i; | 344 | int i; |
342 | for (i = 0; i < workspaces->length; ++i) { | 345 | for (i = 0; i < workspaces->length; ++i) { |
343 | struct workspace *ws = workspaces->items[i]; | 346 | struct workspace *ws = workspaces->items[i]; |
@@ -352,19 +355,20 @@ void render() { | |||
352 | } else { | 355 | } else { |
353 | box_colors = colors.inactive_workspace; | 356 | box_colors = colors.inactive_workspace; |
354 | } | 357 | } |
358 | |||
355 | cairo_set_source_u32(window->cairo, box_colors.background); | 359 | cairo_set_source_u32(window->cairo, box_colors.background); |
356 | 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); |
357 | cairo_fill(window->cairo); | 361 | cairo_fill(window->cairo); |
358 | 362 | ||
359 | cairo_set_source_u32(window->cairo, box_colors.border); | 363 | cairo_set_source_u32(window->cairo, box_colors.border); |
360 | 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); |
361 | cairo_stroke(window->cairo); | 365 | cairo_stroke(window->cairo); |
362 | 366 | ||
363 | cairo_set_source_u32(window->cairo, box_colors.text); | 367 | cairo_set_source_u32(window->cairo, box_colors.text); |
364 | cairo_move_to(window->cairo, x + MARGIN, (window->height - height) / 2 ); | 368 | cairo_move_to(window->cairo, (int)x + ws_hor_padding, margin); |
365 | pango_printf(window, "%s", ws->name); | 369 | pango_printf(window, "%s", ws->name); |
366 | 370 | ||
367 | x += width + MARGIN * 2 + MARGIN; | 371 | x += width + ws_hor_padding * 2 + ws_spacing; |
368 | } | 372 | } |
369 | } | 373 | } |
370 | 374 | ||
@@ -477,7 +481,7 @@ int main(int argc, char **argv) { | |||
477 | 481 | ||
478 | int desired_output = atoi(argv[optind]); | 482 | int desired_output = atoi(argv[optind]); |
479 | struct output_state *output = registry->outputs->items[desired_output]; | 483 | struct output_state *output = registry->outputs->items[desired_output]; |
480 | 484 | ||
481 | window = window_setup(registry, output->width, 30, false); | 485 | window = window_setup(registry, output->width, 30, false); |
482 | if (!window) { | 486 | if (!window) { |
483 | sway_abort("Failed to create window."); | 487 | sway_abort("Failed to create window."); |
@@ -508,7 +512,6 @@ int main(int argc, char **argv) { | |||
508 | line[0] = '\0'; | 512 | line[0] = '\0'; |
509 | } | 513 | } |
510 | 514 | ||
511 | |||
512 | poll_for_update(); | 515 | poll_for_update(); |
513 | 516 | ||
514 | window_teardown(window); | 517 | window_teardown(window); |