diff --git a/src/dbus.c b/src/dbus.c index 8d8ec23c0..000823e07 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -76,13 +76,13 @@ static const char *introspection_xml = " " " " - " " + " " " " " " " " " " - " " - " " + " " + " " " " " " " " @@ -92,7 +92,7 @@ static const char *introspection_xml = " " " " " " - " " + " " " " " " " " @@ -103,7 +103,7 @@ static const char *introspection_xml = " " " " " " - " " + " " " " " " @@ -117,6 +117,18 @@ static const char *introspection_xml = " " " " + " " + " " + " " + + " " + " " + " " + + " " + " " + " " + " " ""; @@ -289,9 +301,11 @@ static void dbus_cb_dunst_NotificationClearHistory(GDBusConnection *connection, GDBusMethodInvocation *invocation) { LOG_D("CMD: Clearing the history"); - queues_history_clear(); + guint n = queues_history_clear(); wake_up(); + signal_history_cleared(n); + g_dbus_method_invocation_return_value(invocation, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL); } @@ -419,6 +433,7 @@ static void dbus_cb_dunst_NotificationRemoveFromHistory(GDBusConnection *connect g_variant_get(parameters, "(u)", &id); queues_history_remove_by_id(id); + signal_history_removed(id); wake_up(); g_dbus_method_invocation_return_value(invocation, NULL); @@ -638,6 +653,8 @@ static void dbus_cb_dunst_ConfigReload(GDBusConnection *connection, g_variant_get(parameters, "(^as)", &configs); reload(configs); + signal_config_reloaded(configs); + g_dbus_method_invocation_return_value(invocation, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL); } @@ -1052,6 +1069,14 @@ void signal_notification_closed(struct notification *n, enum reason reason) GVariant *body = g_variant_new("(uu)", n->id, reason); GError *err = NULL; + g_dbus_connection_emit_signal(dbus_conn, + NULL, + FDN_PATH, + DUNST_IFAC, + "PropertiesChanged", + body, + &err); + g_dbus_connection_emit_signal(dbus_conn, n->dbus_client, FDN_PATH, @@ -1080,16 +1105,14 @@ void signal_notification_closed(struct notification *n, enum reason reason) reason_string="signal"; break; case REASON_UNDEF: - reason_string="undfined"; + reason_string="undefined"; break; default: reason_string="unknown"; } LOG_D("Queues: Closing notification for reason: %s", reason_string); - } - } void signal_action_invoked(const struct notification *n, const char *identifier) @@ -1408,6 +1431,75 @@ int dbus_init(void) return owner_id; } +void signal_history_removed(guint id) +{ + if (!dbus_conn) { + LOG_E("Unable to send signal: No DBus connection."); + } + + GVariant *body = g_variant_new("(u)", id); + GError *err = NULL; + + g_dbus_connection_emit_signal(dbus_conn, + NULL, + FDN_PATH, + DUNST_IFAC, + "NotificationHistoryRemoved", + body, + &err); + + if (err) { + LOG_W("Unable to send NotificationHistoryRemoved signal: %s", err->message); + g_error_free(err); + } +} + +void signal_history_cleared(guint n) +{ + if (!dbus_conn) { + LOG_E("Unable to send signal: No DBus connection."); + } + + GVariant *body = g_variant_new("(u)", n); + GError *err = NULL; + + g_dbus_connection_emit_signal(dbus_conn, + NULL, + FDN_PATH, + DUNST_IFAC, + "NotificationHistoryCleared", + body, + &err); + + if (err) { + LOG_W("Unable to send NotificationHistoryCleared signal: %s", err->message); + g_error_free(err); + } +} + +void signal_config_reloaded(char **const configs) +{ + if (!dbus_conn) { + LOG_E("Unable to send signal: No DBus connection."); + } + + GVariant *body = g_variant_new("(as)", configs); + GError *err = NULL; + + g_dbus_connection_emit_signal(dbus_conn, + NULL, + FDN_PATH, + DUNST_IFAC, + "ConfigReloaded", + body, + &err); + + if (err) { + LOG_W("Unable to send ConfigReloaded signal: %s", err->message); + g_error_free(err); + } +} + void dbus_teardown(int owner_id) { g_clear_pointer(&introspection_data, g_dbus_node_info_unref); diff --git a/src/dbus.h b/src/dbus.h index ebef6542f..ed306ccb3 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -21,6 +21,9 @@ void dbus_teardown(int id); void signal_notification_closed(struct notification *n, enum reason reason); void signal_action_invoked(const struct notification *n, const char *identifier); void signal_length_propertieschanged(void); +void signal_history_removed(guint id); +void signal_history_cleared(guint n); +void signal_config_reloaded(char **const configs); #endif /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/queues.c b/src/queues.c index 64a218022..d903245a8 100644 --- a/src/queues.c +++ b/src/queues.c @@ -349,10 +349,12 @@ void queues_notification_close(struct notification *n, enum reason reason) } /* see queues.h */ -void queues_history_clear(void) +guint queues_history_clear(void) { + guint n = g_queue_get_length(history); g_queue_foreach(history, (GFunc)notification_unref, NULL); g_queue_clear(history); + return n; } /* see queues.h */ diff --git a/src/queues.h b/src/queues.h index 55e85baf0..740e3df68 100644 --- a/src/queues.h +++ b/src/queues.h @@ -109,8 +109,9 @@ void queues_notification_close(struct notification *n, enum reason reason); /** * Removes all notifications from history + * Returns the number of removed notifications */ -void queues_history_clear(void); +guint queues_history_clear(void); /** * Pushes the latest notification of history to the displayed queue @@ -138,7 +139,7 @@ void queues_history_push(struct notification *n); void queues_history_push_all(void); /** - * Removes an notification identified by the given id from the history + * Removes an notification identified by the given id from the history */ void queues_history_remove_by_id(unsigned int id);