From 744712ad77b70e8d2806cf5674f5b7ca1ccb9ff0 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Thu, 16 Nov 2017 16:35:04 +0100 Subject: [PATCH] Use enum for close reason --- src/dbus.c | 4 ++-- src/dbus.h | 9 ++++++++- src/queues.c | 11 +++++------ src/queues.h | 11 +++-------- src/x11/x.c | 5 +++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 2688efa..59c38dc 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -303,7 +303,7 @@ static void on_close_notification(GDBusConnection *connection, { guint32 id; g_variant_get(parameters, "(u)", &id); - queues_notification_close_id(id, 3); + queues_notification_close_id(id, REASON_SIG); wake_up(); g_dbus_method_invocation_return_value(invocation, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL); @@ -322,7 +322,7 @@ static void on_get_server_information(GDBusConnection *connection, g_dbus_connection_flush(connection, NULL, NULL, NULL); } -void notification_closed(notification *n, int reason) +void notification_closed(notification *n, enum reason reason) { if (!dbus_conn) { fprintf(stderr, "ERROR: Tried to close notification but dbus connection not set!\n"); diff --git a/src/dbus.h b/src/dbus.h index 2d231e0..d1a2e22 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -5,10 +5,17 @@ #include "notification.h" +enum reason { + REASON_TIME = 1, + REASON_USER = 2, + REASON_SIG = 3, + REASON_UNDEF = 4, +}; + int initdbus(void); void dbus_tear_down(int id); /* void dbus_poll(int timeout); */ -void notification_closed(notification *n, int reason); +void notification_closed(notification *n, enum reason reason); void action_invoked(notification *n, const char *identifier); #endif diff --git a/src/queues.c b/src/queues.c index 5185f1a..2bb05d6 100644 --- a/src/queues.c +++ b/src/queues.c @@ -7,7 +7,6 @@ #include #include -#include "dbus.h" #include "notification.h" #include "settings.h" @@ -179,7 +178,7 @@ bool queues_notification_replace_id(notification *new) return false; } -int queues_notification_close_id(int id, int reason) +int queues_notification_close_id(int id, enum reason reason) { notification *target = NULL; @@ -215,7 +214,7 @@ int queues_notification_close_id(int id, int reason) return reason; } -int queues_notification_close(notification *n, int reason) +int queues_notification_close(notification *n, enum reason reason) { assert(n != NULL); return queues_notification_close_id(n->id, reason); @@ -250,11 +249,11 @@ void queues_history_push(notification *n) void queues_history_push_all(void) { while (displayed->length > 0) { - queues_notification_close(g_queue_peek_head_link(displayed)->data, 2); + queues_notification_close(g_queue_peek_head_link(displayed)->data, REASON_USER); } while (waiting->length > 0) { - queues_notification_close(g_queue_peek_head_link(waiting)->data, 2); + queues_notification_close(g_queue_peek_head_link(waiting)->data, REASON_USER); } } @@ -288,7 +287,7 @@ void queues_check_timeouts(bool idle) /* remove old message */ if (g_get_monotonic_time() - n->start > n->timeout) { - queues_notification_close(n, 1); + queues_notification_close(n, REASON_TIME); } } } diff --git a/src/queues.h b/src/queues.h index d318180..8bd23f6 100644 --- a/src/queues.h +++ b/src/queues.h @@ -4,6 +4,7 @@ #define DUNST_QUEUE_H #include "notification.h" +#include "dbus.h" /* * Initialise neccessary queues @@ -58,21 +59,15 @@ bool queues_notification_replace_id(notification *new); * * After closing, call wake_up to synchronize the queues with the UI * (which closes the notification on screen) - * - * reasons: - * -1 -> notification is a replacement, no NotificationClosed signal emitted - * 1 -> the notification expired - * 2 -> the notification was dismissed by the user_data - * 3 -> The notification was closed by a call to CloseNotification */ -int queues_notification_close_id(int id, int reason); +int queues_notification_close_id(int id, enum reason reason); /* Close the given notification. SEE queues_notification_close_id. * * @n: (transfer full): The notification to close * @reason: The reason to close * */ -int queues_notification_close(notification *n, int reason); +int queues_notification_close(notification *n, enum reason reason); /* * Pushed the latest notification of history to the displayed queue diff --git a/src/x11/x.c b/src/x11/x.c index aaa4eda..1b17983 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -25,6 +25,7 @@ #include #include +#include "src/dbus.h" #include "src/dunst.h" #include "src/markup.h" #include "src/notification.h" @@ -856,7 +857,7 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, && settings.close_ks.mask == state) { const GList *displayed = queues_get_displayed(); if (displayed && displayed->data) { - queues_notification_close(displayed->data, 2); + queues_notification_close(displayed->data, REASON_USER); wake_up(); } } @@ -937,7 +938,7 @@ static void x_handle_click(XEvent ev) if (n) { if (ev.xbutton.button == Button1) - queues_notification_close(n, 2); + queues_notification_close(n, REASON_USER); else notification_do_action(n); }