Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more signals #1405

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 101 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,18 @@ 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\"/>"
" </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 +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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
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);
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
Loading