#include "window.h" #include "events.h" #include "utils.h" #include "wlstate.h" #include "xdg-shell.h" #include static void wayc_surface_configure(void *data, struct xdg_surface *xdg_surface, u32 serial) { (void)data; xdg_surface_ack_configure(xdg_surface, serial); } static void wayc_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, i32 width, i32 height, struct wl_array *states) { (void)data; (void)xdg_toplevel; (void)width; (void)height; (void)states; } static void wayc_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) { (void)data; (void)xdg_toplevel; } static struct xdg_surface_listener WAYC_SURFACE_LISTENER = { wayc_surface_configure, }; static struct xdg_toplevel_listener WAYC_TOPLEVEL_LISTENER = { wayc_toplevel_configure, wayc_toplevel_close, nullptr, nullptr}; bool wayc_window_init(struct window_s *window, const char *name, struct eventloop_s *loop) { wayc_notnull(window); wayc_notnull(loop); memset(window, 0, sizeof(*window)); struct wlstate_s *wlstate = &loop->state; wl_surface_t surface = wl_compositor_create_surface(wlstate->compositor); if (surface == nullptr) return false; xdg_surface_t xdg_surface = xdg_wm_base_get_xdg_surface(wlstate->wm_base, surface); if (xdg_surface == nullptr) { wl_surface_destroy(surface); return false; } xdg_surface_add_listener(xdg_surface, &WAYC_SURFACE_LISTENER, window); xdg_toplevel_t xdg_toplevel = xdg_surface_get_toplevel(xdg_surface); if (xdg_toplevel == nullptr) { xdg_surface_destroy(xdg_surface); wl_surface_destroy(surface); return false; } xdg_toplevel_add_listener(xdg_toplevel, &WAYC_TOPLEVEL_LISTENER, window); xdg_toplevel_set_title(xdg_toplevel, name); window->surface = surface; window->xdg_surface = xdg_surface; window->xdg_toplevel = xdg_toplevel; window->loop = loop; return true; } void wayc_window_deinit(struct window_s *window) { wayc_notnull(window); if (window->surface == nullptr || window->xdg_surface == nullptr || window->xdg_toplevel == nullptr) return; xdg_toplevel_destroy(window->xdg_toplevel); xdg_surface_destroy(window->xdg_surface); wl_surface_destroy(window->surface); window->xdg_toplevel = nullptr; window->xdg_surface = nullptr; window->surface = nullptr; }