From 0cf7a196163d51c344361bb2b79c145003dc3555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 22 Jul 2021 21:23:59 +0200 Subject: [PATCH] =?UTF-8?q?render:=20csd=5Ftitle():=20use=20a=20custom=20f?= =?UTF-8?q?ont,=20sized=20based=20on=20the=20title=20bar=E2=80=99s=20heigh?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We still use the primary font, but use a custom size, based on the title bar’s height. This fixes an issue where the window title could be way too small, or way too big. And changed size when the terminal font size was changed. --- render.c | 11 ++++++++--- wayland.c | 33 +++++++++++++++++++++++++++++++++ wayland.h | 2 ++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/render.c b/render.c index 82720d22..8fb810b9 100644 --- a/render.c +++ b/render.c @@ -1675,9 +1675,14 @@ render_csd_title(struct terminal *term, const struct csd_data *info, title_text = _title_text; } - const int margin = 10 * term->scale; - render_osd(term, surf->surf, surf->sub, buf, title_text, fg, bg, - margin, (buf->height - term->fonts[0]->height) / 2); + struct wl_window *win = term->window; + const int margin = win->csd.font->space_advance.x > 0 + ? win->csd.font->space_advance.x + : win->csd.font->max_advance.x; + + render_osd(term, surf->surf, surf->sub, win->csd.font, + buf, title_text, fg, bg, margin, + (buf->height - win->csd.font->height) / 2); csd_commit(term, surf->surf, buf); free(_title_text); diff --git a/wayland.c b/wayland.c index 0679dee3..40852ec0 100644 --- a/wayland.c +++ b/wayland.c @@ -30,6 +30,33 @@ #include "util.h" #include "xmalloc.h" +static void +csd_reload_font(struct wl_window *win, int old_scale) +{ + struct terminal *term = win->term; + const struct config *conf = term->conf; + + const int scale = term->scale; + + bool enable_csd = win->csd_mode == CSD_YES && !win->is_fullscreen; + if (!enable_csd) + return; + if (win->csd.font != NULL && scale == old_scale) + return; + + fcft_destroy(win->csd.font); + + char pixelsize[32]; + snprintf(pixelsize, sizeof(pixelsize), + "pixelsize=%u", conf->csd.title_height * scale * 1 / 2); + + LOG_DBG("loading CSD font \"%s:%s\" (old-scale=%d, scale=%d)", + conf->fonts->arr[0].pattern, pixelsize, old_scale, scale); + + win->csd.font = fcft_from_name( + 1, &(const char *){conf->fonts->arr[0].pattern}, pixelsize); +} + static void csd_instantiate(struct wl_window *win) { @@ -46,6 +73,8 @@ csd_instantiate(struct wl_window *win) win, win->csd.surface[CSD_SURF_TITLE].surf, &win->csd.surface[i]); xassert(ret); } + + csd_reload_font(win, -1); } static void @@ -53,6 +82,9 @@ csd_destroy(struct wl_window *win) { struct terminal *term = win->term; + fcft_destroy(term->window->csd.font); + term->window->csd.font = NULL; + for (size_t i = 0; i < ALEN(win->csd.surface); i++) wayl_win_subsurface_destroy(&win->csd.surface[i]); shm_purge(term->render.chains.csd); @@ -294,6 +326,7 @@ update_term_for_output_change(struct terminal *term) render_resize(term, term->width / term->scale, term->height / term->scale); term_font_dpi_changed(term, old_scale); term_font_subpixel_changed(term); + csd_reload_font(term->window, old_scale); } static void diff --git a/wayland.h b/wayland.h index f62819a4..bc044169 100644 --- a/wayland.h +++ b/wayland.h @@ -20,6 +20,7 @@ #include #endif +#include #include #include "fdm.h" @@ -402,6 +403,7 @@ struct wl_window { struct { struct wl_surf_subsurf surface[CSD_SURF_COUNT]; + struct fcft_font *font; int move_timeout_fd; uint32_t serial; } csd;