diff options
author | 2024-01-19 14:48:14 -0500 | |
---|---|---|
committer | 2024-02-07 09:35:13 +0100 | |
commit | 7105992228e58566cfacb6a1d6e10ec60fb05ecf (patch) | |
tree | d67ac19c57adf9a3282e8050cec407f437b86bff /runtime | |
parent | 6f97b62457d924ef690d736c1aabe658f9c5778b (diff) | |
download | iced-7105992228e58566cfacb6a1d6e10ec60fb05ecf.tar.gz iced-7105992228e58566cfacb6a1d6e10ec60fb05ecf.tar.bz2 iced-7105992228e58566cfacb6a1d6e10ec60fb05ecf.zip |
Re-implement against latest iced master. Rename FetchNativeHandle.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/Cargo.toml | 1 | ||||
-rw-r--r-- | runtime/src/window.rs | 15 | ||||
-rw-r--r-- | runtime/src/window/action.rs | 10 |
3 files changed, 26 insertions, 0 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 8089d545..3a47a971 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -20,3 +20,4 @@ iced_futures.workspace = true iced_futures.features = ["thread-pool"] thiserror.workspace = true +raw-window-handle.workspace = true diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 2136d64d..cf47347a 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -15,6 +15,8 @@ use crate::core::{Point, Size}; use crate::futures::event; use crate::futures::Subscription; +use raw_window_handle::WindowHandle; + /// Subscribes to the frames of the window of the running application. /// /// The resulting [`Subscription`] will produce items at a rate equal to the @@ -170,6 +172,19 @@ pub fn change_icon<Message>(id: Id, icon: Icon) -> Command<Message> { Command::single(command::Action::Window(Action::ChangeIcon(id, icon))) } +/// Requests access to the native window handle for the window with the given id. +/// +/// Note that if the window closes before this call is processed the callback will not be run. +pub fn fetch_native_handle<Message>( + id: Id, + f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static, +) -> Command<Message> { + Command::single(command::Action::Window(Action::FetchNativeHandle( + id, + Box::new(f), + ))) +} + /// Captures a [`Screenshot`] from the window. pub fn screenshot<Message>( id: Id, diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 8b532569..763ae1ef 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -3,6 +3,8 @@ use crate::core::{Point, Size}; use crate::futures::MaybeSend; use crate::window::Screenshot; +use raw_window_handle::WindowHandle; + use std::fmt; /// An operation to be performed on some window. @@ -96,6 +98,8 @@ pub enum Action<T> { /// - **X11:** Has no universal guidelines for icon sizes, so you're at the whims of the WM. That /// said, it's usually in the same ballpark as on Windows. ChangeIcon(Id, Icon), + /// Requests access to the windows native handle. + FetchNativeHandle(Id, Box<dyn FnOnce(&WindowHandle<'_>) -> T + 'static>), /// Screenshot the viewport of the window. Screenshot(Id, Box<dyn FnOnce(Screenshot) -> T + 'static>), } @@ -141,6 +145,9 @@ impl<T> Action<T> { Action::FetchId(id, Box::new(move |s| f(o(s)))) } Self::ChangeIcon(id, icon) => Action::ChangeIcon(id, icon), + Self::FetchNativeHandle(id, o) => { + Action::FetchNativeHandle(id, Box::new(move |s| f(o(s)))) + } Self::Screenshot(id, tag) => Action::Screenshot( id, Box::new(move |screenshot| f(tag(screenshot))), @@ -197,6 +204,9 @@ impl<T> fmt::Debug for Action<T> { Self::ChangeIcon(id, _icon) => { write!(f, "Action::ChangeIcon({id:?})") } + Self::FetchNativeHandle(id, _) => { + write!(f, "Action::RequestNativeHandle({id:?})") + } Self::Screenshot(id, _) => write!(f, "Action::Screenshot({id:?})"), } } |