statuscmd
Add clickable status bar sections.
Description
This patch sends mouse button events to a status monitor. When clicking or scrolling on a section, dwm detects the section number and mouse button, then sends them to the status monitor via a signal.
The nosignal version executes shell commands defined in config.h instead of using signals.
Usage
Both the status monitor and nosignal versions will run their respective shell
commands/scripts with the environment variable BUTTON set to the pressed
button.
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 create one yourself. Feel free to add patches for other status monitors.
Patching status monitors
- Associate each section with a signal number in the range of 1-31.
- Print each section's signal number as a raw byte before its text.
- Print the signal number again after the text to end the clickable region.
Create a signal handler:
void sighandler(int signum, siginfo_t *si, void *ucontext) { int signal = signum - SIGRTMIN; /* if button is zero, the signal is not from a button press */ int button = si->si_value.sival_int; ... /* do whatever you want */ }Register the signal handler for each section, with
signalset to the section number: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 section number 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 '\01 Volume \01|\02 CPU \02|\03 Battery \03')"
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
printf '\01Click Me!\01'
- Handle mouse buttons in a switch statement:
1: left button2: middle button (pressing the scroll wheel)3: right button4: scrolling up5: scrolling down6: scrolling left7: scrolling right8: 4th button (backward)9: 5th button (forwards)
- Print the status text surrounded by its section number as a raw byte.
- If using printf, use octal codes as they're POSIX compliant. To represent
signal 30, use
\036.
- If using printf, use octal codes as they're POSIX compliant. To represent
signal 30, use
Notes
- The signal patch doesn't work on OpenBSD since it relies on
sigqueue. - Newline characters (
\n,\012,\x0a) get interpreted as a valid signal number 10. - This patch skips over undrawable characters when rendering the status bar text, which fixes a problem that makes dwm lag when trying to draw them.
Download
dwm patches
- dwm-statuscmd-20260124-a9aa0d8.diff
- dwm-statuscmd-20241009-8933ebc.diff
- dwm-statuscmd-20210405-67d76bd.diff
- dwm-statuscmd-nosignal-20210402-67d76bd.diff
When using status2d, apply these patches instead after patching status2d:
Status monitor patches
Authors
- Daniel Bylinka - daniel.bylinka@gmail.com
- Justinas Grigas - dev@jstnas.com