euv-core 0.47.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Cached `libX11.so.6` function pointer table resolved once per process.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct LinuxX11Syms {
    /// Handle returned by `dlopen("libX11.so.6")`.
    pub(crate) lib: usize,
    /// `XOpenDisplay` symbol address.
    pub(crate) open_display: usize,
    /// `XDefaultScreen` symbol address.
    pub(crate) default_screen: usize,
    /// `XRootWindow` symbol address.
    pub(crate) root_window: usize,
    /// `XCreateSimpleWindow` symbol address.
    pub(crate) create_simple_window: usize,
    /// `XStoreName` symbol address.
    pub(crate) store_name: usize,
    /// `XMapWindow` symbol address.
    pub(crate) map_window: usize,
    /// `XResizeWindow` symbol address.
    pub(crate) resize_window: usize,
    /// `XDestroyWindow` symbol address.
    pub(crate) destroy_window: usize,
    /// `XFlush` symbol address.
    pub(crate) flush: usize,
    /// `XDefaultGC` symbol address.
    pub(crate) default_gc: usize,
    /// `XDefaultVisual` symbol address.
    pub(crate) default_visual: usize,
    /// `XDefaultDepth` symbol address.
    pub(crate) default_depth: usize,
    /// `XCreateImage` symbol address.
    pub(crate) create_image: usize,
    /// `XPutImage` symbol address.
    pub(crate) put_image: usize,
    /// `XFree` symbol address.
    pub(crate) free: usize,
    /// `XSelectInput` symbol address.
    pub(crate) select_input: usize,
    /// `XInternAtom` symbol address.
    pub(crate) intern_atom: usize,
    /// `XSetWMProtocols` symbol address.
    pub(crate) set_wm_protocols: usize,
    /// `XPending` symbol address.
    pub(crate) pending: usize,
    /// `XNextEvent` symbol address.
    pub(crate) next_event: usize,
    /// `XLookupString` symbol address.
    pub(crate) lookup_string: usize,
    /// `XResourceManagerString` symbol address.
    pub(crate) resource_manager_string: usize,
}

/// Cached `libXrandr.so.2` function pointer table resolved once per process.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct LinuxXRandrSyms {
    /// `XRRGetScreenInfo` symbol address.
    pub(crate) get_screen_info: usize,
    /// `XRRConfigCurrentRate` symbol address.
    pub(crate) config_current_rate: usize,
    /// `XRRFreeScreenConfigInfo` symbol address.
    pub(crate) free_screen_config_info: usize,
}

/// Cached `libXext.so.6` MIT-SHM function pointer table resolved once per process.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct LinuxXShmSyms {
    /// `XShmQueryExtension` symbol address.
    pub(crate) query_extension: usize,
    /// `XShmCreateImage` symbol address.
    pub(crate) create_image: usize,
    /// `XShmAttach` symbol address.
    pub(crate) attach: usize,
    /// `XShmDetach` symbol address.
    pub(crate) detach: usize,
    /// `XShmPutImage` symbol address.
    pub(crate) put_image: usize,
}

/// Cached `libwayland-client.so.0` + Vulkan WSI symbol table resolved once per process.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct LinuxWaylandSyms {
    /// Handle returned by `dlopen("libwayland-client.so.0")`.
    pub(crate) lib: usize,
    /// `wl_display_connect` symbol address.
    pub(crate) display_connect: usize,
    /// `wl_display_disconnect` symbol address.
    pub(crate) display_disconnect: usize,
    /// `wl_display_dispatch_pending` symbol address.
    pub(crate) display_dispatch_pending: usize,
    /// `wl_display_dispatch` symbol address.
    pub(crate) display_dispatch: usize,
    /// `wl_display_flush` symbol address.
    pub(crate) display_flush: usize,
    /// `wl_display_roundtrip` symbol address.
    pub(crate) display_roundtrip: usize,
    /// True when `vkCreateWaylandSurfaceKHR` is available in `libvulkan.so.1`.
    pub(crate) vulkan_wsi_available: bool,
}

/// Raw 192-byte X11 `XEvent` union storage aligned for 64-bit Linux LP64 ABI.
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct X11EventRaw {
    /// Raw union payload words.
    pub(crate) pad: [isize; 24],
}

