This patch adds the ability to execute shell commands based on the mouse button and position when clicking the status bar.


Fill 'statuscmds' with commands. Choose which command to run by prefixing the status text with a raw byte of the command's index in 'statuscmds', offset by +1 since '\0' terminates strings. statuscmds[0] runs by default if there is no index to the left of the mouse position. The mouse button clicked is exported as $BUTTON.


With these commands:

static const char *statuscmds[] = { "volume", "cpu", "battery" };

And root name set like this:

xsetroot -name "$(echo -e 'volume |\x02 cpu |\x03 battery')"

Clicking on 'volume |' would run volume, clicking on ' cpu |' would run cpu and clicking on ' battery' would run battery.

The cpu script could look like this:

case $BUTTON in
	1) notify-send "CPU usage" "$(ps axch -o cmd,%cpu --sort=-%cpu | head)";;
	3) st -e htop;;


If you have 10 or more commands, make sure to be careful when adding or removing newline characters since '\n' is equal to '\x0a'. The problem where having certain unprintable characters such as '\n' in the status string can make dwm laggy is "fixed", since they are not copied to the string that is actually drawn.

dwmblocks integration

A program that sets the status for dwm such as dwmblocks can be patched to manage the commands while dwm only finds the location clicked in the status bar. This way, no changes are needed in dwm when adding or reordering modules.

Instead of running a command from within dwm using the control character as an index, the dwm-statuscmd-signal patch sends a SIGUSR1 signal to dwmblocks with the button and control character encoded into the signal value.

The dwmblocks-statuscmd patch makes dwmblocks put each block's signal in front of its output text and handles the SIGUSR1 signal by running the block's command with $BUTTON exported.