gitkraft_gui/window/mod.rs
1//! Native window behaviour: the commands a user expects from any desktop window —
2//! **resize, zoom, minimize, tile** — that the window library does not set up by itself.
3//!
4//! * **macOS**: the system builds *Zoom*, *Fill*, *Move & Resize* (the ⌃⌘← tiling
5//! shortcuts), *Minimize* and *Bring All to Front* from the app's **Window menu**, and
6//! winit's default menu bar has none. `macos` adds it.
7//! * **Windows and Linux**: the OS or the compositor draws the frame and does all of this
8//! already (Win+Arrow snapping, X11 window managers, Wayland client-side decorations),
9//! so there is nothing to add.
10//!
11//! Call [`setup`] once the window exists and run the task it returns.
12
13#[cfg(target_os = "macos")]
14pub mod macos;
15
16/// One-time window setup as an iced task (a no-op where the platform needs nothing).
17///
18/// Generic over the app's message type: the task produces no messages.
19#[cfg(target_os = "macos")]
20pub fn setup<M: Send + 'static>() -> iced::Task<M> {
21 iced::window::oldest()
22 .and_then(|id| {
23 iced::window::run(id, |_window| {
24 macos::install_window_menu();
25 })
26 })
27 .discard()
28}
29
30#[cfg(not(target_os = "macos"))]
31pub fn setup<M: Send + 'static>() -> iced::Task<M> {
32 iced::Task::none()
33}
34
35#[cfg(test)]
36mod tests {
37 #[test]
38 fn setup_builds_a_task_for_any_message_type() {
39 let _: iced::Task<u8> = super::setup();
40 let _: iced::Task<String> = super::setup();
41 }
42}