Remove command handling from notification_init

This commit is contained in:
Benedikt Heine 2017-10-11 12:40:58 +02:00
parent 616b8a1758
commit b57483416e
4 changed files with 28 additions and 22 deletions

View File

@ -266,13 +266,18 @@ static void on_notify(GDBusConnection *connection,
notification_init(n);
int id = queues_notification_insert(n, replaces_id);
wake_up();
GVariant *reply = g_variant_new("(u)", id);
g_dbus_method_invocation_return_value(invocation, reply);
g_dbus_connection_flush(connection, NULL, NULL, NULL);
run(NULL);
// The message got discarded
if (id == 0) {
notification_closed(n, 2);
notification_free(n);
}
wake_up();
}
static void on_close_notification(GDBusConnection *connection,

View File

@ -292,17 +292,6 @@ void notification_init(notification *n)
//Prevent undefined behaviour by initialising required fields
notification_init_defaults(n);
// TODO: this does not belong into notification_init
if (strcmp("DUNST_COMMAND_PAUSE", n->summary) == 0) {
queues_pause_on();
return;
}
if (strcmp("DUNST_COMMAND_RESUME", n->summary) == 0) {
queues_pause_off();
return;
}
n->script = NULL;
n->text_to_render = NULL;
@ -449,15 +438,6 @@ void notification_init(notification *n)
n->first_render = true;
/* TODO: this should not be part of notification_init */
if (strlen(n->msg) == 0) {
queues_notification_close(n, 2);
if (settings.always_run_script) {
notification_run_script(n);
}
printf("skipping notification: %s %s\n", n->body, n->summary);
}
char *tmp = g_strconcat(n->summary, " ", n->body, NULL);
char *tmp_urls = extract_urls(tmp);

View File

@ -4,6 +4,8 @@
#include <assert.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include "dbus.h"
#include "notification.h"
@ -52,6 +54,24 @@ unsigned int queues_length_history()
int queues_notification_insert(notification *n, int replaces_id)
{
/* do not display the message, if the message is empty */
if (strlen(n->msg) == 0) {
if (settings.always_run_script) {
notification_run_script(n);
}
printf("skipping notification: %s %s\n", n->body, n->summary);
return 0;
}
/* Do not insert the message if it's a command */
if (strcmp("DUNST_COMMAND_PAUSE", n->summary) == 0) {
pause_displayed = true;
return 0;
}
if (strcmp("DUNST_COMMAND_RESUME", n->summary) == 0) {
pause_displayed = false;
return 0;
}
if (replaces_id == 0) {
if (settings.stack_duplicates) {

View File

@ -37,6 +37,7 @@ unsigned int queues_length_history();
* If replaces_id == 0, n gets occupies a new position
*
* Returns the assigned notification id
* If returned id == 0, the message was dismissed
*/
int queues_notification_insert(notification *n, int replaces_id);