aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/pango.c5
-rw-r--r--include/pango.h2
-rw-r--r--include/sway/config.h1
-rw-r--r--include/sway/tree/container.h1
-rw-r--r--sway/config.c21
-rw-r--r--sway/debug-tree.c2
-rw-r--r--sway/desktop/render.c12
-rw-r--r--sway/tree/container.c10
-rw-r--r--sway/tree/view.c3
-rw-r--r--swaybar/render.c14
-rw-r--r--swaynag/render.c10
11 files changed, 49 insertions, 32 deletions
diff --git a/common/pango.c b/common/pango.c
index 92703f80..ea71ac4a 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -103,7 +103,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
103} 103}
104 104
105void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, 105void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
106 double scale, bool markup, const char *fmt, ...) { 106 int *baseline, double scale, bool markup, const char *fmt, ...) {
107 static char buf[2048]; 107 static char buf[2048];
108 108
109 va_list args; 109 va_list args;
@@ -116,6 +116,9 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
116 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); 116 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
117 pango_cairo_update_layout(cairo, layout); 117 pango_cairo_update_layout(cairo, layout);
118 pango_layout_get_pixel_size(layout, width, height); 118 pango_layout_get_pixel_size(layout, width, height);
119 if (baseline) {
120 *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
121 }
119 g_object_unref(layout); 122 g_object_unref(layout);
120} 123}
121 124
diff --git a/include/pango.h b/include/pango.h
index 4492f01e..09a535a5 100644
--- a/include/pango.h
+++ b/include/pango.h
@@ -20,7 +20,7 @@ int escape_markup_text(const char *src, char *dest, int dest_length);
20PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, 20PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
21 const char *text, double scale, bool markup); 21 const char *text, double scale, bool markup);
22void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, 22void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
23 double scale, bool markup, const char *fmt, ...); 23 int *baseline, double scale, bool markup, const char *fmt, ...);
24void pango_printf(cairo_t *cairo, const char *font, 24void pango_printf(cairo_t *cairo, const char *font,
25 double scale, bool markup, const char *fmt, ...); 25 double scale, bool markup, const char *fmt, ...);
26 26
diff --git a/include/sway/config.h b/include/sway/config.h
index 2fef0081..b52bb681 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -349,6 +349,7 @@ struct sway_config {
349 enum sway_container_layout default_layout; 349 enum sway_container_layout default_layout;
350 char *font; 350 char *font;
351 size_t font_height; 351 size_t font_height;
352 size_t font_baseline;
352 bool pango_markup; 353 bool pango_markup;
353 size_t urgent_timeout; 354 size_t urgent_timeout;
354 enum sway_fowa focus_on_window_activation; 355 enum sway_fowa focus_on_window_activation;
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 6efecf7c..2735daa3 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -117,6 +117,7 @@ struct sway_container {
117 struct wlr_texture *title_unfocused; 117 struct wlr_texture *title_unfocused;
118 struct wlr_texture *title_urgent; 118 struct wlr_texture *title_urgent;
119 size_t title_height; 119 size_t title_height;
120 size_t title_baseline;
120 121
121 struct { 122 struct {
122 struct wl_signal destroy; 123 struct wl_signal destroy;
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
810static void find_font_height_iterator(struct sway_container *container, 810static 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
818static 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
821void config_update_font_height(bool recalculate) { 828void 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(
diff --git a/swaybar/render.c b/swaybar/render.c
index 702e863c..7303e70f 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -33,8 +33,8 @@ static uint32_t render_status_line_error(cairo_t *cairo,
33 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; 33 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
34 34
35 int text_width, text_height; 35 int text_width, text_height;
36 get_text_size(cairo, config->font, 36 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
37 &text_width, &text_height, output->scale, false, "%s", error); 37 output->scale, false, "%s", error);
38 38
39 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 39 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
40 uint32_t ideal_surface_height = ideal_height / output->scale; 40 uint32_t ideal_surface_height = ideal_height / output->scale;
@@ -63,7 +63,7 @@ static uint32_t render_status_line_text(cairo_t *cairo,
63 config->colors.focused_statusline : config->colors.statusline); 63 config->colors.focused_statusline : config->colors.statusline);
64 64
65 int text_width, text_height; 65 int text_width, text_height;
66 get_text_size(cairo, config->font, &text_width, &text_height, 66 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
67 output->scale, config->pango_markup, "%s", text); 67 output->scale, config->pango_markup, "%s", text);
68 68
69 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; 69 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
@@ -126,7 +126,7 @@ static uint32_t render_status_block(cairo_t *cairo,
126 uint32_t height = surface_height * output->scale; 126 uint32_t height = surface_height * output->scale;
127 127
128 int text_width, text_height; 128 int text_width, text_height;
129 get_text_size(cairo, config->font, &text_width, &text_height, 129 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
130 output->scale, block->markup, "%s", block->full_text); 130 output->scale, block->markup, "%s", block->full_text);
131 131
132 int margin = 3 * output->scale; 132 int margin = 3 * output->scale;
@@ -157,7 +157,7 @@ static uint32_t render_status_block(cairo_t *cairo,
157 int sep_width, sep_height; 157 int sep_width, sep_height;
158 if (!edge) { 158 if (!edge) {
159 if (config->sep_symbol) { 159 if (config->sep_symbol) {
160 get_text_size(cairo, config->font, &sep_width, &sep_height, 160 get_text_size(cairo, config->font, &sep_width, &sep_height, NULL,
161 output->scale, false, "%s", config->sep_symbol); 161 output->scale, false, "%s", config->sep_symbol);
162 uint32_t _ideal_height = sep_height + ws_vertical_padding * 2; 162 uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
163 uint32_t _ideal_surface_height = _ideal_height / output->scale; 163 uint32_t _ideal_surface_height = _ideal_height / output->scale;
@@ -297,7 +297,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
297 uint32_t height = surface_height * output->scale; 297 uint32_t height = surface_height * output->scale;
298 298
299 int text_width, text_height; 299 int text_width, text_height;
300 get_text_size(cairo, config->font, &text_width, &text_height, 300 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
301 output->scale, config->mode_pango_markup, 301 output->scale, config->mode_pango_markup,
302 "%s", mode); 302 "%s", mode);
303 303
@@ -379,7 +379,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
379 uint32_t height = surface_height * output->scale; 379 uint32_t height = surface_height * output->scale;
380 380
381 int text_width, text_height; 381 int text_width, text_height;
382 get_text_size(cairo, config->font, &text_width, &text_height, 382 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
383 output->scale, config->pango_markup, "%s", name); 383 output->scale, config->pango_markup, "%s", name);
384 384
385 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; 385 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
diff --git a/swaynag/render.c b/swaynag/render.c
index 766409e4..7db9fe60 100644
--- a/swaynag/render.c
+++ b/swaynag/render.c
@@ -12,7 +12,7 @@ static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) {
12 height -= swaynag->type->bar_border_thickness * swaynag->scale; 12 height -= swaynag->type->bar_border_thickness * swaynag->scale;
13 13
14 int text_width, text_height; 14 int text_width, text_height;
15 get_text_size(cairo, swaynag->type->font, &text_width, &text_height, 15 get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL,
16 swaynag->scale, true, "%s", swaynag->message); 16 swaynag->scale, true, "%s", swaynag->message);
17 17
18 int padding = swaynag->type->message_padding * swaynag->scale; 18 int padding = swaynag->type->message_padding * swaynag->scale;
@@ -34,7 +34,7 @@ static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) {
34static void render_details_scroll_button(cairo_t *cairo, 34static void render_details_scroll_button(cairo_t *cairo,
35 struct swaynag *swaynag, struct swaynag_button *button) { 35 struct swaynag *swaynag, struct swaynag_button *button) {
36 int text_width, text_height; 36 int text_width, text_height;
37 get_text_size(cairo, swaynag->type->font, &text_width, &text_height, 37 get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL,
38 swaynag->scale, true, "%s", button->text); 38 swaynag->scale, true, "%s", button->text);
39 39
40 int border = swaynag->type->button_border_thickness * swaynag->scale; 40 int border = swaynag->type->button_border_thickness * swaynag->scale;
@@ -60,10 +60,10 @@ static void render_details_scroll_button(cairo_t *cairo,
60static int get_detailed_scroll_button_width(cairo_t *cairo, 60static int get_detailed_scroll_button_width(cairo_t *cairo,
61 struct swaynag *swaynag) { 61 struct swaynag *swaynag) {
62 int up_width, down_width, temp_height; 62 int up_width, down_width, temp_height;
63 get_text_size(cairo, swaynag->type->font, &up_width, &temp_height, 63 get_text_size(cairo, swaynag->type->font, &up_width, &temp_height, NULL,
64 swaynag->scale, true, 64 swaynag->scale, true,
65 "%s", swaynag->details.button_up.text); 65 "%s", swaynag->details.button_up.text);
66 get_text_size(cairo, swaynag->type->font, &down_width, &temp_height, 66 get_text_size(cairo, swaynag->type->font, &down_width, &temp_height, NULL,
67 swaynag->scale, true, 67 swaynag->scale, true,
68 "%s", swaynag->details.button_down.text); 68 "%s", swaynag->details.button_down.text);
69 69
@@ -179,7 +179,7 @@ static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag,
179 struct swaynag_button *button = swaynag->buttons->items[button_index]; 179 struct swaynag_button *button = swaynag->buttons->items[button_index];
180 180
181 int text_width, text_height; 181 int text_width, text_height;
182 get_text_size(cairo, swaynag->type->font, &text_width, &text_height, 182 get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL,
183 swaynag->scale, true, "%s", button->text); 183 swaynag->scale, true, "%s", button->text);
184 184
185 int border = swaynag->type->button_border_thickness * swaynag->scale; 185 int border = swaynag->type->button_border_thickness * swaynag->scale;