hoodie / notify-rust

☝️send desktop notifications from your Rust app.
Apache License 2.0
1.17k stars 74 forks source link

KDE notification sounds #124

Open chutchinson opened 3 years ago

chutchinson commented 3 years ago

I'm trying to display a notification in KDE Plasma 5.22.5 (X11) and cannot seem to trigger notification sounds because some basic searching revealed that KDE may not implement the XDG sound naming specification / sound theme specification. I looked at the source code, but it looks like the library is just sending the sound name as a message hint over DBus.

Are there any more examples or documentation available for triggering sounds in KDE? Specifically, is it possible to trigger a sound as defined in System Settings > Notifications > Plasma Workspace > Configure Events? It appears that specifying an absolute path (SoundFile hint) does not work, so I can't currently do that either. It's unclear to me if this is a KDE issue, configuration issue, etc.

Thanks!

hoodie commented 3 years ago

Hiho, thanks for looking into this, I have to be honest I kinda never "saw" sound working on KDE either. I always assumed it's just not implemented (being a fairly annoying feature if you think about it). So notify-rust sends the sound hint as described in the spec and that's it. But I haven't spent a whole lot of time trying to make sound work either, so maybe there is a way to make it work that I just overlooked.

chutchinson commented 3 years ago

As a follow up, I have looked at the KDE source code for KNotifications API and also KNotify. It seems like KNotification is the API responsible for hooking into DBus and rendering notifications with Plasma. From what I can tell, in order to play sounds with Plasma notifications you are required to create a notifyrc file in /etc/knotifications5 along with some configuration for your application and the specific types of "notification events" it can produce. This seems straightforward, and you can also then further configure these events in the Plasma System Settings applet.

Anyway, I have tried this and the only result I have obtained is changing the icon of the notifications based on the definition of said notifyrc resource. Which is promising... but I still don't get any sounds no matter what. A key problem seems to be there is no way for me to pass an "event id" (not a notification id, but a KNotification adjacent concept called an event ID). There are some custom hints that I extracted from the KDE source that appear to fit the purpose, but do not seem to work:

https://api.kde.org/frameworks/knotifications/html/index.html

// define appname (mainframe) and event id (deviceLocated)
Hint::CustomHint("x-kde-appname".into(), "mainframe".into()),
Hint::CustomHint("x-kde-eventId".into(), "deviceLocated".into()),

Which would correspond to a resource in /etc/knotifications5 as mentioned:

; /etc/knotifications5/mainframe.notifyrc
[Global]
IconName=mainframe
Comment="Mainframe"

[Event/deviceLocated]
Comment="Device located"
Sound="/etc/mainframe/ping.ogg"
Action=Sound

Something like that. That's not exactly what I've used / attempted but it gets the idea across I think. The KDE notification engine appears to be extracting some configuration from that resource file given the appname and event Id I've specified, but it certainly doesn't play a sound. It also doesn't do anything else that can be confgured in that event section, such as say perform text-to-speech or respect the urgency. It's not clear if this is an environment / configuration problem or a missing feature in the KNotification backend.

As I've mentioned, there's custom hints, but I can't seem to get it matching up my notification with the event resource. Additionally, there is a DBus endpoint for KNotify that does accept the eventId as a parameter to the method call, but that is obviously not XDG compliant.

Do you think this library has room for a KDE-specific backend (perhaps KNotify?), or are you only targeting XDG spec? The inclusion of the WinRT backend appears to answer that question, but I want to be sure before I consider contributing or taking up valuable project time.

Thanks!

hoodie commented 3 years ago

Wow! Thank you very much for the extensive documentation. I'd love to support KDE better, as I'm a KDE user myself. I suppose as long as we're just adding another DBus endpoint that needs to be targeted this should be fine. We could technically even send it redundantly if we're not on KDE. I'd becurious if gnome does something similar. So from a "is there room" it should be fine, since we're not gonna bloat the library much. But I'd prefer if we could keep the API nice and simple. For images we actually query the version of the service to make a decision at the start. Maybe we can do something similar for KDE and then hide all the gritty details from the public API altogether.

TomSchammo commented 1 year ago

Are there any news related to this?

mwinters0 commented 3 months ago

As of knotifications v6.4.0, it appears that notification-specific sounds are not supported. Here is the result of GetCapabilities, with "sound" notably missing:

{
  "body",
  "body-hyperlinks",
  "body-markup",
  "body-images",
  "icon-static",
  "actions",
  "persistence",
  "inline-reply",
  "x-kde-urls",
  "x-kde-origin-name",
  "x-kde-display-appname",
  "inhibitions"
}