From 8821c4edd7e1142512d80b33aafa5f1990291027 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 25 Sep 2023 20:56:22 +0000 Subject: [PATCH] sxmo-timer: connect to swaync so that it alerts on completion --- hosts/common/programs/feedbackd.nix | 14 +++- .../programs/swaynotificationcenter.nix | 66 ++++++++++++++++--- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/hosts/common/programs/feedbackd.nix b/hosts/common/programs/feedbackd.nix index 7a5afdfe9..751441084 100644 --- a/hosts/common/programs/feedbackd.nix +++ b/hosts/common/programs/feedbackd.nix @@ -25,7 +25,6 @@ in # - but using that would forbid `parent-theme = "default"` # the default theme ships support for these events: # - alarm-clock-elapsed - # - alarm-clock-elapsed # - battery-caution # - bell-terminal # - button-pressed @@ -66,12 +65,23 @@ in type = "Sound"; effect = "message-new-instant"; } + # re-define sounds from the default theme which we'd like to pass through w/o proxying. + # i guess this means i'm not inheriting the default theme :| { - # i guess we aren't actually inheriting from the default theme? event-name = "phone-incoming-call"; type = "Sound"; effect = "phone-incoming-call"; } + { + event-name = "alarm-clock-elapsed"; + type = "Sound"; + effect = "alarm-clock-elapsed"; + } + { + event-name = "timeout-completed"; + type = "Sound"; + effect = "complete"; + } ]; } ]; diff --git a/hosts/common/programs/swaynotificationcenter.nix b/hosts/common/programs/swaynotificationcenter.nix index 5ac1b2f5f..09fc7f9f3 100644 --- a/hosts/common/programs/swaynotificationcenter.nix +++ b/hosts/common/programs/swaynotificationcenter.nix @@ -64,6 +64,24 @@ let }; fbcli-stop = "${fbcli-stop-wrapper}/bin/fbcli-stop"; + kill-singleton_ = pkgs.writeShellApplication { + name = "kill-singleton"; + runtimeInputs = [ + pkgs.procps # for pgrep + pkgs.gnugrep + ]; + text = '' + pids=$(pgrep --full "$*" | tr '\n' ' ') || true + # only act if there's exactly one pid + if echo "$pids" | grep -Eq '^[0-9]+ ?$'; then + kill "$pids" + else + echo "kill-singleton: skipping because multiple pids match: $pids" + fi + ''; + }; + kill-singleton = "${kill-singleton_}/bin/kill-singleton"; + systemctl-toggle = pkgs.writeShellApplication { name = "systemctl-toggle"; runtimeInputs = [ @@ -175,23 +193,45 @@ in # - SWAYNC_REPLACES_ID # - SWAYNC_ID # - SWAYNC_SUMMARY - sound-im = { + incoming-im = { # trigger notification sound on behalf of these IM clients. - exec = "${fbcli} --event proxied-message-new-instant"; app-name = "(Chats|Dino|discord|Element)"; body = "^(?!Incoming call).*$"; #< don't match Dino Incoming calls + exec = "${fbcli} --event proxied-message-new-instant"; }; - sound-call = { - exec = "${fbcli} --event phone-incoming-call -t 20"; + incoming-call = { app-name = "Dino"; body = "^Incoming call$"; + exec = "${fbcli} --event phone-incoming-call -t 20"; }; - sound-call-end = { - # pkill will kill all processes matching -- not just the first - exec = "${fbcli-stop} --event phone-incoming-call -t 20"; + incoming-call-acted-on = { + # when the notification is clicked, stop sounding the ringer app-name = "Dino"; body = "^Incoming call$"; run-on = "action"; + exec = "${fbcli-stop} --event phone-incoming-call -t 20"; + }; + timer-done = { + # sxmo_timer.sh fires off notifications like "Done with 10m" when a 10minute timer completes. + # it sends such a notification every second until dismissed + app-name = "notify-send"; + summary = "^Done with .*$"; + # XXX: could use alarm-clock-elapsed, but that's got a duration > 1s + # which isn't great for sxmo's 1s repeat. + # TODO: maybe better to have sxmo only notify once, and handle this like with Dino's incoming call + exec = "${fbcli} --event timeout-completed"; + }; + timer-done-acted-on = { + # when the notification is clicked, kill whichever sxmo process is sending it + app-name = "notify-send"; + summary = "^Done with .*$"; + run-on = "action"; + # process tree looks like: + # - foot -T <...> /nix/store/.../sh /nix/store/.../.sxmo_timer.sh-wrapped timerrun + # - /nix/store/.../sh /nix/store/.../.sxmo_timer.sh-wrapped timerrun duration + # we want to match exactly one of those, reliably. + # foot might not be foot, but alacritty, kitty, or any other terminal. + exec = "${kill-singleton} ^[^ ]* ?[^ ]*sxmo_timer.sh(-wrapped)? timerrun"; }; }; notification-visibility = { @@ -214,13 +254,21 @@ in # # test rules by using `notify-send` (libnotify) sxmo-extraneous-daemons = { - state = "ignored"; + app-name = "notify-send"; summary = "(sxmo_hook_lisgd|Autorotate) (Stopped|Started)"; + state = "ignored"; }; sxmo-extraneous-warnings = { - state = "ignored"; + app-name = "notify-send"; # "Modem crashed! 30s recovery.": happens on sxmo_hook_postwake.sh (i.e. unlock) summary = "^Modem crashed.*$"; + state = "ignored"; + }; + sxmo-timer = { + # force timer announcements to bypass DND + app-name = "notify-send"; + summary = "^Done with .*$"; + override-urgency = "critical"; }; }; widgets = [