From 3d7cacdf2be9cdb9c68605bb97297d786ddfabe7 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Tue, 12 Nov 2024 14:11:40 +0300 Subject: [PATCH] Swayscript: Add audio notifications. --- home/config/sway/module/Screenshot.nix | 4 ++-- package/swayscript/script/DisplayWidget.nix | 4 ++++ package/swayscript/script/Reload.nix | 1 + package/swayscript/script/Sound.nix | 1 + package/swayscript/script/Util.nix | 14 +++++++++++++- package/swayscript/script/Vpn.nix | 1 + static/{Screenshot.ogg => Long.ogg} | Bin static/{Screenrec.ogg => Short.ogg} | Bin 8 files changed, 22 insertions(+), 3 deletions(-) rename static/{Screenshot.ogg => Long.ogg} (100%) rename static/{Screenrec.ogg => Short.ogg} (100%) diff --git a/home/config/sway/module/Screenshot.nix b/home/config/sway/module/Screenshot.nix index 0cd3fa99..effc66d3 100644 --- a/home/config/sway/module/Screenshot.nix +++ b/home/config/sway/module/Screenshot.nix @@ -16,8 +16,8 @@ selection = "slurp -d -b ${color.bg.light}${opacity} -c ${color.fg.light} -w 0 -s 00000000"; in { text = let - notifyStart = "${pkgs.pipewire}/bin/pw-cat -p ${} &"; - notifyEnd = "${pkgs.pipewire}/bin/pw-cat -p ${} &"; + notifyStart = "${pkgs.pipewire}/bin/pw-cat -p ${} &"; + notifyEnd = "${pkgs.pipewire}/bin/pw-cat -p ${} &"; picEdit = ''swappy -f - -o -''; picFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; picPrepFile = prepFile "\${XDG_PICTURES_DIR[0]}" "png"; diff --git a/package/swayscript/script/DisplayWidget.nix b/package/swayscript/script/DisplayWidget.nix index b65683d1..edd38d6a 100644 --- a/package/swayscript/script/DisplayWidget.nix +++ b/package/swayscript/script/DisplayWidget.nix @@ -1,6 +1,7 @@ { ... }: { text = '' function monitor() { + _notify_short toggle() { local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power') @@ -22,6 +23,7 @@ } function gaming() { + _notify_short toggle() { local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status') @@ -43,6 +45,7 @@ } function dnd() { + _notify_short toggle() { local state=$(makoctl mode) @@ -59,6 +62,7 @@ # Reset the state of everything. function displayreset() { + _notify_long [[ "''$(monitorstate)" = "Y" ]] && monitorreset [[ "''$(gamingstate)" = "Y" ]] && gamingreset [[ "''$(recordingstate)" = "Y" ]] && pkill wf-recorder diff --git a/package/swayscript/script/Reload.nix b/package/swayscript/script/Reload.nix index 6348f9ba..a2775962 100644 --- a/package/swayscript/script/Reload.nix +++ b/package/swayscript/script/Reload.nix @@ -2,6 +2,7 @@ text = '' # Reload. function reload() { + # _notify_long re() { # Sway. swaymsg reload diff --git a/package/swayscript/script/Sound.nix b/package/swayscript/script/Sound.nix index fa864efc..0329afde 100644 --- a/package/swayscript/script/Sound.nix +++ b/package/swayscript/script/Sound.nix @@ -1,6 +1,7 @@ { ... }: { text = '' function sound_output_cycle() { + _notify_short local IFS=$'\n' local current=$(pactl get-default-sink) local all=($(pactl list short sinks | cut -f2)) diff --git a/package/swayscript/script/Util.nix b/package/swayscript/script/Util.nix index 991d41ea..c59e7c7f 100644 --- a/package/swayscript/script/Util.nix +++ b/package/swayscript/script/Util.nix @@ -1,4 +1,8 @@ -{ ... }: { +{ + __findFile, + pkgs, + ... +}: { text = '' # Find currently active SWAYSOCK paths. function _sway_find_sockets() { @@ -11,5 +15,13 @@ SWAYSOCK="''${socket}" ''${1} done } + + function _notify_short() { + ${pkgs.pipewire}/bin/pw-cat -p ${} & + } + + function _notify_long() { + ${pkgs.pipewire}/bin/pw-cat -p ${} & + } ''; } diff --git a/package/swayscript/script/Vpn.nix b/package/swayscript/script/Vpn.nix index 3b7adf28..f3f4eb4e 100644 --- a/package/swayscript/script/Vpn.nix +++ b/package/swayscript/script/Vpn.nix @@ -2,6 +2,7 @@ text = '' # Toggle vpn. function vpn() { + _notify_short if [[ "$(_vpn)" = "on" ]]; then nmcli connection down vpn else diff --git a/static/Screenshot.ogg b/static/Long.ogg similarity index 100% rename from static/Screenshot.ogg rename to static/Long.ogg diff --git a/static/Screenrec.ogg b/static/Short.ogg similarity index 100% rename from static/Screenrec.ogg rename to static/Short.ogg