closing window works again

This commit is contained in:
Rakarake 2026-02-07 15:38:53 +01:00
parent 57e78e8bde
commit 9912c8ce58
3 changed files with 11 additions and 33 deletions

View file

@ -73,12 +73,10 @@ int main(int argc, char *argv[]) {
if (event.type == EVENT_NONE) { if (event.type == EVENT_NONE) {
printf("nothing, absolutely nothing\n"); 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; return 0;
} }

View file

@ -56,7 +56,7 @@ static void xdg_toplevel_configure (
static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) { static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) {
struct client_state *state = data; 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) { 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); wl_callback_destroy(cb);
surface->dirty = true; surface->dirty = true;
// Don't make it stuck.
//wl_display_dispatch(state->wl_display);
} }
static const struct wl_callback_listener wl_surface_frame_listener = { 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); 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) { struct event wait_for_event(struct client_state *state) {
// before dispatch: check that there is nothing elese to do // before dispatch: check that there is nothing elese to do
// check for dirty surface // check for dirty surface
struct surface_list *next = state->surface_list_next; struct surface_list *next = state->surface_list_next;
// keep track of one loop.
struct surface_list *original = next; struct surface_list *original = next;
// exit app
if (!state->running) {
struct event event = { .type = EVENT_EXIT };
return event;
}
while (true) { while (true) {
if (next == NULL) { if (next == NULL) {
next = state->surface_list; next = state->surface_list;
@ -516,8 +497,6 @@ void swap_buffers(struct client_state *state, struct surface *surface) {
// Set time after eglSwapBuffers. // Set time after eglSwapBuffers.
eglSwapInterval(state->egl_display, 0); eglSwapInterval(state->egl_display, 0);
eglSwapBuffers(state->egl_display, next->data.egl_surface); eglSwapBuffers(state->egl_display, next->data.egl_surface);
// maybe unecessary TODO maybe really bad?
//wl_display_dispatch(state->wl_display);
/* Request another frame */ /* Request another frame */
struct wl_callback *cb = wl_surface_frame(surface->wl_surface); struct wl_callback *cb = wl_surface_frame(surface->wl_surface);

View file

@ -40,7 +40,7 @@ struct surface_list {
}; };
struct client_state { struct client_state {
int running; bool running;
int output_type; int output_type;
/* Globals */ /* Globals */
struct wl_display *wl_display; struct wl_display *wl_display;
@ -67,6 +67,7 @@ struct client_state {
#define EVENT_NONE 0 #define EVENT_NONE 0
#define EVENT_DRAW 1 #define EVENT_DRAW 1
#define EVENT_EXIT 2
struct event { struct event {
int type; int type;