cosmic/surface/
mod.rs

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