/// X11 `XKeyEvent` / `XButtonEvent` ABI layout on LP64 Linux.
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct X11KeyOrButtonEvent {
    /// Event discriminant (`KeyPress`, `KeyRelease`, `ButtonPress`, `ButtonRelease`).
    pub(crate) event_type: i32,
    /// X server serial number.
    pub(crate) serial: usize,
    /// Non-zero when generated by `SendEvent`.
    pub(crate) send_event: i32,
    /// Connection `Display*`.
    pub(crate) display: *mut c_void,
    /// Target `Window` XID.
    pub(crate) window: u64,
    /// Root window XID.
    pub(crate) root: u64,
    /// Subwindow XID.
    pub(crate) subwindow: u64,
    /// Event timestamp in milliseconds.
    pub(crate) time: u64,
    /// Pointer X coordinate relative to window.
    pub(crate) x: i32,
    /// Pointer Y coordinate relative to window.
    pub(crate) y: i32,
    /// Pointer X relative to root window.
    pub(crate) x_root: i32,
    /// Pointer Y relative to root window.
    pub(crate) y_root: i32,
    /// Modifier key / button mask.
    pub(crate) state: u32,
    /// Hardware keycode or mouse button number.
    pub(crate) detail: u32,
    /// Same-screen flag.
    pub(crate) same_screen: i32,
}

/// X11 `XMotionEvent` ABI layout on LP64 Linux.
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct X11MotionEvent {
    /// Event discriminant (`MotionNotify`).
    pub(crate) event_type: i32,
    /// X server serial number.
    pub(crate) serial: usize,
    /// Send-event flag.
    pub(crate) send_event: i32,
    /// Connection `Display*`.
    pub(crate) display: *mut c_void,
    /// Target `Window` XID.
    pub(crate) window: u64,
    /// Root window XID.
    pub(crate) root: u64,
    /// Subwindow XID.
    pub(crate) subwindow: u64,
    /// Timestamp in milliseconds.
    pub(crate) time: u64,
    /// Pointer X coordinate relative to window.
    pub(crate) x: i32,
    /// Pointer Y coordinate relative to window.
    pub(crate) y: i32,
    /// Pointer X relative to root window.
    pub(crate) x_root: i32,
    /// Pointer Y relative to root window.
    pub(crate) y_root: i32,
    /// Active modifier mask.
    pub(crate) state: u32,
    /// Motion hint byte.
    pub(crate) is_hint: c_char,
    /// Same-screen flag.
    pub(crate) same_screen: i32,
}

/// X11 `XConfigureEvent` ABI layout on LP64 Linux.
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct X11ConfigureEvent {
    /// Event discriminant (`ConfigureNotify`).
    pub(crate) event_type: i32,
    /// X server serial number.
    pub(crate) serial: usize,
    /// Send-event flag.
    pub(crate) send_event: i32,
    /// Connection `Display*`.
    pub(crate) display: *mut c_void,
    /// Event-delivery window XID.
    pub(crate) event_window: u64,
    /// Reconfigured target window XID.
    pub(crate) window: u64,
    /// New window X position.
    pub(crate) x: i32,
    /// New window Y position.
    pub(crate) y: i32,
    /// New window client width in physical pixels.
    pub(crate) width: i32,
    /// New window client height in physical pixels.
    pub(crate) height: i32,
}

/// X11 `XClientMessageEvent` ABI layout on LP64 Linux.
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct X11ClientMessageEvent {
    /// Event discriminant (`ClientMessage`).
    pub(crate) event_type: i32,
    /// X server serial number.
    pub(crate) serial: usize,
    /// Send-event flag.
    pub(crate) send_event: i32,
    /// Connection `Display*`.
    pub(crate) display: *mut c_void,
    /// Target `Window` XID.
    pub(crate) window: u64,
    /// Message type atom (`WM_PROTOCOLS`).
    pub(crate) message_type: u64,
    /// Data format (`8`, `16`, or `32`).
    pub(crate) format: i32,
    /// 32-bit protocol data payload (`l[0]` holds `WM_DELETE_WINDOW`).
    pub(crate) data: [u64; 5],
}

