From 1deb87694d48db46fca7c3d40b5ecbba2a4e2416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 8 Jul 2025 00:31:04 +0200 Subject: [PATCH] Make `window::open` pure again --- examples/multi_window/src/main.rs | 11 ++++------- runtime/src/window.rs | 15 +++++---------- winit/src/lib.rs | 5 +++-- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index 77be505b..d940b9da 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -42,13 +42,12 @@ enum Message { impl Example { fn new() -> (Self, Task) { - let (_id, open) = window::open(window::Settings::default()); - ( Self { windows: BTreeMap::new(), }, - open.map(Message::WindowOpened), + window::open(window::Settings::default()) + .map(Message::WindowOpened), ) } @@ -77,12 +76,10 @@ impl Example { }, ); - let (_id, open) = window::open(window::Settings { + window::open(window::Settings { position, ..window::Settings::default() - }); - - open + }) }) .map(Message::WindowOpened) } diff --git a/runtime/src/window.rs b/runtime/src/window.rs index ccd8721b..19044628 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -18,7 +18,7 @@ use raw_window_handle::WindowHandle; #[allow(missing_debug_implementations)] pub enum Action { /// Opens a new window with some [`Settings`]. - Open(Id, Settings, oneshot::Sender), + Open(Settings, oneshot::Sender), /// Close the window and exits the application. Close(Id), @@ -249,15 +249,10 @@ pub fn close_requests() -> Subscription { /// Opens a new window with the given [`Settings`]; producing the [`Id`] /// of the new window on completion. -pub fn open(settings: Settings) -> (Id, Task) { - let id = Id::unique(); - - ( - id, - task::oneshot(|channel| { - crate::Action::Window(Action::Open(id, settings, channel)) - }), - ) +pub fn open(settings: Settings) -> Task { + task::oneshot(|channel| { + crate::Action::Window(Action::Open(settings, channel)) + }) } /// Closes the window with `id`. diff --git a/winit/src/lib.rs b/winit/src/lib.rs index c4e62863..5abdaa4d 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -108,7 +108,7 @@ where let task = if let Some(window_settings) = window_settings { let mut task = Some(task); - let (_id, open) = runtime::window::open(window_settings); + let open = runtime::window::open(window_settings); open.then(move |_| task.take().unwrap_or(Task::none())) } else { @@ -1121,7 +1121,8 @@ fn run_action<'a, P, C>( } }, Action::Window(action) => match action { - window::Action::Open(id, settings, channel) => { + window::Action::Open(settings, channel) => { + let id = core::window::Id::unique(); let monitor = window_manager.last_monitor(); control_sender