#ifndef LUNAR_WM_H #define LUNAR_WM_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Config.h" #include "RayExt.h" struct LunarWM; typedef struct virtual_output { struct wl_global *global; struct wl_display *display; struct wl_list clients; // vo_client_res.link // state we advertise int32_t x, y; // compositor space; keep 0,0 if not relevant int32_t phys_w_mm, phys_h_mm; int32_t width, height; // current mode int32_t refresh_mhz; // mHz int32_t scale; enum wl_output_subpixel subpixel; enum wl_output_transform transform; char const *make, *model; char const *name, *desc; } LunarWM_VirtualOutput; typedef struct { struct LunarWM *server; struct wl_list link; struct wlr_keyboard *wlr_keyboard; struct wl_listener modifiers; struct wl_listener key; struct wl_listener destroy; } LunarWM_Keyboard; typedef struct { uint32_t id; bool is_xwayland; struct LunarWM *server; struct wl_listener commit; struct wl_listener destroy; union { struct wlr_xdg_toplevel *xdg; struct wlr_xwayland_surface *xwl; } u; struct wlr_surface *surface; struct wlr_texture *texture; struct wlr_buffer *locked_buffer; struct wlr_gles2_texture_attribs attribs; struct wlr_gles2_texture *gles_texture; Texture2D rl_texture; } LunarWM_Toplevel; bool LunarWM_Toplevel_init_xdg( LunarWM_Toplevel *tl, struct LunarWM *wm, struct wlr_xdg_toplevel *xdg); bool LunarWM_Toplevel_init_xwayland( LunarWM_Toplevel *tl, struct LunarWM *wm, struct wlr_xwayland_surface *xwl); bool LunarWM_Toplevel_destroy(LunarWM_Toplevel *this); bool LunarWM_Toplevel_update(LunarWM_Toplevel *this); void LunarWM_Toplevel_focus(LunarWM_Toplevel *this); typedef struct { XrSwapchain swapchain; int64_t swapchain_format; GLuint *v_image_views; } LunarWM_SwapchainInfo; typedef struct { XrSwapchain handle; XrSwapchainImageOpenGLESKHR *a_imgs; uint32_t a_imgs_count; } LunarWM_SwapchainImagesEntry; typedef struct { XrHandJointLocationEXT joint_locations[XR_HAND_JOINT_COUNT_EXT]; XrHandTrackerEXT hand_tracker; } LunarWM_Hand; typedef struct { XrTime predicted_display_time; XrCompositionLayerProjection layer_projection; XrCompositionLayerBaseHeader *layers[10]; uint32_t layers_count; XrCompositionLayerProjectionView layer_projection_views[10]; // Hopefully we dont have more than 10. uint32_t layer_projection_views_count; } LunarWM_RenderLayerInfo; typedef struct LunarWM { struct { struct wl_display *display; struct wl_event_loop *event_loop; struct wlr_backend *backend; struct wlr_renderer *renderer; struct wlr_session *session; struct wlr_egl *egl; EGLDisplay egl_display; EGLContext egl_context; EGLConfig egl_config; struct wlr_allocator *allocator; struct wlr_compositor *compositor; struct wlr_subcompositor *subcompositor; struct wlr_data_device_manager *data_device_manager; struct wlr_seat *seat; struct wl_list keyboards; struct wl_listener new_input_listener; struct wlr_xdg_shell *xdg_shell; struct wl_listener new_xdg_toplevel_listener; struct wl_listener new_xdg_popup_listener; struct wlr_cursor *cursor; struct wlr_xwayland *xwayland; struct wl_listener xwayland_ready; struct wl_listener xwayland_new_surface; struct wl_listener xwayland_associate_tmp; // per-surface temp struct wl_listener xwayland_dissociate_tmp; // per-surface temp LunarWM_VirtualOutput *custom_out_virtual; LunarWM_VirtualOutput *custom_out_hud; LunarWM_Toplevel **v_toplevels; int current_focus; } wayland; struct { XrInstance instance; XrSystemId system_id; XrSession session; XrSessionState session_state; struct { LunarWM_SwapchainInfo *v_color; LunarWM_SwapchainInfo *v_depth; } swapchains; LunarWM_SwapchainImagesEntry swapchain_images[2]; // 0 is color, 1 is depth XrViewConfigurationView *a_view_configuration_views; uint32_t view_configuration_views_count; XrEnvironmentBlendMode environment_blend_mode; XrSpace local_space, view_space; LunarWM_Hand hands[2]; XrSystemHandTrackingPropertiesEXT hand_tracking_system_properties; PFN_xrCreateHandTrackerEXT CreateHandTrackerEXT; PFN_xrDestroyHandTrackerEXT DestroyHandTrackerEXT; PFN_xrLocateHandJointsEXT LocateHandJointsEXT; Quaternion recenter_rot; Vector3 recenter_trans; bool recenter_active; bool session_running; } xr; struct { GLuint fbo; RenderTexture2D tmp_rt; RenderTexture2D main_rt; RenderTexture2D hud_rt; Camera3D camera; Shader linear_srgb; Skybox skybox; } renderer; ConfigManager *cman; bool initialized; bool running; } LunarWM; bool LunarWM_init(LunarWM *wm); void LunarWM_destroy(LunarWM *this); void LunarWM_terminate(LunarWM *this); void LunarWM_run(LunarWM *this); extern LunarWM g_wm; #endif // LUNAR_WM_H