/// Bundle returned when opening a native Linux X11 or Wayland window.
#[derive(Clone, Copy, Data, Debug)]
pub(crate) struct LinuxNativeWindowHandle {
    /// Dynamically loaded `libX11` or `libwayland-client` handle.
    #[get(type(copy))]
    pub(crate) lib: usize,
    /// True when backed by Wayland; false when backed by X11.
    #[get(type(copy))]
    pub(crate) is_wayland: bool,
    /// Raw `Display*` or `wl_display*`.
    #[get(type(copy))]
    pub(crate) display: usize,
    /// Native X11 `Window` XID or Wayland surface pointer.
    #[get(type(copy))]
    pub(crate) window: u64,
    /// Cached X11 `GC` handle for `XPutImage`.
    #[get(type(copy))]
    pub(crate) gc: usize,
    /// Cached X11 `Visual*` pointer for `XCreateImage`.
    #[get(type(copy))]
    pub(crate) visual: usize,
    /// X11 default visual color depth (e.g., `24` or `32`).
    #[get(type(copy))]
    pub(crate) depth: u32,
    /// Interned `WM_DELETE_WINDOW` atom for graceful window closing.
    #[get(type(copy))]
    pub(crate) wm_delete_atom: u64,
    /// Probed display DPI scale factor (`1.0..=4.0`).
    #[get(type(copy))]
    pub(crate) scale_factor: f32,
    /// True when X11 MIT-SHM (`XShmQueryExtension`) is supported on this display.
    #[get(type(copy))]
    pub(crate) mit_shm_available: bool,
    /// True when Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is available.
    #[get(type(copy))]
    pub(crate) wayland_vulkan_wsi: bool,
}

/// Native Linux X11 / Wayland window record.
#[derive(Clone, Data, Debug)]
pub struct LinuxWindowRecord {
    /// Window configuration.
    pub(crate) config: WindowConfig,
    /// Live window state.
    #[get(type(copy))]
    pub(crate) state: WindowState,
    /// True when backed by Wayland; false when backed by X11 Xlib.
    #[get(type(copy))]
    pub(crate) is_wayland: bool,
    /// Raw display handle (`Display*` or `wl_display*`).
    #[get(type(copy))]
    pub(crate) display: usize,
    /// Raw window or surface identifier (`Window` or `wl_surface*`).
    #[get(type(copy))]
    pub(crate) window: u64,
    /// Cached X11 `GC` handle used by `XPutImage`.
    #[get(type(copy))]
    pub(crate) gc: usize,
    /// Cached X11 `Visual*` pointer used by `XCreateImage`.
    #[get(type(copy))]
    pub(crate) visual: usize,
    /// X11 visual depth in bits (`24` or `32`).
    #[get(type(copy))]
    pub(crate) depth: u32,
    /// Interned `WM_DELETE_WINDOW` protocol atom.
    #[get(type(copy))]
    pub(crate) wm_delete_atom: u64,
    /// Whether `XMapWindow` has been issued after Frame 1 presentation (eliminates unmapped flash).
    #[get(type(copy))]
    pub(crate) revealed: bool,
    /// Whether X11 MIT-SHM shared-memory image transport is supported by the X server.
    #[get(type(copy))]
    pub(crate) mit_shm_available: bool,
    /// Whether Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is ready on this display.
    #[get(type(copy))]
    pub(crate) wayland_vulkan_wsi: bool,
    /// Reported `wl_output.mode` refresh rate in millihertz (e.g. `240000` for `240Hz`, `0` if unset).
    #[get(type(copy))]
    pub(crate) wayland_output_refresh_milli_hz: u32,
    /// Latest `wp_presentation` feedback timestamp in nanoseconds (`0` before first presentation).
    #[get(type(copy))]
    pub(crate) wayland_presentation_time_ns: u64,
    /// Whether a `wl_surface::frame` callback is currently armed awaiting compositor VSync.
    #[get(type(copy))]
    pub(crate) wayland_frame_callback_pending: bool,
}

/// Direct Linux X11 / Wayland (`dlopen`-loaded) + Vulkan platform backend.
#[derive(Clone, Data, Debug)]
pub struct LinuxPlatform {
    /// Monotonic window handle generator.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) next_id: u64,
    /// Dynamically loaded `libX11` handle if present.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) x11_lib: usize,
    /// Active native Linux windows.
    pub(crate) windows: HashMap<WindowId, LinuxWindowRecord>,
    /// Queued window and input events.
    pub(crate) pending_events: Vec<WindowEvent>,
    /// Clipboard text cache.
    #[get(skip)]
    pub(crate) clipboard_cache: Option<String>,
    /// Whether the Linux X11/Wayland frame pump is paused for background freeze.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) pump_paused: bool,
}