7#include <X11/extensions/Xfixes.h>
15 Display* display = XOpenDisplay(NULL);
16 if (!display)
return NULL;
18 int screen = DefaultScreen(display);
20 Window win = XCreateSimpleWindow(
21 display, RootWindow(display, screen),
22 0, 0, (
unsigned int)width, (
unsigned int)height, 0,
23 BlackPixel(display, screen),
24 WhitePixel(display, screen)
27 XStoreName(display, win, title);
28 XSelectInput(display, win, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask | FocusChangeMask);
30 Atom wmDeleteMessage = XInternAtom(display,
"WM_DELETE_WINDOW", False);
31 XSetWMProtocols(display, win, &wmDeleteMessage, 1);
33 XMapWindow(display, win);
38 XCloseDisplay(display);
44 window->
input = input;
47 window->
width = width;
77 return window ? window->
focused :
false;
81 if (!window || !window->
display)
return;
93 if (!window || !window->
display)
return;
98 ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
99 GrabModeAsync, GrabModeAsync,
100 window->
window, None, CurrentTime);
102 XUngrabPointer(window->
display, CurrentTime);
108 if (!window || !window->
display)
return;
112 while (XPending(window->
display)) {
114 XNextEvent(window->
display, &event);
116 if (event.type == ClientMessage) {
120 }
else if (event.type == ConfigureNotify) {
121 int w =
event.xconfigure.width;
122 int h =
event.xconfigure.height;
123 if (w > 0 && h > 0 && (w != window->
width || h != window->
height)) {
139 clock_gettime(CLOCK_MONOTONIC, &ts);
140 return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec;
145 return 1000000000ULL;
149 return window ? (
void*)(uintptr_t)window->
window : NULL;
158 return window ? (
void*)window->
display : NULL;
Arena allocator implementation.
#define SBL_ARENA_PUSH_STRUCT_ZERO(arena, type)
bool sbgl_os_WasWindowResized(sbgl_Window *window)
Checks if the window has been resized since the last check.
uint64_t sbgl_os_GetPerfCount(sbgl_Window *window)
Gets the high-resolution performance counter.
void x11_internal_process_event(XEvent *event, sbgl_Window *window)
void sbgl_os_PollEvents(sbgl_Window *window)
Dispatches OS events (messages/protocol requests).
void sbgl_os_SetCursorLocked(sbgl_Window *window, bool locked)
Locks or unlocks the cursor within the window bounds.
uint64_t sbgl_os_GetPerfFreq(sbgl_Window *window)
Gets the performance counter frequency.
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.
sbgl_Window * sbgl_os_CreateWindow(struct SblArena *arena, sbgl_InputState *input, int width, int height, const char *title)
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.
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_GetNativeInstanceHandle(sbgl_Window *window)
Retrieves the native instance handle (Win32 specific).
void sbgl_os_DestroyWindow(sbgl_Window *window)
Destroys a native window.