wob: port pulseaudio -> pipewire

This commit is contained in:
Colin 2024-03-03 07:22:03 +00:00
parent fd072883dc
commit 979d07d693
2 changed files with 18 additions and 19 deletions

View File

@ -8,10 +8,10 @@
#
{ config, lib, pkgs, ... }:
let
wob-pulse = pkgs.static-nix-shell.mkBash {
pname = "wob-pulse";
wob-audio = pkgs.static-nix-shell.mkBash {
pname = "wob-audio";
srcRoot = ./.;
pkgs = [ "coreutils" "gnugrep" "gnused" "pulseaudio" ];
pkgs = [ "coreutils" "gnugrep" "gnused" "wireplumber" ];
};
cfg = config.sane.programs.wob;
in
@ -35,7 +35,7 @@ in
sandbox.whitelistWayland = true;
suggestedPrograms = [
"wob-pulse"
"wob-audio"
];
fs.".config/wob/wob.ini".symlink.text = ''
@ -89,8 +89,8 @@ in
};
};
sane.programs.wob-pulse = {
packageUnwrapped = wob-pulse;
sane.programs.wob-audio = {
packageUnwrapped = wob-audio;
sandbox.method = "bwrap";
sandbox.whitelistAudio = true;
sandbox.extraRuntimePaths = [
@ -101,15 +101,15 @@ in
# "coreutils"
"gnugrep"
"gnused"
"pulseaudio" #< TODO: replace with just the one binary we need.
"wireplumber" #< TODO: replace with just the one binary we need.
];
services.wob-pulse = {
description = "wob-pulse: monitor pulseaudio and display volume changes on-screen";
services.wob-audio = {
description = "wob-audio: monitor audio and display volume changes on-screen";
after = [ "wob.service" ];
wantedBy = [ "wob.service" ];
serviceConfig = {
ExecStart = "${wob-pulse}/bin/wob-pulse";
ExecStart = "${wob-audio}/bin/wob-audio";
Type = "simple";
Restart = "always";
RestartSec = "20s";

View File

@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils -p gnugrep -p gnused -p pulseaudio
#!nix-shell -i bash -p coreutils -p gnugrep -p gnused -p wireplumber
set -e
@ -13,22 +13,21 @@ verbose() {
fi
}
volismuted() {
pactl get-sink-mute @DEFAULT_SINK@ | grep -q "Mute: yes"
}
volget() {
if volismuted; then
# returns audio volume, as an integer (0 - 100)
volLine="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)"
if echo "$volLine" | grep -q '\[MUTED\]'; then
verbose "muted"
printf "0"
echo "0"
else
pactl get-sink-volume @DEFAULT_SINK@ | head -n1 | cut -d'/' -f2 | sed 's/ //g' | sed 's/\%//'
vol="$(echo "$vol" | cut -d' ' -f2)"
echo "$(( $vol * 100 ))"
fi
}
notify_volume_change() {
verbose "notify_volume_change"
vol=$(volget)
vol="$(volget)"
verbose "got volume: %d -> %d" "$lastvol" "$vol"
if [ "$vol" != "$lastvol" ]; then
debug "notify wob: %d -> %d" "$lastvol" "$vol"