2024-09-28 05:28:02 +00:00
|
|
|
{ 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;
|
|
|
|
|
2024-09-28 06:24:28 +00:00
|
|
|
let mute_status = str::from_utf8(&mute_status[..]).expect("pamixer output wasn't a string").trim();
|
2024-09-28 05:28:02 +00:00
|
|
|
|
|
|
|
if mute_status == "false" {
|
|
|
|
Command::new("${pamixer}")
|
|
|
|
.args(["--default-source", "--mute"])
|
|
|
|
.output()
|
|
|
|
.expect("Unable to mute via pamixer");
|
|
|
|
|
|
|
|
Command::new("${mpv}")
|
2024-09-29 02:04:36 +00:00
|
|
|
.args(["--no-video", "--volume=80", MUTE_AUDIO])
|
2024-09-28 05:28:02 +00:00
|
|
|
.output()
|
|
|
|
.expect("Unable to play audio via mpv");
|
|
|
|
} else {
|
|
|
|
Command::new("${pamixer}")
|
|
|
|
.args(["--default-source", "--unmute"])
|
|
|
|
.output()
|
2024-09-28 06:40:47 +00:00
|
|
|
.expect("Unable to unmute via pamixer");
|
2024-09-28 05:28:02 +00:00
|
|
|
|
|
|
|
Command::new("${mpv}")
|
2024-09-29 02:04:36 +00:00
|
|
|
.args(["--no-video", "--volume=80", UNMUTE_AUDIO])
|
2024-09-28 05:28:02 +00:00
|
|
|
.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 {
|
2024-09-28 06:34:48 +00:00
|
|
|
snowhawk.sxhkd.enable = true;
|
|
|
|
|
|
|
|
services.sxhkd.keybindings = {
|
|
|
|
"alt + XF86TouchpadOn" = "${lib.getExe pipewire-controller}";
|
|
|
|
};
|
2024-09-28 05:28:02 +00:00
|
|
|
};
|
|
|
|
}
|