Split notification assembly into separate method

Handle replaces_id now via n->id
This commit is contained in:
Benedikt Heine 2017-12-03 14:55:03 +01:00
parent b97a49c09b
commit 3face4ae72
4 changed files with 19 additions and 12 deletions

View File

@ -124,10 +124,7 @@ static void on_get_capabilities(GDBusConnection *connection,
g_dbus_connection_flush(connection, NULL, NULL, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL);
} }
static void on_notify(GDBusConnection *connection, static notification *dbus_message_to_notification(const gchar *sender, GVariant *parameters)
const gchar *sender,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{ {
gchar *appname = NULL; gchar *appname = NULL;
@ -265,6 +262,7 @@ static void on_notify(GDBusConnection *connection,
notification *n = notification_create(); notification *n = notification_create();
n->id = replaces_id;
n->appname = appname; n->appname = appname;
n->summary = summary; n->summary = summary;
n->body = body; n->body = body;
@ -287,7 +285,16 @@ static void on_notify(GDBusConnection *connection,
n->colors[ColBG] = bgcolor; n->colors[ColBG] = bgcolor;
notification_init(n); notification_init(n);
int id = queues_notification_insert(n, replaces_id); return n;
}
static void on_notify(GDBusConnection *connection,
const gchar *sender,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
notification *n = dbus_message_to_notification(sender, parameters);
int id = queues_notification_insert(n);
GVariant *reply = g_variant_new("(u)", id); GVariant *reply = g_variant_new("(u)", id);
g_dbus_method_invocation_return_value(invocation, reply); g_dbus_method_invocation_return_value(invocation, reply);

View File

@ -151,6 +151,7 @@ int dunst_main(int argc, char *argv[])
if (settings.startup_notification) { if (settings.startup_notification) {
notification *n = notification_create(); notification *n = notification_create();
n->id = 0;
n->appname = g_strdup("dunst"); n->appname = g_strdup("dunst");
n->summary = g_strdup("startup"); n->summary = g_strdup("startup");
n->body = g_strdup("dunst is up and running"); n->body = g_strdup("dunst is up and running");
@ -159,7 +160,7 @@ int dunst_main(int argc, char *argv[])
n->markup = MARKUP_NO; n->markup = MARKUP_NO;
n->urgency = URG_LOW; n->urgency = URG_LOW;
notification_init(n); notification_init(n);
queues_notification_insert(n, 0); queues_notification_insert(n);
// we do not call wakeup now, wake_up does not work here yet // we do not call wakeup now, wake_up does not work here yet
} }

View File

@ -51,7 +51,7 @@ unsigned int queues_length_history()
return history->length; return history->length;
} }
int queues_notification_insert(notification *n, int replaces_id) int queues_notification_insert(notification *n)
{ {
/* do not display the message, if the message is empty */ /* do not display the message, if the message is empty */
@ -72,12 +72,11 @@ int queues_notification_insert(notification *n, int replaces_id)
return 0; return 0;
} }
if (replaces_id == 0) { if (n->id == 0) {
n->id = ++next_notification_id; n->id = ++next_notification_id;
if (!settings.stack_duplicates || !queues_stack_duplicate(n)) if (!settings.stack_duplicates || !queues_stack_duplicate(n))
g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL);
} else { } else {
n->id = replaces_id;
if (!queues_notification_replace_id(n)) if (!queues_notification_replace_id(n))
g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL);
} }

View File

@ -34,13 +34,13 @@ unsigned int queues_length_history();
* Insert a fully initialized notification into queues * Insert a fully initialized notification into queues
* Respects stack_duplicates, and notification replacement * Respects stack_duplicates, and notification replacement
* *
* If replaces_id != 0, n replaces notification with id replaces_id * If n->id != 0, n replaces notification with id n->id
* If replaces_id == 0, n gets occupies a new position * If n->id == 0, n gets a new id assigned
* *
* Returns the assigned notification id * Returns the assigned notification id
* If returned id == 0, the message was dismissed * If returned id == 0, the message was dismissed
*/ */
int queues_notification_insert(notification *n, int replaces_id); int queues_notification_insert(notification *n);
/* /*
* Replace the notification which matches the id field of * Replace the notification which matches the id field of