Include basic window resize listener

This commit is contained in:
Phireh 2024-11-21 22:02:16 +01:00
commit 1ed83da395

View file

@ -14,6 +14,7 @@ struct wl_surface *surface = NULL;
struct xdg_wm_base *wm_base = NULL;
struct xdg_surface *xdg_surface = NULL;
struct xdg_toplevel *xdg_toplevel = NULL;
struct wl_egl_window *window = NULL;
EGLBoolean errcode = 0;
char *egl_s(int code)
@ -66,6 +67,17 @@ registry_listener = {
.global_remove = registry_handle_global_remove,
};
/* Window size change callbacks */
static void xdg_toplevel_configure([[maybe_unused]] void *data, [[maybe_unused]] struct xdg_toplevel *t, int32_t width, int32_t height, [[maybe_unused]] struct wl_array *states)
{
if (!width || !height)
return; // compositor is deferring to us
fprintf(stdout, "Trying to resize window to %d W %d H\n", width, height);
wl_egl_window_resize(window, width, height, 0, 0);
glViewport(0, 0, width, height);
}
int main()
{
fprintf(stdout, "Starting platform layer...\n");
@ -97,8 +109,14 @@ int main()
xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
xdg_toplevel_set_title(xdg_toplevel, "Hi");
const struct xdg_toplevel_listener xdg_toplevel_listener = {
.configure = xdg_toplevel_configure
};
if (xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, NULL))
fprintf(stderr, "Could not set XDG toplevel listener\n");
/* WL EGL initialization */
struct wl_egl_window *window = wl_egl_window_create(surface, 480, 460);
window = wl_egl_window_create(surface, 480, 460);
EGLDisplay egl_display = eglGetDisplay((EGLNativeDisplayType) display);
if (egl_display == EGL_NO_DISPLAY)