summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-05-17 00:31:59 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-06-07 03:18:38 +0200
commit74f87250a38e92f0f9db7610f3e316a86016b6e2 (patch)
treedc628171a281f243c1ca46f79dda6ddbb2a35ec1
parent07a2b2e32c442aa5c3d92f90828f99dcafe45d01 (diff)
downloadlibnotify-74f87250a38e92f0f9db7610f3e316a86016b6e2.tar.gz
notify-send: Handle Ctrl+C by closing the notification before exiting
Avoid leaving notifications we're waiting for around on SIGNINT
-rw-r--r--tools/notify-send.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/notify-send.c b/tools/notify-send.c
index aea3435..667f9d5 100644
--- a/tools/notify-send.c
+++ b/tools/notify-send.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include <glib-unix.h>
#include <glib/gprintf.h>
#define N_(x) (x)
@@ -148,6 +149,19 @@ handle_closed (NotifyNotification *notify,
g_main_loop_quit (loop);
}
+static gboolean
+on_sigint (gpointer data)
+{
+ NotifyNotification *notification = data;
+
+ g_printerr ("Wait cancelled, closing notification\n");
+
+ notify_notification_close (notification, NULL);
+ g_main_loop_quit (loop);
+
+ return FALSE;
+}
+
static void
handle_action (NotifyNotification *notify,
char *action,
@@ -458,6 +472,7 @@ main (int argc, char *argv[])
}
if (wait) {
+ g_unix_signal_add (SIGINT, on_sigint, notify);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_main_loop_unref (loop);