euv_core/platform/linux/struct.rs
1use super::*;
2
3/// Cached `libX11.so.6` function pointer table resolved once per process.
4#[derive(Clone, Copy, Debug, Default)]
5pub(crate) struct LinuxX11Syms {
6 /// Handle returned by `dlopen("libX11.so.6")`.
7 pub(crate) lib: usize,
8 /// `XOpenDisplay` symbol address.
9 pub(crate) open_display: usize,
10 /// `XDefaultScreen` symbol address.
11 pub(crate) default_screen: usize,
12 /// `XRootWindow` symbol address.
13 pub(crate) root_window: usize,
14 /// `XCreateSimpleWindow` symbol address.
15 pub(crate) create_simple_window: usize,
16 /// `XStoreName` symbol address.
17 pub(crate) store_name: usize,
18 /// `XMapWindow` symbol address.
19 pub(crate) map_window: usize,
20 /// `XResizeWindow` symbol address.
21 pub(crate) resize_window: usize,
22 /// `XDestroyWindow` symbol address.
23 pub(crate) destroy_window: usize,
24 /// `XFlush` symbol address.
25 pub(crate) flush: usize,
26 /// `XDefaultGC` symbol address.
27 pub(crate) default_gc: usize,
28 /// `XDefaultVisual` symbol address.
29 pub(crate) default_visual: usize,
30 /// `XDefaultDepth` symbol address.
31 pub(crate) default_depth: usize,
32 /// `XCreateImage` symbol address.
33 pub(crate) create_image: usize,
34 /// `XPutImage` symbol address.
35 pub(crate) put_image: usize,
36 /// `XFree` symbol address.
37 pub(crate) free: usize,
38 /// `XSelectInput` symbol address.
39 pub(crate) select_input: usize,
40 /// `XInternAtom` symbol address.
41 pub(crate) intern_atom: usize,
42 /// `XSetWMProtocols` symbol address.
43 pub(crate) set_wm_protocols: usize,
44 /// `XPending` symbol address.
45 pub(crate) pending: usize,
46 /// `XNextEvent` symbol address.
47 pub(crate) next_event: usize,
48 /// `XLookupString` symbol address.
49 pub(crate) lookup_string: usize,
50 /// `XResourceManagerString` symbol address.
51 pub(crate) resource_manager_string: usize,
52}
53
54/// Cached `libXrandr.so.2` function pointer table resolved once per process.
55#[derive(Clone, Copy, Debug, Default)]
56pub(crate) struct LinuxXRandrSyms {
57 /// `XRRGetScreenInfo` symbol address.
58 pub(crate) get_screen_info: usize,
59 /// `XRRConfigCurrentRate` symbol address.
60 pub(crate) config_current_rate: usize,
61 /// `XRRFreeScreenConfigInfo` symbol address.
62 pub(crate) free_screen_config_info: usize,
63}
64
65/// Cached `libXext.so.6` MIT-SHM function pointer table resolved once per process.
66#[derive(Clone, Copy, Debug, Default)]
67pub(crate) struct LinuxXShmSyms {
68 /// `XShmQueryExtension` symbol address.
69 pub(crate) query_extension: usize,
70 /// `XShmCreateImage` symbol address.
71 pub(crate) create_image: usize,
72 /// `XShmAttach` symbol address.
73 pub(crate) attach: usize,
74 /// `XShmDetach` symbol address.
75 pub(crate) detach: usize,
76 /// `XShmPutImage` symbol address.
77 pub(crate) put_image: usize,
78}
79
80/// Cached `libwayland-client.so.0` + Vulkan WSI symbol table resolved once per process.
81#[derive(Clone, Copy, Debug, Default)]
82pub(crate) struct LinuxWaylandSyms {
83 /// Handle returned by `dlopen("libwayland-client.so.0")`.
84 pub(crate) lib: usize,
85 /// `wl_display_connect` symbol address.
86 pub(crate) display_connect: usize,
87 /// `wl_display_disconnect` symbol address.
88 pub(crate) display_disconnect: usize,
89 /// `wl_display_dispatch_pending` symbol address.
90 pub(crate) display_dispatch_pending: usize,
91 /// `wl_display_dispatch` symbol address.
92 pub(crate) display_dispatch: usize,
93 /// `wl_display_flush` symbol address.
94 pub(crate) display_flush: usize,
95 /// `wl_display_roundtrip` symbol address.
96 pub(crate) display_roundtrip: usize,
97 /// True when `vkCreateWaylandSurfaceKHR` is available in `libvulkan.so.1`.
98 pub(crate) vulkan_wsi_available: bool,
99}
100
101/// Raw 192-byte X11 `XEvent` union storage aligned for 64-bit Linux LP64 ABI.
102#[repr(C)]
103#[derive(Clone, Copy)]
104pub(crate) struct X11EventRaw {
105 /// Raw union payload words.
106 pub(crate) pad: [isize; 24],
107}
108
109/// X11 `XKeyEvent` / `XButtonEvent` ABI layout on LP64 Linux.
110#[repr(C)]
111#[derive(Clone, Copy)]
112pub(crate) struct X11KeyOrButtonEvent {
113 /// Event discriminant (`KeyPress`, `KeyRelease`, `ButtonPress`, `ButtonRelease`).
114 pub(crate) event_type: i32,
115 /// X server serial number.
116 pub(crate) serial: usize,
117 /// Non-zero when generated by `SendEvent`.
118 pub(crate) send_event: i32,
119 /// Connection `Display*`.
120 pub(crate) display: *mut c_void,
121 /// Target `Window` XID.
122 pub(crate) window: u64,
123 /// Root window XID.
124 pub(crate) root: u64,
125 /// Subwindow XID.
126 pub(crate) subwindow: u64,
127 /// Event timestamp in milliseconds.
128 pub(crate) time: u64,
129 /// Pointer X coordinate relative to window.
130 pub(crate) x: i32,
131 /// Pointer Y coordinate relative to window.
132 pub(crate) y: i32,
133 /// Pointer X relative to root window.
134 pub(crate) x_root: i32,
135 /// Pointer Y relative to root window.
136 pub(crate) y_root: i32,
137 /// Modifier key / button mask.
138 pub(crate) state: u32,
139 /// Hardware keycode or mouse button number.
140 pub(crate) detail: u32,
141 /// Same-screen flag.
142 pub(crate) same_screen: i32,
143}
144
145/// X11 `XMotionEvent` ABI layout on LP64 Linux.
146#[repr(C)]
147#[derive(Clone, Copy)]
148pub(crate) struct X11MotionEvent {
149 /// Event discriminant (`MotionNotify`).
150 pub(crate) event_type: i32,
151 /// X server serial number.
152 pub(crate) serial: usize,
153 /// Send-event flag.
154 pub(crate) send_event: i32,
155 /// Connection `Display*`.
156 pub(crate) display: *mut c_void,
157 /// Target `Window` XID.
158 pub(crate) window: u64,
159 /// Root window XID.
160 pub(crate) root: u64,
161 /// Subwindow XID.
162 pub(crate) subwindow: u64,
163 /// Timestamp in milliseconds.
164 pub(crate) time: u64,
165 /// Pointer X coordinate relative to window.
166 pub(crate) x: i32,
167 /// Pointer Y coordinate relative to window.
168 pub(crate) y: i32,
169 /// Pointer X relative to root window.
170 pub(crate) x_root: i32,
171 /// Pointer Y relative to root window.
172 pub(crate) y_root: i32,
173 /// Active modifier mask.
174 pub(crate) state: u32,
175 /// Motion hint byte.
176 pub(crate) is_hint: c_char,
177 /// Same-screen flag.
178 pub(crate) same_screen: i32,
179}
180
181/// X11 `XConfigureEvent` ABI layout on LP64 Linux.
182#[repr(C)]
183#[derive(Clone, Copy)]
184pub(crate) struct X11ConfigureEvent {
185 /// Event discriminant (`ConfigureNotify`).
186 pub(crate) event_type: i32,
187 /// X server serial number.
188 pub(crate) serial: usize,
189 /// Send-event flag.
190 pub(crate) send_event: i32,
191 /// Connection `Display*`.
192 pub(crate) display: *mut c_void,
193 /// Event-delivery window XID.
194 pub(crate) event_window: u64,
195 /// Reconfigured target window XID.
196 pub(crate) window: u64,
197 /// New window X position.
198 pub(crate) x: i32,
199 /// New window Y position.
200 pub(crate) y: i32,
201 /// New window client width in physical pixels.
202 pub(crate) width: i32,
203 /// New window client height in physical pixels.
204 pub(crate) height: i32,
205}
206
207/// X11 `XClientMessageEvent` ABI layout on LP64 Linux.
208#[repr(C)]
209#[derive(Clone, Copy)]
210pub(crate) struct X11ClientMessageEvent {
211 /// Event discriminant (`ClientMessage`).
212 pub(crate) event_type: i32,
213 /// X server serial number.
214 pub(crate) serial: usize,
215 /// Send-event flag.
216 pub(crate) send_event: i32,
217 /// Connection `Display*`.
218 pub(crate) display: *mut c_void,
219 /// Target `Window` XID.
220 pub(crate) window: u64,
221 /// Message type atom (`WM_PROTOCOLS`).
222 pub(crate) message_type: u64,
223 /// Data format (`8`, `16`, or `32`).
224 pub(crate) format: i32,
225 /// 32-bit protocol data payload (`l[0]` holds `WM_DELETE_WINDOW`).
226 pub(crate) data: [u64; 5],
227}
228
229/// Bundle returned when opening a native Linux X11 or Wayland window.
230#[derive(Clone, Copy, Data, Debug)]
231pub(crate) struct LinuxNativeWindowHandle {
232 /// Dynamically loaded `libX11` or `libwayland-client` handle.
233 #[get(type(copy))]
234 pub(crate) lib: usize,
235 /// True when backed by Wayland; false when backed by X11.
236 #[get(type(copy))]
237 pub(crate) is_wayland: bool,
238 /// Raw `Display*` or `wl_display*`.
239 #[get(type(copy))]
240 pub(crate) display: usize,
241 /// Native X11 `Window` XID or Wayland surface pointer.
242 #[get(type(copy))]
243 pub(crate) window: u64,
244 /// Cached X11 `GC` handle for `XPutImage`.
245 #[get(type(copy))]
246 pub(crate) gc: usize,
247 /// Cached X11 `Visual*` pointer for `XCreateImage`.
248 #[get(type(copy))]
249 pub(crate) visual: usize,
250 /// X11 default visual color depth (e.g., `24` or `32`).
251 #[get(type(copy))]
252 pub(crate) depth: u32,
253 /// Interned `WM_DELETE_WINDOW` atom for graceful window closing.
254 #[get(type(copy))]
255 pub(crate) wm_delete_atom: u64,
256 /// Probed display DPI scale factor (`1.0..=4.0`).
257 #[get(type(copy))]
258 pub(crate) scale_factor: f32,
259 /// True when X11 MIT-SHM (`XShmQueryExtension`) is supported on this display.
260 #[get(type(copy))]
261 pub(crate) mit_shm_available: bool,
262 /// True when Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is available.
263 #[get(type(copy))]
264 pub(crate) wayland_vulkan_wsi: bool,
265}
266
267/// Native Linux X11 / Wayland window record.
268#[derive(Clone, Data, Debug)]
269pub struct LinuxWindowRecord {
270 /// Window configuration.
271 pub(crate) config: WindowConfig,
272 /// Live window state.
273 #[get(type(copy))]
274 pub(crate) state: WindowState,
275 /// True when backed by Wayland; false when backed by X11 Xlib.
276 #[get(type(copy))]
277 pub(crate) is_wayland: bool,
278 /// Raw display handle (`Display*` or `wl_display*`).
279 #[get(type(copy))]
280 pub(crate) display: usize,
281 /// Raw window or surface identifier (`Window` or `wl_surface*`).
282 #[get(type(copy))]
283 pub(crate) window: u64,
284 /// Cached X11 `GC` handle used by `XPutImage`.
285 #[get(type(copy))]
286 pub(crate) gc: usize,
287 /// Cached X11 `Visual*` pointer used by `XCreateImage`.
288 #[get(type(copy))]
289 pub(crate) visual: usize,
290 /// X11 visual depth in bits (`24` or `32`).
291 #[get(type(copy))]
292 pub(crate) depth: u32,
293 /// Interned `WM_DELETE_WINDOW` protocol atom.
294 #[get(type(copy))]
295 pub(crate) wm_delete_atom: u64,
296 /// Whether `XMapWindow` has been issued after Frame 1 presentation (eliminates unmapped flash).
297 #[get(type(copy))]
298 pub(crate) revealed: bool,
299 /// Whether X11 MIT-SHM shared-memory image transport is supported by the X server.
300 #[get(type(copy))]
301 pub(crate) mit_shm_available: bool,
302 /// Whether Wayland Vulkan WSI (`VK_KHR_wayland_surface`) is ready on this display.
303 #[get(type(copy))]
304 pub(crate) wayland_vulkan_wsi: bool,
305 /// Reported `wl_output.mode` refresh rate in millihertz (e.g. `240000` for `240Hz`, `0` if unset).
306 #[get(type(copy))]
307 pub(crate) wayland_output_refresh_milli_hz: u32,
308 /// Latest `wp_presentation` feedback timestamp in nanoseconds (`0` before first presentation).
309 #[get(type(copy))]
310 pub(crate) wayland_presentation_time_ns: u64,
311 /// Whether a `wl_surface::frame` callback is currently armed awaiting compositor VSync.
312 #[get(type(copy))]
313 pub(crate) wayland_frame_callback_pending: bool,
314}
315
316/// Direct Linux X11 / Wayland (`dlopen`-loaded) + Vulkan platform backend.
317#[derive(Clone, Data, Debug)]
318pub struct LinuxPlatform {
319 /// Monotonic window handle generator.
320 #[get(pub(crate), type(copy))]
321 #[get_mut(pub(crate))]
322 #[set(pub(crate))]
323 pub(crate) next_id: u64,
324 /// Dynamically loaded `libX11` handle if present.
325 #[get(pub(crate), type(copy))]
326 #[get_mut(pub(crate))]
327 #[set(pub(crate))]
328 pub(crate) x11_lib: usize,
329 /// Active native Linux windows.
330 pub(crate) windows: HashMap<WindowId, LinuxWindowRecord>,
331 /// Queued window and input events.
332 pub(crate) pending_events: Vec<WindowEvent>,
333 /// Clipboard text cache.
334 #[get(skip)]
335 pub(crate) clipboard_cache: Option<String>,
336 /// Whether the Linux X11/Wayland frame pump is paused for background freeze.
337 #[get(pub(crate), type(copy))]
338 #[set(pub(crate))]
339 pub(crate) pump_paused: bool,
340}