Add helper scripts and wlroots integration

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-06-29 17:34:45 +03:00
parent 1d99b16685
commit d83e7f4337
5 changed files with 232 additions and 19 deletions

View File

@@ -1,6 +1,13 @@
#include "compositor.h"
#include "common.h"
#include <wayland-server.h>
// wlroots is a C library; wrap headers in extern "C"
extern "C" {
#include <wlr/backend.h>
#include <wlr/util/log.h>
}
#include "wlr/openxr_gl.h"
#include <cstring>
#include <iostream>
@@ -193,10 +200,40 @@ void Compositor::create_session()
ci.createFlags = 0;
OPENXR_CHECK(xrCreateSession, m_xr_instance, &ci, &m_session);
}
// --- wlroots integration: create Wayland display and OpenXR wlroots
// backend --- initialize wlroots logging
wlr_log_init(WLR_DEBUG, nullptr);
// create Wayland display
m_display = wl_display_create();
if (!m_display) {
throw std::runtime_error("Failed to create Wayland display");
}
// get event loop
m_event_loop = wl_display_get_event_loop(m_display);
if (!m_event_loop) {
wl_display_destroy(m_display);
throw std::runtime_error("Failed to get Wayland event loop");
}
// create the OpenXR wlroots backend
m_backend = wlr_openxr_backend_create(m_display, m_event_loop);
if (!m_backend || !wlr_backend_is_openxr(m_backend)) {
wl_display_destroy(m_display);
throw std::runtime_error("Failed to create OpenXR wlroots backend");
}
}
void Compositor::destroy_session()
{
// destroy wlroots backend and Wayland display
if (m_backend) {
wlr_backend_destroy(m_backend);
m_backend = nullptr;
}
if (m_display) {
wl_display_destroy(m_display);
m_display = nullptr;
}
// destroy OpenXR session
OPENXR_CHECK(xrDestroySession, m_session);
}
@@ -249,11 +286,17 @@ void Compositor::poll_events()
void Compositor::run()
{
// start the wlroots backend (this also begins XrSession)
if (!wlr_backend_start(m_backend)) {
throw std::runtime_error("Failed to start wlroots backend");
}
while (m_running) {
this->poll_events();
// dispatch Wayland events
wl_event_loop_dispatch(m_event_loop, 0);
if (m_session_running) {
// TODO: Render frame
// TODO: Render frame (per-eye rendering via OpenXR swapchain)
}
}
}