1
//! Window configuration types, input state, and platform-specific options.
2
//!
3
//! This module defines the core types used by the windowing system:
4
//!
5
//! - **Window configuration**: [`WindowSize`], [`WindowFlags`], [`WindowPosition`],
6
//!   [`RendererOptions`], [`PlatformSpecificOptions`]
7
//! - **Input state**: [`KeyboardState`], [`MouseState`], [`TouchState`], [`CursorPosition`]
8
//! - **Monitor/display info**: [`Monitor`], [`MonitorId`], [`VideoMode`]
9
//! - **Virtual key codes**: [`VirtualKeyCode`], [`ScanCode`]
10
//! - **Window icons**: [`WindowIcon`], [`TaskBarIcon`]
11
//! - **Platform options**: [`WindowsWindowOptions`], [`LinuxWindowOptions`], [`MacWindowOptions`],
12
//!   [`WasmWindowOptions`]
13
//!
14
//! These types are consumed by the platform shell backends in
15
//! `dll/src/desktop/shell2/{windows,macos,linux}/` and by
16
//! `layout/src/window_state.rs` for state management.
17

            
18
#[cfg(not(feature = "std"))]
19
use alloc::string::{String, ToString};
20
use alloc::{
21
    boxed::Box,
22
    collections::{btree_map::BTreeMap, btree_set::BTreeSet},
23
    vec::Vec,
24
};
25
use core::{
26
    cmp::Ordering,
27
    ffi::c_void,
28
    hash::{Hash, Hasher},
29
    ops,
30
    sync::atomic::{AtomicI64, AtomicUsize, Ordering as AtomicOrdering},
31
};
32

            
33
use azul_css::{
34
    css::CssPath,
35
    props::{
36
        basic::{ColorU, FloatValue, LayoutPoint, LayoutRect, LayoutSize},
37
        property::CssProperty,
38
    },
39
    AzString, LayoutDebugMessage, OptionF32, OptionI32, OptionString, OptionU32, U8Vec,
40
};
41
use rust_fontconfig::FcFontCache;
42

            
43
use crate::{
44
    callbacks::{LayoutCallback, LayoutCallbackType, Update},
45
    dom::{DomId, DomNodeId, NodeHierarchy},
46
    geom::{
47
        LogicalPosition, LogicalRect, LogicalSize, OptionLogicalSize, PhysicalPositionI32,
48
        PhysicalSize,
49
    },
50
    gl::OptionGlContextPtr,
51
    hit_test::{ExternalScrollId, OverflowingScrollNode},
52
    id::{NodeDataContainer, NodeId},
53
    refany::OptionRefAny,
54
    resources::{
55
        DpiScaleFactor, Epoch, GlTextureCache, IdNamespace, ImageCache, ImageMask, ImageRef,
56
        RendererResources, ResourceUpdate,
57
    },
58
    selection::SelectionState,
59
    styled_dom::NodeHierarchyItemId,
60
    task::{Instant, ThreadId, TimerId},
61
    FastBTreeSet, OrderedMap,
62
};
63

            
64
pub const DEFAULT_TITLE: &str = "Azul App";
65

            
66
static LAST_WINDOW_ID: AtomicI64 = AtomicI64::new(0);
67

            
68
/// Unique identifier for a window, auto-assigned via atomic counter.
69
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
70
#[repr(transparent)]
71
pub struct WindowId {
72
    pub id: i64,
73
}
74

            
75
impl Default for WindowId {
76
2
    fn default() -> Self {
77
2
        Self::new()
78
2
    }
79
}
80

            
81
impl WindowId {
82
1003
    pub fn new() -> Self {
83
1003
        Self {
84
1003
            id: LAST_WINDOW_ID.fetch_add(1, AtomicOrdering::SeqCst),
85
1003
        }
86
1003
    }
87
}
88

            
89
static LAST_ICON_KEY: AtomicUsize = AtomicUsize::new(0);
90

            
91
/// Key that is used for checking whether a window icon has changed -
92
/// this way azul doesn't need to diff the actual bytes, just the icon key.
93
/// Use `IconKey::new()` to generate a new, unique key
94
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
95
#[repr(C)]
96
pub struct IconKey {
97
    icon_id: usize,
98
}
99

            
100
impl Default for IconKey {
101
2
    fn default() -> Self {
102
2
        Self::new()
103
2
    }
104
}
105

            
106
impl IconKey {
107
1012
    pub fn new() -> Self {
108
1012
        Self {
109
1012
            icon_id: LAST_ICON_KEY.fetch_add(1, AtomicOrdering::SeqCst),
110
1012
        }
111
1012
    }
112
}
113

            
114
#[repr(C)]
115
#[derive(PartialEq, Copy, Clone, Debug, PartialOrd, Ord, Eq, Hash)]
116
pub struct RendererOptions {
117
    pub vsync: Vsync,
118
    pub srgb: Srgb,
119
    pub hw_accel: HwAcceleration,
120
}
121

            
122
impl_option!(
123
    RendererOptions,
124
    OptionRendererOptions,
125
    [PartialEq, Copy, Clone, Debug, PartialOrd, Ord, Eq, Hash]
126
);
127

            
128
impl Default for RendererOptions {
129
109847
    fn default() -> Self {
130
109847
        Self {
131
109847
            vsync: Vsync::Enabled,
132
109847
            srgb: Srgb::Disabled,
133
109847
            // DontCare defers the choice to AZ_BACKEND / the desktop default,
134
109847
            // which is now CPU (software) rendering on all platforms — matching
135
109847
            // what the headless e2e tests render. GPU is re-selectable via
136
109847
            // AZ_BACKEND=gpu / AZ_BACKEND=auto or HwAcceleration::Enabled.
137
109847
            hw_accel: HwAcceleration::DontCare,
138
109847
        }
139
109847
    }
140
}
141

            
142
impl RendererOptions {
143
    #[must_use]
144
54
    pub const fn new(vsync: Vsync, srgb: Srgb, hw_accel: HwAcceleration) -> Self {
145
54
        Self {
146
54
            vsync,
147
54
            srgb,
148
54
            hw_accel,
149
54
        }
150
54
    }
151
}
152

            
153
#[repr(C)]
154
#[derive(PartialEq, Copy, Clone, Debug, PartialOrd, Ord, Eq, Hash)]
155
pub enum Vsync {
156
    Enabled,
157
    Disabled,
158
    DontCare,
159
}
160

            
161
impl Vsync {
162
    #[must_use]
163
4
    pub const fn is_enabled(&self) -> bool {
164
4
        matches!(self, Self::Enabled)
165
4
    }
166
}
167

            
168
#[repr(C)]
169
#[derive(PartialEq, Copy, Clone, Debug, PartialOrd, Ord, Eq, Hash)]
170
pub enum Srgb {
171
    Enabled,
172
    Disabled,
173
    DontCare,
174
}
175
impl Srgb {
176
    #[must_use]
177
4
    pub const fn is_enabled(&self) -> bool {
178
4
        matches!(self, Self::Enabled)
179
4
    }
180
}
181

            
182
#[repr(C)]
183
#[derive(PartialEq, Copy, Clone, Debug, PartialOrd, Ord, Eq, Hash)]
184
pub enum HwAcceleration {
185
    Enabled,
186
    Disabled,
187
    DontCare,
188
}
189
impl HwAcceleration {
190
    #[must_use]
191
4
    pub const fn is_enabled(&self) -> bool {
192
4
        matches!(self, Self::Enabled)
193
4
    }
194
}
195

            
196
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
197
#[repr(C, u8)]
198
pub enum RawWindowHandle {
199
    IOS(IOSHandle),
200
    MacOS(MacOSHandle),
201
    Xlib(XlibHandle),
202
    Xcb(XcbHandle),
203
    Wayland(WaylandHandle),
204
    Windows(WindowsHandle),
205
    Web(WebHandle),
206
    Android(AndroidHandle),
207
    Unsupported,
208
}
209

            
210
// SAFETY: RawWindowHandle contains raw pointers that are only used as opaque
211
// identifiers for platform window handles. The handle values are not
212
// dereferenced across threads; they are passed to platform APIs on the main thread.
213
unsafe impl Send for RawWindowHandle {}
214

            
215
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
216
#[repr(C)]
217
pub struct IOSHandle {
218
    pub ui_window: *mut c_void,
219
    pub ui_view: *mut c_void,
220
    pub ui_view_controller: *mut c_void,
221
}
222

            
223
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
224
#[repr(C)]
225
pub struct MacOSHandle {
226
    pub ns_window: *mut c_void,
227
    pub ns_view: *mut c_void,
228
}
229

            
230
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
231
#[repr(C)]
232
pub struct XlibHandle {
233
    /// An Xlib Window
234
    pub window: u64,
235
    pub display: *mut c_void,
236
}
237

            
238
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
239
#[repr(C)]
240
pub struct XcbHandle {
241
    /// An X11 `xcb_window_t`.
242
    pub window: u32,
243
    /// A pointer to an X server `xcb_connection_t`.
244
    pub connection: *mut c_void,
245
}
246

            
247
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
248
#[repr(C)]
249
pub struct WaylandHandle {
250
    /// A pointer to a `wl_surface`
251
    pub surface: *mut c_void,
252
    /// A pointer to a `wl_display`.
253
    pub display: *mut c_void,
254
}
255

            
256
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
257
#[repr(C)]
258
pub struct WindowsHandle {
259
    /// A Win32 HWND handle.
260
    pub hwnd: *mut c_void,
261
    /// The HINSTANCE associated with this type's HWND.
262
    pub hinstance: *mut c_void,
263
}
264

            
265
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
266
#[repr(C)]
267
pub struct WebHandle {
268
    /// An ID value inserted into the data attributes of the canvas element as 'raw-handle'
269
    ///
270
    /// When accessing from JS, the attribute will automatically be called rawHandle. Each canvas
271
    /// created by the windowing system should be assigned their own unique ID.
272
    /// 0 should be reserved for invalid / null IDs.
273
    pub id: u32,
274
}
275

            
276
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
277
#[repr(C)]
278
pub struct AndroidHandle {
279
    /// A pointer to an `ANativeWindow`.
280
    pub a_native_window: *mut c_void,
281
}
282

            
283
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
284
#[repr(C)]
285
#[derive(Default)]
286
pub enum MouseCursorType {
287
    #[default]
288
    Default,
289
    Crosshair,
290
    Hand,
291
    Arrow,
292
    Move,
293
    Text,
294
    Wait,
295
    Help,
296
    Progress,
297
    NotAllowed,
298
    ContextMenu,
299
    Cell,
300
    VerticalText,
301
    Alias,
302
    Copy,
303
    NoDrop,
304
    Grab,
305
    Grabbing,
306
    AllScroll,
307
    ZoomIn,
308
    ZoomOut,
309
    EResize,
310
    NResize,
311
    NeResize,
312
    NwResize,
313
    SResize,
314
    SeResize,
315
    SwResize,
316
    WResize,
317
    EwResize,
318
    NsResize,
319
    NeswResize,
320
    NwseResize,
321
    ColResize,
322
    RowResize,
323
}
324

            
325
/// Hardware-dependent keyboard scan code.
326
pub type ScanCode = u32;
327

            
328
/// Which lock keys are currently engaged.
329
///
330
/// Not modifiers: a modifier is held, a lock is toggled, and an app that wants
331
/// to warn "Caps Lock is on" in a password field needs the toggle state, which
332
/// no key event carries.
333
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
334
#[repr(C)]
335
pub struct KeyLocks {
336
    pub caps_lock: bool,
337
    pub num_lock: bool,
338
    pub scroll_lock: bool,
339
}
340

            
341
/// A key identified by its PHYSICAL POSITION, independent of layout.
342
///
343
/// The companion to [`VirtualKeyCode`], which is the LOGICAL key — what the
344
/// user's layout says that position produces. Every modern stack splits these
345
/// because they answer different questions: `KeyboardEvent.code` vs `.key` on
346
/// the web, `PhysicalKey` vs `Key` in winit.
347
///
348
/// `ScanCode` already carried the physical key as a raw `u32`, but a raw
349
/// scancode is platform-specific and unnameable — an app cannot write
350
/// `if scancode == 17` and mean anything portable. This is the same
351
/// information in a form that can be matched on.
352
///
353
/// Names follow the W3C UI Events `code` values, which name each position by
354
/// what it produces on US ANSI. `KeyW` is "the key where W sits on a US
355
/// board" — on AZERTY the user sees Z there, and a game binding "forward"
356
/// wants that position regardless.
357
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
358
#[repr(C)]
359
pub enum PhysicalKey {
360
    /// The platform reported a position this enum does not name.
361
    Unidentified,
362
    // Letters — POSITIONAL. `KeyW` is the key where W sits on US ANSI,
363
    // wherever the user's layout maps it: on AZERTY that key produces Z, and
364
    // a first-person game binding "forward" wants the position, not the
365
    // letter, which is the whole reason this enum exists alongside
366
    // `VirtualKeyCode`.
367
    KeyA,
368
    KeyB,
369
    KeyC,
370
    KeyD,
371
    KeyE,
372
    KeyF,
373
    KeyG,
374
    KeyH,
375
    KeyI,
376
    KeyJ,
377
    KeyK,
378
    KeyL,
379
    KeyM,
380
    KeyN,
381
    KeyO,
382
    KeyP,
383
    KeyQ,
384
    KeyR,
385
    KeyS,
386
    KeyT,
387
    KeyU,
388
    KeyV,
389
    KeyW,
390
    KeyX,
391
    KeyY,
392
    KeyZ,
393
    // Number row.
394
    Digit0,
395
    Digit1,
396
    Digit2,
397
    Digit3,
398
    Digit4,
399
    Digit5,
400
    Digit6,
401
    Digit7,
402
    Digit8,
403
    Digit9,
404
    // Punctuation, by position on the US ANSI board.
405
    Backquote,
406
    Minus,
407
    Equal,
408
    BracketLeft,
409
    BracketRight,
410
    Backslash,
411
    Semicolon,
412
    Quote,
413
    Comma,
414
    Period,
415
    Slash,
416
    // Whitespace and editing.
417
    Enter,
418
    Tab,
419
    Space,
420
    Backspace,
421
    Escape,
422
    CapsLock,
423
    // Modifiers, LEFT and RIGHT distinguished — which `VirtualKeyCode` can do
424
    // but `KeyModifiers` deliberately cannot, since a shortcut cares that
425
    // Shift is down and a game may care which one.
426
    ShiftLeft,
427
    ShiftRight,
428
    ControlLeft,
429
    ControlRight,
430
    AltLeft,
431
    AltRight,
432
    MetaLeft,
433
    MetaRight,
434
    ContextMenu,
435
    // Navigation.
436
    Insert,
437
    Delete,
438
    Home,
439
    End,
440
    PageUp,
441
    PageDown,
442
    ArrowUp,
443
    ArrowDown,
444
    ArrowLeft,
445
    ArrowRight,
446
    // Function row.
447
    F1,
448
    F2,
449
    F3,
450
    F4,
451
    F5,
452
    F6,
453
    F7,
454
    F8,
455
    F9,
456
    F10,
457
    F11,
458
    F12,
459
    F13,
460
    F14,
461
    F15,
462
    F16,
463
    F17,
464
    F18,
465
    F19,
466
    F20,
467
    F21,
468
    F22,
469
    F23,
470
    F24,
471
    // System.
472
    PrintScreen,
473
    ScrollLock,
474
    Pause,
475
    // Numpad — always positional, and distinct from the number row even when
476
    // both produce the same character.
477
    NumLock,
478
    NumpadDivide,
479
    NumpadMultiply,
480
    NumpadSubtract,
481
    NumpadAdd,
482
    NumpadEnter,
483
    NumpadDecimal,
484
    NumpadComma,
485
    NumpadEqual,
486
    Numpad0,
487
    Numpad1,
488
    Numpad2,
489
    Numpad3,
490
    Numpad4,
491
    Numpad5,
492
    Numpad6,
493
    Numpad7,
494
    Numpad8,
495
    Numpad9,
496
    // ISO/JIS keys that ANSI boards do not have.
497
    IntlBackslash,
498
    IntlRo,
499
    IntlYen,
500
    Lang1,
501
    Lang2,
502
    Convert,
503
    NonConvert,
504
    KanaMode,
505
}
506

            
507
/// Determines which keys are pressed currently (modifiers, etc.)
508
#[derive(Default, Debug, Clone, PartialEq, Eq)]
509
#[repr(C)]
510
pub struct KeyboardState {
511
    /// Currently pressed virtual keycode - **DO NOT USE THIS FOR TEXT INPUT**.
512
    ///
513
    /// For text input, use the `text_input` parameter in callbacks.
514
    /// For example entering `à` will fire a `VirtualKeyCode::Grave`, then `VirtualKeyCode::A`,
515
    /// so to correctly combine characters, the framework handles text composition internally.
516
    pub current_virtual_keycode: OptionVirtualKeyCode,
517
    /// Currently pressed virtual keycodes (READONLY) - it can happen that more than one key is
518
    /// pressed
519
    ///
520
    /// This is essentially an "extension" of `current_scancodes` - `current_keys` stores the
521
    /// characters, but what if the pressed key is not a character (such as `ArrowRight` or
522
    /// `PgUp`)?
523
    ///
524
    /// Note that this can have an overlap, so pressing "a" on the keyboard will insert
525
    /// both a `VirtualKeyCode::A` into `current_virtual_keycodes` and text input will be handled
526
    /// by the framework automatically for contenteditable nodes.
527
    pub pressed_virtual_keycodes: VirtualKeyCodeVec,
528
    /// Same as `current_virtual_keycodes`, but the scancode identifies the physical key pressed,
529
    /// independent of the keyboard layout. The scancode does not change if the user adjusts the
530
    /// host's keyboard map. Use when the physical location of the key is more important than
531
    /// the key's host GUI semantics, such as for movement controls in a first-person game
532
    /// (German keyboard: Z key, UK keyboard: Y key, etc.)
533
    pub pressed_scancodes: ScanCodeVec,
534
    /// Which modifiers are held right now. (READONLY)
535
    ///
536
    /// Derivable from `pressed_virtual_keycodes` by scanning for the six
537
    /// modifier keycodes, which is what every caller was doing. Carrying it
538
    /// directly makes the common check cheap and makes `ModifiersChanged`
539
    /// possible to emit at all.
540
    pub modifiers: crate::events::KeyModifiers,
541
    /// Which lock keys are engaged. (READONLY)
542
    ///
543
    /// NOT derivable from the pressed set: a lock is a toggle, so it stays on
544
    /// after the key is released and no key event describes it. It has to be
545
    /// read from the OS.
546
    pub locks: KeyLocks,
547
    /// Whether the current key event is an auto-repeat rather than a fresh
548
    /// press. (READONLY)
549
    ///
550
    /// A text field wants repeats; a jump button does not, and without this
551
    /// the two are indistinguishable.
552
    pub is_repeat: bool,
553
    /// Physical position of the currently pressed key. (READONLY)
554
    pub current_physical_key: OptionPhysicalKey,
555
}
556

            
557
impl KeyboardState {
558
    #[must_use]
559
121237
    pub fn shift_down(&self) -> bool {
560
121237
        self.is_key_down(VirtualKeyCode::LShift) || self.is_key_down(VirtualKeyCode::RShift)
561
121237
    }
562
    #[must_use]
563
101265
    pub fn ctrl_down(&self) -> bool {
564
101265
        self.is_key_down(VirtualKeyCode::LControl) || self.is_key_down(VirtualKeyCode::RControl)
565
101265
    }
566
    #[must_use]
567
101222
    pub fn alt_down(&self) -> bool {
568
101222
        self.is_key_down(VirtualKeyCode::LAlt) || self.is_key_down(VirtualKeyCode::RAlt)
569
101222
    }
570
    #[must_use]
571
1874
    pub fn super_down(&self) -> bool {
572
1874
        self.is_key_down(VirtualKeyCode::LWin) || self.is_key_down(VirtualKeyCode::RWin)
573
1874
    }
574
    /// The platform's PRIMARY shortcut modifier: Cmd (super) on macOS, Ctrl
575
    /// everywhere else (MWA-A2). Every standard editing shortcut
576
    /// (copy / cut / paste / select-all / undo / redo) keys off this —
577
    /// hardcoding `ctrl_down()` made Cmd+C/X/V/A/Z dead on macOS, where Cmd
578
    /// arrives as LWin/super.
579
    #[must_use]
580
35
    pub fn primary_down(&self) -> bool {
581
35
        if cfg!(target_os = "macos") {
582
            self.super_down()
583
        } else {
584
35
            self.ctrl_down()
585
        }
586
35
    }
587
    #[must_use]
588
522329
    pub fn is_key_down(&self, key: VirtualKeyCode) -> bool {
589
908247
        self.pressed_virtual_keycodes.iter().any(|k| *k == key)
590
522329
    }
591

            
592
    /// The modifier set implied by the keys currently held.
593
    ///
594
    /// `modifiers` is a stored field because callbacks read it directly and
595
    /// `ModifiersChanged` diffs against it, but its VALUE is a pure function
596
    /// of the pressed set — so it must never be assigned independently, only
597
    /// recomputed from here.
598
    #[must_use]
599
12
    pub fn derived_modifiers(&self) -> crate::events::KeyModifiers {
600
12
        crate::events::KeyModifiers {
601
12
            shift: self.shift_down(),
602
12
            ctrl: self.ctrl_down(),
603
12
            alt: self.alt_down(),
604
12
            meta: self.super_down(),
605
12
        }
606
12
    }
607

            
608
    /// Bring `modifiers` back in step with the pressed set.
609
    ///
610
    /// Call this after ANY change to `pressed_virtual_keycodes`. Nothing did,
611
    /// on any backend, so `modifiers` sat at its default: every callback that
612
    /// read it saw "no modifiers held" no matter what was down, and
613
    /// `ModifiersChanged` could never fire because the diff compared two
614
    /// identical defaults. The derived accessors (`shift_down()` and friends)
615
    /// were right the whole time, which is why shortcuts still worked and the
616
    /// gap stayed invisible.
617
12
    pub fn sync_modifiers(&mut self) {
618
12
        self.modifiers = self.derived_modifiers();
619
12
    }
620

            
621
    /// Returns `true` iff every entry of `chord` is currently active in this
622
    /// keyboard state. Used by accelerator/keymap registrations to evaluate
623
    /// shortcuts like `[Ctrl, Shift, Key(VirtualKeyCode::S)]`.
624
    ///
625
    /// An empty chord matches trivially.
626
    #[must_use]
627
8
    pub fn matches_accelerator(&self, chord: &[AcceleratorKey]) -> bool {
628
20011
        chord.iter().all(|a| a.matches(self))
629
8
    }
630
}
631

            
632
impl_option!(
633
    KeyboardState,
634
    OptionKeyboardState,
635
    copy = false,
636
    [Debug, Clone, PartialEq, Eq]
637
);
638

            
639
// char is not ABI-stable, use u32 instead
640
impl_option!(
641
    u32,
642
    OptionChar,
643
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
644
);
645
impl_option!(
646
    VirtualKeyCode,
647
    OptionVirtualKeyCode,
648
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
649
);
650
impl_option!(
651
    PhysicalKey,
652
    OptionPhysicalKey,
653
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
654
);
655

            
656
impl_vec!(
657
    VirtualKeyCode,
658
    VirtualKeyCodeVec,
659
    VirtualKeyCodeVecDestructor,
660
    VirtualKeyCodeVecDestructorType,
661
    VirtualKeyCodeVecSlice,
662
    OptionVirtualKeyCode
663
);
664
impl_vec_debug!(VirtualKeyCode, VirtualKeyCodeVec);
665
impl_vec_partialord!(VirtualKeyCode, VirtualKeyCodeVec);
666
impl_vec_ord!(VirtualKeyCode, VirtualKeyCodeVec);
667
impl_vec_clone!(
668
    VirtualKeyCode,
669
    VirtualKeyCodeVec,
670
    VirtualKeyCodeVecDestructor
671
);
672
impl_vec_partialeq!(VirtualKeyCode, VirtualKeyCodeVec);
673
impl_vec_eq!(VirtualKeyCode, VirtualKeyCodeVec);
674
impl_vec_hash!(VirtualKeyCode, VirtualKeyCodeVec);
675
impl_vec_mut!(VirtualKeyCode, VirtualKeyCodeVec);
676

            
677
impl_vec_as_hashmap!(VirtualKeyCode, VirtualKeyCodeVec);
678

            
679
impl_vec!(
680
    ScanCode,
681
    ScanCodeVec,
682
    ScanCodeVecDestructor,
683
    ScanCodeVecDestructorType,
684
    ScanCodeVecSlice,
685
    OptionU32
686
);
687
impl_vec_debug!(ScanCode, ScanCodeVec);
688
impl_vec_partialord!(ScanCode, ScanCodeVec);
689
impl_vec_ord!(ScanCode, ScanCodeVec);
690
impl_vec_clone!(ScanCode, ScanCodeVec, ScanCodeVecDestructor);
691
impl_vec_partialeq!(ScanCode, ScanCodeVec);
692
impl_vec_eq!(ScanCode, ScanCodeVec);
693
impl_vec_hash!(ScanCode, ScanCodeVec);
694
impl_vec_mut!(ScanCode, ScanCodeVec);
695

            
696
impl_vec_as_hashmap!(ScanCode, ScanCodeVec);
697

            
698
/// Mouse position, cursor type, user scroll input, etc.
699
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq)]
700
#[repr(C)]
701
pub struct MouseState {
702
    // Field order is by DECREASING ALIGNMENT, not by topic. `#[repr(C)]` lays
703
    // these out literally, so the u64 has to lead and the five bools have to
704
    // trail — the previous grouping cost ~8 bytes of padding per instance,
705
    // and this struct is copied every mouse move.
706
    /// Which physical pointing device is driving, or `0` when the platform
707
    /// does not say. (READONLY)
708
    pub pointer_device_id: u64,
709
    /// Where is the mouse cursor currently? Set to `None` if the window is not focused.
710
    /// (READWRITE)
711
    pub cursor_position: CursorPosition,
712
    /// Current mouse cursor type, set to `None` if the cursor is hidden. (READWRITE)
713
    pub mouse_cursor_type: OptionMouseCursorType,
714
    /// What kind of device is currently driving the pointer. (READONLY)
715
    ///
716
    /// On `MouseState` rather than on the event because it is a property of
717
    /// the DEVICE, not of one motion — an app can ask "is this a trackpad?"
718
    /// from any callback, not only from inside a pointer handler.
719
    pub pointer_source: crate::events::PointerSource,
720
    /// Is the mouse cursor locked to the current window (important for applications like games)?
721
    /// (READWRITE)
722
    pub is_cursor_locked: bool,
723
    /// Is the left mouse button down? (READONLY)
724
    pub left_down: bool,
725
    /// Is the right mouse button down? (READONLY)
726
    pub right_down: bool,
727
    /// Is the middle mouse button down? (READONLY)
728
    pub middle_down: bool,
729
    /// Bitmask of the thumb buttons currently held. (READONLY)
730
    ///
731
    /// A bitmask rather than two bools because the set is open-ended: a mouse
732
    /// can report buttons past forward, and the shells already carry them as
733
    /// `MouseButton::Other(n)`. Bit 0 is back, bit 1 is forward — see
734
    /// `MOUSE_OTHER_MASK_BACK` / `MOUSE_OTHER_MASK_FORWARD`; use
735
    /// [`MouseState::back_down`] and [`MouseState::forward_down`] rather than
736
    /// testing bits by hand.
737
    pub other_down: u8,
738
}
739

            
740
impl MouseState {
741
    /// Whether the thumb "back" button is held.
742
    #[must_use]
743
3500
    pub const fn back_down(&self) -> bool {
744
3500
        self.other_down & crate::events::MOUSE_OTHER_MASK_BACK != 0
745
3500
    }
746

            
747
    /// Whether the thumb "forward" button is held.
748
    #[must_use]
749
3500
    pub const fn forward_down(&self) -> bool {
750
3500
        self.other_down & crate::events::MOUSE_OTHER_MASK_FORWARD != 0
751
3500
    }
752

            
753
    #[must_use]
754
15
    pub const fn matches(&self, context: &ContextMenuMouseButton) -> bool {
755
        use self::ContextMenuMouseButton::{Left, Middle, Right};
756
15
        match context {
757
5
            Left => self.left_down,
758
5
            Right => self.right_down,
759
5
            Middle => self.middle_down,
760
        }
761
15
    }
762
}
763

            
764
impl_option!(
765
    MouseState,
766
    OptionMouseState,
767
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd]
768
);
769

            
770
impl_option!(
771
    MouseCursorType,
772
    OptionMouseCursorType,
773
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
774
);
775

            
776
impl Default for MouseState {
777
111645
    fn default() -> Self {
778
111645
        Self {
779
111645
            mouse_cursor_type: Some(MouseCursorType::Default).into(),
780
111645
            cursor_position: CursorPosition::default(),
781
111645
            is_cursor_locked: false,
782
111645
            left_down: false,
783
111645
            right_down: false,
784
111645
            middle_down: false,
785
111645
            other_down: 0,
786
111645
            pointer_source: crate::events::PointerSource::Unknown,
787
111645
            pointer_device_id: 0,
788
111645
        }
789
111645
    }
790
}
791

            
792
/// The seat id of the PRIMARY pointer - the one `FullWindowState::mouse_state`
793
/// describes. Every platform has exactly this seat; most have only it.
794
pub const PRIMARY_POINTER_SEAT: u64 = 0;
795

            
796
/// One ADDITIONAL pointer seat (9b-ii): an independent cursor with its own
797
/// position, buttons and hover, next to the primary one.
798
///
799
/// A SEAT is not a DEVICE. `MouseState::pointer_device_id` names the physical
800
/// hardware that last drove a cursor; a seat is the cursor itself. The
801
/// distinction is the whole design: on Windows, macOS, Android and iOS the OS
802
/// merges every mouse into ONE cursor, so two mice are two devices driving one
803
/// seat - a click from the second mouse after a move from the first lands
804
/// where the first left the cursor, because that IS where the cursor is.
805
/// Keying state by device would have split that one cursor into two entries
806
/// with different positions, and dispatched the click somewhere the user
807
/// could not see. Only X11 (MPX master pointers) and Wayland (one `wl_seat`
808
/// per user) can present a second cursor, and only there does a second entry
809
/// exist.
810
///
811
/// The primary seat is NOT in `pointer_seats`; it stays `mouse_state` so
812
/// every existing reader of "the mouse" keeps meaning what it meant.
813
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd)]
814
#[repr(C)]
815
pub struct PointerSeat {
816
    /// The platform's identity for this cursor - an X11 master pointer id,
817
    /// a Wayland seat's global name. Never [`PRIMARY_POINTER_SEAT`].
818
    pub seat_id: u64,
819
    /// The seat's own cursor state.
820
    pub state: MouseState,
821
}
822

            
823
impl_option!(
824
    PointerSeat,
825
    OptionPointerSeat,
826
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd]
827
);
828

            
829
impl_vec!(
830
    PointerSeat,
831
    PointerSeatVec,
832
    PointerSeatVecDestructor,
833
    PointerSeatVecDestructorType,
834
    PointerSeatVecSlice,
835
    OptionPointerSeat
836
);
837
impl_vec_debug!(PointerSeat, PointerSeatVec);
838
impl_vec_clone!(PointerSeat, PointerSeatVec, PointerSeatVecDestructor);
839
impl_vec_partialeq!(PointerSeat, PointerSeatVec);
840
impl_vec_mut!(PointerSeat, PointerSeatVec);
841

            
842
/// One NON-primary keyboard seat's state (9b-ii-a-i): the per-seat twin of
843
/// [`PointerSeat`].
844
///
845
/// X11 MPX pairs each master keyboard with a master
846
/// pointer, and a Wayland `wl_seat` carries both; the seat id is the same
847
/// number [`PointerSeat::seat_id`] uses for that pairing, so a keystroke and
848
/// a click from the same person carry the same seat. The primary seat's
849
/// keyboard is `FullWindowState::keyboard_state`, never listed here.
850
///
851
/// FOCUS IS SHARED: azul has one focused node, so every seat's keys reach
852
/// it (MPX's per-keyboard focus is not modelled - 9b-ii-a-i-d).
853
#[derive(Debug, Clone, PartialEq, Eq)]
854
#[repr(C)]
855
pub struct KeyboardSeat {
856
    /// The seat's identity - the same id as the seat's pointer. Never
857
    /// [`PRIMARY_POINTER_SEAT`].
858
    pub seat_id: u64,
859
    /// The seat's own keyboard state.
860
    pub state: KeyboardState,
861
}
862

            
863
impl_option!(
864
    KeyboardSeat,
865
    OptionKeyboardSeat,
866
    copy = false,
867
    [Debug, Clone, PartialEq, Eq]
868
);
869

            
870
impl_vec!(
871
    KeyboardSeat,
872
    KeyboardSeatVec,
873
    KeyboardSeatVecDestructor,
874
    KeyboardSeatVecDestructorType,
875
    KeyboardSeatVecSlice,
876
    OptionKeyboardSeat
877
);
878
impl_vec_debug!(KeyboardSeat, KeyboardSeatVec);
879
impl_vec_clone!(KeyboardSeat, KeyboardSeatVec, KeyboardSeatVecDestructor);
880
impl_vec_partialeq!(KeyboardSeat, KeyboardSeatVec);
881
impl_vec_mut!(KeyboardSeat, KeyboardSeatVec);
882

            
883
#[derive(Debug, Clone, PartialEq, PartialOrd, Hash, Eq, Ord)]
884
#[repr(C)]
885
pub struct VirtualKeyCodeCombo {
886
    pub keys: VirtualKeyCodeVec,
887
}
888

            
889
impl_option!(
890
    VirtualKeyCodeCombo,
891
    OptionVirtualKeyCodeCombo,
892
    copy = false,
893
    [Debug, Clone, PartialEq, PartialOrd, Hash, Eq, Ord]
894
);
895

            
896
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Hash, Eq, Ord)]
897
#[repr(C)]
898
#[derive(Default)]
899
pub enum ContextMenuMouseButton {
900
    #[default]
901
    Right,
902
    Middle,
903
    Left,
904
}
905

            
906
impl MouseState {
907
    /// Returns whether any mouse button (left, right or center) is currently held down
908
    #[must_use]
909
3361
    pub const fn mouse_down(&self) -> bool {
910
3361
        self.right_down || self.left_down || self.middle_down
911
3361
    }
912

            
913
    /// Snapshot the button-down flags as a `MouseButtonState` for drag tracking.
914
    #[must_use]
915
18
    pub const fn button_state(&self) -> crate::events::MouseButtonState {
916
18
        crate::events::MouseButtonState {
917
18
            left_down: self.left_down,
918
18
            right_down: self.right_down,
919
18
            middle_down: self.middle_down,
920
18
        }
921
18
    }
922
}
923

            
924
impl From<&MouseState> for crate::events::MouseButtonState {
925
9
    fn from(s: &MouseState) -> Self {
926
9
        s.button_state()
927
9
    }
928
}
929

            
930
impl crate::events::MouseButtonState {
931
    /// Returns true if any of the tracked buttons is held down.
932
    #[must_use]
933
11
    pub const fn any_down(&self) -> bool {
934
11
        self.left_down || self.right_down || self.middle_down
935
11
    }
936
}
937

            
938
/// Result of dispatching a scroll delta into the system scroll-handling pipeline.
939
///
940
/// Returned by [`process_system_scroll`]. Higher layers can use the
941
/// [`ScrollResult::remaining_delta`] to forward un-consumed scroll to a parent
942
/// container, and [`ScrollResult::hit_scrollbar`] to distinguish scrollbar-drag
943
/// scrolling from wheel-on-content scrolling for hit-testing purposes.
944
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd)]
945
#[repr(C)]
946
pub struct ScrollResult {
947
    /// Number of scrollable nodes whose offset was updated by this dispatch.
948
    pub scrolled_nodes: usize,
949
    /// Delta that could not be consumed (overscroll). May be forwarded to a parent.
950
    pub remaining_delta: LogicalPosition,
951
    /// `true` if the dispatch hit a native scrollbar (drag), `false` for wheel/touch.
952
    pub hit_scrollbar: bool,
953
}
954

            
955
/// Dispatch a system scroll event and return a [`ScrollResult`] describing what
956
/// happened.
957
///
958
/// This is the entry point used by headless integration tests and embedders that
959
/// drive scroll programmatically. The richer per-document scroll handling lives
960
/// in `LayoutWindow::process_scroll`; this helper packages a delta into a
961
/// `ScrollResult` for return to callers so the result type is observable from
962
/// the public API.
963
#[must_use]
964
12
pub fn process_system_scroll(delta: LogicalPosition, hit_scrollbar: bool) -> ScrollResult {
965
12
    let consumed = delta.x != 0.0 || delta.y != 0.0;
966
12
    ScrollResult {
967
12
        scrolled_nodes: usize::from(consumed),
968
12
        remaining_delta: LogicalPosition::zero(),
969
12
        hit_scrollbar,
970
12
    }
971
12
}
972

            
973
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd)]
974
#[repr(C, u8)]
975
#[derive(Default)]
976
pub enum CursorPosition {
977
    OutOfWindow(LogicalPosition),
978
    #[default]
979
    Uninitialized,
980
    InWindow(LogicalPosition),
981
}
982

            
983
impl CursorPosition {
984
    #[must_use]
985
4976
    pub const fn get_position(&self) -> Option<LogicalPosition> {
986
4976
        match self {
987
2017
            Self::InWindow(logical_pos) => Some(*logical_pos),
988
2959
            Self::OutOfWindow(_) | Self::Uninitialized => None,
989
        }
990
4976
    }
991

            
992
    #[must_use]
993
6
    pub const fn is_inside_window(&self) -> bool {
994
6
        self.get_position().is_some()
995
6
    }
996
}
997

            
998
/// Toggles webrender debug flags (will make stuff appear on
999
/// the screen that you might not want to - used for debugging purposes)
///
/// Every field here maps onto a `webrender::DebugFlags` bit except
/// `show_hit_test_areas`, which is azul's own overlay. Populate it from the
/// environment with [`DebugState::from_az_overlay_env`] — see that function for
/// the verb list and why the hit-test overlay is no longer `debug_assertions`-only.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct DebugState {
    /// Paint a translucent red rectangle over every hit-test area.
    ///
    /// azul's own overlay, not a webrender flag: the compositor draws it while
    /// emitting `DisplayListItem::HitTestArea`, so it shows exactly the regions
    /// the hit tester will actually consider — which is the question you have
    /// when a click does nothing, or lands on the wrong node.
    pub show_hit_test_areas: bool,
    pub profiler_dbg: bool,
    pub render_target_dbg: bool,
    pub texture_cache_dbg: bool,
    pub gpu_time_queries: bool,
    pub gpu_sample_queries: bool,
    pub disable_batching: bool,
    pub epochs: bool,
    pub echo_driver_messages: bool,
    pub show_overdraw: bool,
    pub gpu_cache_dbg: bool,
    pub texture_cache_dbg_clear_evicted: bool,
    pub picture_caching_dbg: bool,
    pub primitive_dbg: bool,
    pub zoom_dbg: bool,
    pub small_screen: bool,
    pub disable_opaque_pass: bool,
    pub disable_alpha_pass: bool,
    pub disable_clip_masks: bool,
    pub disable_text_prims: bool,
    pub disable_gradient_prims: bool,
    pub obscure_images: bool,
    pub glyph_flashing: bool,
    pub smart_profiler: bool,
    pub invalidation_dbg: bool,
    pub tile_cache_logging_dbg: bool,
    pub profiler_capture: bool,
    pub force_picture_invalidation: bool,
}
impl DebugState {
    /// Build a `DebugState` from the `AZ_OVERLAY` environment variable.
    ///
    /// `AZ_OVERLAY` is a comma-separated list of verbs, e.g.
    ///
    /// ```text
    /// AZ_OVERLAY=hit-test
    /// AZ_OVERLAY=hit-test,overdraw,profiler
    /// AZ_OVERLAY=list          # print the verbs and exit-code nothing
    /// ```
    ///
    /// WHY THIS EXISTS: the hit-test overlay used to be `#[cfg(debug_assertions)]`
    /// in the compositor, so a debug build painted every hit-test area red and a
    /// release build painted none, with no way to ask for either. That is a
    /// debug/release divergence in VISUAL OUTPUT — running hello-world showed a
    /// red window and the reasonable first guess was "this linked the wrong
    /// DLL". It was not. An overlay you cannot turn on when you need it, and
    /// cannot turn off when you do not, is worse than no overlay.
    ///
    /// Available in RELEASE builds too, deliberately: the moment you need to see
    /// hit-test regions or overdraw is usually on the build a user is running.
    ///
    /// Unknown verbs are reported and ignored rather than fatal — a typo in a
    /// debugging aid must not stop the app you are trying to debug.
    /// Reading the environment needs std; on `no_std` there is no environment to
    /// read, so the overlay is simply off. `from_overlay_spec` stays available
    /// everywhere, so a `no_std` embedder can still enable overlays explicitly.
    #[cfg(feature = "std")]
    #[must_use]
    pub fn from_az_overlay_env() -> Self {
        std::env::var("AZ_OVERLAY")
            .map_or_else(|_| Self::default(), |v| Self::from_overlay_spec(v.as_str()))
    }
    /// `no_std`: there is no environment, so no overlay.
    #[cfg(not(feature = "std"))]
    #[must_use]
    pub fn from_az_overlay_env() -> Self {
        Self::default()
    }
    /// The parser behind [`DebugState::from_az_overlay_env`], separated so it is
    /// testable without touching the process environment.
    #[must_use]
    pub fn from_overlay_spec(spec: &str) -> Self {
        let mut s = Self::default();
        for raw in spec.split(',') {
            let verb = raw.trim().to_ascii_lowercase();
            if verb.is_empty() {
                continue;
            }
            match verb.as_str() {
                // azul's own overlay.
                "hit-test" | "hittest" => s.show_hit_test_areas = true,
                // webrender flags, named for what they SHOW rather than for the
                // flag constant, because the constant names are not obvious.
                "profiler" => s.profiler_dbg = true,
                "smart-profiler" => s.smart_profiler = true,
                "overdraw" => s.show_overdraw = true,
                "render-targets" => s.render_target_dbg = true,
                "texture-cache" => s.texture_cache_dbg = true,
                "gpu-cache" => s.gpu_cache_dbg = true,
                "picture-caching" => s.picture_caching_dbg = true,
                "primitives" => s.primitive_dbg = true,
                "invalidation" => s.invalidation_dbg = true,
                "epochs" => s.epochs = true,
                "zoom" => s.zoom_dbg = true,
                "glyph-flashing" => s.glyph_flashing = true,
                "obscure-images" => s.obscure_images = true,
                "gpu-time" => s.gpu_time_queries = true,
                "gpu-samples" => s.gpu_sample_queries = true,
                "echo-driver" => s.echo_driver_messages = true,
                // Diagnostic switches that DISABLE a stage — for bisecting which
                // stage is responsible for a visual artefact.
                "no-batching" => s.disable_batching = true,
                "no-opaque-pass" => s.disable_opaque_pass = true,
                "no-alpha-pass" => s.disable_alpha_pass = true,
                "no-clip-masks" => s.disable_clip_masks = true,
                "no-text" => s.disable_text_prims = true,
                "no-gradients" => s.disable_gradient_prims = true,
                "all" => {
                    s.show_hit_test_areas = true;
                    s.profiler_dbg = true;
                    s.show_overdraw = true;
                    s.primitive_dbg = true;
                }
                other => {
                    // Not fatal: a typo in a debugging aid must not stop the app.
                    #[cfg(feature = "std")]
                    eprintln!(
                        "[azul] AZ_OVERLAY: unknown verb {other:?}. Known: hit-test, profiler, \
                         smart-profiler, overdraw, render-targets, texture-cache, gpu-cache, \
                         picture-caching, primitives, invalidation, epochs, zoom, glyph-flashing, \
                         obscure-images, gpu-time, gpu-samples, echo-driver, no-batching, \
                         no-opaque-pass, no-alpha-pass, no-clip-masks, no-text, no-gradients, all"
                    );
                }
            }
        }
        s
    }
}
#[derive(Debug, Default, Clone, PartialEq)]
#[repr(C)]
pub struct TouchState {
    /// Number of active touch points (kept in sync with `touch_points.len()`).
    pub num_touches: usize,
    /// Currently active touch points (one entry per finger / stylus).
    /// Backends update this on touch start / move / end events.
    pub touch_points: TouchPointVec,
    /// Intermediate samples the OS captured BETWEEN this frame and the last,
    /// oldest first. APPENDED for ABI stability.
    ///
    /// A digitizer samples far faster than the display refreshes — 120 Hz or
    /// 240 Hz against 60 — and the OS delivers only the newest position per
    /// frame, because that is what a button or a scroll view wants. A drawing
    /// app wants all of them: a fast stroke rendered from one point per frame
    /// is a polyline with visible corners, and the samples that would have
    /// rounded it were captured and discarded.
    ///
    /// Empty when the platform does not report them, or when nothing moved
    /// between frames. The current `touch_points` entry is NOT repeated here.
    pub coalesced_points: TouchPointVec,
    /// Where the OS predicts the touch is about to go, oldest first.
    /// APPENDED for ABI stability.
    ///
    /// These are EXTRAPOLATIONS, not measurements, and they are wrong as
    /// often as the user changes direction. They exist to hide latency: a
    /// stroke drawn through them appears to keep up with the finger, and the
    /// app discards and redraws them next frame when the real samples arrive.
    /// Never persist them — committing a predicted point to a document means
    /// committing a guess.
    pub predicted_points: TouchPointVec,
}
/// What is making a touch contact.
///
/// Mirrors Android's `MotionEvent.TOOL_TYPE_*`, which is the richest of the
/// platform vocabularies; Windows and Wayland report a subset. `Palm` matters
/// even though nothing can be done with it directly: a digitizer that can
/// classify a palm is telling the app to IGNORE that contact, which is the
/// whole of palm rejection.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub enum TouchToolType {
    /// The platform did not say.
    Unknown,
    /// A fingertip.
    Finger,
    /// A stylus tip.
    Stylus,
    /// The inverted end of a stylus.
    Eraser,
    /// A resting palm — the digitizer classified this contact as accidental.
    Palm,
    /// A mouse, reported through the touch stream (Android `SOURCE_MOUSE`
    /// contacts, some digitizer pucks).
    Mouse,
}
/// Single touch point (finger, stylus, etc.)
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub struct TouchPoint {
    /// Unique identifier for this touch point (persists across move events)
    pub id: u64,
    /// Which SEAT's touchscreen this contact is on (9b-ii-a-i-c): a second
    /// seat's fingers have their own id space (Wayland `wl_touch` ids are per
    /// seat, X11 touch events carry their master pointer), so a contact is
    /// identified by (`seat_id`, `id`). `PRIMARY_POINTER_SEAT` for the one
    /// touchscreen every other platform has.
    pub seat_id: u64,
    /// Current position of the touch point in logical coordinates
    pub position: LogicalPosition,
    /// Force/pressure of the touch (0.0 = no pressure, 1.0 = maximum pressure)
    /// Set to 0.5 if pressure is not available
    pub force: f32,
    /// Major axis of the contact ellipse, in logical px. `0.0` = not reported.
    ///
    /// A contact is an area, not a point, and every platform says so: Wayland
    /// `wl_touch.shape`, Windows `POINTER_TOUCH_INFO.rcContact`, Android
    /// `AXIS_TOUCH_MAJOR`. Without it there is no palm rejection, no
    /// brush-size-from-fingertip, and no way to size a hit target to a thumb
    /// rather than to a mouse cursor.
    pub major: f32,
    /// Minor axis of the contact ellipse, in logical px. `0.0` = not reported.
    pub minor: f32,
    /// Rotation of the contact ellipse, radians clockwise from the x-axis.
    /// `0.0` when unreported OR when a circular contact makes it meaningless —
    /// check `major`/`minor` before trusting it.
    pub orientation_rad: f32,
    /// What is touching. `Unknown` where the platform does not classify.
    pub tool_type: TouchToolType,
}
/// The one `u64` a touch contact is tracked under in the hover manager and
/// the gesture sessions (9b-ii-a-i-c).
///
/// It is the raw id for the primary seat, so every existing key stays what it
/// was, and a seat-namespaced value for any other seat, so two seats' finger
/// `0` never share a session.
#[must_use]
154
pub const fn touch_point_key(seat_id: u64, id: u64) -> u64 {
154
    if seat_id == PRIMARY_POINTER_SEAT {
110
        id
    } else {
44
        0x8000_0000_0000_0000 | (seat_id.rotate_left(32) ^ id)
    }
154
}
impl_option!(
    TouchPoint,
    OptionTouchPoint,
    [Debug, Copy, Clone, PartialEq, PartialOrd]
);
impl_vec!(
    TouchPoint,
    TouchPointVec,
    TouchPointVecDestructor,
    TouchPointVecDestructorType,
    TouchPointVecSlice,
    OptionTouchPoint
);
impl_vec_debug!(TouchPoint, TouchPointVec);
impl_vec_clone!(TouchPoint, TouchPointVec, TouchPointVecDestructor);
impl_vec_partialeq!(TouchPoint, TouchPointVec);
/// State, size, etc of the window, for comparing to the last frame
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Hash, Ord, Eq)]
#[repr(C)]
#[derive(Default)]
pub enum WindowTheme {
    DarkMode,
    #[default]
    LightMode,
}
impl_option!(
    WindowTheme,
    OptionWindowTheme,
    [Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash]
);
/// Identifies a specific monitor/display
///
/// Contains both an index (for fast current-session lookup) and a stable hash
/// (for persistence across app restarts and monitor reconfigurations).
///
/// - `index`: Runtime index (0-based), may change if monitors are added/removed
/// - `hash`: Stable identifier based on monitor properties (name, size, position)
///
/// Applications can serialize `hash` to remember which monitor a window was on,
/// then search for matching hash on next launch, falling back to index or PRIMARY.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[repr(C)]
pub struct MonitorId {
    /// Runtime index of the monitor (may change between sessions)
    pub index: usize,
    /// Stable hash of monitor properties (for persistence)
    pub hash: u64,
}
impl MonitorId {
    /// Primary/default monitor (index 0, hash 0)
    pub const PRIMARY: Self = Self { index: 0, hash: 0 };
    /// Create a `MonitorId` from index only (hash will be 0)
    #[must_use]
7
    pub const fn new(index: usize) -> Self {
7
        Self { index, hash: 0 }
7
    }
    /// Create a `MonitorId` from index and hash
    #[must_use]
14
    pub const fn from_index_and_hash(index: usize, hash: u64) -> Self {
14
        Self { index, hash }
14
    }
    /// Create a stable monitor ID from monitor properties
    ///
    /// Uses FNV-1a hash of: name + position + size
    /// This ensures the hash is stable across app restarts as long as
    /// the monitor configuration doesn't change significantly
    #[must_use]
29
    pub fn from_properties(
29
        index: usize,
29
        name: &str,
29
        position: LayoutPoint,
29
        size: LayoutSize,
29
    ) -> Self {
        use core::hash::{Hash, Hasher};
        // FNV-1a hash (simple, fast, good distribution)
        struct FnvHasher(u64);
        impl Hasher for FnvHasher {
174
            fn write(&mut self, bytes: &[u8]) {
                const FNV_PRIME: u64 = 0x0100_0000_01b3;
2001217
                for &byte in bytes {
2001043
                    self.0 ^= u64::from(byte);
2001043
                    self.0 = self.0.wrapping_mul(FNV_PRIME);
2001043
                }
174
            }
29
            fn finish(&self) -> u64 {
29
                self.0
29
            }
        }
        const FNV_OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
29
        let mut hasher = FnvHasher(FNV_OFFSET_BASIS);
        // Hash the monitor properties
29
        name.hash(&mut hasher);
29
        (position.x as i64).hash(&mut hasher);
29
        (position.y as i64).hash(&mut hasher);
29
        (size.width as i64).hash(&mut hasher);
29
        (size.height as i64).hash(&mut hasher);
29
        Self {
29
            index,
29
            hash: hasher.finish(),
29
        }
29
    }
}
impl_option!(
    MonitorId,
    OptionMonitorId,
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
/// Complete information about a monitor/display
#[derive(Debug, PartialEq, PartialOrd, Clone)]
#[repr(C)]
pub struct Monitor {
    /// Unique identifier for this monitor (stable across frames)
    pub monitor_id: MonitorId,
    /// Human-readable name (e.g., "\\.\DISPLAY1", "HDMI-1", "Built-in Retina Display")
    pub monitor_name: OptionString,
    /// Physical size of the monitor in logical pixels
    pub size: LayoutSize,
    /// Position of the monitor in the virtual screen coordinate system
    pub position: LayoutPoint,
    /// DPI scale factor (1.0 = 96 DPI, 2.0 = 192 DPI for Retina)
    pub scale_factor: f64,
    /// Work area (monitor bounds minus taskbars/panels) in logical pixels
    pub work_area: LayoutRect,
    /// Available video modes for this monitor
    pub video_modes: VideoModeVec,
    /// Whether this is the primary/main monitor
    pub is_primary_monitor: bool,
}
impl_option!(
    Monitor,
    OptionMonitor,
    copy = false,
    [Debug, PartialEq, PartialOrd, Clone]
);
impl_vec!(
    Monitor,
    MonitorVec,
    MonitorVecDestructor,
    MonitorVecDestructorType,
    MonitorVecSlice,
    OptionMonitor
);
impl_vec_debug!(Monitor, MonitorVec);
impl_vec_clone!(Monitor, MonitorVec, MonitorVecDestructor);
impl_vec_partialeq!(Monitor, MonitorVec);
impl_vec_partialord!(Monitor, MonitorVec);
impl Hash for Monitor {
    fn hash<H>(&self, state: &mut H)
    where
        H: Hasher,
    {
        self.monitor_id.hash(state);
    }
}
impl Default for Monitor {
3
    fn default() -> Self {
3
        Self {
3
            monitor_id: MonitorId::PRIMARY,
3
            monitor_name: OptionString::None,
3
            size: LayoutSize::zero(),
3
            position: LayoutPoint::zero(),
3
            scale_factor: 1.0,
3
            work_area: LayoutRect::zero(),
3
            video_modes: Vec::new().into(),
3
            is_primary_monitor: false,
3
        }
3
    }
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct VideoMode {
    pub size: LayoutSize,
    pub bit_depth: u16,
    pub refresh_rate: u16,
}
impl_option!(
    VideoMode,
    OptionVideoMode,
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
impl_vec!(
    VideoMode,
    VideoModeVec,
    VideoModeVecDestructor,
    VideoModeVecDestructorType,
    VideoModeVecSlice,
    OptionVideoMode
);
impl_vec_clone!(VideoMode, VideoModeVec, VideoModeVecDestructor);
impl_vec_debug!(VideoMode, VideoModeVec);
impl_vec_partialeq!(VideoMode, VideoModeVec);
impl_vec_partialord!(VideoMode, VideoModeVec);
/// Position of the window on screen
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C, u8)]
#[derive(Default)]
pub enum WindowPosition {
    #[default]
    Uninitialized,
    /// Absolute position on the virtual screen (physical px). The default for
    /// top-level windows.
    Initialized(PhysicalPositionI32),
    /// Offset (physical px) from the PARENT window's top-left corner. Used by
    /// child windows (menus, dropdowns, popups) together with
    /// `WindowCreateOptions.parent_window_id`: the backend resolves the final
    /// screen position as `parent_top_left + offset`. This is robust where
    /// absolute screen coordinates aren't available — notably Wayland, whose
    /// `xdg_popup` / subsurface protocol positions relative to the parent. Falls
    /// back to absolute (`offset` from origin) if there is no parent.
    RelativeToParentWindow(PhysicalPositionI32),
}
#[allow(variant_size_differences)]
// repr(C,u8) FFI enum: boxing the large variant would change the C ABI (api.json bindings); size
// disparity accepted
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C, u8)]
/// IME composition window rectangle (cursor position + height)
#[derive(Default)]
pub enum ImePosition {
    #[default]
    Uninitialized,
    Initialized(LogicalRect),
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct WindowFlags {
    /// Is the window currently maximized, minimized or fullscreen
    pub frame: WindowFrame,
    /// Window decoration style (title bar, native controls)
    pub decorations: WindowDecorations,
    /// Compositor blur/transparency effect material
    pub background_material: WindowBackgroundMaterial,
    /// Window type classification (Normal, Menu, Tooltip, Dialog)
    pub window_type: WindowType,
    /// User clicked the close button (set by `WindowDelegate`, checked by event loop)
    /// The `close_callback` can set this to false to prevent closing
    pub close_requested: bool,
    /// Is the window currently visible?
    pub is_visible: bool,
    /// Is the window always on top?
    pub is_always_on_top: bool,
    /// Whether the window is resizable
    pub is_resizable: bool,
    /// Whether the window has focus or not (mutating this will request user attention)
    pub has_focus: bool,
    /// Is smooth scrolling enabled for this window?
    pub smooth_scroll_enabled: bool,
    /// Is automatic TAB switching supported?
    pub autotab_enabled: bool,
    /// Enable client-side decorations (custom titlebar with CSD)
    /// Only effective when decorations == `WindowDecorations::None`
    pub has_decorations: bool,
    /// Use native menus (Win32 HMENU, macOS `NSMenu`) instead of Azul window-based menus
    /// Default: true on Windows/macOS, false on Linux
    pub use_native_menus: bool,
    /// Use native context menus instead of Azul window-based context menus
    /// Default: true on Windows/macOS, false on Linux
    pub use_native_context_menus: bool,
    /// Keep window above all others (even from other applications)
    /// Platform-specific: Uses `SetWindowPos(HWND_TOPMOST)` on Windows, [`NSWindow` setLevel:] on
    /// macOS, _`NET_WM_STATE_ABOVE` on X11, `zwlr_layer_shell` on Wayland
    pub is_top_level: bool,
    /// Prevent system from sleeping while window is open
    /// Platform-specific: Uses `SetThreadExecutionState` on Windows, `IOPMAssertionCreateWithName`
    /// on macOS, org.freedesktop.ScreenSaver.Inhibit on Linux
    pub prevent_system_sleep: bool,
    /// Desired fullscreen-transition style.
    ///
    /// On macOS this controls whether entering/leaving fullscreen plays the
    /// system animation (`Slow*`) or transitions immediately (`Fast*`). On
    /// other platforms `Slow*` and `Fast*` behave identically.
    ///
    /// The actual current frame state still lives in [`WindowFlags::frame`]; this
    /// field only describes how the next transition should be performed.
    pub fullscreen_mode: FullScreenMode,
    /// Draw UNDER the notch, the home indicator and the status bar (10c-v).
    ///
    /// `false` (the default, and the browser's `viewport-fit=auto`): the
    /// engine insets the root layout by the platform's safe-area insets, so
    /// nothing lands under a bar and the window's clear colour shows there.
    /// `true` (`viewport-fit=cover`): the root fills the whole surface and the
    /// app places its own content with `get_safe_area_insets()` - what a
    /// full-screen video, a map or a photo viewer wants. The on-screen
    /// keyboard is never part of this: it is a transient occlusion the app
    /// reads from `get_safe_area_insets().keyboard`.
    pub extend_into_safe_area: bool,
}
impl_option!(
    WindowFlags,
    OptionWindowFlags,
    copy = false,
    [Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
/// Window type classification for behavior control
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Default)]
#[repr(C)]
pub enum WindowType {
    /// Normal application window
    #[default]
    Normal,
    /// Menu popup window (always-on-top, frameless, auto-closes on focus loss)
    Menu,
    /// Tooltip window (always-on-top, no interaction)
    Tooltip,
    /// Dialog window (blocks parent window)
    Dialog,
}
/// Window frame state (normal, minimized, maximized, fullscreen)
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub enum WindowFrame {
    Normal,
    Minimized,
    Maximized,
    Fullscreen,
}
/// Window decoration style
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Default)]
#[repr(C)]
pub enum WindowDecorations {
    /// Full decorations: title bar with controls
    #[default]
    Normal,
    /// No title text but controls visible (extended frame).
    /// The application must draw its own title text.
    NoTitle,
    /// Like `NoTitle`, but the framework auto-injects a `Titlebar`
    /// at the top of the user's DOM after calling the layout callback.
    ///
    /// The injected titlebar reads `TitlebarMetrics` from `SystemStyle` for
    /// correct padding around the OS-drawn window control buttons, uses the
    /// system title font, and carries the `__azul-native-titlebar` class for
    /// automatic window-drag activation.
    NoTitleAutoInject,
    /// No controls visible but title bar area present
    NoControls,
    /// No decorations at all (borderless)
    None,
}
/// Compositor blur/transparency effects for window background.
///
/// Anything but `Opaque` gives the window PER-PIXEL alpha on the CPU path:
/// the frame is cleared to transparent and whatever the content leaves at
/// alpha 0 shows the desktop through (a `border-radius` on the body makes
/// real rounded corners; a clip mask on the body makes any shape). The
/// window's INPUT shape follows that alpha as well - clicks on fully
/// transparent pixels fall through to whatever is behind, on every backend
/// (macOS does this by itself for a non-opaque window; X11 gets an `XShape`,
/// Wayland an input region, Windows a window region). This is partial
/// (per-pixel) transparency, not whole-window opacity; X11 without an ARGB
/// visual falls back to `_NET_WM_WINDOW_OPACITY`, which is whole-window.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Default)]
#[repr(C)]
pub enum WindowBackgroundMaterial {
    /// No transparency or blur
    #[default]
    Opaque,
    /// Transparent without blur
    Transparent,
    /// macOS: Sidebar material, Windows: Acrylic light
    Sidebar,
    /// macOS: Menu material, Windows: Acrylic
    Menu,
    /// macOS: HUD material, Windows: Acrylic dark
    HUD,
    /// macOS: Titlebar material, Windows: Mica
    Titlebar,
    /// Windows: Mica Alt material
    MicaAlt,
}
impl Default for WindowFlags {
109864
    fn default() -> Self {
109864
        Self {
109864
            frame: WindowFrame::Normal,
109864
            decorations: WindowDecorations::Normal,
109864
            background_material: WindowBackgroundMaterial::Opaque,
109864
            window_type: WindowType::Normal,
109864
            close_requested: false,
109864
            is_visible: true,
109864
            is_always_on_top: false,
109864
            is_resizable: true,
109864
            has_focus: true,
109864
            smooth_scroll_enabled: true,
109864
            autotab_enabled: true,
109864
            has_decorations: false,
109864
            // Native menus are the default on platforms that support them (Windows/macOS)
109864
            // The platform layer will override this appropriately
109864
            use_native_menus: cfg!(any(target_os = "windows", target_os = "macos")),
109864
            use_native_context_menus: cfg!(any(target_os = "windows", target_os = "macos")),
109864
            is_top_level: false,
109864
            prevent_system_sleep: false,
109864
            fullscreen_mode: FullScreenMode::FastFullScreen,
109864
            extend_into_safe_area: false,
109864
        }
109864
    }
}
impl WindowFlags {
    /// Check if window is a menu popup
    #[inline]
    #[must_use]
8
    pub fn is_menu_window(&self) -> bool {
8
        self.window_type == WindowType::Menu
8
    }
    /// Check if window is a tooltip
    #[inline]
    #[must_use]
8
    pub fn is_tooltip_window(&self) -> bool {
8
        self.window_type == WindowType::Tooltip
8
    }
    /// Check if window is a dialog
    #[inline]
    #[must_use]
8
    pub fn is_dialog_window(&self) -> bool {
8
        self.window_type == WindowType::Dialog
8
    }
    /// Check if window currently has focus
    #[inline]
    #[must_use]
3
    pub const fn window_has_focus(&self) -> bool {
3
        self.has_focus
3
    }
    /// Check if close was requested via callback
    #[inline]
    #[must_use]
3
    pub const fn is_close_requested(&self) -> bool {
3
        self.close_requested
3
    }
    /// Check if window has client-side decorations enabled
    #[inline]
    #[must_use]
3
    pub const fn has_csd(&self) -> bool {
3
        self.has_decorations
3
    }
    /// Check if native menus should be used
    #[inline]
    #[must_use]
3
    pub const fn use_native_menus(&self) -> bool {
3
        self.use_native_menus
3
    }
    /// Check if native context menus should be used
    #[inline]
    #[must_use]
3
    pub const fn use_native_context_menus(&self) -> bool {
3
        self.use_native_context_menus
3
    }
}
/// Platform-specific window configuration options (Windows, Linux, macOS, WASM)
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub struct PlatformSpecificOptions {
    pub windows_options: WindowsWindowOptions,
    pub linux_options: LinuxWindowOptions,
    pub mac_options: MacWindowOptions,
    pub wasm_options: WasmWindowOptions,
}
// SAFETY: PlatformSpecificOptions contains raw pointers (X11Visual) that are
// opaque platform handles, not dereferenced across threads.
unsafe impl Sync for PlatformSpecificOptions {}
#[allow(clippy::non_send_fields_in_send_ty)] // opaque platform handles, not dereferenced across
                                             // threads (see note above)
