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;