sim_logic/application/window.rs
1//! Optional window commands, independent of windowing and rendering crates.
2
3/// How a borderless-fullscreen request selects a monitor.
4#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
5pub enum FullscreenMonitor {
6 /// Let the window manager choose, without requiring monitor enumeration.
7 #[default]
8 Automatic,
9 /// Require the monitor currently containing the window; no silent fallback.
10 Current,
11 /// Require the platform's primary monitor; no silent fallback.
12 Primary,
13}
14
15/// Requested window presentation. Exclusive video-mode changes are not used.
16#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
17pub enum WindowMode {
18 /// An ordinary resizable window, restoring windowed placement where supported.
19 #[default]
20 Windowed,
21 /// Borderless fullscreen without changing the monitor's video mode.
22 BorderlessFullscreen(FullscreenMonitor),
23}
24
25/// Native cursor appearance. PointerCapture still controls capture and visibility.
26#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
27pub enum CursorShape {
28 /// Platform's ordinary arrow/default cursor.
29 #[default]
30 Default,
31 /// A clickable link or button.
32 Pointer,
33 /// Text selection/insertion.
34 Text,
35 /// Precise pointing.
36 Crosshair,
37 /// An object can be dragged.
38 Grab,
39 /// An object is being dragged.
40 Grabbing,
41 /// The requested action is unavailable.
42 NotAllowed,
43 /// Wait for an operation to finish.
44 Wait,
45 /// Background progress while interaction remains possible.
46 Progress,
47 /// Movement in all directions.
48 Move,
49 /// Horizontal resize.
50 ResizeHorizontal,
51 /// Vertical resize.
52 ResizeVertical,
53 /// Northeast/southwest resize.
54 ResizeNorthEastSouthWest,
55 /// Northwest/southeast resize.
56 ResizeNorthWestSouthEast,
57}
58
59/// Why a mode could not be submitted. Rejection keeps the old mode.
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
61pub enum WindowModeFailure {
62 /// An explicitly selected current/primary monitor was not available.
63 MonitorUnavailable,
64 /// This adapter does not implement window mode requests.
65 Unsupported,
66}
67
68/// Latest mode submission result, not a compositor-confirmed display state.
69#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
70pub enum WindowModeStatus {
71 /// No native operation attempted (including headless operation).
72 #[default]
73 NotSubmitted,
74 /// Sent to the window manager, which may apply asynchronously or ignore it.
75 /// The native API supplies no reliable visual-completion acknowledgement.
76 Submitted(WindowMode),
77 /// Nothing submitted; inspect the failure and retry on an explicit action.
78 Unavailable(WindowModeFailure),
79}
80
81/// Optional application-owned window/cursor requests.
82///
83/// Register `WindowControls::default()` as an Application Resource and mutate
84/// through `AppResMut<WindowControls>`. Desktop consumes requests after the
85/// logical frame; headless retains them without OS calls. Requests are immediate,
86/// not transactional Commands, and survive World replacement. Last request wins
87/// before consumption; there is no growing queue or automatic F11 binding.
88/// Native cursor themes may substitute the default for an unavailable shape.
89#[derive(Debug, Default)]
90pub struct WindowControls {
91 mode: Option<WindowMode>,
92 cursor: Option<CursorShape>,
93 mode_status: WindowModeStatus,
94 submitted_cursor: Option<CursorShape>,
95}
96
97impl WindowControls {
98 /// Requests a mode, or explicitly retries a previously ignored request.
99 pub fn request_mode(&mut self, mode: WindowMode) {
100 self.mode = Some(mode);
101 }
102
103 /// Requests a cursor; repeating an acknowledged value does no OS work.
104 pub fn request_cursor(&mut self, shape: CursorShape) {
105 self.cursor = (self.submitted_cursor != Some(shape)).then_some(shape);
106 }
107
108 /// Returns the not-yet-submitted mode request, if any.
109 pub const fn pending_mode(&self) -> Option<WindowMode> {
110 self.mode
111 }
112 /// Returns the native submission outcome. Headless never fabricates success.
113 pub const fn mode_status(&self) -> WindowModeStatus {
114 self.mode_status
115 }
116 /// Returns the not-yet-submitted cursor request, if any.
117 pub const fn pending_cursor(&self) -> Option<CursorShape> {
118 self.cursor
119 }
120 /// Returns the cursor last sent to the backend, not a theme-support guarantee.
121 pub const fn submitted_cursor(&self) -> Option<CursorShape> {
122 self.submitted_cursor
123 }
124
125 #[cfg(feature = "desktop")]
126 pub(crate) fn acknowledge_mode(&mut self, status: WindowModeStatus) {
127 self.mode = None;
128 self.mode_status = status;
129 }
130 #[cfg(feature = "desktop")]
131 pub(crate) fn acknowledge_cursor(&mut self, shape: CursorShape) {
132 self.cursor = None;
133 self.submitted_cursor = Some(shape);
134 }
135}