Allow to set urgency for notifications
ClosedPublic

Authored by broulik on Apr 1 2019, 9:01 AM.

Details

Summary

This lets the application set an urgency hint on the notification, which can be low, normal, or critical.
The notification server can then apply different behavior, e.g. show critical notifications on top of full screen windows, or suppress low urgency notifications by default.

See https://developer.gnome.org/notification-spec/#urgency-levels

Test Plan
  • Put Urgency=Critical into a notifyrc file, had it send the hint "2"

Diff Detail

Repository
R289 KNotifications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Apr 1 2019, 9:01 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 1 2019, 9:01 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
broulik requested review of this revision.Apr 1 2019, 9:01 AM

Nicely fits with the Android backend too, although that has one extra level (low, medium, high, urgent).

Nicely fits with the Android backend too, although that has one extra level (low, medium, high, urgent).

I found the following enums in NotificationManager:

  • IMPORTANCE_NONE: won't even show up
  • IMPORTANCE_MIN: could be mapped to Low?
  • IMPORTANCE_DEFAULT: well, the default, Normal
  • IMPORTANCE_HIGH: could be mapped to Critical
  • IMPORTANCE_MAX "unused"

I was looking at https://developer.android.com/training/notify-user/channels#importance which also has IMPORTANCE_LOW mapped to "medium". But yes, it's basically just about finding a suitable mapping, even if we don't cover every possible level on Android.

So, in essence you're fine with adding the enum as it is, and then have some mapping in the Android code? :)

Yep, code looks good to me too, so +1 on this :)

vkrause accepted this revision.Apr 8 2019, 9:05 AM
This revision is now accepted and ready to land.Apr 8 2019, 9:05 AM
This revision was automatically updated to reflect the committed changes.

@vkrause I just noticed xdg portal notification spec (the ones used for sandboxed flatpak apps) has four urgency levels: low, normal, *high*, critical.
Do you think it would be useful to add HighUrgency, too? For Android, maybe? For freedesktop Notifications we could just map High to Normal then (like Gnome does it).
It's not released yet, we can still meddle the enums for another few weeks :)

@vkrause I just noticed xdg portal notification spec (the ones used for sandboxed flatpak apps) has four urgency levels: low, normal, *high*, critical.
Do you think it would be useful to add HighUrgency, too? For Android, maybe? For freedesktop Notifications we could just map High to Normal then (like Gnome does it).
It's not released yet, we can still meddle the enums for another few weeks :)

Yep, Urgent/High/Normal/Low would indeed match Android perfectly. Adding more enum values also should be possible later without breaking compatibility, unless we assume them to be in the right order anywhere. If we need them ordered, maybe explicitly assign them values to leave some space between them?

Good point, I shall space them apart a bit.