From 5685af4a4b5be1c18da0e37139d038d757f3624e Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Fri, 21 Jun 2024 14:15:44 +0200 Subject: [PATCH] notification: Drop private GNOME Shell API Since we have the GNOME specific xdp backend we can move the private GNOME Shell things there and leave this backend implementation more generic. --- data/meson.build | 2 - data/org.gtk.Notifications.xml | 33 ------- src/meson.build | 1 - src/notification.c | 151 +++------------------------------ 4 files changed, 14 insertions(+), 173 deletions(-) delete mode 100644 data/org.gtk.Notifications.xml diff --git a/data/meson.build b/data/meson.build index 900ce24f..18febc21 100644 --- a/data/meson.build +++ b/data/meson.build @@ -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', diff --git a/data/org.gtk.Notifications.xml b/data/org.gtk.Notifications.xml deleted file mode 100644 index c93fceb8..00000000 --- a/data/org.gtk.Notifications.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/meson.build b/src/meson.build index 21efeb30..6b8394e1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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, ], diff --git a/src/notification.c b/src/notification.c index ebf092a7..aaea5a87 100644 --- a/src/notification.c +++ b/src/notification.c @@ -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) { @@ -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; } @@ -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; } @@ -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);