From 7ba55f66cc7b86670877307e908447d805e5cbf8 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Tue, 8 Sep 2026 12:32:11 -0600 Subject: [PATCH] chore: adopt typed surface actions from libcosmic --- src/app.rs | 64 +++++++++++++++++++++++++-------------------------- src/dialog.rs | 9 ++++---- src/tab.rs | 4 ++-- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/app.rs b/src/app.rs index 55c27a7..4ca8e86 100644 --- a/src/app.rs +++ b/src/app.rs @@ -481,7 +481,7 @@ pub enum Message { OutputEvent(OutputEvent, WlOutput), Cosmic(app::Action), None, - Surface(surface::Action), + Surface(surface::Action), CutPaths(Vec), } @@ -2525,7 +2525,7 @@ impl Application for App { { nav = nav .window_id_maybe(self.core().main_window_id()) - .on_surface_action(|m| cosmic::Action::Cosmic(cosmic::app::Action::Surface(m))) + .on_surface_action(|action| cosmic::Action::Surface(action.flatten())) } let mut nav = nav.into_container(); @@ -4520,6 +4520,9 @@ impl Application for App { ])); } tab::Command::Surface(action) => { + // re-type the tab's surface action the way its messages are re-typed + let action = action + .map(move |message| Message::TabMessage(Some(entity), message)); commands.push(self.update(Message::Surface(action))); } tab::Command::Delete(paths) => commands.push(self.delete(paths)), @@ -5249,35 +5252,31 @@ impl Application for App { .insert(surface_id, Window::new(WindowKind::Desktop(entity))); return Task::batch([ command, - cosmic::task::message(cosmic::action::cosmic( - cosmic::app::Action::Surface( - cosmic::surface::action::app_layer_shell( - |_| Default::default(), - move |_: &mut App| SctkLayerSurfaceSettings { - id: surface_id, - layer: Layer::Bottom, - keyboard_interactivity: KeyboardInteractivity::OnDemand, - input_zone: None, - anchor: Anchor::TOP - | Anchor::BOTTOM - | Anchor::LEFT - | Anchor::RIGHT, - output: IcedOutput::Output(output.clone()), - namespace: "cosmic-files-applet".into(), - size: Some((None, None)), - margin: IcedMargin { - top: 0, - bottom: 0, - left: 0, - right: 0, - }, - exclusive_zone: 0, - size_limits: Limits::NONE - .min_width(1.0) - .min_height(1.0), + cosmic::task::message(cosmic::Action::Surface( + cosmic::surface::action::app_layer_shell( + |_| Default::default(), + move |_: &mut App| SctkLayerSurfaceSettings { + id: surface_id, + layer: Layer::Bottom, + keyboard_interactivity: KeyboardInteractivity::OnDemand, + input_zone: None, + anchor: Anchor::TOP + | Anchor::BOTTOM + | Anchor::LEFT + | Anchor::RIGHT, + output: IcedOutput::Output(output.clone()), + namespace: "cosmic-files-applet".into(), + size: Some((None, None)), + margin: IcedMargin { + top: 0, + bottom: 0, + left: 0, + right: 0, }, - None, - ), + exclusive_zone: 0, + size_limits: Limits::NONE.min_width(1.0).min_height(1.0), + }, + None, ), )), #[cfg(all(feature = "wayland", feature = "desktop-applet"))] @@ -5372,9 +5371,7 @@ impl Application for App { }); } Message::Surface(action) => { - return cosmic::task::message(cosmic::Action::Cosmic( - cosmic::app::Action::Surface(action), - )); + return cosmic::task::message(cosmic::Action::Surface(action)); } Message::SaveSortNames => { self.must_save_sort_names = false; @@ -6600,6 +6597,7 @@ impl Application for App { return self.view_main().map(|message| match message { cosmic::Action::App(app) => app, cosmic::Action::Cosmic(cosmic) => Message::Cosmic(cosmic), + cosmic::Action::Surface(action) => Message::Surface(action), cosmic::Action::None => Message::None, }); } diff --git a/src/dialog.rs b/src/dialog.rs index bebbef4..aba4d00 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -468,7 +468,7 @@ enum Message { SearchActivate, SearchClear, SearchInput(String), - Surface(cosmic::surface::Action), + Surface(cosmic::surface::Action), #[allow(clippy::enum_variant_names)] TabMessage(tab::Message), TabRescan( @@ -501,7 +501,7 @@ impl From for Message { AppMessage::ZoomIn(_entity_opt) => Self::ZoomIn, AppMessage::ZoomOut(_entity_opt) => Self::ZoomOut, AppMessage::NewItem(_entity_opt, true) => Self::NewFolder, - AppMessage::Surface(action) => Self::Surface(action), + AppMessage::Surface(action) => Self::Surface(action.map(Self::from)), unsupported => { log::warn!("{unsupported:?} not supported in dialog mode"); Self::None @@ -1750,6 +1750,7 @@ impl Application for App { ])); } tab::Command::Surface(action) => { + let action = action.map(Message::TabMessage); commands.push(self.update(Message::Surface(action))); } tab::Command::Iced(iced_command) => { @@ -1905,9 +1906,7 @@ impl Application for App { }); } Message::Surface(action) => { - return cosmic::task::message(cosmic::Action::Cosmic( - cosmic::app::Action::Surface(action), - )); + return cosmic::task::message(cosmic::Action::Surface(action)); } } diff --git a/src/tab.rs b/src/tab.rs index 28a20f7..6d7831a 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1742,7 +1742,7 @@ impl fmt::Debug for TaskWrapper { #[derive(Debug)] pub enum Command { Action(Action), - Surface(cosmic::surface::Action), + Surface(cosmic::surface::Action), AddNetworkDrive, AddToSidebar(PathBuf), AutoScroll(Option), @@ -1778,7 +1778,7 @@ pub enum Message { Config(TabConfig), ContextAction(Action), RightClickBackground, - Surface(cosmic::surface::Action), + Surface(cosmic::surface::Action), LocationContextMenuIndex(Option), LocationMenuAction(LocationMenuAction), Drag(Option),