Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-08-10 08:00:07 +03:00
parent 3e4d4514ad
commit ab7ca71ba2
2 changed files with 165 additions and 4 deletions

View File

@@ -9,7 +9,11 @@ return {
},
},
keybindings = {
{ bind = main("Escape"), action = lunar.quit_compositor },
{ bind = main("Shift-Q"), action = lunar.quit_compositor },
{ bind = main("Shift-R"), action = lunar.reload_config },
},
space = {
offset = { 0, 0, 0 },
radius = 0.7,
},
}

View File

@@ -1050,6 +1050,12 @@ static bool init_xr(LunarWM *this)
}
}
free(extension_properties);
free(a_view_config_types);
free(a_swapchain_formats);
free(a_environment_blend_modes);
vector_free(v_active_instance_extensions);
return true;
}
@@ -1141,14 +1147,165 @@ bool LunarWM_init(LunarWM *this)
this->initialized = true;
// FIXME: Cleanup.
return true;
}
static void free_swapchain_info(LunarWM_SwapchainInfo *sc)
{
if (!sc)
return;
if (sc->v_image_views) {
for (size_t i = 0; i < vector_size(sc->v_image_views); ++i) {
GLuint fb = sc->v_image_views[i];
if (fb)
glDeleteFramebuffers(1, &fb);
}
vector_free(sc->v_image_views);
sc->v_image_views = NULL;
}
if (sc->swapchain) {
xrDestroySwapchain(sc->swapchain);
sc->swapchain = XR_NULL_HANDLE;
}
}
static void cleanup_xr(LunarWM *this)
{
for (int i = 0; i < 2; ++i) {
if (this->xr.swapchain_images[i].a_imgs) {
free(this->xr.swapchain_images[i].a_imgs);
this->xr.swapchain_images[i].a_imgs = NULL;
this->xr.swapchain_images[i].a_imgs_count = 0;
}
}
if (this->xr.swapchains.v_color) {
for (size_t i = 0; i < vector_size(this->xr.swapchains.v_color); ++i)
free_swapchain_info(&this->xr.swapchains.v_color[i]);
vector_free(this->xr.swapchains.v_color);
this->xr.swapchains.v_color = NULL;
}
if (this->xr.swapchains.v_depth) {
for (size_t i = 0; i < vector_size(this->xr.swapchains.v_depth); ++i)
free_swapchain_info(&this->xr.swapchains.v_depth[i]);
vector_free(this->xr.swapchains.v_depth);
this->xr.swapchains.v_depth = NULL;
}
if (this->renderer.fbo) {
glDeleteFramebuffers(1, &this->renderer.fbo);
this->renderer.fbo = 0;
}
this->renderer.tmp_rt = (RenderTexture2D) { 0 };
if (this->xr.view_space)
xrDestroySpace(this->xr.view_space),
this->xr.view_space = XR_NULL_HANDLE;
if (this->xr.local_space)
xrDestroySpace(this->xr.local_space),
this->xr.local_space = XR_NULL_HANDLE;
for (size_t i = 0; i < 2; ++i) {
if (this->xr.hands[i].hand_tracker && this->xr.DestroyHandTrackerEXT)
this->xr.DestroyHandTrackerEXT(this->xr.hands[i].hand_tracker);
this->xr.hands[i].hand_tracker = XR_NULL_HANDLE;
}
if (this->xr.a_view_configuration_views) {
free(this->xr.a_view_configuration_views);
this->xr.a_view_configuration_views = NULL;
this->xr.view_configuration_views_count = 0;
}
if (this->xr.session != XR_NULL_HANDLE) {
if (this->xr.session_running)
xrEndSession(this->xr.session);
xrDestroySession(this->xr.session);
this->xr.session = XR_NULL_HANDLE;
this->xr.session_running = false;
}
if (this->xr.instance)
xrDestroyInstance(this->xr.instance),
this->xr.instance = XR_NULL_HANDLE;
}
static void cleanup_wayland(LunarWM *this)
{
if (this->wayland.v_toplevels) {
for (size_t i = 0; i < vector_size(this->wayland.v_toplevels); ++i) {
if (this->wayland.v_toplevels[i]) {
LunarWM_Toplevel_destroy(this->wayland.v_toplevels[i]);
free(this->wayland.v_toplevels[i]);
}
}
vector_free(this->wayland.v_toplevels);
this->wayland.v_toplevels = NULL;
}
if (this->wayland.cursor) {
wlr_cursor_destroy(this->wayland.cursor);
this->wayland.cursor = NULL;
}
if (this->wayland.seat) {
wlr_seat_destroy(this->wayland.seat);
this->wayland.seat = NULL;
}
if (this->wayland.allocator) {
wlr_allocator_destroy(this->wayland.allocator);
this->wayland.allocator = NULL;
}
if (this->wayland.renderer) {
wlr_renderer_destroy(this->wayland.renderer);
this->wayland.renderer = NULL;
}
if (this->wayland.session) {
wlr_session_destroy(this->wayland.session);
this->wayland.session = NULL;
}
if (this->wayland.backend) {
wlr_backend_destroy(this->wayland.backend);
this->wayland.backend = NULL;
}
if (this->wayland.display) {
wl_display_destroy(this->wayland.display);
this->wayland.display = NULL;
}
}
static void cleanup_lua_cfg(LunarWM *this)
{
if (this->cman) {
config_manager_destroy(this->cman);
this->cman = NULL;
}
}
static void cleanup_raylib_egl(LunarWM *this)
{
if (IsWindowReady()) {
CloseWindow();
}
}
void LunarWM_destroy(LunarWM *this)
{
// FIXME: Cleanup.
if (!this)
return;
eglMakeCurrent(this->wayland.egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
this->wayland.egl_context);
cleanup_xr(this);
cleanup_raylib_egl(this);
cleanup_wayland(this);
cleanup_lua_cfg(this);
memset(this, 0, sizeof(*this));
}
void LunarWM_terminate(LunarWM *this)