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
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::ResponsiveMenuBar {
89                menu_bar,
90                limits,
91                size,
92            } => f
93                .debug_struct("ResponsiveMenuBar")
94                .field("menu_bar", menu_bar)
95                .field("limits", limits)
96                .field("size", size)
97                .finish(),
98            Self::Ignore => write!(f, "Ignore"),
99            Self::AppWindow(id, arg0, arg1) => f
100                .debug_tuple("AppWindow")
101                .field(id)
102                .field(arg0)
103                .field(arg1)
104                .finish(),
105            Self::Window(id, arg0, arg1) => f
106                .debug_tuple("Window")
107                .field(id)
108                .field(arg0)
109                .field(arg1)
110                .finish(),
111            Self::DestroyWindow(arg0) => f.debug_tuple("DestroyWindow").field(arg0).finish(),
112            Self::Task(_) => f.debug_tuple("Future").finish(),
113        }
114    }
115}