mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-26 07:57:59 -04:00
config: add csd.font option
This commit is contained in:
parent
9985b8c713
commit
50f59fe575
4 changed files with 95 additions and 18 deletions
98
config.c
98
config.c
|
|
@ -503,6 +503,52 @@ str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct config_font_list NOINLINE
|
||||||
|
str_to_fonts(const char *s, struct config *conf, const char *path, int lineno,
|
||||||
|
const char *section, const char *key)
|
||||||
|
{
|
||||||
|
size_t count = 0;
|
||||||
|
size_t size = 0;
|
||||||
|
struct config_font *fonts = NULL;
|
||||||
|
|
||||||
|
char *copy = xstrdup(s);
|
||||||
|
for (const char *font = strtok(copy, ",");
|
||||||
|
font != NULL;
|
||||||
|
font = strtok(NULL, ","))
|
||||||
|
{
|
||||||
|
/* Trim spaces, strictly speaking not necessary, but looks nice :) */
|
||||||
|
while (*font != '\0' && isspace(*font))
|
||||||
|
font++;
|
||||||
|
|
||||||
|
if (font[0] == '\0')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
struct config_font font_data;
|
||||||
|
if (!config_font_parse(font, &font_data)) {
|
||||||
|
LOG_AND_NOTIFY_ERR(
|
||||||
|
"%s:%d: [%s]: %s: invalid font specification: %s",
|
||||||
|
path, lineno, section, key, font);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count + 1 > size) {
|
||||||
|
size += 4;
|
||||||
|
fonts = xrealloc(fonts, size * sizeof(fonts[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
xassert(count + 1 <= size);
|
||||||
|
fonts[count++] = font_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(copy);
|
||||||
|
return (struct config_font_list){.arr = fonts, .count = count};
|
||||||
|
|
||||||
|
err:
|
||||||
|
free(copy);
|
||||||
|
free(fonts);
|
||||||
|
return (struct config_font_list){.arr = NULL, .count = 0};
|
||||||
|
}
|
||||||
|
|
||||||
static void NOINLINE
|
static void NOINLINE
|
||||||
free_argv(struct argv *argv)
|
free_argv(struct argv *argv)
|
||||||
{
|
{
|
||||||
|
|
@ -804,8 +850,9 @@ parse_section_main(const char *key, const char *value, struct config *conf,
|
||||||
|
|
||||||
struct config_font font_data;
|
struct config_font font_data;
|
||||||
if (!config_font_parse(font, &font_data)) {
|
if (!config_font_parse(font, &font_data)) {
|
||||||
LOG_ERR("%s:%d: [default]: %s: invalid font specification",
|
LOG_AND_NOTIFY_ERR(
|
||||||
path, lineno, key);
|
"%s:%d: [default]: %s: invalid font specification: %s",
|
||||||
|
path, lineno, key, font);
|
||||||
free(copy);
|
free(copy);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1328,6 +1375,17 @@ parse_section_csd(const char *key, const char *value, struct config *conf,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (strcmp(key, "font") == 0) {
|
||||||
|
struct config_font_list new_list = str_to_fonts(
|
||||||
|
value, conf, path, lineno, "csd", "font");
|
||||||
|
|
||||||
|
if (new_list.arr == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
config_font_list_destroy(&conf->csd.font);
|
||||||
|
conf->csd.font = new_list;
|
||||||
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "color") == 0) {
|
else if (strcmp(key, "color") == 0) {
|
||||||
uint32_t color;
|
uint32_t color;
|
||||||
if (!str_to_color(value, &color, true, conf, path, lineno, "csd", "color"))
|
if (!str_to_color(value, &color, true, conf, path, lineno, "csd", "color"))
|
||||||
|
|
@ -2706,6 +2764,20 @@ add_default_mouse_bindings(struct config *conf)
|
||||||
memcpy(conf->bindings.mouse.arr, bindings, sizeof(bindings));
|
memcpy(conf->bindings.mouse.arr, bindings, sizeof(bindings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void NOINLINE
|
||||||
|
config_font_list_clone(struct config_font_list *dst,
|
||||||
|
const struct config_font_list *src)
|
||||||
|
{
|
||||||
|
dst->count = src->count;
|
||||||
|
dst->arr = xmalloc(dst->count * sizeof(dst->arr[0]));
|
||||||
|
|
||||||
|
for (size_t j = 0; j < dst->count; j++) {
|
||||||
|
dst->arr[j].pt_size = src->arr[j].pt_size;
|
||||||
|
dst->arr[j].px_size = src->arr[j].px_size;
|
||||||
|
dst->arr[j].pattern = xstrdup(src->arr[j].pattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
config_load(struct config *conf, const char *conf_path,
|
config_load(struct config *conf, const char *conf_path,
|
||||||
user_notifications_t *initial_user_notifications,
|
user_notifications_t *initial_user_notifications,
|
||||||
|
|
@ -2811,6 +2883,7 @@ config_load(struct config *conf, const char *conf_path,
|
||||||
},
|
},
|
||||||
.csd = {
|
.csd = {
|
||||||
.preferred = CONF_CSD_PREFER_SERVER,
|
.preferred = CONF_CSD_PREFER_SERVER,
|
||||||
|
.font = {0},
|
||||||
.title_height = 26,
|
.title_height = 26,
|
||||||
.border_width = 5,
|
.border_width = 5,
|
||||||
.button_width = 26,
|
.button_width = 26,
|
||||||
|
|
@ -2955,6 +3028,9 @@ out:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret && conf->csd.font.count == 0)
|
||||||
|
config_font_list_clone(&conf->csd.font, &conf->fonts[0]);
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
for (size_t i = 0; i < conf->bindings.key.count; i++)
|
for (size_t i = 0; i < conf->bindings.key.count; i++)
|
||||||
xassert(conf->bindings.key.arr[i].action != BIND_ACTION_NONE);
|
xassert(conf->bindings.key.arr[i].action != BIND_ACTION_NONE);
|
||||||
|
|
@ -3107,19 +3183,9 @@ config_clone(const struct config *old)
|
||||||
spawn_template_clone(&conf->bell.command, &old->bell.command);
|
spawn_template_clone(&conf->bell.command, &old->bell.command);
|
||||||
spawn_template_clone(&conf->notify, &old->notify);
|
spawn_template_clone(&conf->notify, &old->notify);
|
||||||
|
|
||||||
for (size_t i = 0; i < ALEN(conf->fonts); i++) {
|
for (size_t i = 0; i < ALEN(conf->fonts); i++)
|
||||||
struct config_font_list *dst = &conf->fonts[i];
|
config_font_list_clone(&conf->fonts[i], &old->fonts[i]);
|
||||||
const struct config_font_list *src = &old->fonts[i];
|
config_font_list_clone(&conf->csd.font, &old->csd.font);
|
||||||
|
|
||||||
dst->count = src->count;
|
|
||||||
dst->arr = xmalloc(dst->count * sizeof(dst->arr[0]));
|
|
||||||
|
|
||||||
for (size_t j = 0; j < dst->count; j++) {
|
|
||||||
dst->arr[j].pt_size = src->arr[j].pt_size;
|
|
||||||
dst->arr[j].px_size = src->arr[j].px_size;
|
|
||||||
dst->arr[j].pattern = xstrdup(src->arr[j].pattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
conf->url.label_letters = xwcsdup(old->url.label_letters);
|
conf->url.label_letters = xwcsdup(old->url.label_letters);
|
||||||
spawn_template_clone(&conf->url.launch, &old->url.launch);
|
spawn_template_clone(&conf->url.launch, &old->url.launch);
|
||||||
|
|
@ -3182,6 +3248,8 @@ config_free(struct config conf)
|
||||||
config_font_list_destroy(&conf.fonts[i]);
|
config_font_list_destroy(&conf.fonts[i]);
|
||||||
free(conf.server_socket_path);
|
free(conf.server_socket_path);
|
||||||
|
|
||||||
|
config_font_list_destroy(&conf.csd.font);
|
||||||
|
|
||||||
free(conf.url.label_letters);
|
free(conf.url.label_letters);
|
||||||
spawn_template_free(&conf.url.launch);
|
spawn_template_free(&conf.url.launch);
|
||||||
for (size_t i = 0; i < conf.url.prot_count; i++)
|
for (size_t i = 0; i < conf.url.prot_count; i++)
|
||||||
|
|
|
||||||
2
config.h
2
config.h
|
|
@ -228,6 +228,8 @@ struct config {
|
||||||
uint32_t maximize;
|
uint32_t maximize;
|
||||||
uint32_t close;
|
uint32_t close;
|
||||||
} color;
|
} color;
|
||||||
|
|
||||||
|
struct config_font_list font;
|
||||||
} csd;
|
} csd;
|
||||||
|
|
||||||
size_t render_worker_count;
|
size_t render_worker_count;
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,10 @@ component.
|
||||||
Titlebar AARRGGBB color. Default: use the default _foreground_
|
Titlebar AARRGGBB color. Default: use the default _foreground_
|
||||||
color.
|
color.
|
||||||
|
|
||||||
|
*font*
|
||||||
|
Font to use for the title bar. This is a list of fonts, similar to
|
||||||
|
the main *font* option. Default: _primary font_.
|
||||||
|
|
||||||
*button-width*
|
*button-width*
|
||||||
Width, in pixels (subject to output scaling), of the
|
Width, in pixels (subject to output scaling), of the
|
||||||
minimize/maximize/close buttons. Default: _26_.
|
minimize/maximize/close buttons. Default: _26_.
|
||||||
|
|
|
||||||
|
|
@ -46,15 +46,18 @@ csd_reload_font(struct wl_window *win, int old_scale)
|
||||||
|
|
||||||
fcft_destroy(win->csd.font);
|
fcft_destroy(win->csd.font);
|
||||||
|
|
||||||
|
const char *patterns[conf->csd.font.count];
|
||||||
|
for (size_t i = 0; i < conf->csd.font.count; i++)
|
||||||
|
patterns[i] = conf->csd.font.arr[i].pattern;
|
||||||
|
|
||||||
char pixelsize[32];
|
char pixelsize[32];
|
||||||
snprintf(pixelsize, sizeof(pixelsize),
|
snprintf(pixelsize, sizeof(pixelsize),
|
||||||
"pixelsize=%u", conf->csd.title_height * scale * 1 / 2);
|
"pixelsize=%u", conf->csd.title_height * scale * 1 / 2);
|
||||||
|
|
||||||
LOG_DBG("loading CSD font \"%s:%s\" (old-scale=%d, scale=%d)",
|
LOG_DBG("loading CSD font \"%s:%s\" (old-scale=%d, scale=%d)",
|
||||||
conf->fonts->arr[0].pattern, pixelsize, old_scale, scale);
|
patterns[0], pixelsize, old_scale, scale);
|
||||||
|
|
||||||
win->csd.font = fcft_from_name(
|
win->csd.font = fcft_from_name(conf->csd.font.count, patterns, pixelsize);
|
||||||
1, &(const char *){conf->fonts->arr[0].pattern}, pixelsize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue