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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0

use std::sync::Arc;

use super::{command, Application, ApplicationExt, Core, Subscription};
use crate::config::CosmicTk;
use crate::theme::{self, Theme, ThemeType, THEME};
use crate::widget::nav_bar;
use crate::{keyboard_nav, Element};
#[cfg(feature = "wayland")]
use cctk::sctk::reexports::csd_frame::{WindowManagerCapabilities, WindowState};
use cosmic_theme::ThemeMode;
#[cfg(feature = "wayland")]
use iced::event::wayland::{self, WindowEvent};
#[cfg(feature = "wayland")]
use iced::event::PlatformSpecific;
#[cfg(all(feature = "winit", feature = "multi-window"))]
use iced::multi_window::Application as IcedApplication;
#[cfg(feature = "wayland")]
use iced::wayland::Application as IcedApplication;
#[cfg(not(any(feature = "multi-window", feature = "wayland")))]
use iced::Application as IcedApplication;
use iced::{window, Command};
use iced_futures::event::listen_with;
#[cfg(not(feature = "wayland"))]
use iced_runtime::command::Action;
#[cfg(not(feature = "wayland"))]
use iced_runtime::window::Action as WindowAction;
use palette::color_difference::EuclideanDistance;

/// A message managed internally by COSMIC.
#[derive(Clone, Debug)]
pub enum Message {
    /// Application requests theme change.
    AppThemeChange(Theme),
    /// Requests to close the window.
    Close,
    /// Closes or shows the context drawer.
    ContextDrawer(bool),
    /// Requests to drag the window.
    Drag,
    /// Keyboard shortcuts managed by libcosmic.
    KeyboardNav(keyboard_nav::Message),
    /// Requests to maximize the window.
    Maximize,
    /// Requests to minimize the window.
    Minimize,
    /// Activates a navigation element from the nav bar.
    NavBar(nav_bar::Id),
    /// Activates a context menu for an item from the nav bar.
    NavBarContext(nav_bar::Id),
    /// Set scaling factor
    ScaleFactor(f32),
    /// Notification of system theme changes.
    SystemThemeChange(Vec<&'static str>, Theme),
    /// Notification of system theme mode changes.
    SystemThemeModeChange(Vec<&'static str>, ThemeMode),
    /// Toggles visibility of the nav bar.
    ToggleNavBar,
    /// Toggles the condensed status of the nav bar.
    ToggleNavBarCondensed,
    /// Toolkit configuration update
    ToolkitConfig(CosmicTk),
    /// Updates the window maximized state
    WindowMaximized(window::Id, bool),
    /// Updates the tracked window geometry.
    WindowResize(window::Id, u32, u32),
    /// Tracks updates to window state.
    #[cfg(feature = "wayland")]
    WindowState(window::Id, WindowState),
    /// Capabilities the window manager supports
    #[cfg(feature = "wayland")]
    WmCapabilities(window::Id, WindowManagerCapabilities),
    /// Notifies that a surface was closed.
    /// Any data relating to the surface should be cleaned up.
    SurfaceClosed(window::Id),
    /// Activate the application
    Activate(String),
    ShowWindowMenu,
    #[cfg(feature = "xdg-portal")]
    DesktopSettings(crate::theme::portal::Desktop),
    /// Window focus changed
    Focus(window::Id),
    /// Window focus lost
    Unfocus(window::Id),
    /// Tracks updates to window suggested size.
    #[cfg(feature = "applet")]
    Configure(cctk::sctk::shell::xdg::window::WindowConfigure),
}

#[derive(Default)]
pub struct Cosmic<App> {
    pub app: App,
}

impl<T: Application> IcedApplication for Cosmic<T>
where
    T::Message: Send + 'static,
{
    type Executor = T::Executor;
    type Flags = (Core, T::Flags);
    type Message = super::Message<T::Message>;
    type Theme = Theme;

    fn new((mut core, flags): Self::Flags) -> (Self, iced::Command<Self::Message>) {
        #[cfg(feature = "dbus-config")]
        {
            use iced_futures::futures::executor::block_on;
            core.settings_daemon = block_on(cosmic_config::dbus::settings_daemon_proxy()).ok();
        }

        let (model, command) = T::init(core, flags);

        (Self::new(model), command)
    }

    #[cfg(not(any(feature = "multi-window", feature = "wayland")))]
    fn title(&self) -> String {
        self.app.title().to_string()
    }

    #[cfg(any(feature = "multi-window", feature = "wayland"))]
    fn title(&self, id: window::Id) -> String {
        self.app.title(id).to_string()
    }

    fn update(&mut self, message: Self::Message) -> iced::Command<Self::Message> {
        match message {
            super::Message::App(message) => self.app.update(message),
            super::Message::Cosmic(message) => self.cosmic_update(message),
            super::Message::None => iced::Command::none(),
            #[cfg(feature = "single-instance")]
            super::Message::DbusActivation(message) => self.app.dbus_activation(message),
        }
    }

    #[cfg(not(any(feature = "multi-window", feature = "wayland")))]
    fn scale_factor(&self) -> f64 {
        f64::from(self.app.core().scale_factor())
    }

    #[cfg(any(feature = "multi-window", feature = "wayland"))]
    fn scale_factor(&self, _id: window::Id) -> f64 {
        f64::from(self.app.core().scale_factor())
    }

    fn style(&self) -> <Self::Theme as iced_style::application::StyleSheet>::Style {
        if let Some(style) = self.app.style() {
            style
        } else if self.app.core().window.sharp_corners {
            theme::Application::default()
        } else {
            theme::Application::Custom(Box::new(|theme| iced_style::application::Appearance {
                background_color: iced_core::Color::TRANSPARENT,
                icon_color: theme.cosmic().on_bg_color().into(),
                text_color: theme.cosmic().on_bg_color().into(),
            }))
        }
    }

    #[allow(clippy::too_many_lines)]
    fn subscription(&self) -> Subscription<Self::Message> {
        let window_events = listen_with(|event, _| {
            match event {
                iced::Event::Window(id, window::Event::Resized { width, height }) => {
                    return Some(Message::WindowResize(id, width, height));
                }
                iced::Event::Window(id, window::Event::Closed) => {
                    return Some(Message::SurfaceClosed(id))
                }
                iced::Event::Window(id, window::Event::Focused) => return Some(Message::Focus(id)),
                iced::Event::Window(id, window::Event::Unfocused) => {
                    return Some(Message::Unfocus(id))
                }
                #[cfg(feature = "wayland")]
                iced::Event::PlatformSpecific(PlatformSpecific::Wayland(event)) => match event {
                    wayland::Event::Window(WindowEvent::State(state), _surface, id) => {
                        return Some(Message::WindowState(id, state));
                    }
                    wayland::Event::Window(
                        WindowEvent::WmCapabilities(capabilities),
                        _surface,
                        id,
                    ) => {
                        return Some(Message::WmCapabilities(id, capabilities));
                    }
                    wayland::Event::Popup(wayland::PopupEvent::Done, _, id)
                    | wayland::Event::Layer(wayland::LayerEvent::Done, _, id) => {
                        return Some(Message::SurfaceClosed(id));
                    }
                    #[cfg(feature = "applet")]
                    wayland::Event::Window(WindowEvent::Configure(conf), _surface, id)
                        if id == window::Id::MAIN =>
                    {
                        return Some(Message::Configure(conf));
                    }
                    _ => (),
                },
                _ => (),
            }

            None
        });

        let mut subscriptions = vec![
            self.app.subscription().map(super::Message::App),
            self.app
                .core()
                .watch_config::<crate::config::CosmicTk>(crate::config::ID)
                .map(|update| {
                    for why in update.errors {
                        tracing::error!(?why, "cosmic toolkit config update error");
                    }

                    super::Message::Cosmic(Message::ToolkitConfig(update.config))
                }),
            self.app
                .core()
                .watch_config::<cosmic_theme::Theme>(
                    if if let ThemeType::System { prefer_dark, .. } =
                        THEME.lock().unwrap().theme_type
                    {
                        prefer_dark
                    } else {
                        None
                    }
                    .unwrap_or_else(|| self.app.core().system_theme_mode.is_dark)
                    {
                        cosmic_theme::DARK_THEME_ID
                    } else {
                        cosmic_theme::LIGHT_THEME_ID
                    },
                )
                .map(|update| {
                    for why in update.errors {
                        tracing::error!(?why, "cosmic theme config update error");
                    }
                    Message::SystemThemeChange(
                        update.keys,
                        crate::theme::Theme::system(Arc::new(update.config)),
                    )
                })
                .map(super::Message::Cosmic),
            self.app
                .core()
                .watch_config::<ThemeMode>(cosmic_theme::THEME_MODE_ID)
                .map(|update| {
                    for e in update.errors {
                        tracing::error!("{e}");
                    }
                    Message::SystemThemeModeChange(update.keys, update.config)
                })
                .map(super::Message::Cosmic),
            window_events.map(super::Message::Cosmic),
            #[cfg(feature = "xdg-portal")]
            crate::theme::portal::desktop_settings()
                .map(Message::DesktopSettings)
                .map(super::Message::Cosmic),
        ];

        if self.app.core().keyboard_nav {
            subscriptions.push(
                keyboard_nav::subscription()
                    .map(Message::KeyboardNav)
                    .map(super::Message::Cosmic),
            );
        }

        #[cfg(feature = "single-instance")]
        if self.app.core().single_instance {
            subscriptions.push(super::single_instance_subscription::<T>());
        }

        Subscription::batch(subscriptions)
    }

    #[cfg(not(any(feature = "multi-window", feature = "wayland")))]
    fn theme(&self) -> Self::Theme {
        crate::theme::active()
    }

    #[cfg(any(feature = "multi-window", feature = "wayland"))]
    fn theme(&self, _id: window::Id) -> Self::Theme {
        crate::theme::active()
    }

    #[cfg(any(feature = "multi-window", feature = "wayland"))]
    fn view(&self, id: window::Id) -> Element<Self::Message> {
        if id != self.app.main_window_id() {
            return self.app.view_window(id).map(super::Message::App);
        }

        if self.app.core().window.use_template {
            self.app.view_main()
        } else {
            self.app.view().map(super::Message::App)
        }
    }

    #[cfg(not(any(feature = "multi-window", feature = "wayland")))]
    fn view(&self) -> Element<Self::Message> {
        self.app.view_main()
    }
}

impl<T: Application> Cosmic<T> {
    #[cfg(feature = "wayland")]
    pub fn close(&mut self) -> iced::Command<super::Message<T::Message>> {
        iced_sctk::commands::window::close_window(self.app.main_window_id())
    }

    #[cfg(not(feature = "wayland"))]
    #[allow(clippy::unused_self)]
    pub fn close(&mut self) -> iced::Command<super::Message<T::Message>> {
        iced::Command::single(Action::Window(WindowAction::Close(
            self.app.main_window_id(),
        )))
    }

    #[allow(clippy::too_many_lines)]
    fn cosmic_update(&mut self, message: Message) -> iced::Command<super::Message<T::Message>> {
        match message {
            Message::WindowMaximized(id, maximized) => {
                if self.app.main_window_id() == id {
                    self.app.core_mut().window.sharp_corners = maximized;
                }
            }

            Message::WindowResize(id, width, height) => {
                if self.app.main_window_id() == id {
                    self.app.core_mut().set_window_width(width);
                    self.app.core_mut().set_window_height(height);
                }

                self.app.on_window_resize(id, width, height);

                //TODO: more efficient test of maximized (winit has no event for maximize if set by the OS)
                #[cfg(not(feature = "wayland"))]
                return iced::window::fetch_maximized(id, move |maximized| {
                    super::Message::Cosmic(Message::WindowMaximized(id, maximized))
                });
            }

            #[cfg(feature = "wayland")]
            Message::WindowState(id, state) => {
                if self.app.main_window_id() == id {
                    self.app.core_mut().window.sharp_corners = state.intersects(
                        WindowState::MAXIMIZED
                            | WindowState::FULLSCREEN
                            | WindowState::TILED
                            | WindowState::TILED_RIGHT
                            | WindowState::TILED_LEFT
                            | WindowState::TILED_TOP
                            | WindowState::TILED_BOTTOM,
                    );
                }
            }

            #[cfg(feature = "wayland")]
            Message::WmCapabilities(id, capabilities) => {
                if self.app.main_window_id() == id {
                    self.app.core_mut().window.show_maximize =
                        capabilities.contains(WindowManagerCapabilities::MAXIMIZE);
                    self.app.core_mut().window.show_minimize =
                        capabilities.contains(WindowManagerCapabilities::MINIMIZE);
                    self.app.core_mut().window.show_window_menu =
                        capabilities.contains(WindowManagerCapabilities::WINDOW_MENU);
                }
            }

            Message::KeyboardNav(message) => match message {
                keyboard_nav::Message::FocusNext => {
                    return iced::widget::focus_next().map(super::Message::Cosmic)
                }
                keyboard_nav::Message::FocusPrevious => {
                    return iced::widget::focus_previous().map(super::Message::Cosmic)
                }
                keyboard_nav::Message::Escape => return self.app.on_escape(),
                keyboard_nav::Message::Search => return self.app.on_search(),

                keyboard_nav::Message::Fullscreen => {
                    return command::toggle_maximize(Some(self.app.main_window_id()))
                }
            },

            Message::ContextDrawer(show) => {
                self.app.core_mut().window.show_context = show;
                return self.app.on_context_drawer();
            }

            Message::Drag => return command::drag(Some(self.app.main_window_id())),

            Message::Minimize => return command::minimize(Some(self.app.main_window_id())),

            Message::Maximize => return command::toggle_maximize(Some(self.app.main_window_id())),

            Message::NavBar(key) => {
                self.app.core_mut().nav_bar_set_toggled_condensed(false);
                return self.app.on_nav_select(key);
            }

            Message::NavBarContext(key) => {
                self.app.core_mut().nav_bar_set_context(key);
                return self.app.on_nav_context(key);
            }

            Message::ToggleNavBar => {
                self.app.core_mut().nav_bar_toggle();
            }

            Message::ToggleNavBarCondensed => {
                self.app.core_mut().nav_bar_toggle_condensed();
            }

            Message::AppThemeChange(mut theme) => {
                if let ThemeType::System { theme: _, .. } = theme.theme_type {
                    self.app.core_mut().theme_sub_counter += 1;

                    let portal_accent = self.app.core().portal_accent;
                    if let Some(a) = portal_accent {
                        let t_inner = theme.cosmic();
                        if a.distance_squared(*t_inner.accent_color()) > 0.00001 {
                            theme = Theme::system(Arc::new(t_inner.with_accent(a)));
                        }
                    };
                }

                THEME.lock().unwrap().set_theme(theme.theme_type);
            }

            Message::SystemThemeChange(keys, theme) => {
                let cur_is_dark = THEME.lock().unwrap().theme_type.is_dark();
                // Ignore updates if the current theme mode does not match.
                if cur_is_dark != theme.cosmic().is_dark {
                    return iced::Command::none();
                }
                let cmd = self.app.system_theme_update(&keys, theme.cosmic());
                // Record the last-known system theme in event that the current theme is custom.
                self.app.core_mut().system_theme = theme.clone();
                let portal_accent = self.app.core().portal_accent;
                {
                    let mut cosmic_theme = THEME.lock().unwrap();

                    // Only apply update if the theme is set to load a system theme
                    if let ThemeType::System {
                        theme: _,
                        prefer_dark,
                    } = cosmic_theme.theme_type
                    {
                        let mut new_theme = if let Some(a) = portal_accent {
                            let t_inner = theme.cosmic();
                            if a.distance_squared(*t_inner.accent_color()) > 0.00001 {
                                Theme::system(Arc::new(t_inner.with_accent(a)))
                            } else {
                                theme
                            }
                        } else {
                            theme
                        };
                        new_theme.theme_type.prefer_dark(prefer_dark);

                        cosmic_theme.set_theme(new_theme.theme_type);
                    }
                }

                return cmd;
            }

            Message::ScaleFactor(factor) => {
                self.app.core_mut().set_scale_factor(factor);
            }

            Message::Close => {
                return match self.app.on_app_exit() {
                    Some(message) => self.app.update(message),
                    None => self.close(),
                };
            }
            Message::SystemThemeModeChange(keys, mode) => {
                if !keys.contains(&"is_dark") {
                    return iced::Command::none();
                }
                if match THEME.lock().unwrap().theme_type {
                    ThemeType::System {
                        theme: _,
                        prefer_dark,
                    } => prefer_dark.is_some(),
                    _ => false,
                } {
                    return iced::Command::none();
                }
                let mut cmds = vec![self.app.system_theme_mode_update(&keys, &mode)];

                let core = self.app.core_mut();
                let prev_is_dark = core.system_is_dark();
                core.system_theme_mode = mode;
                let is_dark = core.system_is_dark();
                let changed = prev_is_dark != is_dark;
                if changed {
                    core.theme_sub_counter += 1;
                    let mut new_theme = if is_dark {
                        crate::theme::system_dark()
                    } else {
                        crate::theme::system_light()
                    };
                    cmds.push(self.app.system_theme_update(&[], new_theme.cosmic()));

                    let core = self.app.core_mut();
                    new_theme = if let Some(a) = core.portal_accent {
                        let t_inner = new_theme.cosmic();
                        if a.distance_squared(*t_inner.accent_color()) > 0.00001 {
                            Theme::system(Arc::new(t_inner.with_accent(a)))
                        } else {
                            new_theme
                        }
                    } else {
                        new_theme
                    };

                    core.system_theme = new_theme.clone();
                    {
                        let mut cosmic_theme = THEME.lock().unwrap();
                        // Only apply update if the theme is set to load a system theme
                        if let ThemeType::System { theme: _, .. } = cosmic_theme.theme_type {
                            cosmic_theme.set_theme(new_theme.theme_type);
                        }
                    }
                }
                return Command::batch(cmds);
            }
            Message::Activate(_token) => {
                #[cfg(feature = "wayland")]
                return iced_sctk::commands::activation::activate(
                    self.app.main_window_id(),
                    #[allow(clippy::used_underscore_binding)]
                    _token,
                );
            }
            Message::SurfaceClosed(id) => {
                if let Some(msg) = self.app.on_close_requested(id) {
                    return self.app.update(msg);
                }
            }
            Message::ShowWindowMenu => {
                return window::show_window_menu(window::Id::MAIN);
            }
            #[cfg(feature = "xdg-portal")]
            Message::DesktopSettings(crate::theme::portal::Desktop::ColorScheme(s)) => {
                use ashpd::desktop::settings::ColorScheme;
                if match THEME.lock().unwrap().theme_type {
                    ThemeType::System {
                        theme: _,
                        prefer_dark,
                    } => prefer_dark.is_some(),
                    _ => false,
                } {
                    return iced::Command::none();
                }
                let is_dark = match s {
                    ColorScheme::NoPreference => None,
                    ColorScheme::PreferDark => Some(true),
                    ColorScheme::PreferLight => Some(false),
                };
                let core = self.app.core_mut();
                let prev_is_dark = core.system_is_dark();
                core.portal_is_dark = is_dark;
                let is_dark = core.system_is_dark();
                let changed = prev_is_dark != is_dark;
                if changed {
                    core.theme_sub_counter += 1;
                    let new_theme = if is_dark {
                        crate::theme::system_dark()
                    } else {
                        crate::theme::system_light()
                    };
                    core.system_theme = new_theme.clone();
                    {
                        let mut cosmic_theme = THEME.lock().unwrap();

                        // Only apply update if the theme is set to load a system theme
                        if let ThemeType::System { theme: _, .. } = cosmic_theme.theme_type {
                            cosmic_theme.set_theme(new_theme.theme_type);
                        }
                    }
                }
            }
            #[cfg(feature = "xdg-portal")]
            Message::DesktopSettings(crate::theme::portal::Desktop::Accent(c)) => {
                use palette::Srgba;
                let c = Srgba::new(c.red() as f32, c.green() as f32, c.blue() as f32, 1.0);
                let core = self.app.core_mut();
                core.portal_accent = Some(c);
                let cur_accent = core.system_theme.cosmic().accent_color();

                if cur_accent.distance_squared(*c) < 0.00001 {
                    // skip calculations if we already have the same color
                    return iced::Command::none();
                }

                {
                    let mut cosmic_theme = THEME.lock().unwrap();

                    // Only apply update if the theme is set to load a system theme
                    if let ThemeType::System {
                        theme: t,
                        prefer_dark,
                    } = cosmic_theme.theme_type.clone()
                    {
                        cosmic_theme.set_theme(ThemeType::System {
                            theme: Arc::new(t.with_accent(c)),
                            prefer_dark,
                        });
                    }
                }
            }
            #[cfg(feature = "xdg-portal")]
            Message::DesktopSettings(crate::theme::portal::Desktop::Contrast(_)) => {
                // TODO when high contrast is integrated in settings and all custom themes
            }

            Message::ToolkitConfig(config) => {
                // Change the icon theme if not defined by the application.
                if !self.app.core().icon_theme_override
                    && crate::icon_theme::default() != config.icon_theme
                {
                    crate::icon_theme::set_default(config.icon_theme.clone());
                }

                *crate::config::COSMIC_TK.lock().unwrap() = config;
            }

            Message::Focus(f) => {
                self.app.core_mut().focused_window = Some(f);
            }

            Message::Unfocus(id) => {
                let core = self.app.core_mut();
                if core.focused_window.as_ref().is_some_and(|cur| *cur == id) {
                    core.focused_window = None;
                }
            }
            #[cfg(feature = "applet")]
            Message::Configure(configure) => {
                if let Some(w) = configure.new_size.0 {
                    self.app.core_mut().set_window_width(w.get());
                }
                if let Some(h) = configure.new_size.1 {
                    self.app.core_mut().set_window_height(h.get());
                }
                self.app.core_mut().applet.configure = Some(configure);
            }
        }

        iced::Command::none()
    }
}

impl<App: Application> Cosmic<App> {
    pub fn new(app: App) -> Self {
        Self { app }
    }
}