From daf046861c2ba4b998b0ad337fd20a24a5d02062 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 4 Jan 2024 13:07:35 +0000 Subject: [PATCH] wob: implement as part of sway instead of exclusive to sxmo --- hosts/common/programs/wob.nix | 57 ++++++++++++++++++- hosts/modules/gui/sway/default.nix | 2 +- hosts/modules/gui/sxmo/default.nix | 10 ++-- .../modules/gui/sxmo/hooks/sxmo_hook_start.sh | 3 +- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/hosts/common/programs/wob.nix b/hosts/common/programs/wob.nix index 5326c019..dd3ab56c 100644 --- a/hosts/common/programs/wob.nix +++ b/hosts/common/programs/wob.nix @@ -2,9 +2,11 @@ # - # - `wob -vv` to see config defaults # +# the wob services defined here are largely based on those from SXMO. +# # this should arguably be just a (user) service. nothing actually needs `wob` on the PATH. # -{ config, lib, ... }: +{ config, lib, pkgs, ... }: let cfg = config.sane.programs.wob; in @@ -60,14 +62,65 @@ in Restart = "always"; RestartSec = "20s"; }; + path = [ cfg.package ]; script = '' wobsock="$XDG_RUNTIME_DIR/${cfg.config.sock}" rm -f "$wobsock" || true - mkfifo "$wobsock" && ${cfg.package}/bin/wob <> "$wobsock" + mkfifo "$wobsock" && wob <> "$wobsock" # TODO: cleanup should be done in a systemd OnFailure, or OnExit, or whatever rm -f "$wobsock" ''; }; + + services.wob-pulse = { + description = "notify wob when pulseaudio volume changes"; + wantedBy = [ "wob.service" ]; + serviceConfig = { + Type = "simple"; + Restart = "always"; + RestartSec = "20s"; + }; + path = with pkgs; [ + # coreutils + gnugrep + gnused + pulseaudio + ]; + + script = '' + + volismuted() { + pactl get-sink-mute @DEFAULT_SINK@ | grep -q "Mute: yes" + } + + volget() { + if volismuted; then + printf "0" + else + pactl get-sink-volume @DEFAULT_SINK@ | head -n1 | cut -d'/' -f2 | sed 's/ //g' | sed 's/\%//' + fi + } + + notify_volume_change() { + vol=$(volget) + if [ "$vol" != "$lastvol" ]; then + printf "%s\n" "$vol" > "$XDG_RUNTIME_DIR/${cfg.config.sock}" + fi + lastvol="$vol" + } + + pactl subscribe | while read -r line; do + case "$line" in + "Event 'change' on sink "*) + notify_volume_change + ;; + "Event 'change' on source "*) + # microphone volume changed. ignore. + ;; + esac + done + ''; + }; }; } diff --git a/hosts/modules/gui/sway/default.nix b/hosts/modules/gui/sway/default.nix index 21e7887c..f76263ed 100644 --- a/hosts/modules/gui/sway/default.nix +++ b/hosts/modules/gui/sway/default.nix @@ -181,7 +181,7 @@ in "playerctl" # for waybar & particularly to have playerctld running # "mako" # notification daemon "swaynotificationcenter" # notification daemon - # # "pavucontrol" + "wob" # render volume changes on-screen # "gnome.gnome-bluetooth" # XXX(2023/05/14): broken # "gnome.gnome-control-center" # XXX(2023/06/28): depends on webkitgtk4_1 "sway-contrib.grimshot" diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index a35f2c5f..ef2d2e6b 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -269,7 +269,6 @@ in "sfeed" # want this here so that the user's ~/.sfeed/sfeedrc gets created # "superd" # make superctl (used by sxmo) be on PATH # "sway-autoscaler" - "wob" # volume/brightness on-screen display ]; persist.byStore.cryptClearOnBoot = [ @@ -628,15 +627,18 @@ in serviceConfig.RestartSec = "20s"; }; in { + # these are defined here, and started mostly in sxmo_hook_start.sh. + # the ones commented our here are the ones i explicitly no longer use. + # uncommenting them here *won't* cause them to be auto-started. sxmo_autosuspend = sxmoService "autosuspend"; - sxmo_battery_monitor = sxmoService "battery_monitor"; + # sxmo_battery_monitor = sxmoService "battery_monitor"; sxmo_desktop_widget = sxmoService "hook_desktop_widget"; sxmo_hook_lisgd = sxmoService "hook_lisgdstart"; sxmo_menumode_toggler = sxmoService "menumode_toggler"; sxmo_modemmonitor = sxmoService "modemmonitor"; - sxmo_networkmonitor = sxmoService "networkmonitor"; + # sxmo_networkmonitor = sxmoService "networkmonitor"; sxmo_notificationmonitor = sxmoService "notificationmonitor"; - sxmo_soundmonitor = sxmoService "soundmonitor"; + # sxmo_soundmonitor = sxmoService "soundmonitor"; # sxmo_wob = sxmoService "wob"; sxmo-x11-status = sxmoService "status_xsetroot"; diff --git a/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh b/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh index 7336abc9..17ee39fd 100755 --- a/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh +++ b/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh @@ -64,7 +64,8 @@ systemctl --user start sxmo_notificationmonitor # monitor for headphone for statusbar # this also invokes `wob` whenever the volume is changed -systemctl --user start sxmo_soundmonitor +# don't: my volume monitoring is handled by sway +# systemctl --user start sxmo_soundmonitor # rotate UI based on physical display angle by default if [ -n "$SXMO_AUTOROTATE" ]; then