aboutsummaryrefslogtreecommitdiff
path: root/wayland.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-07-22 19:23:59 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-07-24 09:02:42 +0000
commit0cf7a196163d51c344361bb2b79c145003dc3555 (patch)
tree88d72ceab929975c7cf07ef60df61f34895a02ef /wayland.c
parentrender: render_osd() now needs a ‘font’ argument (diff)
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.
Diffstat (limited to 'wayland.c')
-rw-r--r--wayland.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/wayland.c b/wayland.c
index 0679dee3..40852ec0 100644
--- a/wayland.c
+++ b/wayland.c
@@ -31,6 +31,33 @@
#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)
{
struct wayland *wayl = win->term->wl;
@@ -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