Skip to main content

cosmic/surface/
mod.rs

1// Copyright 2025 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4pub mod action;
5#[cfg(wayland_platform)]
6pub mod corner_radius;
7
8use iced::{Limits, Size, Task};
9use std::any::Any;
10use std::sync::Arc;
11
12type BoxedSetting = Arc<Box<dyn Any + Send + Sync + 'static>>;
13
14/// Ignore this message in your application. It will be intercepted.
15#[derive(Clone)]
16pub enum Action {
17    /// Create a subsurface with a view function accepting the App as a parameter
18    AppSubsurface(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
19    /// Create a subsurface with a view function
20    Subsurface(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
21    /// Destroy a subsurface with a view function
22    DestroySubsurface(iced::window::Id),
23    /// Create a popup with a view function accepting the App as a parameter
24    AppPopup(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
25    /// Create a popup
26    Popup(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
27    /// Destroy a subsurface with a view function
28    DestroyPopup(iced::window::Id),
29    /// Destroys the global tooltip popup subsurface
30    DestroyTooltipPopup,
31
32    /// Create a window with a view function accepting the App as a parameter
33    AppWindow(
34        iced::window::Id,
35        BoxedSetting,
36        BoxedSetting,
37        Option<BoxedSetting>,
38    ),
39    /// Create a window with a view function
40    Window(
41        iced::window::Id,
42        BoxedSetting,
43        BoxedSetting,
44        Option<BoxedSetting>,
45    ),
46    /// Destroy a window
47    DestroyWindow(iced::window::Id),
48
49    /// Create a layer shell surface with a view function accepting the App as a parameter
50    AppLayerShell(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
51
52    /// Create a layer shell surface with a view function
53    LayerShell(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
54
55    /// Destroy a layer shell surface
56    DestroyLayerShell(iced::window::Id),
57
58    /// Responsive menu bar update
59    ResponsiveMenuBar {
60        /// Id of the menu bar
61        menu_bar: crate::widget::Id,
62        /// Limits of the menu bar
63        limits: Limits,
64        /// Requested Full Size for expanded menu bar
65        size: Size,
66    },
67    Ignore,
68    SyncLiveSettings(iced::window::Id),
69    Task(Arc<dyn Fn() -> Task<Action> + Send + Sync>),
70}
71
72#[cfg(feature = "winit")]
73pub fn surface_task<M: Send + 'static>(action: Action) -> Task<crate::Action<M>> {
74    crate::task::message(crate::Action::Cosmic(crate::app::Action::Surface(action)))
75}
76
77impl std::fmt::Debug for Action {
78    #[cold]
79    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80        match self {
81            Self::AppSubsurface(arg0, arg1, arg2) => f
82                .debug_tuple("AppSubsurface")
83                .field(arg0)
84                .field(arg1)
85                .field(arg2)
86                .finish(),
87            Self::Subsurface(arg0, arg1, arg2) => f
88                .debug_tuple("Subsurface")
89                .field(arg0)
90                .field(arg1)
91                .field(arg2)
92                .finish(),
93            Self::DestroySubsurface(arg0) => {
94                f.debug_tuple("DestroySubsurface").field(arg0).finish()
95            }
96            Self::AppPopup(arg0, arg1, arg2) => f
97                .debug_tuple("AppPopup")
98                .field(arg0)
99                .field(arg1)
100                .field(arg2)
101                .finish(),
102            Self::Popup(arg0, arg1, arg2) => f
103                .debug_tuple("Popup")
104                .field(arg0)
105                .field(arg1)
106                .field(arg2)
107                .finish(),
108            Self::DestroyPopup(arg0) => f.debug_tuple("DestroyPopup").field(arg0).finish(),
109            Self::DestroyTooltipPopup => f.debug_tuple("DestroyTooltipPopup").finish(),
110            Self::ResponsiveMenuBar {
111                menu_bar,
112                limits,
113                size,
114            } => f
115                .debug_struct("ResponsiveMenuBar")
116                .field("menu_bar", menu_bar)
117                .field("limits", limits)
118                .field("size", size)
119                .finish(),
120            Self::Ignore => write!(f, "Ignore"),
121            Self::AppWindow(id, arg0, arg1, arg2) => f
122                .debug_tuple("AppWindow")
123                .field(id)
124                .field(arg0)
125                .field(arg1)
126                .field(arg2)
127                .finish(),
128            Self::Window(id, arg0, arg1, arg2) => f
129                .debug_tuple("Window")
130                .field(id)
131                .field(arg0)
132                .field(arg1)
133                .field(arg2)
134                .finish(),
135            Self::DestroyWindow(arg0) => f.debug_tuple("DestroyWindow").field(arg0).finish(),
136            Self::Task(_) => f.debug_tuple("Future").finish(),
137            Self::AppLayerShell(arg, arg1, arg2) => f
138                .debug_tuple("AppLayerShell")
139                .field(arg)
140                .field(arg1)
141                .field(arg2)
142                .finish(),
143            Self::LayerShell(arg, arg1, arg2) => f
144                .debug_tuple("LayerShell")
145                .field(arg)
146                .field(arg1)
147                .field(arg2)
148                .finish(),
149            Self::DestroyLayerShell(arg0) => {
150                f.debug_tuple("DestroyLayerShell").field(arg0).finish()
151            }
152            Self::SyncLiveSettings(arg0) => f.debug_tuple("SyncLiveSettings").field(arg0).finish(),
153        }
154    }
155}