From 7e92619967f21b6744776ddc5e165be720c6df09 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Thu, 22 Aug 2019 23:28:51 +0200 Subject: [PATCH] Add ability to trigger action of latest notification Currently triggers only the latest notification. TODO: implement it either with ActionsAll or more favorable: with an optional paramter, which should trigger only the action of a single notification. The problem currently: I have got no ability to check the DBus docs, as I'm on a bad internet connection. --- dunstctl | 5 ++++- src/dbus.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dunstctl b/dunstctl index bce3028..d8b7f16 100755 --- a/dunstctl +++ b/dunstctl @@ -26,7 +26,7 @@ function show_help() { } function method_call() { - dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${1}" + dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" $* } function property_get() { @@ -42,6 +42,9 @@ command -v dbus-send >/dev/null 2>/dev/null || \ case "${1:-}" in + "action") + method_call "${DBUS_IFAC_DUNST}.NotificationAction" "int32:${2:-0}" >/dev/null + ;; "close") method_call "${DBUS_IFAC_DUNST}.NotificationCloseLast" >/dev/null ;; diff --git a/src/dbus.c b/src/dbus.c index d554bcc..39867af 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -73,6 +73,10 @@ static const char *introspection_xml = " " " " +// TODO: add an optional parmater definining the action of notification number X to invoke + " " + " " + " " " " " " " " @@ -152,12 +156,14 @@ void dbus_cb_fdn_methods(GDBusConnection *connection, } DBUS_METHOD(dunst_ContextMenuCall); +DBUS_METHOD(dunst_NotificationAction); DBUS_METHOD(dunst_NotificationCloseAll); DBUS_METHOD(dunst_NotificationCloseLast); DBUS_METHOD(dunst_NotificationShow); DBUS_METHOD(dunst_Ping); static struct dbus_method methods_dunst[] = { {"ContextMenuCall", dbus_cb_dunst_ContextMenuCall}, + {"NotificationAction", dbus_cb_dunst_NotificationAction}, {"NotificationCloseAll", dbus_cb_dunst_NotificationCloseAll}, {"NotificationCloseLast", dbus_cb_dunst_NotificationCloseLast}, {"NotificationShow", dbus_cb_dunst_NotificationShow}, @@ -201,6 +207,33 @@ static void dbus_cb_dunst_ContextMenuCall(GDBusConnection *connection, g_dbus_connection_flush(connection, NULL, NULL, NULL); } +static void dbus_cb_dunst_NotificationAction(GDBusConnection *connection, + const gchar *sender, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + int notification_nr = 0; + g_variant_get(parameters, "(i)", ¬ification_nr); + + LOG_D("CMD: Calling action for notification %d", notification_nr); + + if (notification_nr < 0 || queues_length_waiting() < notification_nr) + return; //FIXME return error + + const GList *list = g_list_nth_data(queues_get_displayed(), notification_nr); + + if (list && list->data) { + struct notification *n = list->data; + LOG_D("CMD: Calling action for notification %s", n->summary); + notification_do_action(n); + // TODO: do we need to wake up after notification action? + wake_up(); + } + + g_dbus_method_invocation_return_value(invocation, NULL); + g_dbus_connection_flush(connection, NULL, NULL, NULL); +} + static void dbus_cb_dunst_NotificationCloseAll(GDBusConnection *connection, const gchar *sender, GVariant *parameters, @@ -606,10 +639,16 @@ gboolean dbus_cb_dunst_Properties_Set(GDBusConnection *connection, GError **error, gpointer user_data) { - if (STR_EQ(property_name, "running")) + if (STR_EQ(property_name, "running")) { dunst_status(S_RUNNING, g_variant_get_boolean(value)); + return true; + } + - return true; + //FIXME: don't we have to return true on successful setting, but return false, if e.g. the parameter name is wrong? + //return true; + // so like this? + return false; }