Better poly than sorry!

Better (mode-line) for StumpWM

As I was using StumpWM for the past week or so, I realized that a desktop completely devoid of any "widgets" is not my kind of thing. I don't want to run six separate programs for monitoring different things like display backlight, network connection and so on. I want this information to be always available somewhere. Vanilla StumpWM comes with no GUI at all, save for a simple input box and echo area, but you can enable something called "mode-line" (the concept is borrow from Emacs).

Well, the mode-line by itself is just a simple gray bar on top or at the bottom of a screen. You need to configure it for it to display anything useful.

So now I have, on the left side of a modeline: a clock, groups (desktops) and windows in current desktop.

On the right side I crammed a couple of indicators: volume, backlight intensity, WiFi signal strength and battery status:

And here's the code for all this, you can paste it directly to your .stumpwmrc

(load-module "cpu")
(setf *window-format* "%m%n%s%c")
(setf *mode-line-timeout* 0.7)

(defun get-volume ()
   (string #\newline)
   (run-shell-command "amixer sget Master | awk '/^ +Front L/{print $5}'" t)))

(defun get-backlight ()
  (car (split-string (run-shell-command "xbacklight" t) ".")))

(defun get-signal-strength ()
   (concat "." (string #\newline))
   (run-shell-command "awk 'NR==3{print $3}' /proc/net/wireless" t)))

(defun get-battery-status ()
  "Needs the upower utility to be installed in the system, i.e.

$ sudo dnf install -y upower"
   (string #\newline)
   (run-shell-command (concat
                       "upower -i /org/freedesktop/UPower/devices/battery_BAT0 "
                       "| grep perc "
                       "| awk '{print $2}'") t)))

(setf stumpwm:*screen-mode-line-format*
      (list "^2%d^]    ^1[|>^] %g    ^1[|>^] %W "
            " ^> "                      ; remaining elements become left-aligned
            "^2%c %t^]  "               ; CPU usage indicators, from load-module
            ;; my own indicators:
            "   Vol:"   '(:eval (get-volume))
            "   Disp:[" '(:eval (get-backlight))
            "]  WiFi:[" '(:eval (get-signal-strength))
            "]  BAT:["  '(:eval (get-battery-status)) "]"))