aboutsummaryrefslogtreecommitdiff
path: root/src/comet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/comet.c')
-rw-r--r--src/comet.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/comet.c b/src/comet.c
index 64d24c0..eb401b9 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <locale.h>
-#include <unistd.h>
+#include <math.h>
#include "window.h"
#include "layout.h"
@@ -10,26 +10,6 @@
#define ANY_LOG_IMPLEMENT
#include "any_log.h"
-void update(block_t *block)
-{
- if (block->update_cb != NULL) {
- struct timespec now, diff;
- timespec_get(&now, TIME_UTC);
- diff = timespec_diff(block->update_last, now);
-
- if (timespec_greater(diff, block->update_interval)) {
- log_debug("Updating block");
- block->update_cb(block);
- block->update_last = now;
- }
- }
-
- if (block->type == BLOCK_GROUP) {
- for (int i = 0; i < block->group.n_children; i++)
- update(&block->group.children[i]);
- }
-}
-
cairo_surface_t *render(layout_t *layout, layout_info_t info)
{
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, info.width, info.height);
@@ -41,9 +21,9 @@ cairo_surface_t *render(layout_t *layout, layout_info_t info)
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
- color_t color = layout->block->color;
- cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
- cairo_paint(cr);
+ //color_t color = layout->block->color;
+ //cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
+ //cairo_paint(cr);
layout_render(layout, cr);
log_trace("Rendered layouts");
@@ -93,8 +73,8 @@ int main(int argc, char **argv)
.line_width = 0,
.x_padding = 0,
.y_padding = 0,
- .min_width = 0,
- .max_width = 0,
+ .min_width = 100,
+ .max_width = 100,
.update_interval = 0,
.update_last = { 0 },
.update_cb = NULL,
@@ -114,9 +94,9 @@ int main(int argc, char **argv)
.line_width = 0,
.x_padding = 0,
.y_padding = 0,
- .min_width = 0,
+ .min_width = 1000,
.max_width = 0,
- .update_interval = 0,
+ .update_interval = { 0 },
.update_last = { 0 },
.update_cb = NULL,
.event_cb = NULL,
@@ -128,10 +108,11 @@ int main(int argc, char **argv)
},
};
- int width = 1200;
- int height = 200;
- int x_padding = 20;
- int y_padding = 40;
+ 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"),
@@ -144,17 +125,33 @@ int main(int argc, char **argv)
window_resize(&window, width, height);
window_move(&window, x_padding, y_padding);
+
+ 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;
+
while (true) {
- update(&top);
+ struct timespec start;
+ timespec_get(&start, TIME_UTC);
- layout_t *layout = layout_create(&top, info);
+ block_update(&top);
- event_dispatch(&display, layout);
+ layout_t layout;
+ layout_init(&layout, &top, info);
- cairo_surface_t *surface = render(layout, info);
+ event_dispatch(&display, &layout);
+
+ cairo_surface_t *surface = render(&layout, info);
window_present(&window, surface, width, height);
cairo_surface_destroy(surface);
- layout_free(layout);
+ layout_free(&layout);
+
+ struct timespec end;
+ timespec_get(&end, TIME_UTC);
+
+ struct timespec delta = timespec_diff(timespec_diff(end, start), rate);
+ nanosleep(&delta, NULL);
}
window_close(&window);