Skip to content

Commit

Permalink
fix: use subscription for popup Done event
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Dec 13, 2023
1 parent 4b28935 commit 919aa33
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 63 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions cosmic-app-list/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand All @@ -1145,8 +1150,4 @@ impl cosmic::Application for CosmicAppList {
fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
Some(cosmic::applet::style())
}

fn on_close_requested(&self, id: window::Id) -> Option<Message> {
Some(Message::CloseRequested(id))
}
}
17 changes: 13 additions & 4 deletions cosmic-applet-audio/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}),
])
}

Expand Down Expand Up @@ -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<Message> {
Some(Message::CloseRequested(id))
}
}

fn revealer(
Expand Down
16 changes: 12 additions & 4 deletions cosmic-applet-battery/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Message> {
Some(Message::CloseRequested(id))
}

fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
Some(cosmic::applet::style())
}
Expand Down
16 changes: 12 additions & 4 deletions cosmic-applet-bluetooth/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<<Theme as application::StyleSheet>::Style> {
Some(cosmic::applet::style())
}

fn on_close_requested(&self, id: window::Id) -> Option<Message> {
Some(Message::CloseRequested(id))
}
}
4 changes: 0 additions & 4 deletions cosmic-applet-graphics/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ impl cosmic::Application for Window {
fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
Some(cosmic::applet::style())
}

fn on_close_requested(&self, id: window::Id) -> Option<Message> {
Some(Message::PopupClosed(id))
}
}

fn button_icon<'a>(
Expand Down
20 changes: 14 additions & 6 deletions cosmic-applet-network/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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())
Expand All @@ -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<<Theme as application::StyleSheet>::Style> {
Some(cosmic::applet::style())
}

fn on_close_requested(&self, id: window::Id) -> Option<Message> {
Some(Message::CloseRequested(id))
}
}
16 changes: 12 additions & 4 deletions cosmic-applet-notifications/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}
}),
])
}

Expand Down Expand Up @@ -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<Message> {
Some(Message::CloseRequested(id))
}
}

fn text_icon(name: &str, size: u16) -> cosmic::widget::Icon {
Expand Down
7 changes: 3 additions & 4 deletions cosmic-applet-power/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ impl cosmic::Application for Power {
)
}

fn on_close_requested(&self, id: window::Id) -> Option<Message> {
Some(Message::Closed(id))
}

fn subscription(&self) -> Subscription<Message> {
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() {
Expand Down
Loading

0 comments on commit 919aa33

Please sign in to comment.