summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/plugins.org16
-rw-r--r--etc/notify-once.sh31
-rw-r--r--nix/readme.org2
-rw-r--r--xmobar.cabal1
4 files changed, 47 insertions, 3 deletions
diff --git a/doc/plugins.org b/doc/plugins.org
index 4facc85..442af34 100644
--- a/doc/plugins.org
+++ b/doc/plugins.org
@@ -306,7 +306,7 @@
"--", "-O", "<fc=green>On</fc> - ", "-i", "",
"-L", "-15", "-H", "-5",
"-l", "red", "-m", "blue", "-h", "green",
- "-a", "notify-send -u critical 'Battery running out!!'",
+ "-a", "notify-once \"xmobar\" -u critical 'Battery running out!!'",
"-A", "3"]
600
#+end_src
@@ -316,7 +316,19 @@
separator affect how =<watts>= is displayed. For this monitor, neither
the generic nor the specific options have any effect on =<timeleft>=.
We are also telling the monitor to execute the unix command
- =notify-send= when the percentage left in the battery reaches 6%.
+ =notify-once= when the percentage left in the battery reaches 6%.
+
+ =notify-once= is a bash wrapper script provided with the =xmobar= package.
+ =xmobar= will run the notification command according to the refresh period,
+ this has the effect of spamming the notification tray if calling =notify-send= directly.
+ =notify-once= script deduplicates the notification by indicating to =notify-send=
+ the last notification we want to replace.
+ See [[https://codeberg.org/xmobar/xmobar/issues/746][#746]] for more information.
+ Note that your notification daemon should handle notification replacement
+ for this to work. Whether the replacement resets the timeout is also handled by the
+ notification daemon.
+ For example, the =wired-notify= implementation has =replacing_enabled=
+ and =replacing_resets_timeout= configuration options [[https://github.com/Toqozz/wired-notify/wiki/Config]].
It is also possible to specify template variables in the =-O= and =-o=
switches, as in the following example:
diff --git a/etc/notify-once.sh b/etc/notify-once.sh
new file mode 100644
index 0000000..1c46401
--- /dev/null
+++ b/etc/notify-once.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+help() {
+ echo "notify-send: send deduplicated notifications"
+ echo "Usage: notify-once <name> [ARGS]"
+ echo " ARGS are arguments passed directly to notify-send"
+}
+
+if [ $# -lt 1 ]; then
+ echo "Should get at least one argument, a name" >&2
+ help
+ exit 1
+fi
+APPNAME="$1"
+shift
+
+ID_PATH="/tmp/notify-state-$APPNAME"
+
+if [ -e "$ID_PATH" ]; then
+ # Exists, replace
+ ID=$(cat "$ID_PATH")
+ ID=$(notify-send -r "$ID" -p "$@")
+else
+ # Doesn't exist, create
+ ID=$(notify-send -p "$@")
+fi
+
+# Store new ID
+echo "$ID" >"$ID_PATH"
diff --git a/nix/readme.org b/nix/readme.org
index ac00ce7..6a492e5 100644
--- a/nix/readme.org
+++ b/nix/readme.org
@@ -67,7 +67,7 @@ Here is how to set it up:
Run MultiCoreTemp ["-t", "<fc=#bd93f9><fn=1>\xf2c9</fn></fc><avg>°", "-L", "60", "-H", "95", "-l", "white", "-n", "white", "-h", "red"] 50,
Run CatInt 0 "/sys/class/hwmon/hwmon4/fan1_input" [] 50,
Run MultiCpu ["-t", "<fc=#bd93f9><fn=1>\xf4bc</fn></fc> <vbar0><vbar1><vbar2><vbar3><vbar4><vbar5><vbar6><vbar7>", "-w", "99", "-L", "3", "-H", "50", "--normal", "green", "--high", "red"] 10,
- Run BatteryP ["BAT0"] ["-t", "<fc=#bd93f9><fn=1>󱊣</fn></fc><left>%", "-L", "10", "-H", "80", "-p", "3", "--", "-O", "<fc=green>On</fc> - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green", "-a", "notify-send -u critical 'Battery running out!!'", "-A", "3"] 600,
+ Run BatteryP ["BAT0"] ["-t", "<fc=#bd93f9><fn=1>󱊣</fn></fc><left>%", "-L", "10", "-H", "80", "-p", "3", "--", "-O", "<fc=green>On</fc> - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green", "-a", "notify-once \"xmobar\" -u critical 'Battery running out!!'", "-A", "3"] 600,
Run Alsa "default" "Master" ["-t", "<fc=#bd93f9><fn=1>\xf028</fn></fc> <volume>%"],
Run Date "%a %_d %b %H:%M:%S" "date" 10,
Run Load ["-t", "<fc=#bd93f9><fn=0>L</fn></fc><load1>", "-L", "1", "-H", "3", "-d", "2"] 300,
diff --git a/xmobar.cabal b/xmobar.cabal
index ff8bc59..5d4dd07 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -26,6 +26,7 @@ extra-source-files: readme.org, changelog.md,
etc/xmobar.hs,
etc/xmonadpropwrite.hs,
etc/xmobar.el
+ etc/notify-once.sh
source-repository head
type: git