From daa2975b21a2b36c7f1b9bcf8fb0c7f552ebcfce Mon Sep 17 00:00:00 2001 From: Felix Palmen Date: Sun, 13 Oct 2024 07:33:42 +0200 Subject: [PATCH] Xmoji: Fix font settings for tooltips There was already a resource `tooltipFont` implemented, but not documented. For fallback, it uses the class name (`Font`), but this creates a problem because it was also used for the `emojiFont`, which should almost always be a different font. Therefore: * add a `classname` property to `FontOptions`, and use this in Widget_createFontResName(), so we can override the class name for the emoji font. * Use class `EmojiFont` when creating the emoji font in xmoji.c * Document the `tooltipFont` resource in README.md, together with an example using the `Font` resource. Fixes: #15 --- README.md | 12 ++++++++---- src/bin/xmoji/font.h | 1 + src/bin/xmoji/widget.c | 3 ++- src/bin/xmoji/xmoji.c | 8 +++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4d9c95d..e9b8fda 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,9 @@ individual widgets. * `font` (class `Font`): The font for display of normal text. Default: `sans`. -* `emojiFont` (class `Font`): The font for display of emojis. Default: +* `tooltipFont` (class `Font`): The font for display of tooltips. Default: + `sans`. +* `emojiFont` (class `EmojiFont`): The font for display of emojis. Default: `emoji`. ### Generic rendering options @@ -156,10 +158,12 @@ names. The following colors are available: ### Example -The following X resources configure a different emoji font, a slightly larger -scroll bar, a dark color scheme and a shorter delay before displaying emoji -names (by scoping the value only to EmojiButton): +The following X resources configure a slightly smaller default font (for +normal text and tooltips by specifying the class name), a different emoji +font, a slightly larger scroll bar, a dark color scheme and a shorter delay +before displaying emoji names (by scoping the value only to EmojiButton): + Xmoji*Font: sans-10 Xmoji*emojiFont: Twitter Color Emoji Xmoji*Foreground: #c8c6c5 Xmoji*Background: #211f1d diff --git a/src/bin/xmoji/font.h b/src/bin/xmoji/font.h index 70571e4..e108150 100644 --- a/src/bin/xmoji/font.h +++ b/src/bin/xmoji/font.h @@ -27,6 +27,7 @@ typedef enum FontGlyphType typedef struct FontOptions { + const char *classname; float maxUnscaledDeviation; uint8_t pixelFractionBits; } FontOptions; diff --git a/src/bin/xmoji/widget.c b/src/bin/xmoji/widget.c index 20a449b..09d366c 100644 --- a/src/bin/xmoji/widget.c +++ b/src/bin/xmoji/widget.c @@ -260,7 +260,8 @@ Font *Widget_createFontResName(void *self, const char *name, { if (!name) name = "font"; XRdb *rdb = X11Adapter_resources(); - XRdb_register(rdb, "Font", name); + XRdb_register(rdb, options && options->classname + ? options->classname : "Font", name); const char *pattern = XRdb_value(rdb, XRdbKey(Widget_resname(self), name), XRQF_OVERRIDES); char *reqpat = 0; diff --git a/src/bin/xmoji/xmoji.c b/src/bin/xmoji/xmoji.c index 76c96d9..d4e8771 100644 --- a/src/bin/xmoji/xmoji.c +++ b/src/bin/xmoji/xmoji.c @@ -501,7 +501,13 @@ static int startup(void *app) Config_injectorFlags(self->config)); /* Create emoji font */ - self->emojiFont = Widget_createFontResName(win, "emojiFont", "emoji", 0); + FontOptions options = { + .classname = "EmojiFont", + .maxUnscaledDeviation = 0, + .pixelFractionBits = (uint8_t)-1 + }; + self->emojiFont = Widget_createFontResName(win, + "emojiFont", "emoji", &options); ConfigChangedEventArgs ea = { 0 }; onscalechanged(self, 0, &ea);