euv_core/platform/linux/struct.rs
1use super::*;
2
3/// Raw 192-byte X11 `XEvent` union storage aligned for 64-bit Linux LP64 ABI.
4#[repr(C)]
5#[derive(Clone, Copy)]
6pub(crate) struct X11EventRaw {
7 /// Raw union payload words.
8 pub(crate) pad: [isize; 24],
9}
10
11/// X11 `XKeyEvent` / `XButtonEvent` ABI layout on LP64 Linux.
12#[repr(C)]
13#[derive(Clone, Copy)]
14pub(crate) struct X11KeyOrButtonEvent {
15 /// Event discriminant (`KeyPress`, `KeyRelease`, `ButtonPress`, `ButtonRelease`).
16 pub(crate) event_type: i32,
17 /// X server serial number.
18 pub(crate) serial: usize,
19 /// Non-zero when generated by `SendEvent`.
20 pub(crate) send_event: i32,
21 /// Connection `Display*`.
22 pub(crate) display: *mut c_void,
23 /// Target `Window` XID.
24 pub(crate) window: u64,
25 /// Root window XID.
26 pub(crate) root: u64,
27 /// Subwindow XID.
28 pub(crate) subwindow: u64,
29 /// Event timestamp in milliseconds.
30 pub(crate) time: u64,
31 /// Pointer X coordinate relative to window.
32 pub(crate) x: i32,
33 /// Pointer Y coordinate relative to window.
34 pub(crate) y: i32,
35 /// Pointer X relative to root window.
36 pub(crate) x_root: i32,
37 /// Pointer Y relative to root window.
38 pub(crate) y_root: i32,
39 /// Modifier key / button mask.
40 pub(crate) state: u32,
41 /// Hardware keycode or mouse button number.
42 pub(crate) detail: u32,
43 /// Same-screen flag.
44 pub(crate) same_screen: i32,
45}
46
47/// X11 `XMotionEvent` ABI layout on LP64 Linux.
48#[repr(C)]
49#[derive(Clone, Copy)]
50pub(crate) struct X11MotionEvent {
51 /// Event discriminant (`MotionNotify`).
52 pub(crate) event_type: i32,
53 /// X server serial number.
54 pub(crate) serial: usize,
55 /// Send-event flag.
56 pub(crate) send_event: i32,
57 /// Connection `Display*`.
58 pub(crate) display: *mut c_void,
59 /// Target `Window` XID.
60 pub(crate) window: u64,
61 /// Root window XID.
62 pub(crate) root: u64,
63 /// Subwindow XID.
64 pub(crate) subwindow: u64,
65 /// Timestamp in milliseconds.
66 pub(crate) time: u64,
67 /// Pointer X coordinate relative to window.
68 pub(crate) x: i32,
69 /// Pointer Y coordinate relative to window.
70 pub(crate) y: i32,
71 /// Pointer X relative to root window.
72 pub(crate) x_root: i32,
73 /// Pointer Y relative to root window.
74 pub(crate) y_root: i32,
75 /// Active modifier mask.
76 pub(crate) state: u32,
77 /// Motion hint byte.
78 pub(crate) is_hint: c_char,
79 /// Same-screen flag.
80 pub(crate) same_screen: i32,
81}
82
83/// X11 `XConfigureEvent` ABI layout on LP64 Linux.
84#[repr(C)]
85#[derive(Clone, Copy)]
86pub(crate) struct X11ConfigureEvent {
87 /// Event discriminant (`ConfigureNotify`).
88 pub(crate) event_type: i32,
89 /// X server serial number.
90 pub(crate) serial: usize,
91 /// Send-event flag.
92 pub(crate) send_event: i32,
93 /// Connection `Display*`.
94 pub(crate) display: *mut c_void,
95 /// Event-delivery window XID.
96 pub(crate) event_window: u64,
97 /// Reconfigured target window XID.
98 pub(crate) window: u64,
99 /// New window X position.
100 pub(crate) x: i32,
101 /// New window Y position.
102 pub(crate) y: i32,
103 /// New window client width in physical pixels.
104 pub(crate) width: i32,
105 /// New window client height in physical pixels.
106 pub(crate) height: i32,
107}
108
109/// X11 `XClientMessageEvent` ABI layout on LP64 Linux.
110#[repr(C)]
111#[derive(Clone, Copy)]
112pub(crate) struct X11ClientMessageEvent {
113 /// Event discriminant (`ClientMessage`).
114 pub(crate) event_type: i32,
115 /// X server serial number.
116 pub(crate) serial: usize,
117 /// Send-event flag.
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 /// Message type atom (`WM_PROTOCOLS`).
124 pub(crate) message_type: u64,
125 /// Data format (`8`, `16`, or `32`).
126 pub(crate) format: i32,
127 /// 32-bit protocol data payload (`l[0]` holds `WM_DELETE_WINDOW`).
128 pub(crate) data: [u64; 5],
129}
130
131/// Bundle returned when opening a native Linux X11 or Wayland window.
132#[derive(Clone, Copy, Data, Debug)]
133pub(crate) struct LinuxNativeWindowHandle {
134 /// Dynamically loaded `libX11` or `libwayland-client` handle.
135 #[get(type(copy))]
136 pub(crate) lib: usize,
137 /// True when backed by Wayland; false when backed by X11.
138 #[get(type(copy))]
139 pub(crate) is_wayland: bool,
140 /// Raw `Display*` or `wl_display*`.
141 #[get(type(copy))]
142 pub(crate) display: usize,
143 /// Native X11 `Window` XID or Wayland surface pointer.
144 #[get(type(copy))]
145 pub(crate) window: u64,
146 /// Cached X11 `GC` handle for `XPutImage`.
147 #[get(type(copy))]
148 pub(crate) gc: usize,
149 /// Cached X11 `Visual*` pointer for `XCreateImage`.
150 #[get(type(copy))]
151 pub(crate) visual: usize,
152 /// X11 default visual color depth (e.g., `24` or `32`).
153 #[get(type(copy))]
154 pub(crate) depth: u32,
155 /// Interned `WM_DELETE_WINDOW` atom for graceful window closing.
156 #[get(type(copy))]
157 pub(crate) wm_delete_atom: u64,
158 /// Probed display DPI scale factor (`1.0..=4.0`).
159 #[get(type(copy))]
160 pub(crate) scale_factor: f32,
161}
162
163/// Native Linux X11 / Wayland window record.
164#[derive(Clone, Data, Debug)]
165pub struct LinuxWindowRecord {
166 /// Window configuration.
167 pub(crate) config: WindowConfig,
168 /// Live window state.
169 #[get(type(copy))]
170 pub(crate) state: WindowState,
171 /// True when backed by Wayland; false when backed by X11 Xlib.
172 #[get(type(copy))]
173 pub(crate) is_wayland: bool,
174 /// Raw display handle (`Display*` or `wl_display*`).
175 #[get(type(copy))]
176 pub(crate) display: usize,
177 /// Raw window or surface identifier (`Window` or `wl_surface*`).
178 #[get(type(copy))]
179 pub(crate) window: u64,
180 /// Cached X11 `GC` handle used by `XPutImage`.
181 #[get(type(copy))]
182 pub(crate) gc: usize,
183 /// Cached X11 `Visual*` pointer used by `XCreateImage`.
184 #[get(type(copy))]
185 pub(crate) visual: usize,
186 /// X11 visual depth in bits (`24` or `32`).
187 #[get(type(copy))]
188 pub(crate) depth: u32,
189 /// Interned `WM_DELETE_WINDOW` protocol atom.
190 #[get(type(copy))]
191 pub(crate) wm_delete_atom: u64,
192}
193
194/// Direct Linux X11 / Wayland (`dlopen`-loaded) + Vulkan platform backend.
195#[derive(Clone, Data, Debug)]
196pub struct LinuxPlatform {
197 /// Monotonic window handle generator.
198 #[get(pub(crate), type(copy))]
199 #[get_mut(pub(crate))]
200 #[set(pub(crate))]
201 pub(crate) next_id: u64,
202 /// Dynamically loaded `libX11` handle if present.
203 #[get(pub(crate), type(copy))]
204 #[get_mut(pub(crate))]
205 #[set(pub(crate))]
206 pub(crate) x11_lib: usize,
207 /// Active native Linux windows.
208 pub(crate) windows: HashMap<WindowId, LinuxWindowRecord>,
209 /// Queued window and input events.
210 pub(crate) pending_events: Vec<WindowEvent>,
211 /// Clipboard text cache.
212 #[get(skip)]
213 pub(crate) clipboard_cache: Option<String>,
214 /// Whether the Linux X11/Wayland frame pump is paused for background freeze.
215 #[get(pub(crate), type(copy))]
216 #[set(pub(crate))]
217 pub(crate) pump_paused: bool,
218}