render: csd_title(): use a custom font, sized based on the title bar’s height

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.
This commit is contained in:
Daniel Eklöf 2021-07-22 21:23:59 +02:00
parent 4a41575cb5
commit 0cf7a19616
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 43 additions and 3 deletions

View file

@ -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);

View file

@ -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

View file

@ -20,6 +20,7 @@
#include <xdg-activation-v1.h>
#endif
#include <fcft/fcft.h>
#include <tllist.h>
#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;