Skip to content

Commit

Permalink
notification: Drop private GNOME Shell API
Browse files Browse the repository at this point in the history
Since we have the GNOME specific xdp backend we can move the private
GNOME Shell things there and leave this backend implementation more generic.
  • Loading branch information
jsparber authored and TingPing committed Jun 26, 2024
1 parent 48bbf07 commit 5bfbd9b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 173 deletions.
2 changes: 0 additions & 2 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fdo_dbus_interfaces = files(
'org.freedesktop.Accounts.User.xml',
)

gtk_dbus_interfaces = files('org.gtk.Notifications.xml')

gnome_dbus_interfaces = files(
'org.gnome.SessionManager.xml',
'org.gnome.ScreenSaver.xml',
Expand Down
33 changes: 0 additions & 33 deletions data/org.gtk.Notifications.xml

This file was deleted.

1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ portal_built_sources += gnome.gdbus_codegen('xdg-desktop-portal-dbus',

portal_built_sources += gnome.gdbus_codegen('shell-dbus',
sources: [
gtk_dbus_interfaces,
fdo_dbus_interfaces,
gnome_dbus_interfaces,
],
Expand Down
151 changes: 14 additions & 137 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,64 +23,6 @@
#include "request.h"
#include "utils.h"

/* org.gtk.Notifications support. This is easy, since we can
* just pass the calls through unseen, and gnome-shell does
* the right thing.
*/
static OrgGtkNotifications *gtk_notifications;

static void
notification_added (GObject *source,
GAsyncResult *result,
gpointer data)
{
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) reply = NULL;

if (!org_gtk_notifications_call_add_notification_finish (gtk_notifications, result, &error))
g_warning ("Error from gnome-shell: %s", error->message);
}

static void
handle_add_notification_gtk (XdpImplNotification *object,
GDBusMethodInvocation *invocation,
const char *arg_app_id,
const char *arg_id,
GVariant *arg_notification)
{
if (gtk_notifications)
org_gtk_notifications_call_add_notification (gtk_notifications,
arg_app_id,
arg_id,
arg_notification,
NULL,
notification_added,
NULL);

g_debug ("handle add-notification from %s using the gtk implementation", arg_app_id);

xdp_impl_notification_complete_add_notification (object, invocation);
}

static void
handle_remove_notification_gtk (XdpImplNotification *object,
GDBusMethodInvocation *invocation,
const char *arg_app_id,
const char *arg_id)
{
if (gtk_notifications)
org_gtk_notifications_call_remove_notification (gtk_notifications,
arg_app_id,
arg_id,
NULL,
NULL,
NULL);

g_debug ("handle remove-notification from %s using the gtk implementation", arg_app_id);

xdp_impl_notification_complete_remove_notification (object, invocation);
}

static char *
app_path_for_id (const gchar *app_id)
{
Expand Down Expand Up @@ -169,84 +111,20 @@ activate_action (GDBusConnection *connection,
}
}

static void
handle_add_notification_fdo (XdpImplNotification *object,
GDBusMethodInvocation *invocation,
const gchar *arg_app_id,
const gchar *arg_id,
GVariant *arg_notification)
static gboolean
handle_add_notification (XdpImplNotification *object,
GDBusMethodInvocation *invocation,
const gchar *arg_app_id,
const gchar *arg_id,
GVariant *arg_notification)
{
GDBusConnection *connection;

g_debug ("handle add-notification from %s using the freedesktop implementation", arg_app_id);

connection = g_dbus_method_invocation_get_connection (invocation);

fdo_add_notification (connection, arg_app_id, arg_id, arg_notification, activate_action, NULL);

xdp_impl_notification_complete_add_notification (object, invocation);
}

static gboolean
handle_remove_notification_fdo (XdpImplNotification *object,
GDBusMethodInvocation *invocation,
const gchar *arg_app_id,
const gchar *arg_id)
{
GDBusConnection *connection;

connection = g_dbus_method_invocation_get_connection (invocation);
if (fdo_remove_notification (connection, arg_app_id, arg_id))
{
g_debug ("handle remove-notification from %s using the freedesktop implementation", arg_app_id);
xdp_impl_notification_complete_remove_notification (object, invocation);
return TRUE;
}
return FALSE;
}

static gboolean
has_unprefixed_action (GVariant *notification)
{
const char *action;
g_autoptr(GVariant) buttons = NULL;
int i;

if (g_variant_lookup (notification, "default-action", "&s", &action) &&
!g_str_has_prefix (action, "app."))
return TRUE;

buttons = g_variant_lookup_value (notification, "buttons", G_VARIANT_TYPE("aa{sv}"));
if (buttons)
for (i = 0; i < g_variant_n_children (buttons); i++)
{
g_autoptr(GVariant) button = NULL;

button = g_variant_get_child_value (buttons, i);
if (g_variant_lookup (button, "action", "&s", &action) &&
!g_str_has_prefix (action, "app."))
return TRUE;
}

return FALSE;
}

static gboolean
handle_add_notification (XdpImplNotification *object,
GDBusMethodInvocation *invocation,
const gchar *arg_app_id,
const gchar *arg_id,
GVariant *arg_notification)
{
g_autofree char* owner = gtk_notifications != NULL ?
g_dbus_proxy_get_name_owner (G_DBUS_PROXY (gtk_notifications)) :
NULL;
if (owner == NULL ||
!g_application_id_is_valid (arg_app_id) ||
has_unprefixed_action (arg_notification))
handle_add_notification_fdo (object, invocation, arg_app_id, arg_id, arg_notification);
else
handle_add_notification_gtk (object, invocation, arg_app_id, arg_id, arg_notification);

return TRUE;
}
Expand All @@ -257,8 +135,14 @@ handle_remove_notification (XdpImplNotification *object,
const gchar *arg_app_id,
const gchar *arg_id)
{
if (!handle_remove_notification_fdo (object, invocation, arg_app_id, arg_id))
handle_remove_notification_gtk (object, invocation, arg_app_id, arg_id);
GDBusConnection *connection;

connection = g_dbus_method_invocation_get_connection (invocation);

fdo_remove_notification (connection, arg_app_id, arg_id);

xdp_impl_notification_complete_remove_notification (object, invocation);

return TRUE;
}

Expand All @@ -268,13 +152,6 @@ notification_init (GDBusConnection *bus,
{
GDBusInterfaceSkeleton *helper;

gtk_notifications = org_gtk_notifications_proxy_new_sync (bus,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"org.gtk.Notifications",
"/org/gtk/Notifications",
NULL,
NULL);

helper = G_DBUS_INTERFACE_SKELETON (xdp_impl_notification_skeleton_new ());

g_signal_connect (helper, "handle-add-notification", G_CALLBACK (handle_add_notification), NULL);
Expand Down

0 comments on commit 5bfbd9b

Please sign in to comment.