From 74f87250a38e92f0f9db7610f3e316a86016b6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 17 May 2022 00:31:59 +0200 Subject: notify-send: Handle Ctrl+C by closing the notification before exiting Avoid leaving notifications we're waiting for around on SIGNINT --- tools/notify-send.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 #include #include +#include #include #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); -- cgit v1.2.1