diff --git a/.gitignore b/.gitignore index 1cd791b..2e1a5c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ result/ +target/ diff --git a/home/audio/discord-mute.mp3 b/home/audio/discord-mute.mp3 new file mode 100644 index 0000000..986d999 Binary files /dev/null and b/home/audio/discord-mute.mp3 differ diff --git a/home/audio/discord-unmute.mp3 b/home/audio/discord-unmute.mp3 new file mode 100644 index 0000000..787e6bb Binary files /dev/null and b/home/audio/discord-unmute.mp3 differ diff --git a/home/modules/pipewire-controller.nix b/home/modules/pipewire-controller.nix new file mode 100644 index 0000000..6020473 --- /dev/null +++ b/home/modules/pipewire-controller.nix @@ -0,0 +1,58 @@ +{ lib, config, pkgs, ... }: + +let + cfg = config.snowhawk.pipewire-controller; + + pipewire-controller = + let + mpv = lib.getExe pkgs.mpv; + pamixer = lib.getExe pkgs.pamixer; + in + pkgs.writers.writeRustBin "pipewire-controller" { } '' + use std::{process::Command, str}; + + const MUTE_AUDIO: &str = "${../audio/discord-mute.mp3}"; + const UNMUTE_AUDIO: &str = "${../audio/discord-unmute.mp3}"; + + fn main() { + let mute_status = Command::new("${pamixer}") + .args(["--default-source", "--get-mute"]) + .output() + .expect("Unable to get mute status from pamixer") + .stdout; + + let mute_status = str::from_utf8(&mute_status[..]).expect("pamixer output wasn't a string"); + + if mute_status == "false" { + Command::new("${pamixer}") + .args(["--default-source", "--mute"]) + .output() + .expect("Unable to mute via pamixer"); + + Command::new("${mpv}") + .args(["--no-video", MUTE_AUDIO]) + .output() + .expect("Unable to play audio via mpv"); + } else { + Command::new("${pamixer}") + .args(["--default-source", "--unmute"]) + .output() + .expect("Unable to mute via pamixer"); + + Command::new("${mpv}") + .args(["--no-video", UNMUTE_AUDIO]) + .output() + .expect("Unable to play audio via mpv"); + } + } + ''; +in +{ + options.snowhawk.pipewire-controller = { + enable = lib.mkEnableOption "pipewire-controller home-manager module"; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ pipewire-controller ]; + }; +} diff --git a/hosts/snowhawk/home.nix b/hosts/snowhawk/home.nix index c7403dc..96f172e 100644 --- a/hosts/snowhawk/home.nix +++ b/hosts/snowhawk/home.nix @@ -14,6 +14,7 @@ playerctl.enable = true; alacritty.enable = true; defaultPrograms.enable = true; + pipewire-controller.enable = true; # Games xivlauncher.enable = true;