diff options
| author | Federico Angelilli <code@fedang.net> | 2023-11-12 12:38:56 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2023-11-12 12:38:56 +0100 |
| commit | 965ce846f4d209866ea3a59a3589f6405fa5b91d (patch) | |
| tree | 85582d0d34cd656bf8e63d2c8bc0d6cc4d4df887 /comet.c | |
| parent | 3868d1918c76e963a077ca0a56ef7de7409beb05 (diff) | |
Add xcb event loop using glib's mainloop
Diffstat (limited to 'comet.c')
| -rw-r--r-- | comet.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -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; |
