emersion / mako

A lightweight Wayland notification daemon
https://wayland.emersion.fr/mako
MIT License
2.18k stars 139 forks source link

Hints: Support 'sound-file' and 'sound-name' hints in makoctl list #470

Open earboxer opened 1 year ago

earboxer commented 1 year ago

Reference: https://specifications.freedesktop.org/notification-spec/latest/ar01s08.html

Added sound-file and sound-name to the data so they'll appear in makoctl list. Also added a criteria for sound-name.

You can use this config to play the sounds:

# Play a sound file when it exists and on-notify isn't overridden
on-notify=exec mpv --really-quiet "$(makoctl list | jq -r '.data[0][0]."sound-file".data')"

# Ring until you click or tap on it
[sound-name="phone-incoming-call"]
on-notify=exec mpv --really-quiet --loop /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga
on-button-left=exec pkill -9 -f 'mpv .*phone-incoming-call.oga'
on-touch=exec pkill -9 -f 'mpv .*phone-incoming-call.oga'

# Specify any of the sounds you want to hear
[sound-name="message-new-instant"]
on-notify=exec mpv --really-quiet /usr/share/sounds/freedesktop/stereo/message-new-instant.oga
[sound-name="message-new-email"]
on-notify=exec mpv --really-quiet /usr/share/sounds/freedesktop/stereo/message-new-email.oga

Closes #424

Testing notes:

# sound-file hint
notify-send "Where am I?" -h STRING:sound-file:/usr/share/sounds/freedesktop/stereo/audio-channel-front-right.oga
makoctl list | jq -r '.data[0][0]."sound-file".data'
# sound-name hint
notify-send "Click to silence" -h STRING:sound-name:phone-incoming-call
makoctl list | jq -r '.data[0][0]."sound-name".data'
earboxer commented 1 year ago

Should probably add a "suppress-sound" BOOLEAN criteria... not sure how widely used any of these are.

Dino at least sends sound-name:phone-incoming-call, so, for mako users, this could be an alternative to https://github.com/dino/dino/pull/1203 (assuming you're okay with binding the action to dismiss it).

To improve the user-experience, maybe there should be an 'on-dismiss' binding, because I want to kill the sound AND close the notification.

(And probably the actions should work with this... not sure if that would be possible to script. maybe I'm asking too much of mako at this point.)

earboxer commented 1 year ago

If we implement "truthy/falsey" string comparisons first as in https://github.com/emersion/mako/pull/471, then it will be easier to specify the config:

[sound-file]
on-notify=exec mpv --really-quiet "$(makoctl list | jq -r '.data[0][0]."sound-file".data')"
[sound-name]
on-notify=exec mpv --really-quiet "/usr/share/sounds/freedesktop/stereo/$(makoctl list | jq -r '.data[0][0]."sound-name".data').oga"

#override specific sound
[sound-name="phone-incoming-call"]
on-notify=exec mpv --really-quiet --loop /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga
on-button-left=exec pkill -9 -f 'mpv .*phone-incoming-call.oga'
on-button-right=exec pkill -9 -f 'mpv .*phone-incoming-call.oga'
on-button-middle=exec pkill -9 -f 'mpv .*phone-incoming-call.oga'
on-touch=exec pkill -9 -f 'mpv .*phone-incoming-call.oga'