From 8b45d620d048c33febbead4480d9ef62f196c9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 12 Aug 2024 05:50:22 +0200 Subject: [PATCH] Revert `window::close` producing a `window::Id` Instead, subscribing to `window::close_events` is preferable; since most use cases will want to react to the user closing a window as well. --- examples/events/src/main.rs | 6 ++---- examples/exit/src/main.rs | 4 +--- runtime/src/window.rs | 6 +++--- winit/src/program.rs | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index e432eb1496..5bada9b530 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -37,7 +37,7 @@ impl Events { } Message::EventOccurred(event) => { if let Event::Window(window::Event::CloseRequested) = event { - window::get_latest().and_then(window::close).discard() + window::get_latest().and_then(window::close) } else { Task::none() } @@ -47,9 +47,7 @@ impl Events { Task::none() } - Message::Exit => { - window::get_latest().and_then(window::close).discard() - } + Message::Exit => window::get_latest().and_then(window::close), } } diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs index d8334bcc4b..48b0864c8e 100644 --- a/examples/exit/src/main.rs +++ b/examples/exit/src/main.rs @@ -20,9 +20,7 @@ enum Message { impl Exit { fn update(&mut self, message: Message) -> Task { match message { - Message::Confirm => { - window::get_latest().and_then(window::close).discard() - } + Message::Confirm => window::get_latest().and_then(window::close), Message::Exit => { self.show_confirm = true; diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 0d280f1fe1..cd27cdfe1c 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -24,7 +24,7 @@ pub enum Action { Open(Id, Settings, oneshot::Sender), /// Close the window and exits the application. - Close(Id, oneshot::Sender), + Close(Id), /// Gets the [`Id`] of the oldest window. GetOldest(oneshot::Sender>), @@ -230,8 +230,8 @@ pub fn open(settings: Settings) -> (Id, Task) { } /// Closes the window with `id`. -pub fn close(id: Id) -> Task { - task::oneshot(|channel| crate::Action::Window(Action::Close(id, channel))) +pub fn close(id: Id) -> Task { + task::effect(crate::Action::Window(Action::Close(id))) } /// Gets the window [`Id`] of the oldest window. diff --git a/winit/src/program.rs b/winit/src/program.rs index 66f359f441..efe8a978a9 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -1211,10 +1211,9 @@ fn run_action( *is_window_opening = true; } - window::Action::Close(id, channel) => { + window::Action::Close(id) => { let _ = window_manager.remove(id); let _ = ui_caches.remove(&id); - let _ = channel.send(id); events.push(( id,