diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-08 16:19:31 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-08 16:25:07 +1000 |
commit | 9215ca0f01f7d155191d11fd9caa2574387c6f84 (patch) | |
tree | a1defcadae4b1d07388fd9e6bfe2a09051aec777 /sway | |
parent | Fix gaps in title textures and vertically center them (diff) | |
download | sway-9215ca0f01f7d155191d11fd9caa2574387c6f84.tar.gz sway-9215ca0f01f7d155191d11fd9caa2574387c6f84.tar.zst sway-9215ca0f01f7d155191d11fd9caa2574387c6f84.zip |
Align titles to baseline
This does the following:
* Adds a baseline argument to get_text_size (the baseline is the
distance from the top of the texture to the baseline).
* Stores the baseline in the container when calculating the title
height.
* Takes the baseline into account when calculating the config's max font
height.
* When rendering, pads the textures according to the baseline so they
line up.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/config.c | 21 | ||||
-rw-r--r-- | sway/debug-tree.c | 2 | ||||
-rw-r--r-- | sway/desktop/render.c | 12 | ||||
-rw-r--r-- | sway/tree/container.c | 10 | ||||
-rw-r--r-- | sway/tree/view.c | 3 |
5 files changed, 30 insertions, 18 deletions
diff --git a/sway/config.c b/sway/config.c index 89701640..6ff4da03 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -807,22 +807,31 @@ int workspace_output_cmp_workspace(const void *a, const void *b) { | |||
807 | return lenient_strcmp(wsa->workspace, wsb->workspace); | 807 | return lenient_strcmp(wsa->workspace, wsb->workspace); |
808 | } | 808 | } |
809 | 809 | ||
810 | static void find_font_height_iterator(struct sway_container *container, | 810 | static void find_font_height_iterator(struct sway_container *con, void *data) { |
811 | void *data) { | 811 | size_t amount_below_baseline = con->title_height - con->title_baseline; |
812 | size_t extended_height = config->font_baseline + amount_below_baseline; | ||
813 | if (extended_height > config->font_height) { | ||
814 | config->font_height = extended_height; | ||
815 | } | ||
816 | } | ||
817 | |||
818 | static void find_baseline_iterator(struct sway_container *con, void *data) { | ||
812 | bool *recalculate = data; | 819 | bool *recalculate = data; |
813 | if (*recalculate) { | 820 | if (*recalculate) { |
814 | container_calculate_title_height(container); | 821 | container_calculate_title_height(con); |
815 | } | 822 | } |
816 | if (container->title_height > config->font_height) { | 823 | if (con->title_baseline > config->font_baseline) { |
817 | config->font_height = container->title_height; | 824 | config->font_baseline = con->title_baseline; |
818 | } | 825 | } |
819 | } | 826 | } |
820 | 827 | ||
821 | void config_update_font_height(bool recalculate) { | 828 | void config_update_font_height(bool recalculate) { |
822 | size_t prev_max_height = config->font_height; | 829 | size_t prev_max_height = config->font_height; |
823 | config->font_height = 0; | 830 | config->font_height = 0; |
831 | config->font_baseline = 0; | ||
824 | 832 | ||
825 | root_for_each_container(find_font_height_iterator, &recalculate); | 833 | root_for_each_container(find_baseline_iterator, &recalculate); |
834 | root_for_each_container(find_font_height_iterator, NULL); | ||
826 | 835 | ||
827 | if (config->font_height != prev_max_height) { | 836 | if (config->font_height != prev_max_height) { |
828 | arrange_root(); | 837 | arrange_root(); |
diff --git a/sway/debug-tree.c b/sway/debug-tree.c index 973c6d88..9644f4e5 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c | |||
@@ -84,7 +84,7 @@ static int draw_node(cairo_t *cairo, struct sway_node *node, | |||
84 | struct sway_node *focus, int x, int y) { | 84 | struct sway_node *focus, int x, int y) { |
85 | int text_width, text_height; | 85 | int text_width, text_height; |
86 | char *buffer = get_string(node); | 86 | char *buffer = get_string(node); |
87 | get_text_size(cairo, "monospace", &text_width, &text_height, | 87 | get_text_size(cairo, "monospace", &text_width, &text_height, NULL, |
88 | 1, false, buffer); | 88 | 1, false, buffer); |
89 | cairo_save(cairo); | 89 | cairo_save(cairo); |
90 | cairo_rectangle(cairo, x + 2, y, text_width - 2, text_height); | 90 | cairo_rectangle(cairo, x + 2, y, text_width - 2, text_height); |
diff --git a/sway/desktop/render.c b/sway/desktop/render.c index ecac262e..8a6f63aa 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c | |||
@@ -466,12 +466,12 @@ static void render_titlebar(struct sway_output *output, | |||
466 | &texture_box.width, &texture_box.height); | 466 | &texture_box.width, &texture_box.height); |
467 | title_ob_width = texture_box.width; | 467 | title_ob_width = texture_box.width; |
468 | 468 | ||
469 | // The title texture might be shorter than the config->font_height, in | 469 | // The title texture might be shorter than the config->font_height, |
470 | // which case we need to pad it as evenly as possible above and below. | 470 | // in which case we need to pad it above and below. |
471 | int ob_padding_total = config->font_height * output_scale - | 471 | int ob_padding_above = (config->font_baseline - con->title_baseline) |
472 | texture_box.height; | 472 | * output_scale; |
473 | int ob_padding_above = floor(ob_padding_total / 2); | 473 | int ob_padding_below = (config->font_height - con->title_height) |
474 | int ob_padding_below = ceil(ob_padding_total / 2); | 474 | * output_scale - ob_padding_above; |
475 | 475 | ||
476 | // Render texture | 476 | // Render texture |
477 | texture_box.x = (x - output_x + TITLEBAR_H_PADDING) * output_scale; | 477 | texture_box.x = (x - output_x + TITLEBAR_H_PADDING) * output_scale; |
diff --git a/sway/tree/container.c b/sway/tree/container.c index cbbb1f56..ccd79f0e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -455,8 +455,8 @@ static void update_title_texture(struct sway_container *con, | |||
455 | int height = con->title_height * scale; | 455 | int height = con->title_height * scale; |
456 | 456 | ||
457 | cairo_t *c = cairo_create(NULL); | 457 | cairo_t *c = cairo_create(NULL); |
458 | get_text_size(c, config->font, &width, NULL, scale, config->pango_markup, | 458 | get_text_size(c, config->font, &width, NULL, NULL, scale, |
459 | "%s", con->formatted_title); | 459 | config->pango_markup, "%s", con->formatted_title); |
460 | cairo_destroy(c); | 460 | cairo_destroy(c); |
461 | 461 | ||
462 | cairo_surface_t *surface = cairo_image_surface_create( | 462 | cairo_surface_t *surface = cairo_image_surface_create( |
@@ -505,10 +505,12 @@ void container_calculate_title_height(struct sway_container *container) { | |||
505 | } | 505 | } |
506 | cairo_t *cairo = cairo_create(NULL); | 506 | cairo_t *cairo = cairo_create(NULL); |
507 | int height; | 507 | int height; |
508 | get_text_size(cairo, config->font, NULL, &height, 1, config->pango_markup, | 508 | int baseline; |
509 | "%s", container->formatted_title); | 509 | get_text_size(cairo, config->font, NULL, &height, &baseline, 1, |
510 | config->pango_markup, "%s", container->formatted_title); | ||
510 | cairo_destroy(cairo); | 511 | cairo_destroy(cairo); |
511 | container->title_height = height; | 512 | container->title_height = height; |
513 | container->title_baseline = baseline; | ||
512 | } | 514 | } |
513 | 515 | ||
514 | /** | 516 | /** |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 312c62d1..53215b40 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -935,7 +935,8 @@ static void update_marks_texture(struct sway_view *view, | |||
935 | int height = view->container->title_height * scale; | 935 | int height = view->container->title_height * scale; |
936 | 936 | ||
937 | cairo_t *c = cairo_create(NULL); | 937 | cairo_t *c = cairo_create(NULL); |
938 | get_text_size(c, config->font, &width, NULL, scale, false, "%s", buffer); | 938 | get_text_size(c, config->font, &width, NULL, NULL, scale, false, |
939 | "%s", buffer); | ||
939 | cairo_destroy(c); | 940 | cairo_destroy(c); |
940 | 941 | ||
941 | cairo_surface_t *surface = cairo_image_surface_create( | 942 | cairo_surface_t *surface = cairo_image_surface_create( |