diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index a00fc41b..26aae493 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -293,7 +293,7 @@ in enable = true; # we manage the greeter ourselves (TODO: merge this into sway config as well) useGreeter = false; - waybar.top = import ./waybar-top.nix; + waybar.top = import ./waybar-top.nix { inherit pkgs; }; # reset extra waybar style waybar.extra_style = ""; config = { diff --git a/hosts/modules/gui/sxmo/waybar-sxmo-status b/hosts/modules/gui/sxmo/waybar-sxmo-status new file mode 100755 index 00000000..e64dd5fd --- /dev/null +++ b/hosts/modules/gui/sxmo/waybar-sxmo-status @@ -0,0 +1,109 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p sxmo-utils -p sxmo-utils.runtimeDeps +# +# usage: +# waybar-sxmo-status widget1 [ widget2 [...]] +# +# where each widget is one of: +# - modem-state +# - modem-tech +# - modem-signal +# - wifi-status + +# sxmo_hook_statusbar.sh assumes: +# - mmcli, jq on PATH +# - sxmo_hook_icons.sh and sxmo_common.sh are sourcable +# - from sxmo_common, it only uses sxmobar (and aliases jq=gojq) + +# setup environment so that the hooks will be on PATH: +# - sxmo_hook_statusbar.sh +# - sxmo_hook_icons.sh +export HOME="${HOME:-/home/colin}" +export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" +export PATH="$XDG_CONFIG_HOME/sxmo/hooks:$PATH" + +# clunky interaction between us and sxmo_hook_statusbar.sh: +# - we export `sxmobar` to it, but within that function cannot modify the environment +# of *this* script, because it gets run in a different process. +# - so, `sxmobar` prints info to stdout, and then this script re-interprets that info. +# - practically, `sxmobar` prints shell commands, and then this script `eval`s them, to achieve that IPC. +sxmobar() { + action="$1" + shift + if [ "$action" = "-a" ]; then + while [ -n "$*" ]; do + arg="$1" + case "$arg" in + "-f"|"-b"|"-t"|"-e") + # foreground/background/text/emphasis: ignore it + shift + shift + ;; + *) + # begin arguments + break + ;; + esac + done + + echo "setitem $@" + fi +} +export -f sxmobar + +setitem() { + id="$1" + priority="$2" + value="$3" + case "$id" in + modem-state) + modem_state="$value" + ;; + modem-tech) + modem_tech="$value" + ;; + modem-signal) + modem_signal="$value" + ;; + wifi-status) + wifi_status="$value" + ;; + esac +} + +while [ -n "$*" ]; do + variable="$1" + shift + case "$variable" in + "--verbose") + set -x + ;; + "modem-state") + if [ -z "$modem_state" ]; then + eval "$(sxmo_hook_statusbar.sh modem)" + fi + echo -n "$modem_state" + ;; + "modem-tech") + if [ -z "$modem_tech" ]; then + eval "$(sxmo_hook_statusbar.sh modem)" + fi + echo -n "$modem_tech" + ;; + "modem-signal") + if [ -z "$modem_signal" ]; then + eval "$(sxmo_hook_statusbar.sh modem)" + fi + echo -n "$modem_signal" + ;; + "wifi-status") + if [ -z "$wifi_status" ]; then + eval "$(sxmo_hook_statusbar.sh network wifi wlan0)" + fi + echo -n "$wifi_status" + ;; + *) + echo -n "UNK: $variable" + ;; + esac +done diff --git a/hosts/modules/gui/sxmo/waybar-top.nix b/hosts/modules/gui/sxmo/waybar-top.nix index 5464ab40..b9b344e4 100644 --- a/hosts/modules/gui/sxmo/waybar-top.nix +++ b/hosts/modules/gui/sxmo/waybar-top.nix @@ -1,6 +1,14 @@ # docs: https://github.com/Alexays/Waybar/wiki/Configuration # format specifiers: https://fmt.dev/latest/syntax.html#syntax # this is merged with the sway/waybar-top.nix defaults +{ pkgs }: +let + waybar-sxmo-status = pkgs.static-nix-shell.mkBash { + pname = "waybar-sxmo-status"; + src = ./.; + pkgs = [ "sxmo-utils" "sxmo-utils.runtimeDeps" ]; + }; +in { height = 26; @@ -10,10 +18,12 @@ "custom/swaync" "clock" "battery" + "custom/sxmo-sane" + # "custom/sxmo" # "custom/sxmo/modem-state" - "custom/sxmo/modem-tech" - "custom/sxmo/modem-signal" - "custom/sxmo/wifi" + # "custom/sxmo/modem-tech" + # "custom/sxmo/modem-signal" + # "custom/sxmo/wifi" ]; "sway/workspaces" = { @@ -28,6 +38,14 @@ }; }; + "custom/sxmo-sane" = { + # this calls all the SXMO indicators, inline. + # so it works even without the "statusbar periodics" sxmo service running. + interval = 2; + format = "{}"; + exec = "${waybar-sxmo-status}/bin/waybar-sxmo-status modem-state modem-tech modem-signal wifi-status"; + }; + "custom/sxmo" = { # this gives wifi state, battery, mic/speaker, lockstate, time all as one widget. # a good starting point, but may want to split these apart later to make things configurable.