aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--render.c11
-rw-r--r--wayland.c33
-rw-r--r--wayland.h2
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
@@ -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
diff --git a/wayland.h b/wayland.h
index f62819a4..bc044169 100644
--- a/wayland.h
+++ b/wayland.h
@@ -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;