sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

index.md (3627B)


      1 statuscmd
      2 =========
      3 
      4 Description
      5 -----------
      6 This patch adds the ability to signal a status monitor program such as
      7 [dwmblocks](https://github.com/torrinfail/dwmblocks) the location and button
      8 when clicking on the status bar. Alternatively, there is a version that
      9 executes shell commands defined in config.h instead of using signals.
     10 
     11 Usage
     12 -----
     13 Both the nosignal version and the dwmblocks version will run their respective
     14 shell commands/scripts with the environment variable BUTTON set to the button
     15 that was pressed.
     16 
     17 ### With signals
     18 Apply the statuscmd patch and set the `STATUSBAR` macro in config.h
     19 to the name of the status monitor.
     20 
     21 Apply the corresponding statuscmd patch to your status monitor if there is
     22 one, or extend the program on your own. Feel free to add patches for other
     23 status monitors.
     24 
     25 #### Patching status monitors
     26 * Associate each section with a signal number in the range of 1-31.
     27 * When setting the status text, print each section's respective signal number
     28   as a raw byte before its text.
     29 * Create a signal handler:
     30 
     31 	void sighandler(int signum, siginfo_t *si, void *ucontext)
     32 	{
     33 		int signal = signum - SIGRTMIN;
     34 		int button = si->si_value.sival_int; /* if button is zero, the signal is not from a button press */
     35 		... /* do whatever you want */
     36 	}
     37 
     38 * Register the signal handler for each section in the following way, with
     39   'signal' being the same signal from the first step:
     40 
     41 	struct sigaction sa = { .sa_sigaction = sighandler, .sa_flags = SA_SIGINFO };
     42 	sigaction(SIGRTMIN+signal, &sa, NULL);
     43 
     44 ### Without signals
     45 Apply the statuscmd-nosignal patch and fill the `statuscmds` array in config.h
     46 with `StatusCmd` structs, which take a shell command string and an integer
     47 identifier.
     48 
     49 When setting the status, print the integer identifier as a raw byte before its
     50 respective text.
     51 
     52 For example, with `statuscmds` defined as such:
     53 
     54 	static const StatusCmd statuscmds[] = {
     55 		{ "volume",  1 },
     56 		{ "cpu",     2 },
     57 		{ "battery", 3 },
     58 	};
     59 
     60 And root name set like this:
     61 
     62 	xsetroot -name "$(printf '\x01Volume |\x02 CPU |\x03 Battery')"
     63 
     64 Clicking on 'Volume |' would run `volume`, clicking on ' CPU |'
     65 would run `cpu` and clicking on ' Battery' would run `battery`.
     66 
     67 Example
     68 -------
     69 A script run from dwm or dwmblocks with this patch might look like this:
     70 
     71 	#!/bin/sh
     72 
     73 	case $BUTTON in
     74 		1) notify-send "CPU usage" "$(ps axch -o cmd,%cpu --sort=-%cpu | head)" ;;
     75 		3) st -e htop ;;
     76 	esac
     77 
     78 Notes
     79 -----
     80 The signal version is not compatible with OpenBSD since it relies on `sigqueue`.
     81 
     82 Be careful with newline characters in the status text since '\n' is equal to
     83 '\x0a', which is a valid signal number. The problem where having certain
     84 undrawable characters in the status bar can make dwm laggy is fixed since dwm
     85 will not attempt to draw them with this patch.
     86 
     87 Download
     88 --------
     89 ### dwm patches
     90 * [dwm-statuscmd-20210405-67d76bd.diff](dwm-statuscmd-20210405-67d76bd.diff)
     91 * [dwm-statuscmd-nosignal-20210402-67d76bd.diff](dwm-statuscmd-nosignal-20210402-67d76bd.diff)
     92 
     93 If using [status2d](https://dwm.suckless.org/patches/status2d/), use these patches instead of the
     94 above ones on top of a build already patched with status2d:
     95 
     96 * [dwm-statuscmd-status2d-20210405-60bb3df.diff](dwm-statuscmd-status2d-20210405-60bb3df.diff)
     97 * [dwm-statuscmd-nosignal-status2d-20210402-60bb3df.diff](dwm-statuscmd-nosignal-status2d-20210402-60bb3df.diff)
     98 
     99 ### Status monitor patches
    100 * [dwmblocks-statuscmd-20210402-96cbb45.diff](dwmblocks-statuscmd-20210402-96cbb45.diff)
    101 * [gocaudices](https://github.com/LordRusk/gocaudices/tree/master/patches/statuscmd)
    102 
    103 Author
    104 ------
    105 * Daniel Bylinka - <daniel.bylinka@gmail.com>