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
Provenance
- Commit
ce5a3b2- Tree
ba669bc- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
df7b8fd
4 files changed+55 added−9 removed
modified:doc/fuzzel.scd+3 added-3 removed
18 unmodified lines19 list the available outputs with *swaymsg -t get_outputs*.20 21 The default is to let the compositor choose output.22 23-*-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_.26 27 *-i*,*--icon-theme*=_NAME_28 Icon theme to use. Example: _Adwaita_. Default: _hicolor_.29 104 unmodified linesmodified:CHANGELOG.md+4 added
14 unmodified lines151617181920212223242526158 unmodified linesExpand all14 unmodified lines
## Unreleased### Added### Changed
* `-f,--font` now supports explicit font fallbacks.
### Deprecated### Removed### Fixed### Security158 unmodified linesExpand allmodified:wayland.c+47 added-5 removed
1 #include "wayland.h"2 3 #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 lines143 struct matches *matches;144 145 const struct render_options *render_options;146 146- 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 lines849 if (wayl->dpi != new_dpi) {850 char attrs[256];851 snprintf(attrs, sizeof(attrs), "dpi=%.2f", new_dpi);852 851- 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;857 858 if (wayl->font_reloaded.cb != NULL)594 unmodified lines1453 .enter = &surface_enter,1454 .leave = &surface_leave,1455 };1456 1457+static void1458+parse_font_spec(const char *font_spec, size_t *count, char ***names)1459+{1460+ tll(char *) fonts = tll_init();1461+1462+ 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++;1469+1470+ size_t len = strlen(font);1471+ while (len > 0 && isspace(font[len - 1]))1472+ len--;1473+1474+ if (font[0] == '\0')1475+ continue;1476+1477+ tll_push_back(fonts, strndup(font, len));1478+ }1479+ free(copy);1480+1481+ *count = tll_length(fonts);1482+ *names = malloc(*count * sizeof((*names)[0]));1483+1484+ char **p = *names;1485+ tll_foreach(fonts, it) {1486+ *p = it->item;1487+ tll_remove(fonts, it);1488+ p++;1489+ }1490+}1491+1492 struct wayland *1493 wayl_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 lines1505 .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 };1515 1516+ parse_font_spec(font_spec, &wayl->font_count, &wayl->font_names);1517+1518 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 lines1659 wayl_flush(wayl);1660 wl_display_disconnect(wayl->display);1661 }1662 1663+ for (size_t i = 0; i < wayl->font_count; i++)1664+ free(wayl->font_names[i]);1665+ free(wayl->font_names);1666+1667 free(wayl->output_name);1625- free(wayl->font_name);1668 free(wayl);1669 }1670 1671 void16 unmodified linesmodified:wayland.h+1 added-1 removed
19 unmodified lines20 struct 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);26 27 void wayl_destroy(struct wayland *wayl);28 5 unmodified lines