diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index f7c57d2a..3183ecee 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -42,12 +42,13 @@ enum Message { impl Example { fn new() -> (Self, Task) { + let (_, open) = window::open(window::Settings::default()); + ( Self { windows: BTreeMap::new(), }, - window::open(window::Settings::default()) - .map(Message::WindowOpened), + open.map(Message::WindowOpened), ) } @@ -76,10 +77,12 @@ impl Example { }, ); - window::open(window::Settings { + let (_, open) = 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 19044628..ccd8721b 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(Settings, oneshot::Sender), + Open(Id, Settings, oneshot::Sender), /// Close the window and exits the application. Close(Id), @@ -249,10 +249,15 @@ 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) -> Task { - task::oneshot(|channel| { - crate::Action::Window(Action::Open(settings, channel)) - }) +pub fn open(settings: Settings) -> (Id, Task) { + let id = Id::unique(); + + ( + id, + task::oneshot(|channel| { + crate::Action::Window(Action::Open(id, settings, channel)) + }), + ) } /// Closes the window with `id`. diff --git a/test/src/emulator.rs b/test/src/emulator.rs index ef358d7a..9b74dee3 100644 --- a/test/src/emulator.rs +++ b/test/src/emulator.rs @@ -145,8 +145,8 @@ impl Emulator

{ dbg!(action); } Action::Window(action) => match action { - window::Action::Open(_settings, sender) => { - self.window = core::window::Id::unique(); + window::Action::Open(id, _settings, sender) => { + self.window = id; let _ = sender.send(self.window); } diff --git a/winit/src/lib.rs b/winit/src/lib.rs index de1a9f9f..0ad2c507 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -109,7 +109,7 @@ where let task = if let Some(window_settings) = window_settings { let mut task = Some(task); - let open = runtime::window::open(window_settings); + let (_id, open) = runtime::window::open(window_settings); open.then(move |_| task.take().unwrap_or(Task::none())) } else { @@ -1122,8 +1122,7 @@ fn run_action<'a, P, C>( } }, Action::Window(action) => match action { - window::Action::Open(settings, channel) => { - let id = core::window::Id::unique(); + window::Action::Open(id, settings, channel) => { let monitor = window_manager.last_monitor(); control_sender