diff --git a/Cargo.lock b/Cargo.lock index 8e8b8564..4e66e81d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1065,7 +1065,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1082,7 +1082,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "quote", "syn 1.0.109", @@ -1152,7 +1152,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "almost", "cosmic-config", @@ -2624,7 +2624,7 @@ dependencies = [ [[package]] name = "iced" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "dnd", "iced_accessibility", @@ -2642,7 +2642,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "accesskit", "accesskit_winit", @@ -2651,7 +2651,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "bitflags 2.5.0", "dnd", @@ -2671,7 +2671,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "futures", "iced_core", @@ -2684,7 +2684,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "bitflags 2.5.0", "bytemuck", @@ -2708,7 +2708,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2720,7 +2720,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "dnd", "iced_core", @@ -2732,7 +2732,7 @@ dependencies = [ [[package]] name = "iced_style" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "iced_core", "once_cell", @@ -2742,7 +2742,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "bytemuck", "cosmic-text", @@ -2759,7 +2759,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "bitflags 2.5.0", "bytemuck", @@ -2778,7 +2778,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "dnd", "iced_renderer", @@ -2794,7 +2794,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "dnd", "iced_graphics", @@ -3120,7 +3120,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e" +source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8" dependencies = [ "apply", "ashpd 0.7.0", diff --git a/Cargo.toml b/Cargo.toml index 077194b7..8a7c4302 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ slotmap = "1.0.7" [dependencies.libcosmic] git = "https://github.com/pop-os/libcosmic.git" +branch = "nav-bar-close-icon" default-features = false features = ["multi-window", "tokio", "winit"] @@ -77,10 +78,6 @@ test-log = "0.2" # libcosmic = { path = "../libcosmic" } # cosmic-config = { path = "../libcosmic/cosmic-config" } # cosmic-theme = { path = "../libcosmic/cosmic-theme" } -# libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "dnd" } -# cosmic-config = { git = "https://github.com/pop-os/libcosmic//", branch = "dnd" } -# cosmic-theme = { git = "https://github.com/pop-os/libcosmic//", branch = "dnd" } # [patch.'https://github.com/pop-os/smithay-clipboard'] -# smithay-clipboard = { git = "https://github.com/pop-os/smithay-clipboard//", rev = "2f2430b" } # smithay-clipboard = { path = "../smithay-clipboard" } diff --git a/src/app.rs b/src/app.rs index ace4040e..0cf71edd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -182,6 +182,7 @@ pub enum Message { Modifiers(Modifiers), MoveToTrash(Option), MounterItems(MounterKey, MounterItems), + NavBarClose(Entity), NavBarContext(Entity), NavMenuAction(NavMenuAction), NewItem(Option, bool), @@ -734,7 +735,13 @@ impl Application for App { cosmic::app::Message::App(Message::DndDropNav(entity, data, action)) }) .on_context(|entity| cosmic::app::Message::App(Message::NavBarContext(entity))) + .on_close(|entity| cosmic::app::Message::App(Message::NavBarClose(entity))) .context_menu(self.nav_context_menu(self.nav_bar_context_id)) + .close_icon( + widget::icon::from_name("media-eject-symbolic") + .size(16) + .icon(), + ) .into_container(); if !self.core().is_condensed() { @@ -1065,15 +1072,7 @@ impl Application for App { let mut entity = self .nav_model .insert() - .text(format!( - "{} ({})", - item.name(), - if item.is_mounted() { - "mounted" - } else { - "not mounted" - } - )) + .text(item.name()) .data(MounterData(key, item.clone())); if let Some(path) = item.path() { entity = entity.data(Location::Path(path.clone())); @@ -1081,6 +1080,9 @@ impl Application for App { if let Some(icon) = item.icon() { entity = entity.icon(widget::icon::icon(icon).size(16)); } + if item.is_mounted() { + entity = entity.closable(); + } } } Message::NewItem(entity_opt, dir) => { @@ -1650,6 +1652,14 @@ impl Application for App { } } + Message::NavBarClose(entity) => { + if let Some(data) = self.nav_model.data::(entity) { + if let Some(mounter) = self.mounters.get(&data.0) { + return mounter.unmount(data.1.clone()).map(|_| message::none()); + } + } + } + // Tracks which nav bar item to show a context menu for. Message::NavBarContext(entity) => { self.nav_bar_context_id = entity; diff --git a/src/mounter/gvfs.rs b/src/mounter/gvfs.rs index d0625445..76c52d83 100644 --- a/src/mounter/gvfs.rs +++ b/src/mounter/gvfs.rs @@ -24,6 +24,7 @@ fn gio_icon_to_path(icon: &gio::Icon, size: u16) -> Option { enum Cmd { Rescan, Mount(MounterItem), + Unmount(MounterItem), } enum Event { @@ -189,6 +190,34 @@ impl Gvfs { ); } } + Cmd::Unmount(mounter_item) => { + let MounterItem::Gvfs(item) = mounter_item else { continue }; + let ItemKind::Mount = item.kind else { continue }; + for (i, mount) in monitor.mounts().into_iter().enumerate() { + if i != item.index { + continue; + } + + let name = MountExt::name(&mount); + if item.name != name { + log::warn!("trying to unmount mount {} failed: name is {:?} when {:?} was expected", i, name, item.name); + continue; + } + + //TODO: do eject instead of unmount? + log::info!("unmount {}", name); + MountExt::unmount_with_operation( + &mount, + gio::MountUnmountFlags::NONE, + //TODO: gio::MountOperation needed for network shares with auth + gio::MountOperation::NONE, + gio::Cancellable::NONE, + move |result| { + log::info!("unmount {}: result {:?}", name, result); + }, + ); + } + } } } }); @@ -213,6 +242,17 @@ impl Mounter for Gvfs { ) } + fn unmount(&self, item: MounterItem) -> Command<()> { + let command_tx = self.command_tx.clone(); + Command::perform( + async move { + command_tx.send(Cmd::Unmount(item)).unwrap(); + () + }, + |x| x, + ) + } + fn subscription(&self) -> subscription::Subscription { let command_tx = self.command_tx.clone(); let event_rx = self.event_rx.clone(); diff --git a/src/mounter/mod.rs b/src/mounter/mod.rs index 0be732f4..79f90ad1 100644 --- a/src/mounter/mod.rs +++ b/src/mounter/mod.rs @@ -51,6 +51,7 @@ pub type MounterItems = Vec; pub trait Mounter { //TODO: send result fn mount(&self, item: MounterItem) -> Command<()>; + fn unmount(&self, item: MounterItem) -> Command<()>; fn subscription(&self) -> subscription::Subscription; }