aboutsummaryrefslogtreecommitdiff
path: root/comet.c
diff options
context:
space:
mode:
Diffstat (limited to 'comet.c')
-rw-r--r--comet.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/comet.c b/comet.c
index b125d78..40a302d 100644
--- a/comet.c
+++ b/comet.c
@@ -5,14 +5,41 @@
#include "log.h"
#include "draw.h"
+ GMainLoop *mainloop = NULL;
+
+static gboolean mainloop_quit(gpointer data)
+{
+ g_main_loop_quit(mainloop);
+ return G_SOURCE_CONTINUE;
+}
+
+static gboolean mainloop_do(gpointer data)
+{
+ draw(data);
+ return G_SOURCE_REMOVE;
+}
+
int main(int argc, char **argv)
{
log_init(G_LOG_LEVEL_DEBUG);
+ mainloop = g_main_loop_new(g_main_context_default(), FALSE);
+
Window *win = window_create();
- draw(win);
- sleep(10);
+ guint source_term = g_unix_signal_add(SIGTERM, mainloop_quit, mainloop);
+ guint source_int = g_unix_signal_add(SIGINT, mainloop_quit, mainloop);
+
+ guint id = g_timeout_add(100, mainloop_do, win);
+
+ log_debug("Starting main loop");
+ g_main_loop_run(mainloop);
+
+ log_debug("Cleaning main loop");
+ g_clear_pointer(&mainloop, g_main_loop_unref);
+
+ g_source_remove(source_term);
+ g_source_remove(source_int);
window_destroy(win);
return 0;