From 7c00bb0014de5b95b8c67f05ad4bd3fa3d39194d Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 13 Dec 2023 16:43:45 -0500 Subject: [PATCH] fix: use subscription for popup Done event --- Cargo.lock | 32 +++++++++---------- cosmic-app-list/src/app.rs | 9 +++--- cosmic-applet-audio/src/main.rs | 17 +++++++--- cosmic-applet-battery/src/app.rs | 16 +++++++--- cosmic-applet-bluetooth/src/app.rs | 16 +++++++--- cosmic-applet-graphics/src/window.rs | 4 --- cosmic-applet-network/src/app.rs | 20 ++++++++---- cosmic-applet-notifications/src/main.rs | 16 +++++++--- cosmic-applet-power/src/main.rs | 8 ++--- .../src/components/app.rs | 17 +++++++--- cosmic-applet-tiling/src/window.rs | 20 +++++++++--- cosmic-applet-time/src/window.rs | 16 +++++++--- 12 files changed, 128 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5c4111a..8b9e399a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1005,7 +1005,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1019,7 +1019,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "quote", "syn 1.0.109", @@ -1133,7 +1133,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "almost", "cosmic-config", @@ -2616,7 +2616,7 @@ dependencies = [ [[package]] name = "iced" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "iced_accessibility", "iced_core", @@ -2631,7 +2631,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "accesskit", "accesskit_unix", @@ -2640,7 +2640,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "bitflags 1.3.2", "iced_accessibility", @@ -2658,7 +2658,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "futures", "iced_core", @@ -2671,7 +2671,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -2694,7 +2694,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2707,7 +2707,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "iced_accessibility", "iced_core", @@ -2719,7 +2719,7 @@ dependencies = [ [[package]] name = "iced_sctk" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "enum-repr", "float-cmp", @@ -2743,7 +2743,7 @@ dependencies = [ [[package]] name = "iced_style" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "iced_core", "once_cell", @@ -2753,7 +2753,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "bytemuck", "cosmic-text", @@ -2771,7 +2771,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -2791,7 +2791,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "iced_renderer", "iced_runtime", @@ -3059,7 +3059,7 @@ checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#696437506c783da5ce588d26d1f2c2f550c846f1" +source = "git+https://github.com/pop-os/libcosmic#8725497827e87536ac9cad5ddad1a537d68fb8f4" dependencies = [ "apply", "ashpd", diff --git a/cosmic-app-list/src/app.rs b/cosmic-app-list/src/app.rs index ac1d9f76..bb8c91d2 100755 --- a/cosmic-app-list/src/app.rs +++ b/cosmic-app-list/src/app.rs @@ -24,6 +24,8 @@ use cosmic::iced::widget::vertical_space; use cosmic::iced::widget::{column, dnd_source, mouse_area, row, Column, Row}; use cosmic::iced::Color; use cosmic::iced::{window, Subscription}; +use cosmic::iced_core::event::wayland; +use cosmic::iced_core::event::PlatformSpecific; use cosmic::iced_runtime::core::alignment::Horizontal; use cosmic::iced_runtime::core::event; use cosmic::iced_sctk::commands::data_device::accept_mime_type; @@ -1125,6 +1127,9 @@ impl cosmic::Application for CosmicAppList { | event::wayland::DndOfferEvent::DropPerformed, )), ) => Some(Message::StopListeningForDnd), + cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) => Some(Message::CloseRequested(id)), _ => None, }), rectangle_tracker_subscription(0).map(|update| Message::Rectangle(update.1)), @@ -1145,8 +1150,4 @@ impl cosmic::Application for CosmicAppList { fn style(&self) -> Option<::Style> { Some(cosmic::applet::style()) } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } } diff --git a/cosmic-applet-audio/src/main.rs b/cosmic-applet-audio/src/main.rs index 4d5943b8..657e045f 100644 --- a/cosmic-applet-audio/src/main.rs +++ b/cosmic-applet-audio/src/main.rs @@ -20,6 +20,9 @@ use cosmic::iced::{ widget::{column, row, slider, text}, window, Alignment, Length, Subscription, }; +use cosmic::iced_core::event::wayland; +use cosmic::iced_core::event::PlatformSpecific; +use cosmic::iced_futures::event::listen_with; use cosmic::iced_runtime::core::alignment::Horizontal; use cosmic::iced_style::application; use cosmic::widget::button; @@ -570,6 +573,16 @@ impl cosmic::Application for Audio { }), mpris_subscription::mpris_subscription(0).map(Message::Mpris), activation_token_subscription(0).map(Message::Token), + listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::CloseRequested(id)) + } else { + None + } + }), ]) } @@ -767,10 +780,6 @@ impl cosmic::Application for Audio { self.core.applet.popup_container(container(content)).into() } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } } fn revealer( diff --git a/cosmic-applet-battery/src/app.rs b/cosmic-applet-battery/src/app.rs index 0e61f0c2..a0bc3c34 100644 --- a/cosmic-applet-battery/src/app.rs +++ b/cosmic-applet-battery/src/app.rs @@ -21,6 +21,8 @@ use cosmic::iced::{ widget::{column, container, row, slider, text}, window, Alignment, Length, Subscription, }; +use cosmic::iced_core::event::{wayland, PlatformSpecific}; +use cosmic::iced_futures::event::listen_with; use cosmic::iced_runtime::core::layout::Limits; use cosmic::iced_style::application; use cosmic::widget::{divider, horizontal_space, icon}; @@ -504,13 +506,19 @@ impl cosmic::Application for CosmicBatteryApplet { .as_subscription() .map(|(_, now)| Message::Frame(now)), activation_token_subscription(0).map(Message::Token), + listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::CloseRequested(id)) + } else { + None + } + }), ]) } - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } - fn style(&self) -> Option<::Style> { Some(cosmic::applet::style()) } diff --git a/cosmic-applet-bluetooth/src/app.rs b/cosmic-applet-bluetooth/src/app.rs index 7b07786a..01949736 100644 --- a/cosmic-applet-bluetooth/src/app.rs +++ b/cosmic-applet-bluetooth/src/app.rs @@ -5,6 +5,8 @@ use cosmic::applet::token::subscription::{ use cosmic::cctk::sctk::reexports::calloop; use cosmic::applet::{menu_button, padded_control}; +use cosmic::iced_core::event::{wayland, PlatformSpecific}; +use cosmic::iced_futures::event::listen_with; use cosmic::Command; use cosmic::{ iced::{ @@ -556,14 +558,20 @@ impl cosmic::Application for CosmicBluetoothApplet { self.timeline .as_subscription() .map(|(_, now)| Message::Frame(now)), + listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::CloseRequested(id)) + } else { + None + } + }), ]) } fn style(&self) -> Option<::Style> { Some(cosmic::applet::style()) } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } } diff --git a/cosmic-applet-graphics/src/window.rs b/cosmic-applet-graphics/src/window.rs index 294fbeb6..8373104c 100644 --- a/cosmic-applet-graphics/src/window.rs +++ b/cosmic-applet-graphics/src/window.rs @@ -327,10 +327,6 @@ impl cosmic::Application for Window { fn style(&self) -> Option<::Style> { Some(cosmic::applet::style()) } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::PopupClosed(id)) - } } fn button_icon<'a>( diff --git a/cosmic-applet-network/src/app.rs b/cosmic-applet-network/src/app.rs index 3dd47ee6..8a045287 100644 --- a/cosmic-applet-network/src/app.rs +++ b/cosmic-applet-network/src/app.rs @@ -4,6 +4,8 @@ use cosmic::applet::token::subscription::{ }; use cosmic::applet::{menu_button, menu_control_padding, padded_control}; use cosmic::cctk::sctk::reexports::calloop; +use cosmic::iced_core::event::{wayland, PlatformSpecific}; +use cosmic::iced_futures::event::listen_with; use cosmic::iced_widget::Row; use cosmic::{ iced::{ @@ -819,13 +821,23 @@ impl cosmic::Application for CosmicNetworkApplet { .as_subscription() .map(|(_, now)| Message::Frame(now)); let token_sub = activation_token_subscription(0).map(Message::Token); - + let close_sub = listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::CloseRequested(id)) + } else { + None + } + }); if let Some(conn) = self.conn.as_ref() { let has_popup = self.popup.is_some(); Subscription::batch(vec![ timeline, network_sub, token_sub, + close_sub, active_conns_subscription(self.toggle_wifi_ctr, conn.clone()) .map(Message::NetworkManagerEvent), devices_subscription(self.toggle_wifi_ctr, has_popup, conn.clone()) @@ -834,15 +846,11 @@ impl cosmic::Application for CosmicNetworkApplet { .map(Message::NetworkManagerEvent), ]) } else { - Subscription::batch(vec![timeline, network_sub, token_sub]) + Subscription::batch(vec![timeline, network_sub, token_sub, close_sub]) } } fn style(&self) -> Option<::Style> { Some(cosmic::applet::style()) } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } } diff --git a/cosmic-applet-notifications/src/main.rs b/cosmic-applet-notifications/src/main.rs index 2dafbc52..5582555e 100644 --- a/cosmic-applet-notifications/src/main.rs +++ b/cosmic-applet-notifications/src/main.rs @@ -15,6 +15,8 @@ use cosmic::iced::{ use cosmic::iced_core::alignment::Horizontal; use cosmic::Command; +use cosmic::iced_core::event::{wayland, PlatformSpecific}; +use cosmic::iced_futures::event::listen_with; use cosmic::iced_style::application; use cosmic::iced_widget::{scrollable, Column}; @@ -171,6 +173,16 @@ impl cosmic::Application for Notifications { subscriptions::dbus::proxy().map(Message::DbusEvent), subscriptions::notifications::notifications().map(Message::NotificationEvent), activation_token_subscription(0).map(Message::Token), + listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::CloseRequested(id)) + } else { + None + } + }), ]) } @@ -527,10 +539,6 @@ impl cosmic::Application for Notifications { self.core.applet.popup_container(content).into() } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } } fn text_icon(name: &str, size: u16) -> cosmic::widget::Icon { diff --git a/cosmic-applet-power/src/main.rs b/cosmic-applet-power/src/main.rs index 4e37bcc0..b10c8056 100644 --- a/cosmic-applet-power/src/main.rs +++ b/cosmic-applet-power/src/main.rs @@ -102,16 +102,15 @@ impl cosmic::Application for Power { ) } - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::Closed(id)) - } - fn subscription(&self) -> Subscription { let mut subscriptions = Vec::with_capacity(2); subscriptions.push(listen_with(|e, _status| match e { cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( wayland::Event::Layer(LayerEvent::Unfocused, ..), )) => Some(Message::Cancel), + cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) => Some(Message::Closed(id)), _ => None, })); if self.action_to_confirm.is_some() { @@ -215,6 +214,7 @@ impl cosmic::Application for Power { Command::none() } Message::Closed(id) => { + dbg!("closed"); if self.popup == Some(id) { self.popup = None; } diff --git a/cosmic-applet-status-area/src/components/app.rs b/cosmic-applet-status-area/src/components/app.rs index 51a9a755..76f73786 100644 --- a/cosmic-applet-status-area/src/components/app.rs +++ b/cosmic-applet-status-area/src/components/app.rs @@ -8,6 +8,8 @@ use cosmic::{ }, window, Subscription, }, + iced_core::event::{wayland, PlatformSpecific}, + iced_futures::event::listen_with, iced_style::application, Theme, }; @@ -168,6 +170,17 @@ impl cosmic::Application for App { subscriptions.push(menu.subscription().with(*id).map(Msg::StatusMenu)); } + subscriptions.push(listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Msg::Closed(id)) + } else { + None + } + })); + iced::Subscription::batch(subscriptions) } @@ -201,10 +214,6 @@ impl cosmic::Application for App { None => iced::widget::text("").into(), } } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Msg::Closed(id)) - } } pub fn main() -> iced::Result { diff --git a/cosmic-applet-tiling/src/window.rs b/cosmic-applet-tiling/src/window.rs index 29c77a7d..cf698979 100644 --- a/cosmic-applet-tiling/src/window.rs +++ b/cosmic-applet-tiling/src/window.rs @@ -5,7 +5,9 @@ use cosmic::cosmic_config::{ConfigGet, ConfigSet}; use cosmic::iced::wayland::popup::{destroy_popup, get_popup}; use cosmic::iced::window::Id; use cosmic::iced::{Command, Length, Limits, Subscription}; +use cosmic::iced_core::event::{wayland, PlatformSpecific}; use cosmic::iced_core::Alignment; +use cosmic::iced_futures::event::listen_with; use cosmic::iced_style::application; use cosmic::iced_widget::{column, row}; use cosmic::widget::{container, divider, spin_button, text}; @@ -76,16 +78,24 @@ impl cosmic::Application for Window { (window, Command::none()) } - fn on_close_requested(&self, id: Id) -> Option { - Some(Message::PopupClosed(id)) - } - fn subscription(&self) -> Subscription { let timeline = self .timeline .as_subscription() .map(|(_, now)| Message::Frame(now)); - Subscription::batch(vec![timeline]) + Subscription::batch(vec![ + timeline, + listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::PopupClosed(id)) + } else { + None + } + }), + ]) } fn update(&mut self, message: Self::Message) -> Command> { diff --git a/cosmic-applet-time/src/window.rs b/cosmic-applet-time/src/window.rs index d7444d06..6b20d84f 100644 --- a/cosmic-applet-time/src/window.rs +++ b/cosmic-applet-time/src/window.rs @@ -7,6 +7,8 @@ use cosmic::iced::{ window, Alignment, Length, Rectangle, Subscription, }; use cosmic::iced_core::alignment::{Horizontal, Vertical}; +use cosmic::iced_core::event::{wayland, PlatformSpecific}; +use cosmic::iced_futures::event::listen_with; use cosmic::iced_style::application; use cosmic::widget::{button, container, divider, grid, Button, Grid, Space}; use cosmic::{app, applet::cosmic_panel_config::PanelAnchor, Command}; @@ -112,6 +114,16 @@ impl cosmic::Application for Window { )) .map(|_| Message::Tick), activation_token_subscription(0).map(Message::Token), + listen_with(|e, _| { + if let cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Popup(wayland::PopupEvent::Done, _, id), + )) = e + { + Some(Message::CloseRequested(id)) + } else { + None + } + }), ]) } @@ -320,10 +332,6 @@ impl cosmic::Application for Window { .popup_container(container(content_list)) .into() } - - fn on_close_requested(&self, id: window::Id) -> Option { - Some(Message::CloseRequested(id)) - } } fn date_button(