unsafe impl Send for PlatformSpecificOptions {}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[repr(C)]
pub struct WindowsWindowOptions {
    /// STARTUP ONLY: Whether the window should allow drag + drop operations (default: true)
    pub allow_drag_and_drop: bool,
    /// STARTUP ONLY: Sets `WS_EX_NOREDIRECTIONBITMAP`
    pub no_redirection_bitmap: bool,
    /// STARTUP ONLY: Window icon (decoded bytes), appears at the top right corner of the window
    pub window_icon: OptionWindowIcon,
    /// READWRITE: Taskbar icon (decoded bytes), usually 256x256x4 bytes large (`ICON_BIG`).
    ///
    /// Can be changed in callbacks / at runtime.
    pub taskbar_icon: OptionTaskBarIcon,
    // NOTE: the old Windows-specific `parent_window: OptionHwndHandle` field was
    // removed in favor of the cross-platform `WindowCreateOptions.parent_window_id`
    // (+ `WindowPosition::RelativeToParentWindow`), which every backend resolves
    // through its window registry. One parenting model for all platforms.
}
impl Default for WindowsWindowOptions {
109846
    fn default() -> Self {
109846
        Self {
109846
            allow_drag_and_drop: true,
109846
            no_redirection_bitmap: false,
109846
            window_icon: OptionWindowIcon::None,
109846
            taskbar_icon: OptionTaskBarIcon::None,
109846
        }
109846
    }
}
/// X window type. Maps directly to
/// [`_NET_WM_WINDOW_TYPE`](https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html).
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
#[derive(Default)]
pub enum XWindowType {
    /// A desktop feature. This can include a single window containing desktop icons with the same
    /// dimensions as the screen, allowing the desktop environment to have full control of the
    /// desktop, without the need for proxying root window clicks.
    Desktop,
    /// A dock or panel feature. Typically a Window Manager would keep such windows on top of all
    /// other windows.
    Dock,
    /// Toolbar windows. "Torn off" from the main application.
    Toolbar,
    /// Pinnable menu windows. "Torn off" from the main application.
    Menu,
    /// A small persistent utility window, such as a palette or toolbox.
    Utility,
    /// The window is a splash screen displayed as an application is starting up.
    Splash,
    /// This is a dialog window.
    Dialog,
    /// A dropdown menu that usually appears when the user clicks on an item in a menu bar.
    /// This property is typically used on override-redirect windows.
    DropdownMenu,
    /// A popup menu that usually appears when the user right clicks on an object.
    /// This property is typically used on override-redirect windows.
    PopupMenu,
    /// A tooltip window. Usually used to show additional information when hovering over an object
    /// with the cursor. This property is typically used on override-redirect windows.
    Tooltip,
    /// The window is a notification.
    /// This property is typically used on override-redirect windows.
    Notification,
    /// This should be used on the windows that are popped up by combo boxes.
    /// This property is typically used on override-redirect windows.
    Combo,
    /// This indicates the the window is being dragged.
    /// This property is typically used on override-redirect windows.
    Dnd,
    /// This is a normal, top-level window.
    #[default]
    Normal,
}
impl_option!(
    XWindowType,
    OptionXWindowType,
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)]
#[repr(C)]
#[derive(Default)]
pub enum UserAttentionType {
    #[default]
    None,
    Critical,
    Informational,
}
/// State for tracking hover and interaction with Linux window decoration elements (CSD).
#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)]
#[repr(C)]
pub struct LinuxDecorationsState {
    pub is_dragging_titlebar: bool,
    pub close_button_hover: bool,
    pub maximize_button_hover: bool,
    pub minimize_button_hover: bool,
}
impl_option!(
    LinuxDecorationsState,
    OptionLinuxDecorationsState,
    [Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash]
);
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub struct LinuxWindowOptions {
    pub wayland_theme: OptionWaylandTheme,
    pub window_icon: OptionWindowIcon,
    /// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only
    /// relevant on X11. Can only be set at window creation, can't be changed in callbacks.
    pub x11_gtk_theme_variant: OptionString,
    /// Build window with a given application ID. It should match the `.desktop` file distributed
    /// with your program. Only relevant on Wayland.
    /// Can only be set at window creation, can't be changed in callbacks.
    ///
    /// For details about application ID conventions, see the
    /// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
    pub wayland_app_id: OptionString,
    /// Build window with `WM_CLASS` hint; defaults to the name of the binary. Only relevant on
    /// X11. Can only be set at window creation, can't be changed in callbacks.
    pub x11_wm_classes: StringPairVec,
    /// Build window with `_NET_WM_WINDOW_TYPE` hint; defaults to `Normal`. Only relevant on X11.
    /// Can only be set at window creation, can't be changed in callbacks.
    pub x11_window_types: XWindowTypeVec,
    /// (Unimplemented) - Can only be set at window creation, can't be changed in callbacks.
    pub x11_visual: OptionX11Visual,
    /// Build window with resize increment hint. Only implemented on X11.
    /// Can only be set at window creation, can't be changed in callbacks.
    pub x11_resize_increments: OptionLogicalSize,
    /// Build window with base size hint. Only implemented on X11.
    /// Can only be set at window creation, can't be changed in callbacks.
    pub x11_base_size: OptionLogicalSize,
    /// (Unimplemented) - Can only be set at window creation, can't be changed in callbacks.
    pub x11_screen: OptionI32,
    pub request_user_attention: UserAttentionType,
    /// X11-specific: Client-side decoration state (drag position, button hover, etc.)
    pub x11_decorations_state: OptionLinuxDecorationsState,
    /// Build window with override-redirect flag; defaults to false. Only relevant on X11.
    /// Can only be set at window creation, can't be changed in callbacks.
    pub x11_override_redirect: bool,
}
pub type X11Visual = *const c_void;
impl_option!(
    X11Visual,
    OptionX11Visual,
    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
);
/// A key-value pair of strings, used for X11 `WM_CLASS` and other platform properties
#[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[repr(C)]
pub struct AzStringPair {
    pub key: AzString,
    pub value: AzString,
}
impl_option!(
    AzStringPair,
    OptionStringPair,
    copy = false,
    [Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash]
);
impl_vec!(
    AzStringPair,
    StringPairVec,
    StringPairVecDestructor,
    StringPairVecDestructorType,
    StringPairVecSlice,
    OptionStringPair
);
impl_vec_mut!(AzStringPair, StringPairVec);
impl_vec_debug!(AzStringPair, StringPairVec);
impl_vec_partialord!(AzStringPair, StringPairVec);
impl_vec_ord!(AzStringPair, StringPairVec);
impl_vec_clone!(AzStringPair, StringPairVec, StringPairVecDestructor);
impl_vec_partialeq!(AzStringPair, StringPairVec);
impl_vec_eq!(AzStringPair, StringPairVec);
impl_vec_hash!(AzStringPair, StringPairVec);
impl_option!(
    StringPairVec,
    OptionStringPairVec,
    copy = false,
    [Debug, Clone, PartialOrd, PartialEq, Ord, Eq, Hash]
);
impl StringPairVec {
    #[must_use]
2308750
    pub fn get_key(&self, search_key: &str) -> Option<&AzString> {
4756726
        self.as_ref().iter().find_map(|v| {
4744314
            if v.key.as_str() == search_key {
319054
                Some(&v.value)
            } else {
4425260
                None
            }
4744314
        })
2308750
    }
114
    pub fn get_key_mut(&mut self, search_key: &str) -> Option<&mut AzStringPair> {
114
        self.as_mut()
114
            .iter_mut()
118
            .find(|v| v.key.as_str() == search_key)
114
    }
109
    pub fn insert_kv<I: Into<AzString>>(&mut self, key: I, value: I) {
109
        let key = key.into();
109
        let value = value.into();
109
        match self.get_key_mut(key.as_str()) {
6
            None => {}
103
            Some(s) => {
103
                s.value = value;
103
                return;
            }
        }
6
        self.push(AzStringPair { key, value });
109
    }
}
impl_vec!(
    XWindowType,
    XWindowTypeVec,
    XWindowTypeVecDestructor,
    XWindowTypeVecDestructorType,
    XWindowTypeVecSlice,
    OptionXWindowType
);
impl_vec_debug!(XWindowType, XWindowTypeVec);
impl_vec_partialord!(XWindowType, XWindowTypeVec);
impl_vec_ord!(XWindowType, XWindowTypeVec);
impl_vec_clone!(XWindowType, XWindowTypeVec, XWindowTypeVecDestructor);
impl_vec_partialeq!(XWindowType, XWindowTypeVec);
impl_vec_eq!(XWindowType, XWindowTypeVec);
impl_vec_hash!(XWindowType, XWindowTypeVec);
impl_option!(
    WaylandTheme,
    OptionWaylandTheme,
    copy = false,
    [Debug, Clone, PartialEq, PartialOrd]
);
/// macOS-specific window options (reserved for future use)
#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[repr(C)]
// `_`-prefixed fields are C-ABI/api.json names; cannot rename.
#[allow(clippy::pub_underscore_fields)]
pub struct MacWindowOptions {
    // empty for now, single field must be present for ABI compat - always set to 0
    pub _reserved: u8,
}
/// WASM/web-specific window options (reserved for future use)
#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[repr(C)]
// `_`-prefixed fields are C-ABI/api.json names; cannot rename.
#[allow(clippy::pub_underscore_fields)]
pub struct WasmWindowOptions {
    // empty for now, single field must be present for ABI compat - always set to 0
    pub _reserved: u8,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
#[derive(Default)]
pub enum FullScreenMode {
    /// - macOS: If the window is in windowed mode, transitions it slowly to fullscreen mode
    /// - other: Does the same as `FastFullScreen`.
    SlowFullScreen,
    /// Window should immediately go into fullscreen mode (on macOS this is not the default
    /// behaviour).
    #[default]
    FastFullScreen,
    /// - macOS: If the window is in fullscreen mode, transitions slowly back to windowed state.
    /// - other: Does the same as `FastWindowed`.
    SlowWindowed,
    /// If the window is in fullscreen mode, will immediately go back to windowed mode (on macOS
    /// this is not the default behaviour).
    FastWindowed,
}
// Translation type because in winit 24.0 the WinitWaylandTheme is a trait instead
// of a struct, which makes things more complicated
#[derive(Debug, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub struct WaylandTheme {
    pub title_bar_active_background_color: ColorU,
    pub title_bar_active_separator_color: ColorU,
    pub title_bar_active_text_color: ColorU,
    pub title_bar_inactive_background_color: ColorU,
    pub title_bar_inactive_separator_color: ColorU,
    pub title_bar_inactive_text_color: ColorU,
    pub maximize_idle_foreground_inactive_color: ColorU,
    pub minimize_idle_foreground_inactive_color: ColorU,
    pub close_idle_foreground_inactive_color: ColorU,
    pub maximize_hovered_foreground_inactive_color: ColorU,
    pub minimize_hovered_foreground_inactive_color: ColorU,
    pub close_hovered_foreground_inactive_color: ColorU,
    pub maximize_disabled_foreground_inactive_color: ColorU,
    pub minimize_disabled_foreground_inactive_color: ColorU,
    pub close_disabled_foreground_inactive_color: ColorU,
    pub maximize_idle_background_inactive_color: ColorU,
    pub minimize_idle_background_inactive_color: ColorU,
    pub close_idle_background_inactive_color: ColorU,
    pub maximize_hovered_background_inactive_color: ColorU,
    pub minimize_hovered_background_inactive_color: ColorU,
    pub close_hovered_background_inactive_color: ColorU,
    pub maximize_disabled_background_inactive_color: ColorU,
    pub minimize_disabled_background_inactive_color: ColorU,
    pub close_disabled_background_inactive_color: ColorU,
    pub maximize_idle_foreground_active_color: ColorU,
    pub minimize_idle_foreground_active_color: ColorU,
    pub close_idle_foreground_active_color: ColorU,
    pub maximize_hovered_foreground_active_color: ColorU,
    pub minimize_hovered_foreground_active_color: ColorU,
    pub close_hovered_foreground_active_color: ColorU,
    pub maximize_disabled_foreground_active_color: ColorU,
    pub minimize_disabled_foreground_active_color: ColorU,
    pub close_disabled_foreground_active_color: ColorU,
    pub maximize_idle_background_active_color: ColorU,
    pub minimize_idle_background_active_color: ColorU,
    pub close_idle_background_active_color: ColorU,
    pub maximize_hovered_background_active_color: ColorU,
    pub minimize_hovered_background_active_color: ColorU,
    pub close_hovered_background_active_color: ColorU,
    pub maximize_disabled_background_active_color: ColorU,
    pub minimize_disabled_background_active_color: ColorU,
    pub close_disabled_background_active_color: ColorU,
    pub title_bar_font: AzString,
    pub title_bar_font_size: f32,
}
/// The global CSS viewport breakpoints for `@media`-style conditions.
///
/// The dynamic-selector system evaluates against these, and they are one of
/// the three signals the resize fast path checks: crossing any of these
/// (on either axis) re-invokes the
/// app's `layout()`; staying between them re-flows the existing DOM.
///
/// Lived in `azul-dll`'s shell (`shell2::common::CSS_BREAKPOINTS`, still
/// re-exported there) until the headless E2E runner needed the same resize
/// decision — the list is engine policy, not shell policy.
pub const CSS_BREAKPOINTS: &[f32] = &[320.0, 480.0, 640.0, 768.0, 1024.0, 1280.0, 1440.0, 1920.0];
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd)]
#[repr(C)]
pub struct WindowSize {
    /// Width and height of the window, in logical
    /// units (may not correspond to the physical on-screen size)
    pub dimensions: LogicalSize,
    /// Actual DPI value (default: 96)
    pub dpi: u32,
    /// Minimum dimensions of the window
    pub min_dimensions: OptionLogicalSize,
    /// Maximum dimensions of the window
    pub max_dimensions: OptionLogicalSize,
}
impl WindowSize {
    #[allow(clippy::cast_possible_truncation)] // bounded DPI/dimension/number conversion
    #[must_use]
9
    pub fn get_layout_size(&self) -> LayoutSize {
9
        LayoutSize::new(
9
            libm::roundf(self.dimensions.width) as isize,
9
            libm::roundf(self.dimensions.height) as isize,
        )
9
    }
    /// Get the actual logical size
    #[must_use]
17
    pub const fn get_logical_size(&self) -> LogicalSize {
17
        self.dimensions
17
    }
    #[must_use]
26
    pub fn get_physical_size(&self) -> PhysicalSize<u32> {
26
        self.dimensions
26
            .to_physical(self.get_hidpi_factor().inner.get())
26
    }
    #[allow(clippy::cast_precision_loss)] // bounded DPI/dimension/number conversion
    #[must_use]
39679
    pub fn get_hidpi_factor(&self) -> DpiScaleFactor {
        // Guard against `dpi == 0` (uninitialized / misreporting platform),
        // which would yield a 0.0 scale factor and later divide-by-zero when
        // converting physical <-> logical sizes (`to_logical` divides by this).
        // Fall back to the standard 96 DPI (scale 1.0).
39679
        let dpi = if self.dpi == 0 { 96 } else { self.dpi };
39679
        DpiScaleFactor {
39679
            inner: FloatValue::new(dpi as f32 / 96.0),
39679
        }
39679
    }
}
impl Default for WindowSize {
109914
    fn default() -> Self {
109914
        Self {
109914
            dimensions: LogicalSize::new(640.0, 480.0),
109914
            dpi: 96,
109914
            min_dimensions: None.into(),
109914
            max_dimensions: None.into(),
109914
        }
109914
    }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)]
