Add support for controlling the sound played with notifications

This commit is contained in:
Kovid Goyal
2024-08-03 13:46:38 +05:30
parent 5e809d2767
commit bd8162fa42
11 changed files with 104 additions and 24 deletions

View File

@@ -333,6 +333,25 @@ The terminal *must not* send a response unless report is requested with
.. _notifications_query:
Playing a sound with notifications
-----------------------------------------
.. versionadded:: 0.36.0
The ability to control the sound played with notifications
By default, notifications may or may not have a sound associated with them
depending on the policies of the OS notifications service. Sometimes it
might be useful to ensure a notification is not accompanied by a sound.
This can be done by using the ``s`` key which accepts :ref:`base64` encoded
UTF-8 text as its value. Using a value of ``silent`` means the notification
will not be accompanied with a sound. A value of ``system`` (the default)
means that the OS notifications default policies are followed. Any other name
is implementation dependent. For example, on Linux, one can use the `standard
sound names
<https://specifications.freedesktop.org/sound-naming-spec/latest/#names>`__.
Support for sounds can be queried as described below.
Querying for support
-------------------------
@@ -372,6 +391,12 @@ Key Value
``p`` key that the terminal implements). These must contain at least
``title``.
``s`` Comma separated list of keywords ``silent`` and ``xdg-names`` indicating
support for silent notifications and for passing of `Freedesktop
standard sound names
<https://specifications.freedesktop.org/sound-naming-spec/latest/#names>`__ to the
desktop notification service for custom sounds.
``u`` Comma separated list of urgency values that the terminal implements.
If urgency is not supported, the ``u`` key must be absent from the
query response.
@@ -441,6 +466,10 @@ Key Value Default Description
``?``, ``alive``,
``buttons``
``s`` :ref:`base64` ``system`` The sound name to play with the notification. ``silent`` means no sound.
encoded sound ``system`` means to play the default sound, if any, of the platform notification service.
name Other names are implementation dependent.
``t`` :ref:`base64` ``unset`` The type of the notification. Used to filter out notifications. Can be specified multiple times.
encoded UTF-8
notification type

View File

@@ -34,6 +34,9 @@ def main(nc: NotificationCommand) -> bool:
if 'unwanted' in nc.title.lower():
return True
# force the notification to be silent
nc.sound_name = 'silent'
# filter out notifications from the application badapp
if nc.application_name == 'badapp':
return True