From 9912c8ce5863a693147590c9e7dff84d225f2606 Mon Sep 17 00:00:00 2001 From: Rakarake Date: Sat, 7 Feb 2026 15:38:53 +0100 Subject: [PATCH] closing window works again --- glonkers.c | 8 +++----- wayland.c | 33 ++++++--------------------------- wayland.h | 3 ++- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/glonkers.c b/glonkers.c index 7a6ce5f..ac3313e 100644 --- a/glonkers.c +++ b/glonkers.c @@ -73,12 +73,10 @@ int main(int argc, char *argv[]) { if (event.type == EVENT_NONE) { printf("nothing, absolutely nothing\n"); } + if (event.type == EVENT_EXIT) { + running = false; + } } - //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 af7303c..15f06b3 100644 --- a/wayland.c +++ b/wayland.c @@ -56,7 +56,7 @@ static void xdg_toplevel_configure ( static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) { struct client_state *state = data; - state->running = 0; + state->running = false; } void xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, int32_t w, int32_t h) { @@ -108,9 +108,6 @@ wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time) { wl_callback_destroy(cb); surface->dirty = true; - - // Don't make it stuck. - //wl_display_dispatch(state->wl_display); } static const struct wl_callback_listener wl_surface_frame_listener = { @@ -426,32 +423,16 @@ void wayland_init(struct client_state *state, int output_type) { egl_init(state); } -/// 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) { - wl_display_dispatch(state->wl_display); - - // TESTING maybe need to set current egl window or whatever - if (eglMakeCurrent(state->egl_display, next->data.egl_surface, - next->data.egl_surface, state->egl_context)) { - fprintf(stderr, "Made current\n"); - } else { - fprintf(stderr, "Made current failed\n"); - } - - eglSwapBuffers(state->egl_display, next->data.egl_surface); - next = next->next; - } -} - struct event wait_for_event(struct client_state *state) { // 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; + // exit app + if (!state->running) { + struct event event = { .type = EVENT_EXIT }; + return event; + } while (true) { if (next == NULL) { next = state->surface_list; @@ -516,8 +497,6 @@ void swap_buffers(struct client_state *state, struct surface *surface) { // Set time after eglSwapBuffers. eglSwapInterval(state->egl_display, 0); eglSwapBuffers(state->egl_display, next->data.egl_surface); - // maybe unecessary TODO maybe really bad? - //wl_display_dispatch(state->wl_display); /* Request another frame */ struct wl_callback *cb = wl_surface_frame(surface->wl_surface); diff --git a/wayland.h b/wayland.h index abe58f9..dde6af9 100644 --- a/wayland.h +++ b/wayland.h @@ -40,7 +40,7 @@ struct surface_list { }; struct client_state { - int running; + bool running; int output_type; /* Globals */ struct wl_display *wl_display; @@ -67,6 +67,7 @@ struct client_state { #define EVENT_NONE 0 #define EVENT_DRAW 1 +#define EVENT_EXIT 2 struct event { int type;