Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action to get window id #1589

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions native/src/window/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub enum Action<T> {
///
/// - **Web / Wayland:** Unsupported.
ChangeAlwaysOnTop(bool),
/// Fetch an identifier unique to the window.
FetchId(Box<dyn FnOnce(u64) -> T + 'static>),
}

impl<T> Action<T> {
Expand Down Expand Up @@ -105,6 +107,7 @@ impl<T> Action<T> {
Self::ChangeAlwaysOnTop(on_top) => {
Action::ChangeAlwaysOnTop(on_top)
}
Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))),
}
}
}
Expand Down Expand Up @@ -138,6 +141,7 @@ impl<T> fmt::Debug for Action<T> {
Self::ChangeAlwaysOnTop(on_top) => {
write!(f, "Action::AlwaysOnTop({on_top})")
}
Self::FetchId(_) => write!(f, "Action::FetchId"),
}
}
}
5 changes: 5 additions & 0 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,11 @@ pub fn run_command<A, E>(
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) => {
Expand Down
9 changes: 9 additions & 0 deletions winit/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ pub fn change_always_on_top<Message>(on_top: bool) -> Command<Message> {
on_top,
)))
}

/// Fetches an identifier unique to the window.
pub fn fetch_id<Message>(
f: impl FnOnce(u64) -> Message + 'static,
) -> Command<Message> {
Command::single(command::Action::Window(window::Action::FetchId(Box::new(
f,
))))
}