From eb7b2e92d1cf2d88540719e803392e38c1254128 Mon Sep 17 00:00:00 2001 From: lenemter Date: Fri, 3 Oct 2025 19:48:58 +0300 Subject: [PATCH 1/2] Add support for sound capabilities --- src/CanberraGtk4.vala | 2 ++ src/DBus.vala | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/CanberraGtk4.vala b/src/CanberraGtk4.vala index 4a3a34c7..72633a9d 100644 --- a/src/CanberraGtk4.vala +++ b/src/CanberraGtk4.vala @@ -19,6 +19,8 @@ namespace CanberraGtk4 { return null; } + proplist.sets (Canberra.PROP_CANBERRA_XDG_THEME_NAME, Gtk.Settings.get_default ().gtk_sound_theme_name); + unowned var name = GLib.Environment.get_application_name (); if (name != null) { proplist.sets (Canberra.PROP_APPLICATION_NAME, name); diff --git a/src/DBus.vala b/src/DBus.vala index 3e23b0f7..aea1d32e 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -74,6 +74,7 @@ public class Notifications.Server : Object { "actions", "body", "body-markup", + "sound", X_CANONICAL_PRIVATE_SYNCHRONOUS }; } @@ -172,13 +173,28 @@ public class Notifications.Server : Object { bubbles[id].present (); } - if (app_settings.get_boolean ("sounds")) { - var sound = notification.priority != URGENT ? "dialog-information" : "dialog-warning"; - if ("category" in hints && hints["category"].is_of_type (VariantType.STRING)) { + var suppress_sound = ( + "suppress-sound" in hints && + hints["suppress-sound"].is_of_type (GLib.VariantType.BOOLEAN) && + hints["suppress-sound"].get_boolean () + ); + + if (app_settings.get_boolean ("sounds") && !suppress_sound) { + string sound; + var is_filename = false; + + if ("sound-file" in hints && hints["sound-file"].is_of_type (GLib.VariantType.STRING)) { + sound = hints["sound-file"].get_string (); + is_filename = true; + } else if ("sound-name" in hints && hints["sound-name"].is_of_type (GLib.VariantType.STRING)) { + sound = hints["sound-namefile"].get_string (); + } else if ("category" in hints && hints["category"].is_of_type (VariantType.STRING)) { sound = category_to_sound_name (hints["category"].get_string ()); + } else { + sound = notification.priority != URGENT ? "dialog-information" : "dialog-warning"; } - send_sound (sound); + send_sound (sound, is_filename); } } } @@ -219,7 +235,7 @@ public class Notifications.Server : Object { confirmation.present (); } - private void send_sound (string sound_name) { + private void send_sound (string sound_name, bool is_filename = false) { if (sound_name == "") { return; } @@ -228,7 +244,12 @@ public class Notifications.Server : Object { Canberra.Proplist.create (out props); props.sets (Canberra.PROP_CANBERRA_CACHE_CONTROL, "volatile"); - props.sets (Canberra.PROP_EVENT_ID, sound_name); + + if (is_filename) { + props.sets (Canberra.PROP_MEDIA_FILENAME, sound_name); + } else { + props.sets (Canberra.PROP_EVENT_ID, sound_name); + } CanberraGtk4.context_get ().play_full (0, props); } From dc8f3c39cc0cb82f60d43dd7ad5ca8c7c8cc7bef Mon Sep 17 00:00:00 2001 From: lenemter Date: Fri, 3 Oct 2025 19:57:21 +0300 Subject: [PATCH 2/2] Fix lint --- src/DBus.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DBus.vala b/src/DBus.vala index aea1d32e..9065e8ed 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -174,7 +174,7 @@ public class Notifications.Server : Object { } var suppress_sound = ( - "suppress-sound" in hints && + "suppress-sound" in hints && hints["suppress-sound"].is_of_type (GLib.VariantType.BOOLEAN) && hints["suppress-sound"].get_boolean () ); @@ -249,7 +249,7 @@ public class Notifications.Server : Object { props.sets (Canberra.PROP_MEDIA_FILENAME, sound_name); } else { props.sets (Canberra.PROP_EVENT_ID, sound_name); - } + } CanberraGtk4.context_get ().play_full (0, props); }