Troubleshooters.Com®, Linux Library and Steve's ctwm Secret Stash Present:

Incorporating dmenu in ctwm

Contents:

Introduction

If you type more than 20 words per minute, your WMDE (Window Manager or Desktop Environment) gives you a substantial productivity boost if you incorporate Suckless Tools' dmenu into your WMDE. Ctwm is no exception: In fact ctwm benefits even more from dmenu because if ctwm's menus become un-navigable for some reason, you can still use dmenu to run editors and terminals.

Install dmenu

Most distros have a package for dmenu, and most of those packages work reasonably well. If possible, install dmenu from a package. Otherwise, go to Suckless Tools, download dmenu, and follow the instructions for compilation.

Careful!

As of September 2017, the current dmenu version is 4.7. Some distributions, such as Debian, offer very old dmenu versions with their package manager. Some distros offer broken or incomplete dmenu versions. Unless your distribution gives you a modern, working ctwm, you might be better off hand-compiling dmenu.

Compilations from Suckless Tools dmenu source code, as well as most distros' dmenu packages, yield a very small horizontal menu across the top of the screen, containing an alphabetized list of every executable on $PATH. You get that simply by running the dmenu_run command. Run the command and look for the menu, and if you don't see the menu, troubleshoot.

Make dmenu Vertical, Large Font, High Contrast, and Case Insensitive

For those not lucky enough to have 20/5 vision, the tiny horizontal menu with almost no contrast is insufficient to work quickly. Squinting is the enemy productivity: You must know at a glance. So you're going to make yourself a shellscript, called dmenu_run_vertical, which you can put anywhere. It doesn't need to be on $PATH, because the only place it's ever called from is various WMDEs, where its entire path can be configured. So if for some reason you put dmenu_run_vertical in /usr/local/share, you'll need to record its location, within ~/.ctwmrc as /usr/local/share/dmenu_run_vertical. Anyway, here's approximately what dmenu_run_vertical looks like:

#!/bin/sh

dmenu_run  -i -l 26  \
  -fn 12x24 \
  -nf yellow -nb black \
  -sf black -sb white

All the preceding shellscript does is run dmenu_run with a set of arguments to make the menu of executables case insensitive in both search and sort (-i), vertical instead of horizontal (-l, 26 lines of menu (the 26 in -l26, gives it a big font (-fn 12x24), high contrast (-nf yellow -nb black), and high contrast for the highlighted item (-sf black -sb white).

dmenu_run_vertical assumes that dmenu_run is on $PATH, so if it isn't, put the whole path to dmenu_run in dmenu_run_vertical.

You'll probably need to adjust some of this shellscript's arguments. I doubt you'll need to adjust the colors unless you have an unusual vision problem or you just like to experiment with colors. You'll probably want to change the number in the -l argument after you've completely set up the font's typeface, size, weight, and other style factors.

Setting the dmenu Font

Version 4.6 of dmenu, released in late 2015, changed dmenu's font mechanism from the old style "X logical font description" (the style that uses xfontsel) to "fontconfig" (the style that allows you to browser fonts with the fc-list command). The way you specify the -fn argument in your dmenu_run_vertical depends on whether your dmenu version is 4.6 or later, as opposed to 4.5 or earlier. Different distros package different versions of dmenu. Devuan packages the 4.5 version released in 2012. Void Linux packages the 4.7 version released in May 2017. Other distros? Who knows, but I'd guess it's all over the map.

Anyway, you should be able to change the dmenu font by changing the -fn argument. If you can't, further steps need to be taken...

Maybe You'll Get Lucky

Maybe you'll get lucky, and the default font will be the right size and style. If so, run with it.

Another lucky break would be if -fn 10x20, -fn 12x24, or -fn 9x15 work on your system and give you the program picklist appearance you want. If you don't get lucky, a little more exploration is called for.

However, if you find that dmenu_run_vertical displays with very small print or other productivity-killing font anomalies, you need to dive deeper, and the exact method of doing that depends on your dmenu version.

Find your dmenu version

Run the following command:

dmenu -v

The preceding command gives you a number like 4.7, 4.6, 4.5, etc. Fonts are handled differently for 4.6 and later, than for 4.5 and earlier.

Dmenu font setup with versions 4.5 and earlier

Dmenu 4.5 and earlier used the "X logical font description" style of defining fonts. It's the one with all the dashes. You can use xfontsel to assemble a font designation that works with your dmenu. Before doing that, I'd recommend using the locate command to find all instances of a file called fonts.alias, and try to find an alias that gives you an acceptable appearance.

Dmenu font setup with versions 4.6 and later

Dmenu 4.6 and later use the fontconfig system, which makes your life a whole lot easier, because the fc-list program reveals all your fonts, and how to refer to them. Each line of the output has two fields: The fully-pathed filename, and the font name. The following is an example, with each field taking up its own line just for proper display on a web page:

/usr/share/fonts/Type1/c059013l.pfb: 
Century Schoolbook L:style=Roman

As mentioned before, the real output would have the preceding on one line, but I put a linebreak between the fields so it can be read on a small device. If you wanted to use the preceding font, at 18 points, in dmenu, your -fn command would look as follows:

-fn "Century Schoolbook L:style=Roman:size=18"

In the preceding, the doublequotes mean you don't need special escapes for spaces. All you did was take the second field of the output of fc_list for the font in question, and append

:size=18
. It's pretty easy when you et used to it: MUCH easier than the old methods involving xfontsel and the various fonts.alias files.

The path/file field tells you the kind of font. Notice the Type1 in the path? That means this is a type 1 font, and is therefore fully scaleable. Fonts from the 75dpi, 100dpi, and misc groups aren't fully scaleable. At sizes less than 17 point, the system uses interpolation techniques to make them look pretty good. Above 17 points, they start to have too much spacing, uneven spacing, and a sort of "small letters on a large area" problem.

To find all the TrueType fonts, use the following command:

fc-list | grep -i ttf

Here are some other commands to find specific types of fonts:

fc-list | grep misc
fc-list | grep Type1
fc-list | grep 100dpi
fc-list | grep 75dpi

Connect dmenu With a ctwm hotkey

You previously made your dmenu_run_vertical shellscript and for some odd reason put it in /usr/local/share. To have the Shift+Ctrl+semicolon hotkey run it, put the following line in your ~ctwmrc file:

"semicolon" = s | c  : all  : f.exec "/usr/local/share/dmenu_run_vertical"

Now the question is where to put the preceding line. The best place to put it is with all your other keyboard hotkeys. If you have no keyboard hotkeys, then the best place to put it is right below the mouse click definitions, which all begin with "Button1" or "Button2" ... "Button9". Put the line below those, after suitable blank lines and an appropriate comment, which starts with a pound sign (#).

Now left-click on the ctwm background, and from the menu pick:

Exit->No, restart ctwm

Then press Shift+Ctrl+semicolon, and notice that it runs dmenu_run_vertical. Troubleshoot as necessary. Feel free to change the hotkey to whatever is convenient for you.

Once you have this hotkey to dmenu, you can run a program in half the time it takes to move your hand to the mouse. If an often used program requires arguments, create a shellscript to run it with those arguments, and use dmenu to run that shellscript.

If you type at least 20 words per minute, I predict that after a month of dmenu integration, your workflow will depend on it, and you'll wonder how you ever got along without it.


[ Training | Troubleshooters.Com | Email Steve Litt ]