dunst-project / dunst

Lightweight and customizable notification daemon
https://dunst-project.org
Other
4.64k stars 343 forks source link

Support custom script execution on clicking on a notification #1369

Open cmihail opened 4 months ago

cmihail commented 4 months ago

Issue description

I have a custom Waybar module that displays notifications count via dunstctl and on click it pops the latest notification from history. Whenever a new notification is received a custom script is executed to send a signal to Waybar to update the notification count.

But the problem is that dunst doesn't have any proper custom script execution on clicking on a notification (i.e. closing it). For normal notifications, I use the following code to send a signal to waybar for notifications whenever a notification is closed:

#!/bin/bash
dbus-monitor --profile "interface='org.freedesktop.Notifications'" | \
  awk '/NotificationClosed/ { system("$HOME/.config/waybar/scripts/update_notifications_signal.sh") }'

While this works for normal notifications, it doesn't work for notifications retrieved from history as those do not emit a DBUS event (see https://github.com/dunst-project/dunst/issues/1352).

Though I think that the proper solution here is not to finish https://github.com/dunst-project/dunst/issues/1352, but to be able to execute a custom script on clicking on a notification similarly to the following when receiving a notification:

[script_waybar_signal]
  summary = "*"
  script = $HOME/.config/waybar/scripts/update_notifications_signal.sh

Installation info

Minimal dunstrc ```ini [global] follow = mouse origin = top-center idle_threshold = 10s mouse_left_click = "do_action, close_current" mouse_right_click = "close_current" mouse_middle_click = "close_all" icon_path = "/usr/share/icons/AdwaitaLegacy/48x48/legacy/" icon_theme = AdwaitaLegacy [script_waybar_signal] summary = "*" script = $HOME/.config/waybar/scripts/update_notifications_signal.sh [ignore_volume_change] stack_tag = "change_volume" history_ignore = yes timeout = 1s [ignore_brightness_change] stack_tag = "change_brightness" history_ignore = yes timeout = 1s [skip_google_meet_notifications] body = "*meet.google.com*" skip_display = yes history_ignore = yes ```

Note: I'd be interested in implementing this feature myself if that is fine.

bynect commented 1 month ago

Hello, sorry for the late reply. This is a great idea and probably will be added some time in the future.

Probably it could be accomplished by adding a run_script option to

mouse_[left/middle/right]_click (values: [none/do_action/close_current/close_all/context/context_all])

I'm not sure about how to specify the script though. Any suggestion is appreciated 👍🏻