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/config.c | |
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/config.c')
-rw-r--r-- | sway/config.c | 21 |
1 files changed, 15 insertions, 6 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(); |