aboutsummaryrefslogtreecommitdiff
path: root/src/comet.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-17 15:42:49 +0100
committerFederico Angelilli <code@fedang.net>2023-11-17 15:42:49 +0100
commitab92cac18652f72be12f68b5a96095ba8eb5afdf (patch)
treee52a5f295c7cda59e67a341fa87d25983bd56745 /src/comet.c
parentf8363e89257e8b0a4ff71accbd7b6be22935274f (diff)
Reorganize project structure
Diffstat (limited to 'src/comet.c')
-rw-r--r--src/comet.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/comet.c b/src/comet.c
new file mode 100644
index 0000000..9733d4b
--- /dev/null
+++ b/src/comet.c
@@ -0,0 +1,72 @@
+#include <math.h>
+#include <glib.h>
+#include <glib-unix.h>
+
+#include "window.h"
+#include "log.h"
+#include "draw.h"
+#include "connect.h"
+#include "state.h"
+
+#define EVEN(n) ((int)(n) - ((int)(n) % 2 != 0))
+
+static gboolean mainloop_quit(gpointer data)
+{
+ g_main_loop_quit(data);
+ return G_SOURCE_CONTINUE;
+}
+
+static gboolean mainloop_draw(gpointer data)
+{
+ State *state = data;
+ draw_paint(state->draw, state->win);
+ return G_SOURCE_REMOVE;
+}
+
+int main(int argc, char **argv)
+{
+ log_init(G_LOG_LEVEL_DEBUG);
+
+ GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
+
+ Connection *con = connect_create();
+
+ Window *win = window_create(con);
+
+ int screen_width = con->screen_size->width;
+ int screen_height = con->screen_size->height;
+
+ int height = EVEN(round(screen_height * 0.021));
+ int x_padding = EVEN(round(screen_width * 0.005));
+ int y_padding = EVEN(round(screen_height * 0.004));
+
+ log_debug("Calculated dimensions [height=%d, x_pad=%d, y_pad=%d]", height, x_padding, y_padding);
+
+ Drawable *draw = draw_create("Hack 12", height, x_padding, x_padding, y_padding, 1);
+
+ State *state = state_create(win, draw);
+ connect_attach_state(con, state);
+ connect_attach_source(con);
+
+ 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_draw, state);
+
+ 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);
+
+ state_destroy(state);
+ draw_destroy(draw);
+ window_destroy(win);
+
+ return 0;
+}
+
+// vim: ts=4 sw=4 et