Custom font with dmenu

I found references at various places running dmenu like so :

dmenu_run -b -fn 'Inconsolata 12'

However, whatever variation of the font name I try, I always get dmenu: warning: cannot load font <font name>

fc-list | grep cons gives me:

/usr/share/fonts/truetype/inconsolata/Inconsolata.otf: Inconsolata:style=Medium

It does not show in xlsfonts and all the fonts that do show up with xlsfonts work fine.

What is the correct way to reference these fonts from command line ?

Also, is that a standard way to reference fonts or will it change when using programs like pango?


Solution 1:

The standard version of dmenu doesn't include support for xft fonts. To use fonts like Inconsolata you'll need to build a patched version of dmenu.

  1. Download the source code and the patch.
  2. Open up a terminal, cd to the directory containing both the source code and the patch.
  3. Run the following commands to apply the patch:

    tar zxvf dmenu-4.5.tar.gz
    cd dmenu-4.5
    mv ../dmenu-4.5-xft.diff .
    patch -p1 < dmenu-4.5-xft.diff
    
  4. To build the modified version of dmenu, you'll need to have the following packages installed: libxft-dev libxft2 libxinerama-dev

  5. UPDATE on UBUNTU 14.04 the build fails with

    fatal error: ft2build.h: No such file or directory

    to fix this edit the config.mk File and change

    XFTINC = -I/usr/local/include/freetype2

    to

    XFTINC = -I/usr/include/freetype2

  6. Run the following commands to build and install the modified version of dmenu:

    make
    sudo make install
    

Solution 2:

You must to use the X Logical Font Description (XLFD) full name for the font provided by xfontsel. For example, you can use something like this : -bitstream-*-*-*-*-*-12-*-*-*-*-*-*-*:

dmenu_run -b -fn -bitstream-*-*-*-*-*-12-*-*-*-*-*-*-*

xfontsell tool allows you to preview the different settings.

If you want to use a syntax like:

dmenu_run -b -fn <family>-<size>:<name>=<value>

which is closer to what you asked, you can use Xft support patch. See here the instructions about how to use a patch for dmenu.

Solution 3:

Since dmenu 4.6 (released in Nov 2015), XFT font rendering is enabled by default (4.6 Release Notes) and this just works:

dmenu_run -fn 'Inconsolata 12'