teksilo_core/window/placement.rs
1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Window placement enum.
5//!
6//! A single unified type covers the four placement modes every modern
7//! desktop OS supports: floating, maximized, fullscreen, minimized.
8//! Represent state, not transitions — the platform layer decides how to
9//! move between any two variants.
10//!
11//! Size and position are deliberately *not* inside `Floating`. They are
12//! independent signals on [`WindowState`](super::state::WindowState)
13//! that always hold the last-known *restored* values. This matches
14//! native behavior on macOS (`frameAutosaveName`) and Windows
15//! (`WINDOWPLACEMENT`), and it removes the "what size do I go back to
16//! after un-maximize?" ambiguity that boolean fullscreen/maximize
17//! representations expose.
18
19/// Top-level placement state for a window.
20///
21/// Transitions between any two variants are legal — the platform layer
22/// is responsible for preserving the restored rect (held by the
23/// `size` / `position` signals on `WindowState`) when crossing through
24/// `Maximized`, `Fullscreen`, or `Minimized`.
25#[derive(
26 Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, Default,
27)]
28pub enum WindowPlacement {
29 /// Regular overlapping window. Uses `WindowState::size` and
30 /// `WindowState::position` as the current geometry.
31 #[default]
32 Floating,
33 /// Maximized to fill the current monitor's work area (minus taskbar
34 /// / dock / menu bar on platforms that have one).
35 Maximized,
36 /// Exclusive fullscreen — covers the entire display, title bar and
37 /// all chrome hidden. On macOS this is Space-based fullscreen.
38 Fullscreen,
39 /// Minimized to the taskbar / dock. The window is not visible
40 /// on-screen but retains its state and may be restored.
41 Minimized,
42}
43
44impl WindowPlacement {
45 /// Returns `true` when the window is currently in `Fullscreen`.
46 pub fn is_fullscreen(self) -> bool {
47 matches!(self, WindowPlacement::Fullscreen)
48 }
49
50 /// Returns `true` when the window is currently in `Maximized`.
51 pub fn is_maximized(self) -> bool {
52 matches!(self, WindowPlacement::Maximized)
53 }
54
55 /// Returns `true` when the window is currently in `Minimized`.
56 pub fn is_minimized(self) -> bool {
57 matches!(self, WindowPlacement::Minimized)
58 }
59
60 /// Returns `true` when the window is currently `Floating` — i.e.
61 /// neither maximized, fullscreen, nor minimized.
62 pub fn is_floating(self) -> bool {
63 matches!(self, WindowPlacement::Floating)
64 }
65}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn predicates_match_variant() {
73 assert!(WindowPlacement::Floating.is_floating());
74 assert!(!WindowPlacement::Floating.is_fullscreen());
75 assert!(WindowPlacement::Fullscreen.is_fullscreen());
76 assert!(WindowPlacement::Maximized.is_maximized());
77 assert!(WindowPlacement::Minimized.is_minimized());
78 }
79
80 #[test]
81 fn default_is_floating() {
82 assert_eq!(WindowPlacement::default(), WindowPlacement::Floating);
83 }
84}