Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CanberraGtk4.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 27 additions & 6 deletions src/DBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class Notifications.Server : Object {
"actions",
"body",
"body-markup",
"sound",
X_CANONICAL_PRIVATE_SYNCHRONOUS
};
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down