1#define _POSIX_C_SOURCE 199309L
11static void wm_base_ping(
void* data,
struct xdg_wm_base* wm_base, uint32_t serial) {
13 xdg_wm_base_pong(wm_base, serial);
18static void registry_handle_global(
void* data,
struct wl_registry* registry, uint32_t name,
const char* interface, uint32_t version) {
21 if (strcmp(interface, wl_compositor_interface.name) == 0) {
22 window->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
23 }
else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
24 window->wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
26 }
else if (strcmp(interface, wl_seat_interface.name) == 0) {
28 }
else if (strcmp(interface, zwp_pointer_constraints_v1_interface.name) == 0) {
29 window->pointer_constraints = wl_registry_bind(registry, name, &zwp_pointer_constraints_v1_interface, 1);
30 }
else if (strcmp(interface, zwp_relative_pointer_manager_v1_interface.name) == 0) {
31 window->relative_pointer_manager = wl_registry_bind(registry, name, &zwp_relative_pointer_manager_v1_interface, 1);
42 if (w > 0 && h > 0 && (w != win->
width || h != win->
height)) {
58 xdg_surface_ack_configure(surf, serial);
63static void locked_pointer_locked(
void* data,
struct zwp_locked_pointer_v1* locked_pointer) { (void)data; (void)locked_pointer; }
64static void locked_pointer_unlocked(
void* data,
struct zwp_locked_pointer_v1* locked_pointer) { (void)data; (void)locked_pointer; }
85 window->cursor_visible =
true;
86 window->
input = input;
88 window->
display = wl_display_connect(NULL);
91 struct wl_registry* reg = wl_display_get_registry(window->
display);
93 wl_display_roundtrip(window->
display);
95 window->surface = wl_compositor_create_surface(window->compositor);
98 window->xdg_surface = xdg_wm_base_get_xdg_surface(window->wm_base, window->surface);
102 window->xdg_toplevel = xdg_surface_get_toplevel(window->xdg_surface);
106 xdg_toplevel_set_title(window->xdg_toplevel, title);
109 struct wl_keyboard* k = wl_seat_get_keyboard(window->seat);
111 struct wl_pointer* p = wl_seat_get_pointer(window->seat);
115 wl_surface_commit(window->surface);
116 wl_display_roundtrip(window->
display);
126 if (window->relative_pointer && window->
input) {
133 while (wl_display_prepare_read(window->
display) != 0) {
134 wl_display_dispatch_pending(window->
display);
136 wl_display_flush(window->
display);
138 struct pollfd pfd = { .fd = wl_display_get_fd(window->
display), .events = POLLIN };
139 if (poll(&pfd, 1, 0) > 0) {
140 wl_display_read_events(window->
display);
142 wl_display_cancel_read(window->
display);
145 wl_display_dispatch_pending(window->
display);
162 window->cursor_visible = visible;
164 if (!visible && window->seat) {
165 struct wl_pointer* pointer = wl_seat_get_pointer(window->seat);
168 wl_pointer_set_cursor(pointer, window->pointer_serial, NULL, 0, 0);
176 if (!window || !window->seat || !window->pointer_constraints)
return;
177 struct wl_pointer* pointer = wl_seat_get_pointer(window->seat);
178 if (!pointer)
return;
180 if (locked && !window->locked_pointer) {
181 window->locked_pointer = zwp_pointer_constraints_v1_lock_pointer(
182 window->pointer_constraints, window->surface, pointer, NULL,
183 ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
186 if (window->relative_pointer_manager) {
187 window->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(
188 window->relative_pointer_manager, pointer);
191 }
else if (!locked && window->locked_pointer) {
192 zwp_locked_pointer_v1_destroy(window->locked_pointer);
193 window->locked_pointer = NULL;
194 if (window->relative_pointer) {
195 zwp_relative_pointer_v1_destroy(window->relative_pointer);
196 window->relative_pointer = NULL;
201uint64_t
sbgl_os_GetPerfCount(
sbgl_Window* window) { (void)window;
struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000000000ULL + ts.tv_nsec; }
207 if (window->relative_pointer) zwp_relative_pointer_v1_destroy(window->relative_pointer);
208 if (window->locked_pointer) zwp_locked_pointer_v1_destroy(window->locked_pointer);
209 if (window->relative_pointer_manager) zwp_relative_pointer_manager_v1_destroy(window->relative_pointer_manager);
210 if (window->pointer_constraints) zwp_pointer_constraints_v1_destroy(window->pointer_constraints);
211 xdg_toplevel_destroy(window->xdg_toplevel);
212 xdg_surface_destroy(window->xdg_surface);
213 wl_surface_destroy(window->surface);
214 wl_display_disconnect(window->
display);
sbgl_platform_Result
Result codes for platform layer operations.
@ SBGL_PLATFORM_ERROR_INIT_FAILED
@ SBGL_PLATFORM_ERROR_NO_DISPLAY
@ SBGL_PLATFORM_ERROR_WINDOW_FAILED
Arena allocator implementation.
#define SBL_ARENA_PUSH_STRUCT_ZERO(arena, type)
static void xdg_surface_handle_configure(void *data, struct xdg_surface *surf, uint32_t serial)
bool sbgl_os_WasWindowResized(sbgl_Window *window)
Checks if the window has been resized since the last check.
static const struct xdg_wm_base_listener wm_base_listener
uint64_t sbgl_os_GetPerfCount(sbgl_Window *window)
Gets the high-resolution performance counter.
static void locked_pointer_locked(void *data, struct zwp_locked_pointer_v1 *locked_pointer)
static void toplevel_handle_configure(void *data, struct xdg_toplevel *t, int32_t w, int32_t h, struct wl_array *s)
void sbgl_os_PollEvents(sbgl_Window *window)
Dispatches OS events (messages/protocol requests).
const struct zwp_relative_pointer_v1_listener relative_pointer_listener
void sbgl_os_SetCursorLocked(sbgl_Window *window, bool locked)
Locks or unlocks the cursor within the window bounds.
static void toplevel_handle_close(void *data, struct xdg_toplevel *t)
uint64_t sbgl_os_GetPerfFreq(sbgl_Window *window)
Gets the performance counter frequency.
static const struct zwp_locked_pointer_v1_listener locked_pointer_listener
void * sbgl_os_GetNativeWindowHandle(sbgl_Window *window)
Retrieves the raw window handle for Vulkan surface creation.
void sbgl_os_SetCursorVisible(sbgl_Window *window, bool visible)
Sets the visibility of the OS cursor for the given window.
static const struct xdg_surface_listener xdg_surface_listener
bool sbgl_os_WindowShouldClose(sbgl_Window *window)
Checks the window's close flag.
void sbgl_os_GetWindowSize(sbgl_Window *window, int *w, int *h)
Retrieves the current client area size.
static const struct wl_registry_listener registry_listener
static void wm_base_ping(void *data, struct xdg_wm_base *wm_base, uint32_t serial)
static const struct xdg_toplevel_listener toplevel_listener
sbgl_platform_Result sbgl_os_CreateWindow(struct SblArena *arena, sbgl_InputState *input, int width, int height, const char *title, sbgl_Window **outWindow)
Creates a native OS window.
bool sbgl_os_IsWindowFocused(sbgl_Window *window)
Checks if the window currently has input focus.
void * sbgl_os_GetNativeDisplayHandle(sbgl_Window *window)
Retrieves the native display handle (Linux specific).
void sbgl_os_DestroyWindow(sbgl_Window *window)
Destroys a native window.
static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
static void locked_pointer_unlocked(void *data, struct zwp_locked_pointer_v1 *locked_pointer)