Skip to content
Myr

Add support for fallback fonts

Before adoption: this commit came in with the history the project adopted, so no landing records it.

-f,--font now accepts a comma separated list, consisting of the primary font, optionally followed by one or more fallback fonts.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent df7b8fd · Browse files · 4 files+55 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+55 added−9 removed

  • other:+55 added−9 removed

4 files+55 added−9 removed

modified:doc/fuzzel.scd+3 added-3 removed
18 unmodified lines
19 list the available outputs with *swaymsg -t get_outputs*.2021 The default is to let the compositor choose output.2223*-f*,*--font*=_FONT_24 Font and style to use, in fontconfig format. See *FONT FORMAT*.25 Default: _monospace_.23*-f*,*--font*=_FONT_[,_FALLBACK1_,_FALLBACK2_,...]24 Comma separated list of primary font, and fallback fonts, in25 FontConfig format. See *FONT FORMAT*. Default: _monospace_.2627*-i*,*--icon-theme*=_NAME_28 Icon theme to use. Example: _Adwaita_. Default: _hicolor_.29
104 unmodified lines
modified:CHANGELOG.md+4 added
modified:wayland.c+47 added-5 removed
1#include "wayland.h"23#include <stdlib.h>4#include <string.h>5#include <ctype.h>6#include <wctype.h>7#include <unistd.h>8#include <errno.h>9#include <locale.h>
133 unmodified lines
143 struct matches *matches;144145 const struct render_options *render_options;146146 char *font_name;147 char **font_names;148 size_t font_count;149 struct {150 font_reloaded_t cb;151 void *data;152 } font_reloaded;
696 unmodified lines
849 if (wayl->dpi != new_dpi) {850 char attrs[256];851 snprintf(attrs, sizeof(attrs), "dpi=%.2f", new_dpi);852851 font = fcft_from_name(1, (const char *[]){wayl->font_name}, attrs);853 font = fcft_from_name(854 wayl->font_count, (const char **)wayl->font_names, attrs);855 if (font == NULL)856 return false;857858 if (wayl->font_reloaded.cb != NULL)
594 unmodified lines
1453 .enter = &surface_enter,1454 .leave = &surface_leave,1455};14561457static void1458parse_font_spec(const char *font_spec, size_t *count, char ***names)1459{1460 tll(char *) fonts = tll_init();14611462 char *copy = strdup(font_spec);1463 for (const char *font = strtok(copy, ",");1464 font != NULL;1465 font = strtok(NULL, ","))1466 {1467 while (*font != '\0' && isspace(*font))1468 font++;14691470 size_t len = strlen(font);1471 while (len > 0 && isspace(font[len - 1]))1472 len--;14731474 if (font[0] == '\0')1475 continue;14761477 tll_push_back(fonts, strndup(font, len));1478 }1479 free(copy);14801481 *count = tll_length(fonts);1482 *names = malloc(*count * sizeof((*names)[0]));14831484 char **p = *names;1485 tll_foreach(fonts, it) {1486 *p = it->item;1487 tll_remove(fonts, it);1488 p++;1489 }1490}14911492struct wayland *1493wayl_init(struct fdm *fdm,1494 struct render *render, struct prompt *prompt, struct matches *matches,1495 const struct render_options *render_options, bool dmenu_mode,1458 const char *output_name, const char *font_name,1496 const char *output_name, const char *font_spec,1497 font_reloaded_t font_reloaded_cb, void *data)1498{1499 struct wayland *wayl = malloc(sizeof(*wayl));1500 *wayl = (struct wayland){
4 unmodified lines
1505 .status = KEEP_RUNNING,1506 .exit_code = EXIT_FAILURE,1507 .dmenu_mode = dmenu_mode,1508 .output_name = output_name != NULL ? strdup(output_name) : NULL,1471 .font_name = strdup(font_name),1509 .render_options = render_options,1510 .font_reloaded = {1511 .cb = font_reloaded_cb,1512 .data = data,1513 },1514 };15151516 parse_font_spec(font_spec, &wayl->font_count, &wayl->font_names);15171518 wayl->display = wl_display_connect(NULL);1519 if (wayl->display == NULL) {1520 LOG_ERR("failed to connect to wayland; no compositor running?");1521 goto out;
137 unmodified lines
1659 wayl_flush(wayl);1660 wl_display_disconnect(wayl->display);1661 }16621663 for (size_t i = 0; i < wayl->font_count; i++)1664 free(wayl->font_names[i]);1665 free(wayl->font_names);16661667 free(wayl->output_name);1625 free(wayl->font_name);1668 free(wayl);1669}16701671void
16 unmodified lines
modified:wayland.h+1 added-1 removed
19 unmodified lines
20struct wayland *wayl_init(21 struct fdm *fdm,22 struct render *render, struct prompt *prompt, struct matches *matches,23 const struct render_options *render_options, bool dmenu_mode,24 const char *output_name, const char *font_name,24 const char *output_name, const char *font_spec,25 font_reloaded_t font_reloaded_cb, void *data);2627void wayl_destroy(struct wayland *wayl);28
5 unmodified lines