diff --git a/glonkers.c b/glonkers.c index 1369325..f45ebba 100644 --- a/glonkers.c +++ b/glonkers.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -55,11 +56,23 @@ int main(int argc, char *argv[]) { Renderer renderer = new_renderer(); - while (state.running) { + bool running = true; + while (running) { double time = time_since_start(); - render(&renderer, state.width, state.height, time, shader_path, 0); - commit(&state); + + struct event event; + wait_for_event(&state, &event); + if (event.type == EVENT_DRAW) { + int width = event.data.draw.width; + int height = event.data.draw.height; + render(&renderer, width, height, time, shader_path, 0); + } } + //while (state.running) { + // double time = time_since_start(); + // render(&renderer, state.width, state.height, time, shader_path, 0); + // commit(&state); + //} return 0; } diff --git a/wayland.c b/wayland.c index 33594ef..0bb46aa 100644 --- a/wayland.c +++ b/wayland.c @@ -295,9 +295,13 @@ void wayland_init(struct client_state *state, int output_type) { } egl_init(state); + + // TODO fix frame callbacks for all surfaces + } /// Swaps front/backbuffers and dispatches pending wayland commands. +// TODO move logic to wait_for_event void commit(struct client_state *state) { struct surface_list *next = state->surface_list; while (next != NULL) { @@ -316,3 +320,7 @@ void commit(struct client_state *state) { } } +void wait_for_event(struct client_state *state, struct event event) { + wl_display_dispatch(state->wl_display); +} + diff --git a/wayland.h b/wayland.h index eedfa46..d423984 100644 --- a/wayland.h +++ b/wayland.h @@ -43,6 +43,20 @@ struct client_state { EGLContext egl_context; }; +#define EVENT_DRAW 0 + +struct event { + int type; + union { + /// EVENT_DRAW + struct { + int width, height; + } draw; + } data; +}; + void wayland_init(struct client_state *state, int output_type); void commit(struct client_state *state); +/// Provide pointer to be filled. +void wait_for_event(struct client_state *state, struct event event);