From 8ffc556d441013e06236f144020b91ea4e3a3f86 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 31 Aug 2021 19:42:22 +0200 Subject: main: verify primary font is monospaced at startup Load a couple of ASCII glyphs and check if their advance widths matches. If not, warn the user that the font is probably not monospaced. This can be disabled by setting tweak.font-monospace-warn=no. Closes #704. --- config.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index ac6dd24d..ca1278df 100644 --- a/config.c +++ b/config.c @@ -2452,6 +2452,9 @@ parse_section_tweak( conf->tweak.box_drawing_solid_shades ? "yes" : "no"); } + else if (strcmp(key, "font-monospace-warn") == 0) + conf->tweak.font_monospace_warn = str_to_bool(value); + else { LOG_AND_NOTIFY_ERR("%s:%u: [tweak]: %s: invalid key", path, lineno, key); return false; @@ -2957,6 +2960,7 @@ config_load(struct config *conf, const char *conf_path, .damage_whole_window = false, .box_drawing_base_thickness = 0.04, .box_drawing_solid_shades = true, + .font_monospace_warn = true, }, .notifications = tll_init(), @@ -3356,3 +3360,51 @@ config_font_list_destroy(struct config_font_list *font_list) font_list->count = 0; font_list->arr = NULL; } + + +bool +check_if_font_is_monospaced(const char *pattern, + user_notifications_t *notifications) +{ + struct fcft_font *f = fcft_from_name( + 1, (const char *[]){pattern}, ":size=8"); + + if (f == NULL) + return true; + + static const wchar_t chars[] = {L'a', L'i', L'l', L'M', L'W'}; + + bool is_monospaced = true; + int last_width = -1; + + for (size_t i = 0; i < sizeof(chars) / sizeof(chars[0]); i++) { + const struct fcft_glyph *g = fcft_glyph_rasterize( + f, chars[i], FCFT_SUBPIXEL_NONE); + + if (g == NULL) + continue; + + if (last_width >= 0 && g->advance.x != last_width) { + LOG_WARN("%s: font does not appear to be monospace; " + "check your config, or disable this warning by " + "setting [tweak].font-monospace-warn=no", + pattern); + + user_notification_add( + notifications, + USER_NOTIFICATION_WARNING, + "%s: font does not appear to be monospace; " + "check your config, or disable this warning by " + "settting \033[1m[tweak].font-monospace-warn=no\033[22m", + pattern); + + is_monospaced = false; + break; + } + + last_width = g->advance.x; + } + + fcft_destroy(f); + return is_monospaced; +} -- cgit v1.3 From 73b488a2b217bf43fb88a14f6c664e33b0827663 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 31 Aug 2021 20:01:35 +0200 Subject: config: codespell: setting has only two ‘t’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index ca1278df..4241060d 100644 --- a/config.c +++ b/config.c @@ -3395,7 +3395,7 @@ check_if_font_is_monospaced(const char *pattern, USER_NOTIFICATION_WARNING, "%s: font does not appear to be monospace; " "check your config, or disable this warning by " - "settting \033[1m[tweak].font-monospace-warn=no\033[22m", + "setting \033[1m[tweak].font-monospace-warn=no\033[22m", pattern); is_monospaced = false; -- cgit v1.3 From a669ba0bf6b764d0b25a83f887a41b30dd23eacf Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 25 Sep 2021 02:46:22 +0100 Subject: config: simplify initialization of color table in config_load() --- config.c | 77 ++++++++++++++++++++++++++-------------------------------------- 1 file changed, 31 insertions(+), 46 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 4241060d..b148ec47 100644 --- a/config.c +++ b/config.c @@ -31,7 +31,19 @@ static const uint32_t default_foreground = 0xdcdccc; static const uint32_t default_background = 0x111111; -static const uint32_t default_regular[] = { +#define cube6(r, g) \ + r|g|0x00, r|g|0x5f, r|g|0x87, r|g|0xaf, r|g|0xd7, r|g|0xff + +#define cube36(r) \ + cube6(r, 0x0000), \ + cube6(r, 0x5f00), \ + cube6(r, 0x8700), \ + cube6(r, 0xaf00), \ + cube6(r, 0xd700), \ + cube6(r, 0xff00) + +static const uint32_t default_color_table[256] = { + // Regular 0x222222, 0xcc9393, 0x7f9f7f, @@ -40,9 +52,8 @@ static const uint32_t default_regular[] = { 0xdc8cc3, 0x93e0e3, 0xdcdccc, -}; -static const uint32_t default_bright[] = { + // Bright 0x666666, 0xdca3a3, 0xbfebbf, @@ -51,6 +62,22 @@ static const uint32_t default_bright[] = { 0xfcace3, 0xb3ffff, 0xffffff, + + // 6x6x6 RGB cube + cube36(0x000000), + cube36(0x5f0000), + cube36(0x870000), + cube36(0xaf0000), + cube36(0xd70000), + cube36(0xff0000), + + // 24 shades of gray + 0x080808, 0x121212, 0x1c1c1c, 0x262626, + 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e, + 0x585858, 0x626262, 0x6c6c6c, 0x767676, + 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e, + 0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, + 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee }; static const char *const binding_action_map[] = { @@ -2887,25 +2914,6 @@ config_load(struct config *conf, const char *conf_path, .colors = { .fg = default_foreground, .bg = default_background, - .table = { - default_regular[0], - default_regular[1], - default_regular[2], - default_regular[3], - default_regular[4], - default_regular[5], - default_regular[6], - default_regular[7], - - default_bright[0], - default_bright[1], - default_bright[2], - default_bright[3], - default_bright[4], - default_bright[5], - default_bright[6], - default_bright[7], - }, .alpha = 0xffff, .selection_fg = 0x80000000, /* Use default bg */ .selection_bg = 0x80000000, /* Use default fg */ @@ -2966,30 +2974,7 @@ config_load(struct config *conf, const char *conf_path, .notifications = tll_init(), }; - /* Initialize the color cube */ - { - /* First 16 entries correspond to the "regular" and "bright" - * colors, and have already been initialized */ - - /* Then follows 216 RGB shades */ - for (size_t r = 0; r < 6; r++) { - for (size_t g = 0; g < 6; g++) { - for (size_t b = 0; b < 6; b++) { - uint8_t red = r ? r * 40 + 55 : 0; - uint8_t green = g ? g * 40 + 55 : 0; - uint8_t blue = b ? b * 40 + 55 : 0; - conf->colors.table[16 + r * 6 * 6 + g * 6 + b] - = red << 16 | green << 8 | blue << 0; - } - } - } - - /* And finally 24 shades of gray */ - for (size_t i = 0; i < 24; i++) { - uint8_t level = i * 10 + 8; - conf->colors.table[232 + i] = level << 16 | level << 8 | level << 0; - } - } + memcpy(conf->colors.table, default_color_table, sizeof(default_color_table)); tokenize_cmdline("notify-send -a ${app-id} -i ${app-id} ${title} ${body}", &conf->notify.argv.args); -- cgit v1.3 From 9361e7c0723c15328d4e66747d5d1822ccb5c484 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 25 Sep 2021 22:01:03 +0100 Subject: config: add comments to default_color_table[] about color channel values --- config.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index b148ec47..e3b79e3e 100644 --- a/config.c +++ b/config.c @@ -64,6 +64,7 @@ static const uint32_t default_color_table[256] = { 0xffffff, // 6x6x6 RGB cube + // (color channels = i ? i*40+55 : 0, where i = 0..5) cube36(0x000000), cube36(0x5f0000), cube36(0x870000), @@ -72,6 +73,7 @@ static const uint32_t default_color_table[256] = { cube36(0xff0000), // 24 shades of gray + // (color channels = i*10+8, where i = 0..23) 0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e, 0x585858, 0x626262, 0x6c6c6c, 0x767676, -- cgit v1.3