From 74609a80d884e364b04cb6b33738f2ce6a46334c Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Fri, 22 Nov 2024 18:44:10 +0300 Subject: [PATCH] Swayscript: Silent on DND. --- home/file/mako/default.nix | 2 +- home/file/sway/module/Screenshot.nix | 4 ++-- package/swayscript/default.nix | 3 +-- package/swayscript/script/DisplayWidget.nix | 7 ++++--- package/swayscript/script/Notify.nix | 22 +++++++++++++++++++++ package/swayscript/script/Scratchpad.nix | 1 + package/swayscript/script/Sound.nix | 2 +- package/swayscript/script/Util.nix | 8 -------- package/swayscript/script/Vpn.nix | 2 +- 9 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 package/swayscript/script/Notify.nix diff --git a/home/file/mako/default.nix b/home/file/mako/default.nix index b34894ac..b52fdd65 100644 --- a/home/file/mako/default.nix +++ b/home/file/mako/default.nix @@ -20,7 +20,7 @@ in { margin = 32; max-history = max; max-visible = max; - on-notify = "exec ${pkgs.pipewire}/bin/pw-cat -p ${}"; + on-notify = "exec swayscript notify"; text-color = "#${config.module.style.color.bg.dark}"; width = 480; }; diff --git a/home/file/sway/module/Screenshot.nix b/home/file/sway/module/Screenshot.nix index d7f67e59..30dd5558 100644 --- a/home/file/sway/module/Screenshot.nix +++ b/home/file/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 = ''swayscript notify_short''; + notifyEnd = ''swayscript notify_long''; 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/default.nix b/package/swayscript/default.nix index 76c3fb65..7c43d033 100644 --- a/package/swayscript/default.nix +++ b/package/swayscript/default.nix @@ -2,5 +2,4 @@ pkgs, util, ... -} @args: - pkgs.writeShellScriptBin "swayscript" (util.catText (util.ls ./script) args + "\${@}") +} @args: pkgs.writeShellScriptBin "swayscript" (util.catText (util.ls ./script) args + "\${@}") diff --git a/package/swayscript/script/DisplayWidget.nix b/package/swayscript/script/DisplayWidget.nix index edd38d6a..ec2e7675 100644 --- a/package/swayscript/script/DisplayWidget.nix +++ b/package/swayscript/script/DisplayWidget.nix @@ -1,7 +1,7 @@ { ... }: { text = '' function monitor() { - _notify_short + 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') @@ -23,7 +23,7 @@ } function gaming() { - _notify_short + 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') @@ -45,13 +45,14 @@ } function dnd() { - _notify_short toggle() { local state=$(makoctl mode) if [[ "''${state}" = "dnd" ]]; then makoctl mode -s default + notify_short else + notify_short makoctl mode -s dnd fi diff --git a/package/swayscript/script/Notify.nix b/package/swayscript/script/Notify.nix new file mode 100644 index 00000000..5bfb5c37 --- /dev/null +++ b/package/swayscript/script/Notify.nix @@ -0,0 +1,22 @@ +{ + __findFile, + pkgs, + ... +}: { + text = '' + function notify() { + [[ "''$(dndstate)" = "Y" ]] && return + ${pkgs.pipewire}/bin/pw-cat -p ${} & + } + + function notify_short() { + [[ "''$(dndstate)" = "Y" ]] && return + ${pkgs.pipewire}/bin/pw-cat -p ${} & + } + + function notify_long() { + [[ "''$(dndstate)" = "Y" ]] && return + ${pkgs.pipewire}/bin/pw-cat -p ${} & + } + ''; +} diff --git a/package/swayscript/script/Scratchpad.nix b/package/swayscript/script/Scratchpad.nix index d8ae3457..b3e9c45b 100644 --- a/package/swayscript/script/Scratchpad.nix +++ b/package/swayscript/script/Scratchpad.nix @@ -2,6 +2,7 @@ text = '' # Kill all windows in Sway scratchpad. function scratchpad_kill() { + notify_short kill() { for window in $(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?) | select(.name == "__i3_scratch").floating_nodes[].id'); do swaymsg [ con_id="$window" ] kill diff --git a/package/swayscript/script/Sound.nix b/package/swayscript/script/Sound.nix index 0329afde..a92455f4 100644 --- a/package/swayscript/script/Sound.nix +++ b/package/swayscript/script/Sound.nix @@ -1,7 +1,7 @@ { ... }: { text = '' function sound_output_cycle() { - _notify_short + 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 c59e7c7f..6c91622d 100644 --- a/package/swayscript/script/Util.nix +++ b/package/swayscript/script/Util.nix @@ -15,13 +15,5 @@ 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 f3f4eb4e..b6759b3b 100644 --- a/package/swayscript/script/Vpn.nix +++ b/package/swayscript/script/Vpn.nix @@ -2,7 +2,7 @@ text = '' # Toggle vpn. function vpn() { - _notify_short + notify_short if [[ "$(_vpn)" = "on" ]]; then nmcli connection down vpn else