From 7e2171681dc5f42ce1b7433e13e0a82bc104b8b7 Mon Sep 17 00:00:00 2001 From: Rakarake Date: Thu, 25 Dec 2025 13:43:19 +0100 Subject: [PATCH] resizing and closing --- glonkers.c | 4 +--- wayland.c | 30 ++++++++++++++++++++++++++++-- wayland.h | 1 + 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/glonkers.c b/glonkers.c index 8bcaa7c..4bebc35 100644 --- a/glonkers.c +++ b/glonkers.c @@ -12,8 +12,6 @@ struct timespec program_start; -int running = 1; - void init_timer() { clock_gettime(CLOCK_MONOTONIC, &program_start); } @@ -40,7 +38,7 @@ int main(int argc, char *argv[]) { Renderer renderer = new_renderer(); - while (running) { + while (state.running) { double time = time_since_start(); render(&renderer, state.width, state.height, time, shader_path, 0); commit(&state); diff --git a/wayland.c b/wayland.c index ac0c535..c571f98 100644 --- a/wayland.c +++ b/wayland.c @@ -34,6 +34,31 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = { .ping = xdg_wm_base_ping, }; +static void xdg_toplevel_configure ( + void *data, + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height, + struct wl_array *states + ) { + + struct client_state *state = data; + state->width = width; + state->height = height; + // resize egl window + wl_egl_window_resize(state->egl_window, width, height, 0, 0); +} + +static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) { + struct client_state *state = data; + state->running = 0; +} + +static const struct xdg_toplevel_listener xdg_toplevel_listener = { + .configure = xdg_toplevel_configure, + .close = xdg_toplevel_close, +}; + static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) @@ -53,7 +78,6 @@ registry_handle_global(void *data, struct wl_registry *registry, xdg_wm_base_add_listener(state->xdg_wm_base, &xdg_wm_base_listener, state); } - } static void @@ -160,6 +184,7 @@ void wayland_init(struct client_state *state) { int width = 700, height = 700; state->width = width; state->height = height; + state->running = 1; state->wl_display = wl_display_connect(NULL); state->wl_registry = wl_display_get_registry(state->wl_display); wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state); @@ -170,7 +195,8 @@ void wayland_init(struct client_state *state) { state->xdg_wm_base, state->wl_surface); xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state); state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface); - xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS!"); + xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS! 🕴️"); + xdg_toplevel_add_listener(state->xdg_toplevel, &xdg_toplevel_listener, state); wl_surface_commit(state->wl_surface); egl_init(state); diff --git a/wayland.h b/wayland.h index 3d05bdc..8d79e9b 100644 --- a/wayland.h +++ b/wayland.h @@ -4,6 +4,7 @@ struct client_state { int width, height; + int running; /* Globals */ struct wl_display *wl_display; struct wl_registry *wl_registry;