From 9215ca0f01f7d155191d11fd9caa2574387c6f84 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 8 Sep 2018 16:19:31 +1000 Subject: 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. --- sway/config.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'sway/config.c') 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) { return lenient_strcmp(wsa->workspace, wsb->workspace); } -static void find_font_height_iterator(struct sway_container *container, - void *data) { +static void find_font_height_iterator(struct sway_container *con, void *data) { + size_t amount_below_baseline = con->title_height - con->title_baseline; + size_t extended_height = config->font_baseline + amount_below_baseline; + if (extended_height > config->font_height) { + config->font_height = extended_height; + } +} + +static void find_baseline_iterator(struct sway_container *con, void *data) { bool *recalculate = data; if (*recalculate) { - container_calculate_title_height(container); + container_calculate_title_height(con); } - if (container->title_height > config->font_height) { - config->font_height = container->title_height; + if (con->title_baseline > config->font_baseline) { + config->font_baseline = con->title_baseline; } } void config_update_font_height(bool recalculate) { size_t prev_max_height = config->font_height; config->font_height = 0; + config->font_baseline = 0; - root_for_each_container(find_font_height_iterator, &recalculate); + root_for_each_container(find_baseline_iterator, &recalculate); + root_for_each_container(find_font_height_iterator, NULL); if (config->font_height != prev_max_height) { arrange_root(); -- cgit v1.2.3