Skip to content

x11

FreeBodyEngine.core.window.x11 #

Native X11 backend for FreeBodyEngine.

This mirrors the public behaviour of WaylandWindow, but talks directly to X11 instead of GLFW. It intentionally contains NO graphics API code: EGL/OpenGL stays in the renderer, exactly like the native Wayland backend.

Dependencies
  • system libX11 (Arch: pacman -S libx11)
  • xkbcommon is not required here; X11 resolves keysyms through XLookupKeysym.
Native handles exposed for the graphics backend

window.native_display -> Display* as ctypes.c_void_p window.native_window -> X11 Window/XID as int window.native_visual_id -> X11 visual ID of the window's default visual

For EGL on X11, the renderer should normally use: eglGetDisplay(window.native_display) eglCreateWindowSurface(..., window.native_window, ...)

The EGL config should be compatible with the X11 visual used by this window. For the simple/default X11 path implemented here, native_visual_id is exposed so the renderer can constrain EGL_NATIVE_VISUAL_ID when choosing a config.

Atom = ctypes.c_ulong module-attribute #

Bool = ctypes.c_int module-attribute #

DisplayPtr = ctypes.c_void_p module-attribute #

KEYSYM_NAME_TO_KEY = {name: key for key, name in (_KEY_TO_KEYSYM_NAME.items())} module-attribute #

KeySym = ctypes.c_ulong module-attribute #

Time = ctypes.c_ulong module-attribute #

XID = ctypes.c_ulong module-attribute #

X_COPY_FROM_PARENT = 0 module-attribute #

X_EVENT_BUTTON_PRESS = 4 module-attribute #

X_EVENT_BUTTON_RELEASE = 5 module-attribute #

X_EVENT_CLIENT_MESSAGE = 33 module-attribute #

X_EVENT_CONFIGURE_NOTIFY = 22 module-attribute #

X_EVENT_KEY_PRESS = 2 module-attribute #

X_EVENT_KEY_RELEASE = 3 module-attribute #

X_EVENT_MASK_BUTTON_PRESS = 1 << 2 module-attribute #

X_EVENT_MASK_BUTTON_RELEASE = 1 << 3 module-attribute #

X_EVENT_MASK_KEY_PRESS = 1 << 0 module-attribute #

X_EVENT_MASK_KEY_RELEASE = 1 << 1 module-attribute #

X_EVENT_MASK_POINTER_MOTION = 1 << 6 module-attribute #

X_EVENT_MASK_STRUCTURE_NOTIFY = 1 << 17 module-attribute #

X_EVENT_MOTION_NOTIFY = 6 module-attribute #

X_INPUT_OUTPUT = 1 module-attribute #

X11Mouse(window) #

Bases: Mouse

Mouse implementation matching the externally-visible Wayland backend.

Sets up per-button event/state tracking for window; position starts at the origin until a motion event arrives.

drag_threshold = 0.2 instance-attribute #

last_click_time = -500 instance-attribute #

position = Vector(0, 0) instance-attribute #

window = window instance-attribute #

world_position = Vector(0, 0) instance-attribute #

get_double_click(button) #

True on the frame button was pressed as part of a double-click.

get_down(button) #

True for as long as button is held down.

get_pressed(button) #

True on the frame button was pressed.

get_released(button) #

True on the frame button was released.

update() #

Latches this frame's pressed/released events (set by _handle_event) and updates world-space position.

X11Window(size, title) #

Bases: Window

Native X11/XWayland window backend for FreeBodyEngine.

Opens the X11 display, creates a simple window, and registers for the events this backend handles.

Also opts into detectable autorepeat where the server supports it (_HAS_XKB_DETECTABLE_REPEAT), so a held key reports as PRESS then REPEAT rather than a synthetic RELEASE/PRESS pair per repeat tick.

framebuffer_size property #

The window size scaled by _scale.

mouse = None instance-attribute #

native_display property #

X11 Display* suitable for eglGetDisplay().

native_visual_id property #

Visual ID used by the X11 window; useful for EGL_NATIVE_VISUAL_ID.

native_window property #

X11 Window/XID suitable for eglCreateWindowSurface().

position property writable #

The window's position on screen, in pixels, read via XGetWindowAttributes (falls back to (0, 0) on failure).

size property writable #

The window's last known size, in pixels, as (width, height).

window_type = 'x11' instance-attribute #

close() #

Destroys the X11 window and closes the display connection, if not already closed.

create_mouse() #

Creates this window's X11Mouse and stores it so event handling (e.g. _handle_event) can reach it.

draw() #

Asks the renderer to swap buffers, presenting the frame.

is_ready() #

True until the window has received a WM_DELETE_WINDOW client message.

resize(window, width, height) #

Convenience wrapper that resizes through the size setter.

set_title(new_title) #

Sets the window's WM_NAME via XStoreName.

update() #

Drains all currently queued X11 events (non-blocking) and quits the engine once closed.