Skip to content

Commit

Permalink
Xmoji: Fix font settings for tooltips
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Zirias committed Oct 13, 2024
1 parent 0788726 commit daa2975
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/bin/xmoji/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef enum FontGlyphType

typedef struct FontOptions
{
const char *classname;
float maxUnscaledDeviation;
uint8_t pixelFractionBits;
} FontOptions;
Expand Down
3 changes: 2 additions & 1 deletion src/bin/xmoji/widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/bin/xmoji/xmoji.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit daa2975

Please sign in to comment.