diff options
| author | Federico Angelilli <code@fedang.net> | 2024-07-10 00:34:56 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-07-10 00:34:56 +0200 |
| commit | dbd61ded1f7ddd55743b324a5b27017f2a7a886b (patch) | |
| tree | 048c97f242cefbb97361d906109b21d3da0c0854 /src | |
| parent | d2f3c14d1f208a11242949e767e4ff1b4d838134 (diff) | |
Refactor main
Diffstat (limited to 'src')
| -rw-r--r-- | src/comet.c | 84 | ||||
| -rw-r--r-- | src/display.c | 7 | ||||
| -rw-r--r-- | src/event.c | 7 |
3 files changed, 36 insertions, 62 deletions
diff --git a/src/comet.c b/src/comet.c index eb401b9..7e3f12c 100644 --- a/src/comet.c +++ b/src/comet.c @@ -43,23 +43,29 @@ int main(int argc, char **argv) window_t window; window_init(&window, &display); - window_move(&window, 100, 100); - window_resize(&window, 1000, 1000); + int x_padding = 10; + int y_padding = 8; + + int height = 30; + int width = display.screen_size->width - 2 * x_padding; + + const char *font = "Hack 12"; + log_debug("Loading font '%s'", font); + + layout_info_t info = { + .fontdesc = pango_font_description_from_string(font), + .context = pango_cairo_create_context(window.cr), + .x_offset = 0, + .height = height, + .width = width, + }; + + window_resize(&window, width, height); + window_move(&window, x_padding, y_padding); block_t blocks[2] = { { - .hidden = false, .color = { 0.2, 0.2, 0.2, 1 }, - .line_color = { 0 }, - .line_width = 0, - .x_padding = 0, - .y_padding = 0, - .min_width = 0, - .max_width = 0, - .update_interval = 0, - .update_last = { 0 }, - .update_cb = NULL, - .event_cb = NULL, .type = BLOCK_TEXT, .text = { .text = "A", @@ -67,22 +73,12 @@ int main(int argc, char **argv) }, }, { - .hidden = false, - .color = { 0.2, 0.2, 0.8, 1 }, - .line_color = { 0 }, - .line_width = 0, - .x_padding = 0, - .y_padding = 0, - .min_width = 100, - .max_width = 100, - .update_interval = 0, - .update_last = { 0 }, - .update_cb = NULL, - .event_cb = NULL, + .color = { 0.2, 0.2, 0.2, 1 }, .type = BLOCK_TEXT, + .min_width = 100, .text = { .text = "B", - .text_color = { 0.8, 0.9, 0.2, 1 }, + .text_color = { 0.8, 0.9, 0.3, 1 }, }, }, }; @@ -90,16 +86,7 @@ int main(int argc, char **argv) block_t top = { .hidden = false, .color = { 0.3, 0.2, 0.5, 1 }, - .line_color = { 0 }, - .line_width = 0, - .x_padding = 0, - .y_padding = 0, .min_width = 1000, - .max_width = 0, - .update_interval = { 0 }, - .update_last = { 0 }, - .update_cb = NULL, - .event_cb = NULL, .type = BLOCK_GROUP, .group = { .spacing = 10, @@ -108,31 +95,16 @@ int main(int argc, char **argv) }, }; - int x_padding = 10; - int y_padding = 8; - - int height = 30; - int width = display.screen_size->width - 2 * x_padding; - - layout_info_t info = { - .fontdesc = pango_font_description_from_string("Hack 13"), - .context = pango_cairo_create_context(window.cr), - .x_offset = 0, - .height = height, - .width = width, - }; - - window_resize(&window, width, height); - window_move(&window, x_padding, y_padding); - + // TODO: Allow ondemand rendering double freq = 1.0 / 60.0 + 0.5e-9; struct timespec rate; rate.tv_sec = (long)freq; rate.tv_nsec = (freq - rate.tv_sec) * 1000000000ul; + struct timespec start, end, diff; + while (true) { - struct timespec start; timespec_get(&start, TIME_UTC); block_update(&top); @@ -147,11 +119,9 @@ int main(int argc, char **argv) cairo_surface_destroy(surface); layout_free(&layout); - struct timespec end; timespec_get(&end, TIME_UTC); - - struct timespec delta = timespec_diff(timespec_diff(end, start), rate); - nanosleep(&delta, NULL); + diff = timespec_diff(timespec_diff(end, start), rate); + nanosleep(&diff, NULL); } window_close(&window); diff --git a/src/display.c b/src/display.c index 0e2754a..2c8519f 100644 --- a/src/display.c +++ b/src/display.c @@ -14,7 +14,7 @@ void display_init(display_t *display) display->connection = xcb_connect(NULL, &preferred_screen); assert(display->connection != NULL && !xcb_connection_has_error(display->connection)); - log_value_debug("Connected to xcb" + log_value_debug("Connected to xcb", "i:preferred_screen", preferred_screen); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(display->connection)); @@ -46,9 +46,12 @@ void display_init(display_t *display) display->info_reply = xcb_randr_get_screen_info_reply(display->connection, cookie, &error); assert(error == NULL); + // TODO: Listen to xrandr notify with select input + // and select the monitor by name + display->screen_size = xcb_randr_get_screen_info_sizes(display->info_reply); assert(display->screen_size != NULL); - log_value_info("Display size", + log_value_info("Display information", "i:width", display->screen_size->width, "i:height", display->screen_size->height); diff --git a/src/event.c b/src/event.c index 909abca..9e65a9e 100644 --- a/src/event.c +++ b/src/event.c @@ -16,7 +16,7 @@ bool event_dispatch_block(layout_t *layout, event_t event) return true; } - log_value_debug("Dispatching event to block", + log_value_trace("Event targeted a block", "i:event_x", event.x, "i:event_y", event.y, "i:x", layout->x, @@ -102,7 +102,8 @@ void event_dispatch(display_t *display, layout_t *layout) break; default: - log_debug("Ignoring button release", button->detail); + log_value_trace("Ignoring button release", + "u:value", button->detail); break; } break; @@ -124,7 +125,7 @@ void event_dispatch(display_t *display, layout_t *layout) const char *extension; const char *name = xcb_errors_get_name_for_xcb_event(display->errors, xevent, &extension); - log_value_debug("Ignoring Xcb event", + log_value_trace("Ignoring Xcb event", "s:name", name, "u:type", xevent->response_type & 0x7f, "s:extension", extension ? extension : "none"); |
