From 5ff85b3d28434f531aab3af10c56ac432a9c2998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 9 Jul 2014 16:48:24 +0200 Subject: [PATCH] Integrate signal handling with the GLib main loop --- dunst.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/dunst.c b/dunst.c index c695002..74c3fcc 100644 --- a/dunst.c +++ b/dunst.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -271,6 +272,22 @@ gboolean run(void *data) return false; } +gboolean pause_signal (gpointer data) +{ + pause_display = true; + wake_up(); + + return G_SOURCE_CONTINUE; +} + +gboolean unpause_signal (gpointer data) +{ + pause_display = false; + wake_up(); + + return G_SOURCE_CONTINUE; +} + int main(int argc, char *argv[]) { @@ -300,9 +317,6 @@ int main(int argc, char *argv[]) x_setup(); - signal(SIGUSR1, pause_signal_handler); - signal(SIGUSR2, pause_signal_handler); - if (settings.startup_notification) { notification *n = malloc(sizeof(notification)); n->appname = strdup("dunst"); @@ -345,6 +359,9 @@ int main(int argc, char *argv[]) g_source_attach(x11_source, NULL); + g_unix_signal_add(SIGUSR1, pause_signal, NULL); + g_unix_signal_add(SIGUSR2, unpause_signal, NULL); + run(NULL); g_main_loop_run(mainloop); @@ -353,20 +370,6 @@ int main(int argc, char *argv[]) return 0; } -void pause_signal_handler(int sig) -{ - if (sig == SIGUSR1) { - pause_display = true; - wake_up(); - } - if (sig == SIGUSR2) { - pause_display = false; - wake_up(); - } - - signal(sig, pause_signal_handler); -} - void usage(int exit_status) { fputs("usage:\n", stderr);