Skip to content

Commit

Permalink
Add more signals
Browse files Browse the repository at this point in the history
  • Loading branch information
bynect committed Dec 4, 2024
1 parent e1e772c commit 6ce6566
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 12 deletions.
114 changes: 105 additions & 9 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ static const char *introspection_xml =
" </interface>"
" <interface name=\""DUNST_IFAC"\">"

" <method name=\"ContextMenuCall\" />"
" <method name=\"ContextMenuCall\"/>"
" <method name=\"NotificationAction\">"
" <arg name=\"number\" type=\"u\"/>"
" </method>"
" <method name=\"NotificationClearHistory\"/>"
" <method name=\"NotificationCloseLast\" />"
" <method name=\"NotificationCloseAll\" />"
" <method name=\"NotificationCloseLast\"/>"
" <method name=\"NotificationCloseAll\"/>"
" <method name=\"NotificationListHistory\">"
" <arg direction=\"out\" name=\"notifications\" type=\"aa{sv}\"/>"
" </method>"
Expand All @@ -92,7 +92,7 @@ static const char *introspection_xml =
" <method name=\"NotificationRemoveFromHistory\">"
" <arg direction=\"in\" name=\"id\" type=\"u\"/>"
" </method>"
" <method name=\"NotificationShow\" />"
" <method name=\"NotificationShow\"/>"
" <method name=\"RuleEnable\">"
" <arg name=\"name\" type=\"s\"/>"
" <arg name=\"state\" type=\"i\"/>"
Expand All @@ -103,7 +103,7 @@ static const char *introspection_xml =
" <method name=\"ConfigReload\">"
" <arg direction=\"in\" name=\"configs\" type=\"as\"/>"
" </method>"
" <method name=\"Ping\" />"
" <method name=\"Ping\"/>"

" <property name=\"paused\" type=\"b\" access=\"readwrite\">"
" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"true\"/>"
Expand All @@ -117,6 +117,19 @@ static const char *introspection_xml =
" <property name=\"historyLength\" type=\"u\" access=\"read\" />"
" <property name=\"waitingLength\" type=\"u\" access=\"read\" />"

" <signal name=\"NotificationHistoryRemoved\">"
" <arg name=\"id\" type=\"u\"/>"
" <arg name=\"is_pop\" type=\"b\"/>"
" </signal>"

" <signal name=\"NotificationHistoryCleared\">"
" <arg name=\"n\" type=\"u\"/>"
" </signal>"

" <signal name=\"ConfigReloaded\">"
" <arg name=\"configs\" type=\"as\"/>"
" </signal>"

" </interface>"
"</node>";

Expand Down Expand Up @@ -289,9 +302,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);
}
Expand Down Expand Up @@ -402,6 +417,8 @@ static void dbus_cb_dunst_NotificationPopHistory(GDBusConnection *connection,
g_variant_get(parameters, "(u)", &id);

queues_history_pop_by_id(id);
signal_history_removed(id, true);

wake_up();

g_dbus_method_invocation_return_value(invocation, NULL);
Expand All @@ -419,6 +436,8 @@ static void dbus_cb_dunst_NotificationRemoveFromHistory(GDBusConnection *connect
g_variant_get(parameters, "(u)", &id);

queues_history_remove_by_id(id);
signal_history_removed(id, false);

wake_up();

g_dbus_method_invocation_return_value(invocation, NULL);
Expand Down Expand Up @@ -638,6 +657,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);
}
Expand Down Expand Up @@ -1052,6 +1073,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,
Expand Down Expand Up @@ -1080,16 +1109,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)
Expand Down Expand Up @@ -1408,6 +1435,75 @@ int dbus_init(void)
return owner_id;
}

void signal_history_removed(guint id, bool is_pop)
{
if (!dbus_conn) {
LOG_E("Unable to send signal: No DBus connection.");
}

GVariant *body = g_variant_new("(ub)", id, is_pop);
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);
Expand Down
3 changes: 3 additions & 0 deletions src/dbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, bool is_pop);
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: */
4 changes: 3 additions & 1 deletion src/queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 3 additions & 2 deletions src/queues.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6ce6566

Please sign in to comment.