git.lucas.co / cce-window-manager
window management library
git clone https://git.lucas.co/cce-window-manager.git

src/tiling.rs (2.3K)

 1 // Window modes.
 2 //
 3 // A window is either `Floating` (positioned freely on the virtual surface) or
 4 // `Tiled` (every content edge lies on a visible desktop-grid cell edge). Tiled
 5 // windows report the xdg maximized state to their client. The remaining
 6 // variants are internal roles (`Popup`, `Overlay`, `Status`, `Utility`) or the
 7 // orthogonal `Fullscreen` toggle.
 8 //
 9 // `Utility` is `Status` minus the docking: a tool window whose shape is decided
10 // by its contents (stacked sliders, fixed rows, nothing worth dragging). The
11 // client owns the size, the compositor offers no resize affordance and saves no
12 // geometry for it, but it floats and moves like any ordinary window. It is
13 // never inferred from a sizing hint — a window is `Utility` only because the
14 // client said so, via `set_utility` on the cce window-management protocol.
15 //
16 // Serde aliases keep old `state.json` files loading: the retired `Cascade` /
17 // `Grid` layout modes collapse to `Floating`, and `Maximized` (the old name
18 // for grid-locked windows) maps to `Tiled`.
19 
20 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
21 pub enum TilingMode {
22     #[serde(alias = "Cascade", alias = "Grid")]
23     Floating,
24     #[serde(alias = "Maximized")]
25     Tiled,
26     Fullscreen,
27     Popup,
28     Overlay,
29     Status,
30     Utility,
31 }
32 
33 impl TilingMode {
34     pub fn as_str(&self) -> &'static str {
35         match self {
36             TilingMode::Floating => "Floating",
37             TilingMode::Tiled => "Tiled",
38             TilingMode::Fullscreen => "Fullscreen",
39             TilingMode::Popup => "Popup",
40             TilingMode::Overlay => "Overlay",
41             TilingMode::Status => "Status",
42             TilingMode::Utility => "Utility",
43         }
44     }
45 }
46 
47 #[cfg(test)]
48 mod tests {
49     use super::*;
50 
51     #[test]
52     fn legacy_state_names_still_deserialize() {
53         // Old state.json files carry the retired mode names.
54         for (json, expected) in [
55             ("\"Cascade\"", TilingMode::Floating),
56             ("\"Grid\"", TilingMode::Floating),
57             ("\"Maximized\"", TilingMode::Tiled),
58             ("\"Floating\"", TilingMode::Floating),
59             ("\"Tiled\"", TilingMode::Tiled),
60         ] {
61             let mode: TilingMode = serde_json::from_str(json).unwrap();
62             assert_eq!(mode, expected, "{json}");
63         }
64     }
65 }