aboutsummaryrefslogtreecommitdiff
path: root/comet.c
blob: 38c6db8a67033c1feed4217d27539ceb0db1ec61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <math.h>
#include <glib.h>
#include <glib-unix.h>

#include "window.h"
#include "log.h"
#include "draw.h"
#include "connection.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_do(gpointer data)
{
        draw(data);
        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 = connection_create();

    Window *win = window_create(con);

    int screen_width = con->screen_size->width;
    int screen_height = con->screen_size->height;
    log_info("w=%d, h=%d", screen_width, screen_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);

    draw_init("Hack 12", height, x_padding, y_padding);

    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;
}

// vim: ts=4 sw=4 et