pub enum RendererType {
    /// Force hardware rendering
    Hardware,
    /// Force software rendering
    Software,
}
impl_option!(
    RendererType,
    OptionRendererType,
    [Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash]
);
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)]
pub enum UpdateFocusWarning {
    FocusInvalidDomId(DomId),
    FocusInvalidNodeId(NodeHierarchyItemId),
    CouldNotFindFocusNode(CssPath),
}
impl ::core::fmt::Display for UpdateFocusWarning {
4
    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        use self::UpdateFocusWarning::{
            CouldNotFindFocusNode, FocusInvalidDomId, FocusInvalidNodeId,
        };
4
        match self {
1
            FocusInvalidDomId(dom_id) => write!(f, "Focusing on DOM with invalid ID: {dom_id:?}"),
2
            FocusInvalidNodeId(node_id) => {
2
                write!(f, "Focusing on node with invalid ID: {node_id}")
            }
1
            CouldNotFindFocusNode(css_path) => {
1
                write!(f, "Could not find focus node for path: {css_path}")
            }
        }
4
    }
}
/// Utility function for easier creation of a keymap - i.e. `[vec![Ctrl, S], my_function]`
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C, u8)]
pub enum AcceleratorKey {
    Ctrl,
    Alt,
    Shift,
    Key(VirtualKeyCode),
}
impl AcceleratorKey {
    /// Checks if the current keyboard state contains the given char or modifier,
    /// i.e. if the keyboard state currently has the shift key pressed and the
    /// accelerator key is `Shift`, evaluates to true, otherwise to false.
    #[must_use]
20020
    pub fn matches(&self, keyboard_state: &KeyboardState) -> bool {
        use self::AcceleratorKey::{Alt, Ctrl, Key, Shift};
20020
        match self {
8
            Ctrl => keyboard_state.ctrl_down(),
3
            Alt => keyboard_state.alt_down(),
20004
            Shift => keyboard_state.shift_down(),
5
            Key(k) => keyboard_state.is_key_down(*k),
        }
20020
    }
}
/// Symbolic name for a keyboard key, does NOT take the keyboard locale into account
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub enum VirtualKeyCode {
    Key1,
    Key2,
    Key3,
    Key4,
    Key5,
    Key6,
    Key7,
    Key8,
    Key9,
    Key0,
    A,
    B,
    C,
    D,
    E,
    F,
    G,
    H,
    I,
    J,
    K,
    L,
    M,
    N,
    O,
    P,
    Q,
    R,
    S,
    T,
    U,
    V,
    W,
    X,
    Y,
    Z,
    Escape,
    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    F11,
    F12,
    F13,
    F14,
    F15,
    F16,
    F17,
    F18,
    F19,
    F20,
    F21,
    F22,
    F23,
    F24,
    Snapshot,
    Scroll,
    Pause,
    Insert,
    Home,
    Delete,
    End,
    PageDown,
    PageUp,
    Left,
    Up,
    Right,
    Down,
    Back,
    Return,
    Space,
    Compose,
    Caret,
    Numlock,
    Numpad0,
    Numpad1,
    Numpad2,
    Numpad3,
    Numpad4,
    Numpad5,
    Numpad6,
    Numpad7,
    Numpad8,
    Numpad9,
    NumpadAdd,
    NumpadDivide,
    NumpadDecimal,
    NumpadComma,
    NumpadEnter,
    NumpadEquals,
    NumpadMultiply,
    NumpadSubtract,
    AbntC1,
    AbntC2,
    Apostrophe,
    Apps,
    Asterisk,
    At,
    Ax,
    Backslash,
    Calculator,
    Capital,
    Colon,
    Comma,
    Convert,
    Equals,
    Grave,
    Kana,
    Kanji,
    LAlt,
    LBracket,
    LControl,
    LShift,
    LWin,
    Mail,
    MediaSelect,
    MediaStop,
    Minus,
    Mute,
    MyComputer,
    NavigateForward,
    NavigateBackward,
    NextTrack,
    NoConvert,
    OEM102,
    Period,
    PlayPause,
    Plus,
    Power,
    PrevTrack,
    RAlt,
    RBracket,
    RControl,
    RShift,
    RWin,
    Semicolon,
    Slash,
    Sleep,
    Stop,
    Sysrq,
    Tab,
    Underline,
    Unlabeled,
    VolumeDown,
    VolumeUp,
    Wake,
    WebBack,
    WebFavorites,
    WebForward,
    WebHome,
    WebRefresh,
    WebSearch,
    WebStop,
    Yen,
    Copy,
    Paste,
    Cut,
}
impl VirtualKeyCode {
    /// Reconstructs a `VirtualKeyCode` from its `as u32` discriminant.
    ///
    /// This enum is a fieldless `#[repr(C)]` enum with no explicit discriminants,
    /// so the discriminants are assigned sequentially in declaration order and
    /// `VariantN as u32` round-trips through this table. Used to recover the key
    /// of a keyboard *event* from its `key_code` (which is stored as
    /// `VirtualKeyCode as u32`) instead of reading live keyboard state.
    #[must_use]
    #[allow(clippy::too_many_lines)] // exhaustive keycode match table
2793
    pub const fn from_u32(v: u32) -> Option<Self> {
2793
        match v {
7
            0 => Some(Self::Key1),
6
            1 => Some(Self::Key2),
6
            2 => Some(Self::Key3),
6
            3 => Some(Self::Key4),
6
            4 => Some(Self::Key5),
6
            5 => Some(Self::Key6),
6
            6 => Some(Self::Key7),
6
            7 => Some(Self::Key8),
6
            8 => Some(Self::Key9),
6
            9 => Some(Self::Key0),
9
            10 => Some(Self::A),
8
            11 => Some(Self::B),
12
            12 => Some(Self::C),
8
            13 => Some(Self::D),
7
            14 => Some(Self::E),
7
            15 => Some(Self::F),
7
            16 => Some(Self::G),
7
            17 => Some(Self::H),
7
            18 => Some(Self::I),
7
            19 => Some(Self::J),
7
            20 => Some(Self::K),
7
            21 => Some(Self::L),
7
            22 => Some(Self::M),
7
            23 => Some(Self::N),
7
            24 => Some(Self::O),
7
            25 => Some(Self::P),
8
            26 => Some(Self::Q),
7
            27 => Some(Self::R),
7
            28 => Some(Self::S),
7
            29 => Some(Self::T),
7
            30 => Some(Self::U),
8
            31 => Some(Self::V),
7
            32 => Some(Self::W),
8
            33 => Some(Self::X),
8
            34 => Some(Self::Y),
9
            35 => Some(Self::Z),
8
            36 => Some(Self::Escape),
6
            37 => Some(Self::F1),
6
            38 => Some(Self::F2),
6
            39 => Some(Self::F3),
6
            40 => Some(Self::F4),
7
            41 => Some(Self::F5),
6
            42 => Some(Self::F6),
6
            43 => Some(Self::F7),
6
            44 => Some(Self::F8),
6
            45 => Some(Self::F9),
6
            46 => Some(Self::F10),
6
            47 => Some(Self::F11),
6
            48 => Some(Self::F12),
6
            49 => Some(Self::F13),
6
            50 => Some(Self::F14),
6
            51 => Some(Self::F15),
6
            52 => Some(Self::F16),
6
            53 => Some(Self::F17),
6
            54 => Some(Self::F18),
6
            55 => Some(Self::F19),
6
            56 => Some(Self::F20),
6
            57 => Some(Self::F21),
6
            58 => Some(Self::F22),
6
            59 => Some(Self::F23),
6
            60 => Some(Self::F24),
6
            61 => Some(Self::Snapshot),
6
            62 => Some(Self::Scroll),
6
            63 => Some(Self::Pause),
6
            64 => Some(Self::Insert),
7
            65 => Some(Self::Home),
10
            66 => Some(Self::Delete),
7
            67 => Some(Self::End),
6
            68 => Some(Self::PageDown),
6
            69 => Some(Self::PageUp),
11
            70 => Some(Self::Left),
7
            71 => Some(Self::Up),
8
            72 => Some(Self::Right),
9
            73 => Some(Self::Down),
11
            74 => Some(Self::Back),
6
            75 => Some(Self::Return),
7
            76 => Some(Self::Space),
6
            77 => Some(Self::Compose),
6
            78 => Some(Self::Caret),
6
            79 => Some(Self::Numlock),
6
            80 => Some(Self::Numpad0),
6
            81 => Some(Self::Numpad1),
6
            82 => Some(Self::Numpad2),
6
            83 => Some(Self::Numpad3),
6
            84 => Some(Self::Numpad4),
6
            85 => Some(Self::Numpad5),
6
            86 => Some(Self::Numpad6),
6
            87 => Some(Self::Numpad7),
6
            88 => Some(Self::Numpad8),
6
            89 => Some(Self::Numpad9),
6
            90 => Some(Self::NumpadAdd),
6
            91 => Some(Self::NumpadDivide),
6
            92 => Some(Self::NumpadDecimal),
6
            93 => Some(Self::NumpadComma),
6
            94 => Some(Self::NumpadEnter),
6
            95 => Some(Self::NumpadEquals),
6
            96 => Some(Self::NumpadMultiply),
6
            97 => Some(Self::NumpadSubtract),
6
            98 => Some(Self::AbntC1),
6
            99 => Some(Self::AbntC2),
6
            100 => Some(Self::Apostrophe),
6
            101 => Some(Self::Apps),
6
            102 => Some(Self::Asterisk),
6
            103 => Some(Self::At),
6
            104 => Some(Self::Ax),
6
            105 => Some(Self::Backslash),
6
            106 => Some(Self::Calculator),
6
            107 => Some(Self::Capital),
6
            108 => Some(Self::Colon),
6
            109 => Some(Self::Comma),
6
            110 => Some(Self::Convert),
6
            111 => Some(Self::Equals),
6
            112 => Some(Self::Grave),
6
            113 => Some(Self::Kana),
6
            114 => Some(Self::Kanji),
6
            115 => Some(Self::LAlt),
6
            116 => Some(Self::LBracket),
7
            117 => Some(Self::LControl),
6
            118 => Some(Self::LShift),
6
            119 => Some(Self::LWin),
6
            120 => Some(Self::Mail),
6
            121 => Some(Self::MediaSelect),
6
            122 => Some(Self::MediaStop),
6
            123 => Some(Self::Minus),
6
            124 => Some(Self::Mute),
6
            125 => Some(Self::MyComputer),
6
            126 => Some(Self::NavigateForward),
6
            127 => Some(Self::NavigateBackward),
6
            128 => Some(Self::NextTrack),
6
            129 => Some(Self::NoConvert),
6
            130 => Some(Self::OEM102),
6
            131 => Some(Self::Period),
6
            132 => Some(Self::PlayPause),
6
            133 => Some(Self::Plus),
6
            134 => Some(Self::Power),
6
            135 => Some(Self::PrevTrack),
6
            136 => Some(Self::RAlt),
6
            137 => Some(Self::RBracket),
6
            138 => Some(Self::RControl),
6
            139 => Some(Self::RShift),
6
            140 => Some(Self::RWin),
6
            141 => Some(Self::Semicolon),
6
            142 => Some(Self::Slash),
6
            143 => Some(Self::Sleep),
6
            144 => Some(Self::Stop),
6
            145 => Some(Self::Sysrq),
14
            146 => Some(Self::Tab),
6
            147 => Some(Self::Underline),
6
            148 => Some(Self::Unlabeled),
6
            149 => Some(Self::VolumeDown),
6
            150 => Some(Self::VolumeUp),
6
            151 => Some(Self::Wake),
6
            152 => Some(Self::WebBack),
6
            153 => Some(Self::WebFavorites),
6
            154 => Some(Self::WebForward),
6
            155 => Some(Self::WebHome),
6
            156 => Some(Self::WebRefresh),
6
            157 => Some(Self::WebSearch),
6
            158 => Some(Self::WebStop),
6
            159 => Some(Self::Yen),
6
            160 => Some(Self::Copy),
6
            161 => Some(Self::Paste),
7
            162 => Some(Self::Cut),
1737
            _ => None,
        }
2793
    }
    #[must_use]
208
    pub const fn get_lowercase(&self) -> Option<char> {
        use self::VirtualKeyCode::{
            Asterisk, At, Caret, Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8, Key9, Minus,
            Numpad0, Numpad1, Numpad2, Numpad3, Numpad4, Numpad5, Numpad6, Numpad7, Numpad8,
            Numpad9, Period, Semicolon, Slash, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
            R, S, T, U, V, W, X, Y, Z,
        };
208
        match self {
2
            A => Some('a'),
2
            B => Some('b'),
2
            C => Some('c'),
2
            D => Some('d'),
2
            E => Some('e'),
2
            F => Some('f'),
2
            G => Some('g'),
2
            H => Some('h'),
2
            I => Some('i'),
2
            J => Some('j'),
2
            K => Some('k'),
2
            L => Some('l'),
2
            M => Some('m'),
2
            N => Some('n'),
2
            O => Some('o'),
2
            P => Some('p'),
2
            Q => Some('q'),
2
            R => Some('r'),
2
            S => Some('s'),
2
            T => Some('t'),
2
            U => Some('u'),
2
            V => Some('v'),
2
            W => Some('w'),
2
            X => Some('x'),
2
            Y => Some('y'),
2
            Z => Some('z'),
4
            Key0 | Numpad0 => Some('0'),
4
            Key1 | Numpad1 => Some('1'),
2
            Key2 | Numpad2 => Some('2'),
2
            Key3 | Numpad3 => Some('3'),
2
            Key4 | Numpad4 => Some('4'),
4
            Key5 | Numpad5 => Some('5'),
2
            Key6 | Numpad6 => Some('6'),
2
            Key7 | Numpad7 => Some('7'),
2
            Key8 | Numpad8 => Some('8'),
4
            Key9 | Numpad9 => Some('9'),
2
            Minus => Some('-'),
1
            Asterisk => Some('*'),
1
            At => Some('@'),
2
            Period => Some('.'),
1
            Semicolon => Some(';'),
2
            Slash => Some('/'),
2
            Caret => Some('^'),
117
            _ => None,
        }
208
    }
}
/// 16x16x4 bytes icon
#[derive(Debug, Clone)]
#[repr(C)]
pub struct SmallWindowIconBytes {
    pub key: IconKey,
    pub rgba_bytes: U8Vec,
}
/// 32x32x4 bytes icon
#[derive(Debug, Clone)]
#[repr(C)]
pub struct LargeWindowIconBytes {
    pub key: IconKey,
    pub rgba_bytes: U8Vec,
}
// Window icon that usually appears in the top-left corner of the window
#[derive(Debug, Clone)]
#[repr(C, u8)]
pub enum WindowIcon {
    Small(SmallWindowIconBytes),
    /// 32x32x4 bytes icon
    Large(LargeWindowIconBytes),
}
impl_option!(
    WindowIcon,
    OptionWindowIcon,
    copy = false,
    [Debug, Clone, PartialOrd, PartialEq, Eq, Hash, Ord]
);
impl WindowIcon {
    #[must_use]
19
    pub const fn get_key(&self) -> IconKey {
19
        match &self {
15
            Self::Small(SmallWindowIconBytes { key, .. })
19
            | Self::Large(LargeWindowIconBytes { key, .. }) => *key,
        }
19
    }
}
// -- Only compare the IconKey (for WindowIcon and TaskBarIcon)
impl PartialEq for WindowIcon {
3
    fn eq(&self, rhs: &Self) -> bool {
3
        self.get_key() == rhs.get_key()
3
    }
}
impl PartialOrd for WindowIcon {
1
    fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
1
        Some((self.get_key()).cmp(&rhs.get_key()))
1
    }
}
impl Eq for WindowIcon {}
impl Ord for WindowIcon {
2
    fn cmp(&self, rhs: &Self) -> Ordering {
2
        (self.get_key()).cmp(&rhs.get_key())
2
    }
}
impl Hash for WindowIcon {
4
    fn hash<H>(&self, state: &mut H)
4
    where
4
        H: Hasher,
    {
4
        self.get_key().hash(state);
4
    }
}
/// 256x256x4 bytes window icon
#[derive(Debug, Clone)]
#[repr(C)]
pub struct TaskBarIcon {
    pub key: IconKey,
    pub rgba_bytes: U8Vec,
}
impl_option!(
    TaskBarIcon,
    OptionTaskBarIcon,
    copy = false,
    [Debug, Clone, PartialOrd, PartialEq, Eq, Hash, Ord]
);
impl PartialEq for TaskBarIcon {
    fn eq(&self, rhs: &Self) -> bool {
        self.key == rhs.key
    }
}
impl PartialOrd for TaskBarIcon {
    fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
        Some((self.key).cmp(&rhs.key))
    }
}
impl Eq for TaskBarIcon {}
impl Ord for TaskBarIcon {
    fn cmp(&self, rhs: &Self) -> Ordering {
        (self.key).cmp(&rhs.key)
    }
}
impl Hash for TaskBarIcon {
    fn hash<H>(&self, state: &mut H)
    where
        H: Hasher,
    {
        self.key.hash(state);
    }
}
/// A built-in system dialog the engine presents on the app's behalf.
///
/// Invoked via `CallbackInfo::invoke_system_dialog`. These dialogs are
/// rendered by azul itself in a new window that is ALWAYS CPU-rendered — a
/// dialog reporting a problem (possibly a GPU problem) must not depend on
/// the GPU working.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub enum SysDialogType {
    /// "Report a problem": a message box (user text + optional screenshot of
    /// the current window + optional system information) mailed to
    /// `AppConfig.report_problem`, or saved to disk when no address is set.
    ReportProblem,
    /// "Check for updates": runs the update check on a background thread,
    /// shows the release's Markdown changelog, and — only where the install
    /// permits self-update and the user consents — downloads and applies it.
    /// Package-managed installs get a "update via your package manager" note.
    UpdateVersion,
    /// "Data collection": the telemetry consent dialog. Lists EVERY
    /// instrument the app can record with per-metric checkmarks, the four
    /// signal switches (crashes / logs / metrics / app state on crash), and
    /// "remember for all azul apps" (writes the machine-wide shared config).
    TelemetryConsent,
    /// "Graphics check": shows what the engine's GPU probe found (vendor /
    /// renderer / verdict) and, when GPU rendering is unusable, per-platform
    /// driver guidance - for apps that NEED working video acceleration.
    GpuCheck,
}
#[cfg(test)]
#[path = "window_test.rs"]
mod window_test;