phillbush / xmenu

a x11 menu utility
Other
296 stars 26 forks source link

font not properly loaded #15

Closed B4rb3rouss closed 3 years ago

B4rb3rouss commented 3 years ago

The font defined in config.h is not loaded. It seems to be only "sans". Actually, only a font found in ~/.Xresources is used, but is not suitable for xmenu. i.e. :

-misc-dejavu sans mono-medium-r-normal-*-17-*-*-*-*-*-iso10646-1

I didn't manage to make xmenu.c handle config.h properly. Instead, I changed the Resource used and now, the font is the good one.

in ~/.Xresources :

*faceName: DejaVuSansMono:pixelsize=12:antialias=true

And applied this diff:

    diff --git a/xmenu.c b/xmenu.c
index 51412b3..0069264 100644
--- a/xmenu.c
+++ b/xmenu.c
@@ -225,7 +225,7 @@ initresources(void)
    config.separator_color = strdup(xval.addr);
  if (XrmGetResource(xdb, "xmenu.border", "*", &type, &xval) == True)
    config.border_color = strdup(xval.addr);
- if (XrmGetResource(xdb, "xmenu.font", "*", &type, &xval) == True)
+ if (XrmGetResource(xdb, "xmenu.faceName", "*", &type, &xval) == True)
    config.font = strdup(xval.addr);

  XrmDestroyDatabase(xdb);

It is more like a workaround than a real fix... sorry for that.

phillbush commented 3 years ago

It occurs because (1) there are two types of font specification in X, the old X Logical Font Description and the modern Fontconfig, xmenu uses the modern fontconfig; and (2), xmenu gives preference to the configuration in .Xresources over config.h.
So if you are using the old-style X Logical Font Description in your .Xresources, xmenu will try to use that and fail, because it'll not understand the font description.

The solution is to add the following line to your .Xresources:

xmenu.font: DejaVuSansMono:pixelsize=12:antialias=true

A specific xmenu.font will override the more general *font in your .Xresources.

There's no need to change the code.

B4rb3rouss commented 3 years ago

I get it why my diff isn't appropriate. However, if xmenu find in Xresources this string "-misc-dejavu sans mono-medium-r-normal--17------iso10646-1", I guess it should fallback to fonts defined in config.h. That's not what's happening in my case.

The solution is to add the following line to your .Xresources:

It might be written somewhere in README (maybe I missed it).

btw, thank you for xmenu, it was missing :)

B4rb3rouss commented 3 years ago

It might be written somewhere in README (maybe I missed it).

That's in the manpage, sorry :/

phillbush commented 3 years ago

However, if xmenu find in Xresources this string -misc-dejavu sans mono-medium-r-normal-*-17-*-*-*-*-*-iso10646-1, I guess it should fallback to fonts defined in config.h. That's not what's happening in my case.

If I do it for the font X resource I would have to do it for all X resources, and that would add some overhead to xmenu initialization.