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

  1. Associate each section with a signal number in the range of 1-31.
  2. 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.
  3. 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 */
     }
    
  4. Register the signal handler for each section, with signal set 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'

Notes

Download

dwm patches

When using status2d, apply these patches instead after patching status2d:

Status monitor patches

Authors