diff --git a/gio/gapplication.c b/gio/gapplication.c index 38f1241b8..609b8ceba 100644 --- a/gio/gapplication.c +++ b/gio/gapplication.c @@ -3074,7 +3074,13 @@ g_application_get_is_busy (GApplication *application) * * If a previous notification was sent with the same @id, it will be * replaced with @notification and shown again as if it was a new - * notification. This works even for notifications sent from a previous + * notification. If the flag [flags@Gio.NotificationDisplayHintFlags.UPDATE] is set + * on @notification via g_notification_set_display_hint() the + * notification will be updated instead of replaced + * if a notification with the same ID exists already + * otherwise a new one is created. When updating a notification + * no sound is played and the banner isn't shown again. + * This works even for notifications sent from a previous * execution of the application, as long as @id is the same string. * * @id may be `NULL`, but it is impossible to replace or withdraw diff --git a/gio/gioenums.h b/gio/gioenums.h index 51a03a26a..b38623c0c 100644 --- a/gio/gioenums.h +++ b/gio/gioenums.h @@ -2083,6 +2083,32 @@ typedef enum { G_NOTIFICATION_PRIORITY_URGENT } GNotificationPriority; +/** + * GNotificationDisplayHintFlags: + * @G_NOTIFICATION_DISPLAY_HINT_NONE: No flags. + * @G_NOTIFICATION_DISPLAY_HINT_TRANSIENT: The notification is displayed only as a banner and won’t be kept by the server in a tray. + * @G_NOTIFICATION_DISPLAY_HINT_TRAY: No banner for the notification will be displayed and the notification is placed in the tray. + * @G_NOTIFICATION_DISPLAY_HINT_PERSISTENT: Make the notification persistent in the notification tray. + * @G_NOTIFICATION_DISPLAY_HIDE_ON_LOCKSCREEN: Hide the notification on the lockscreen. + * @G_NOTIFICATION_DISPLAY_HIDE_CONTENT_ON_LOCKSCREEN: All content other then the title of the notification will be hidden on the lockscreen. + * @G_NOTIFICATION_DISPLAY_HIDE_UPDATE: If a notification with the same ID exists already, it will be updated instead of replaced. + * + * Display hints for a [class@Gio.Notification]. + * + * Depending on the platform or additional policies the hints may behave different or be fully ignored. + * + * Since: 2.85 + */ +typedef enum { + G_NOTIFICATION_DISPLAY_HINT_NONE = 0, + G_NOTIFICATION_DISPLAY_HINT_TRANSIENT = (1 << 0), + G_NOTIFICATION_DISPLAY_HINT_TRAY = (1 << 1), + G_NOTIFICATION_DISPLAY_HINT_PERSISTENT = (1 << 2), + G_NOTIFICATION_DISPLAY_HINT_HIDE_ON_LOCKSCREEN = (1 << 3), + G_NOTIFICATION_DISPLAY_HINT_HIDE_CONTENT_ON_LOCKSCREEN = (1 << 4), + G_NOTIFICATION_DISPLAY_HINT_UPDATE = (1 << 5), +} GNotificationDisplayHintFlags; + /** * GNetworkConnectivity: * @G_NETWORK_CONNECTIVITY_LOCAL: The host is not configured with a diff --git a/gio/gnotification-private.h b/gio/gnotification-private.h index 28383ecef..1219123f4 100644 --- a/gio/gnotification-private.h +++ b/gio/gnotification-private.h @@ -39,6 +39,8 @@ GNotificationSound * g_notification_get_sound (GNotifi GNotificationPriority g_notification_get_priority (GNotification *notification); +GNotificationDisplayHintFlags g_notification_get_display_hint_flags (GNotification *notification); + guint g_notification_get_n_buttons (GNotification *notification); void g_notification_get_button (GNotification *notification, diff --git a/gio/gnotification.c b/gio/gnotification.c index 33942201e..66b725e3e 100644 --- a/gio/gnotification.c +++ b/gio/gnotification.c @@ -91,6 +91,7 @@ struct _GNotification GNotificationSound *sound; GNotificationPriority priority; gchar *category; + GNotificationDisplayHintFlags display_hint; GPtrArray *buttons; gchar *default_action; GVariant *default_action_target; /* (nullable) (owned), not floating */ @@ -428,6 +429,38 @@ g_notification_set_category (GNotification *notification, notification->category = g_strdup (category); } +/*< private > + * g_notification_get_display_hint_flags: + * @notification: a [class@Gio.Notification] + * + * Returns: the display hint flags of @notification + * + * Since: 2.85 + */ +GNotificationDisplayHintFlags +g_notification_get_display_hint_flags (GNotification *notification) +{ + g_return_val_if_fail (G_IS_NOTIFICATION (notification), G_NOTIFICATION_DISPLAY_HINT_NONE); + + return notification->display_hint; +} + +/** + * g_notification_set_display_hint_flags: + * @notification: a [class@Gio.Notification] + * @flags: the display hint flags for @notification + * + * Since: 2.85 + */ +void +g_notification_set_display_hint_flags (GNotification *notification, + GNotificationDisplayHintFlags flags) +{ + g_return_if_fail (G_IS_NOTIFICATION (notification)); + + notification->display_hint = flags; +} + /** * g_notification_set_priority: * @notification: a #GNotification diff --git a/gio/gnotification.h b/gio/gnotification.h index 00f0dac29..f7ff45820 100644 --- a/gio/gnotification.h +++ b/gio/gnotification.h @@ -65,6 +65,10 @@ GIO_AVAILABLE_IN_2_42 void g_notification_set_priority (GNotification *notification, GNotificationPriority priority); +GIO_AVAILABLE_IN_2_85 +void g_notification_set_display_hint_flags (GNotification *notification, + GNotificationDisplayHintFlags flags); + GIO_AVAILABLE_IN_2_70 void g_notification_set_category (GNotification *notification, const gchar *category); diff --git a/gio/tests/gnotification.c b/gio/tests/gnotification.c index b79d25210..30ccac9c5 100644 --- a/gio/tests/gnotification.c +++ b/gio/tests/gnotification.c @@ -173,6 +173,7 @@ struct _GNotification GNotificationSound *sound; GNotificationPriority priority; gchar *category; + GNotificationDisplayHintFlags display_hint; GPtrArray *buttons; gchar *default_action; GVariant *default_action_target; @@ -230,6 +231,7 @@ test_properties (void) g_object_unref (icon); g_notification_set_priority (n, G_NOTIFICATION_PRIORITY_HIGH); g_notification_set_category (n, "cate.gory"); + g_notification_set_display_hint_flags (n, G_NOTIFICATION_DISPLAY_HINT_TRANSIENT); g_notification_add_button (n, "label1", "app.action1::target1"); g_notification_set_default_action (n, "app.action2::target2"); @@ -244,6 +246,7 @@ test_properties (void) g_assert_null (names[2]); g_assert_cmpint (rn->priority, ==, G_NOTIFICATION_PRIORITY_HIGH); g_assert_cmpstr (rn->category, ==, "cate.gory"); + g_assert_true (rn->display_hint == G_NOTIFICATION_DISPLAY_HINT_TRANSIENT); g_assert_cmpint (rn->buttons->len, ==, 1); b = (Button*)rn->buttons->pdata[0];