Use enum for close reason
This commit is contained in:
parent
5f51147263
commit
744712ad77
@ -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");
|
||||
|
@ -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
|
||||
|
11
src/queues.c
11
src/queues.c
@ -7,7 +7,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
src/queues.h
11
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
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user