From 9f75f01ddb7a13a3ab1cffdfa59997cb5b131f72 Mon Sep 17 00:00:00 2001 From: Night_Hunter Date: Sat, 10 Dec 2022 01:54:57 +1300 Subject: [PATCH 1/2] add action to get window id --- native/src/window/action.rs | 4 ++++ winit/src/application.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index c636144975..ce36d129d7 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -76,6 +76,8 @@ pub enum Action { /// /// - **Web / Wayland:** Unsupported. ChangeAlwaysOnTop(bool), + /// Fetch an identifier unique to the window. + FetchId(Box T + 'static>), } impl Action { @@ -105,6 +107,7 @@ impl Action { Self::ChangeAlwaysOnTop(on_top) => { Action::ChangeAlwaysOnTop(on_top) } + Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))), } } } @@ -138,6 +141,7 @@ impl fmt::Debug for Action { Self::ChangeAlwaysOnTop(on_top) => { write!(f, "Action::AlwaysOnTop({on_top})") } + Self::FetchId(_) => write!(f, "Action::FetchId"), } } } diff --git a/winit/src/application.rs b/winit/src/application.rs index 1f37ffeff2..3fdec6586d 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -794,6 +794,11 @@ pub fn run_command( window::Action::ChangeAlwaysOnTop(on_top) => { window.set_always_on_top(on_top); } + window::Action::FetchId(tag) => { + proxy + .send_event(tag(window.id().into())) + .expect("Send message to event loop"); + } }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { From 2c2421ae5dad9afce1058e67ae8bcabd787fa373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 17 Feb 2023 13:47:46 +0100 Subject: [PATCH 2/2] Expose `fetch_id` helper in `window` module --- winit/src/window.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/winit/src/window.rs b/winit/src/window.rs index 3d5a765b8c..961562bd7b 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -95,3 +95,12 @@ pub fn change_always_on_top(on_top: bool) -> Command { on_top, ))) } + +/// Fetches an identifier unique to the window. +pub fn fetch_id( + f: impl FnOnce(u64) -> Message + 'static, +) -> Command { + Command::single(command::Action::Window(window::Action::FetchId(Box::new( + f, + )))) +}