cosmic/surface/
action.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2025 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0

use super::Action;
#[cfg(feature = "winit")]
use crate::Application;

use std::{any::Any, sync::Arc};

/// Used to produce a destroy popup message from within a widget.
#[cfg(feature = "wayland")]
#[must_use]
pub fn destroy_popup(id: iced_core::window::Id) -> Action {
    Action::DestroyPopup(id)
}

#[cfg(feature = "wayland")]
#[must_use]
pub fn destroy_subsurface(id: iced_core::window::Id) -> Action {
    Action::DestroySubsurface(id)
}

#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn app_popup<App: Application>(
    settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
        + Send
        + Sync
        + 'static,
    view: Option<
        Box<
            dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
                + Send
                + Sync
                + 'static,
        >,
    >,
) -> Action {
    let boxed: Box<
        dyn Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
            + Send
            + Sync
            + 'static,
    > = Box::new(settings);
    let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);

    Action::AppPopup(
        Arc::new(boxed),
        view.map(|view| {
            let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
            Arc::new(boxed)
        }),
    )
}

/// Used to create a subsurface message from within a widget.
#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn simple_subsurface<Message: 'static, V>(
    settings: impl Fn() -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings
        + Send
        + Sync
        + 'static,
    view: Option<
        Box<dyn Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static>,
    >,
) -> Action {
    let boxed: Box<
        dyn Fn() -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings
            + Send
            + Sync
            + 'static,
    > = Box::new(settings);
    let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);

    Action::Subsurface(
        Arc::new(boxed),
        view.map(|view| {
            let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
            Arc::new(boxed)
        }),
    )
}

/// Used to create a popup message from within a widget.
#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn simple_popup<Message: 'static, V>(
    settings: impl Fn() -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
        + Send
        + Sync
        + 'static,
    view: Option<
        impl Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
    >,
) -> Action {
    let boxed: Box<
        dyn Fn() -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
            + Send
            + Sync
            + 'static,
    > = Box::new(settings);
    let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);

    Action::Popup(
        Arc::new(boxed),
        view.map(|view| {
            let boxed: Box<
                dyn Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
            > = Box::new(view);
            let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
            Arc::new(boxed)
        }),
    )
}

#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn subsurface<App: Application>(
    settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings
        + Send
        + Sync
        + 'static,
    // XXX Boxed trait object is required for less cumbersome type inference, but we box it anyways.
    view: Option<
        Box<
            dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
                + Send
                + Sync
                + 'static,
        >,
    >,
) -> Action {
    let boxed: Box<
        dyn Fn(
                &mut App,
            )
                -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings
            + Send
            + Sync
            + 'static,
    > = Box::new(settings);
    let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);

    Action::AppSubsurface(
        Arc::new(boxed),
        view.map(|view| {
            let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
            Arc::new(boxed)
        }),
    )
}