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.
This commit is contained in:
Benedikt Heine 2019-08-22 23:28:51 +02:00 committed by Nikos Tsipinakis
parent a3342d0ced
commit 7e92619967
2 changed files with 45 additions and 3 deletions

View File

@ -26,7 +26,7 @@ function show_help() {
} }
function method_call() { 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() { function property_get() {
@ -42,6 +42,9 @@ command -v dbus-send >/dev/null 2>/dev/null || \
case "${1:-}" in case "${1:-}" in
"action")
method_call "${DBUS_IFAC_DUNST}.NotificationAction" "int32:${2:-0}" >/dev/null
;;
"close") "close")
method_call "${DBUS_IFAC_DUNST}.NotificationCloseLast" >/dev/null method_call "${DBUS_IFAC_DUNST}.NotificationCloseLast" >/dev/null
;; ;;

View File

@ -73,6 +73,10 @@ static const char *introspection_xml =
" <interface name=\""DUNST_IFAC"\">" " <interface name=\""DUNST_IFAC"\">"
" <method name=\"ContextMenuCall\" />" " <method name=\"ContextMenuCall\" />"
// TODO: add an optional parmater definining the action of notification number X to invoke
" <method name=\"NotificationAction\">"
" <arg name=\"number\" type=\"i\"/>"
" </method>"
" <method name=\"NotificationCloseLast\" />" " <method name=\"NotificationCloseLast\" />"
" <method name=\"NotificationCloseAll\" />" " <method name=\"NotificationCloseAll\" />"
" <method name=\"NotificationShow\" />" " <method name=\"NotificationShow\" />"
@ -152,12 +156,14 @@ void dbus_cb_fdn_methods(GDBusConnection *connection,
} }
DBUS_METHOD(dunst_ContextMenuCall); DBUS_METHOD(dunst_ContextMenuCall);
DBUS_METHOD(dunst_NotificationAction);
DBUS_METHOD(dunst_NotificationCloseAll); DBUS_METHOD(dunst_NotificationCloseAll);
DBUS_METHOD(dunst_NotificationCloseLast); DBUS_METHOD(dunst_NotificationCloseLast);
DBUS_METHOD(dunst_NotificationShow); DBUS_METHOD(dunst_NotificationShow);
DBUS_METHOD(dunst_Ping); DBUS_METHOD(dunst_Ping);
static struct dbus_method methods_dunst[] = { static struct dbus_method methods_dunst[] = {
{"ContextMenuCall", dbus_cb_dunst_ContextMenuCall}, {"ContextMenuCall", dbus_cb_dunst_ContextMenuCall},
{"NotificationAction", dbus_cb_dunst_NotificationAction},
{"NotificationCloseAll", dbus_cb_dunst_NotificationCloseAll}, {"NotificationCloseAll", dbus_cb_dunst_NotificationCloseAll},
{"NotificationCloseLast", dbus_cb_dunst_NotificationCloseLast}, {"NotificationCloseLast", dbus_cb_dunst_NotificationCloseLast},
{"NotificationShow", dbus_cb_dunst_NotificationShow}, {"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); 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)", &notification_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, static void dbus_cb_dunst_NotificationCloseAll(GDBusConnection *connection,
const gchar *sender, const gchar *sender,
GVariant *parameters, GVariant *parameters,
@ -606,10 +639,16 @@ gboolean dbus_cb_dunst_Properties_Set(GDBusConnection *connection,
GError **error, GError **error,
gpointer user_data) gpointer user_data)
{ {
if (STR_EQ(property_name, "running")) if (STR_EQ(property_name, "running")) {
dunst_status(S_RUNNING, g_variant_get_boolean(value)); 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;
} }