statuscmd

Description

This patch adds the ability to signal a status monitor program such as dwmblocks the location and button when clicking on the status bar. Alternatively, there is a version that executes shell commands defined in config.h instead of using signals.

Usage

Both the nosignal version and the dwmblocks version will run their respective shell commands/scripts with the environment variable BUTTON set to the button that was pressed.

With signals

Apply the statuscmd patch and set the STATUSBAR macro in config.h to the name of the status monitor.

Apply the corresponding statuscmd patch to your status monitor if there is one, or extend the program on your own. Feel free to add patches for other status monitors.

Patching status monitors

void sighandler(int signum, siginfo_t *si, void *ucontext)
{
	int signal = signum - SIGRTMIN;
	int button = si->si_value.sival_int; /* if button is zero, the signal is not from a button press */
	... /* do whatever you want */
}
struct sigaction sa = { .sa_sigaction = sighandler, .sa_flags = SA_SIGINFO };
sigaction(SIGRTMIN+signal, &sa, NULL);

Without signals

Apply the statuscmd-nosignal patch and fill the statuscmds array in config.h with StatusCmd structs, which take a shell command string and an integer identifier.

When setting the status, print the integer identifier as a raw byte before its respective text.

For example, with statuscmds defined as such:

static const StatusCmd statuscmds[] = {
	{ "volume",  1 },
	{ "cpu",     2 },
	{ "battery", 3 },
};

And root name set like this:

xsetroot -name "$(printf '\x01Volume |\x02 CPU |\x03 Battery')"

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

Example

A script run from dwm or dwmblocks with this patch might look like this:

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

Notes

The signal version is not compatible with OpenBSD since it relies on sigqueue.

Be careful with newline characters in the status text since '\n' is equal to '\x0a', which is a valid signal number. The problem where having certain undrawable characters in the status bar can make dwm laggy is fixed since dwm will not attempt to draw them with this patch.

Download

dwm patches

If using status2d, use these patches instead of the above ones on top of a build already patched with status2d:

Status monitor patches

Author