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