Skip to content

Commit

Permalink
notification: Set correct platform data for action activation
Browse files Browse the repository at this point in the history
Since [1] FDO notifications can transfer a `ActivateToken` to the client
application, we can use this token to set the correct platform data to
get wayland startup notification working correctly.
GNOME Shell gained the feature already in [2], so this is the last piece
missing to get rid of the annoying "<Application> is ready" notifications,
when clicking on a notification.

We can set the platform data only for actions that are activated via
`org.freedesktop.Application`.

Fixes: #406

[1] https://gitlab.freedesktop.org/xdg/xdg-specs/-/commit/b9a470004d
[2] https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3199/
  • Loading branch information
jsparber committed Jun 21, 2024
1 parent d14e30d commit 3306a4d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/fdonotification.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct
char *default_action;
GVariant *default_action_target;
ActivateAction activate_action;
char *activation_token;
gpointer data;
} FdoNotification;

Expand All @@ -49,6 +50,7 @@ fdo_notification_free (gpointer data)
g_free (n->app_id);
g_free (n->id);
g_free (n->default_action);
g_free (n->activation_token);
if (n->default_action_target)
g_variant_unref (n->default_action_target);

Expand Down Expand Up @@ -98,6 +100,7 @@ notify_signal (GDBusConnection *connection,
{
guint32 id = 0;
const char *action = NULL;
const char *activation_token = NULL;
FdoNotification *n;

if (g_str_equal (signal_name, "NotificationClosed") &&
Expand All @@ -110,13 +113,25 @@ notify_signal (GDBusConnection *connection,
{
g_variant_get (parameters, "(u&s)", &id, &action);
}
else if (g_str_equal (signal_name, "ActivationToken") &&
g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(us)")))
{
g_variant_get (parameters, "(u&s)", &id, &activation_token);
}
else
return;

n = fdo_find_notification_by_notify_id (id);
if (n == NULL)
return;

if (activation_token)
{
g_clear_pointer (&n->activation_token, g_free);
n->activation_token = g_strdup (activation_token);
return;
}

if (action)
{
if (g_str_equal (action, "default"))
Expand All @@ -126,6 +141,7 @@ notify_signal (GDBusConnection *connection,
n->id,
n->default_action,
n->default_action_target,
n->activation_token,
n->data);
}
else
Expand All @@ -140,6 +156,7 @@ notify_signal (GDBusConnection *connection,
n->id,
name,
target,
n->activation_token,
n->data);
g_free (name);
if (target)
Expand Down Expand Up @@ -414,6 +431,7 @@ fdo_add_notification (GDBusConnection *connection,
n->id = g_strdup (id);
n->notify_id = 0;
n->activate_action = activate_action;
n->activation_token = NULL;
n->data = data;

fdo_notifications = g_slist_prepend (fdo_notifications, n);
Expand Down
1 change: 1 addition & 0 deletions src/fdonotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef void (*ActivateAction) (GDBusConnection *connection,
const char *id,
const char *name,
GVariant *parameter,
const char *activation_token,
gpointer data);

void fdo_add_notification (GDBusConnection *connection,
Expand Down
11 changes: 11 additions & 0 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ activate_action (GDBusConnection *connection,
const char *id,
const char *name,
GVariant *parameter,
const char *activation_token,
gpointer data)
{
g_autofree char *object_path = NULL;
Expand All @@ -116,6 +117,16 @@ activate_action (GDBusConnection *connection,
if (parameter)
g_variant_builder_add (&parms, "v", parameter);

if (activation_token)
{
/* Used by `GTK` < 4.10 */
g_variant_builder_add (&pdata, "{sv}",
"desktop-startup-id", g_variant_new_string (activation_token));
/* Used by `GTK` and `QT` */
g_variant_builder_add (&pdata, "{sv}",
"activation-token", g_variant_new_string (activation_token));
}

if (name && g_str_has_prefix (name, "app."))
{
g_dbus_connection_call (connection,
Expand Down

0 comments on commit 3306a4d

Please sign in to comment.