aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-10-01 18:50:32 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-10-01 18:50:32 +0000
commita082fec786d44bfbe8d2172c6317121027735a6b (patch)
treecf2a9fc4a822f4701a0a90db41b1c3ac03dd333a /config.c
parentmeson/pkgbuild: bump version to 1.9.0 (diff)
parentMerge branch 'hacktober-theme' (diff)
Merge branch 'master' into releases/1.9
Diffstat (limited to 'config.c')
-rw-r--r--config.c131
1 files changed, 85 insertions, 46 deletions
diff --git a/config.c b/config.c
index ac6dd24d..e3b79e3e 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,24 @@ static const uint32_t default_bright[] = {
0xfcace3,
0xb3ffff,
0xffffff,
+
+ // 6x6x6 RGB cube
+ // (color channels = i ? i*40+55 : 0, where i = 0..5)
+ cube36(0x000000),
+ cube36(0x5f0000),
+ cube36(0x870000),
+ cube36(0xaf0000),
+ cube36(0xd70000),
+ 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,
+ 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e,
+ 0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6,
+ 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
};
static const char *const binding_action_map[] = {
@@ -2452,6 +2481,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;
@@ -2884,25 +2916,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 */
@@ -2957,35 +2970,13 @@ 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(),
};
- /* 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);
@@ -3356,3 +3347,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 "
+ "setting \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;
+}