diff --git a/glonkers.c b/glonkers.c index 081b737..7a6ce5f 100644 --- a/glonkers.c +++ b/glonkers.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { render(&renderer, width, height, time, shader_path, 0); printf("about to 🦬 swap buf %p\n", event.data.draw.surface); swap_buffers(&state, event.data.draw.surface); - printf("🦬🦬🦬 swaping a buffalo\n"); + printf("🦬🦬🦬 swaped a buffalo\n"); } if (event.type == EVENT_NONE) { printf("nothing, absolutely nothing\n"); diff --git a/wayland.c b/wayland.c index b4aef6e..88bcca3 100644 --- a/wayland.c +++ b/wayland.c @@ -330,6 +330,7 @@ void wayland_init(struct client_state *state, int output_type) { state->wl_display = wl_display_connect(NULL); state->wl_registry = wl_display_get_registry(state->wl_display); state->surface_list = NULL; + state->surface_list_next = NULL; wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state); wl_display_roundtrip(state->wl_display); @@ -363,55 +364,83 @@ void commit(struct client_state *state) { } struct event wait_for_event(struct client_state *state) { - for (;;) { - // before dispatch: check that there is nothing elese to do - // check for dirty surface - struct surface_list *next = state->surface_list; - printf("checking for events\n"); - while (next != NULL) { - if (next->data.dirty) { - next->data.dirty = false; - printf("dirty\n"); - - if (eglMakeCurrent(state->egl_display, next->data.egl_surface, - next->data.egl_surface, state->egl_context)) { - } else { - fprintf(stderr, "Made current failed\n"); - } - struct event event = { - .type = EVENT_DRAW, - .data = { - .draw = { - .width = next->data.width, - .height = next->data.height, - .surface = &next->data, - } - } - }; - return event; - } - next = next->next; + // before dispatch: check that there is nothing elese to do + // check for dirty surface + struct surface_list *next = state->surface_list_next; + // keep track of one loop. + struct surface_list *original = next; + while (true) { + if (next == NULL) { + next = state->surface_list; + } + + // do here + if (next->data.dirty) { + next->data.dirty = false; + state->surface_list->next = next->next; + + printf("dirty %p\n", &next->data); + + if (eglMakeCurrent(state->egl_display, next->data.egl_surface, + next->data.egl_surface, state->egl_context)) { + } else { + fprintf(stderr, "Made current failed\n"); + } + struct event event = { + .type = EVENT_DRAW, + .data = { + .draw = { + .width = next->data.width, + .height = next->data.height, + .surface = &next->data, + } + } + }; + return event; + } + + next = next->next; + if (next == original) { + state->surface_list_next = next; + break; } - wl_display_dispatch(state->wl_display); } + wl_display_dispatch(state->wl_display); + struct event event = { + .type = EVENT_NONE, + }; + return event; +} + +void print_surface_list(struct client_state *state) { + struct surface_list *next = state->surface_list; + printf("[\n"); + while (next != NULL) { + printf("ITEM: %p\n", &next->data); + next = next->next; + } + printf("]\n"); } void swap_buffers(struct client_state *state, struct surface *surface) { struct surface_list *next = state->surface_list; + print_surface_list(state); while (next != NULL) { + printf("going to swap buffers 🐃🐃🐃: %p, surface: %p\n", &next->data, surface); if (&next->data == surface) { printf("swapping this buffer 🐃: %p\n", &next->data); eglSwapBuffers(state->egl_display, next->data.egl_surface); // maybe unecessary TODO maybe really bad? - wl_display_dispatch(state->wl_display); + //wl_display_dispatch(state->wl_display); /* Request another frame */ //struct wl_callback *cb = wl_surface_frame(surface->wl_surface); //wl_callback_add_listener(cb, &wl_surface_frame_listener, surface); + printf("done swapping\n"); return; } + printf("next BUF: %p\n", next->next); next = next->next; } fprintf(stderr, "didn't find surface for buffer swap\n"); } - diff --git a/wayland.h b/wayland.h index 446baf8..f6edbb5 100644 --- a/wayland.h +++ b/wayland.h @@ -43,6 +43,8 @@ struct client_state { struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1; struct surface_list *surface_list; + /// Next in queue to check if it wants to be rendered. + struct surface_list *surface_list_next; EGLDisplay egl_display; EGLConfig egl_config;