From 7105992228e58566cfacb6a1d6e10ec60fb05ecf Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Fri, 19 Jan 2024 14:48:14 -0500 Subject: Re-implement against latest iced master. Rename FetchNativeHandle. --- runtime/src/window.rs | 15 +++++++++++++++ runtime/src/window/action.rs | 10 ++++++++++ 2 files changed, 25 insertions(+) (limited to 'runtime/src') 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(id: Id, icon: Icon) -> Command { 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( + id: Id, + f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static, +) -> Command { + Command::single(command::Action::Window(Action::FetchNativeHandle( + id, + Box::new(f), + ))) +} + /// Captures a [`Screenshot`] from the window. pub fn screenshot( 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 { /// - **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) -> T + 'static>), /// Screenshot the viewport of the window. Screenshot(Id, Box T + 'static>), } @@ -141,6 +145,9 @@ impl Action { 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 fmt::Debug for Action { 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:?})"), } } -- cgit From f18a81451fffa2ead0eb6be72f9a32f5f683a016 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Feb 2024 09:47:15 +0100 Subject: Rename `fetch_native_handle` to `run_with_handle` in `window` --- runtime/src/window.rs | 8 +++++--- runtime/src/window/action.rs | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/window.rs b/runtime/src/window.rs index cf47347a..4d97d5ee 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; +pub use raw_window_handle; + use raw_window_handle::WindowHandle; /// Subscribes to the frames of the window of the running application. @@ -172,14 +174,14 @@ pub fn change_icon(id: Id, icon: Icon) -> Command { Command::single(command::Action::Window(Action::ChangeIcon(id, icon))) } -/// Requests access to the native window handle for the window with the given id. +/// Runs the given callback with 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( +pub fn run_with_handle( id: Id, f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static, ) -> Command { - Command::single(command::Action::Window(Action::FetchNativeHandle( + Command::single(command::Action::Window(Action::RunWithHandle( id, Box::new(f), ))) diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 763ae1ef..532c1243 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -99,7 +99,7 @@ pub enum Action { /// said, it's usually in the same ballpark as on Windows. ChangeIcon(Id, Icon), /// Requests access to the windows native handle. - FetchNativeHandle(Id, Box) -> T + 'static>), + RunWithHandle(Id, Box) -> T + 'static>), /// Screenshot the viewport of the window. Screenshot(Id, Box T + 'static>), } @@ -145,8 +145,8 @@ impl Action { 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::RunWithHandle(id, o) => { + Action::RunWithHandle(id, Box::new(move |s| f(o(s)))) } Self::Screenshot(id, tag) => Action::Screenshot( id, @@ -204,8 +204,8 @@ impl fmt::Debug for Action { Self::ChangeIcon(id, _icon) => { write!(f, "Action::ChangeIcon({id:?})") } - Self::FetchNativeHandle(id, _) => { - write!(f, "Action::RequestNativeHandle({id:?})") + Self::RunWithHandle(id, _) => { + write!(f, "Action::RunWithHandle({id:?})") } Self::Screenshot(id, _) => write!(f, "Action::Screenshot({id:?})"), } -- cgit From 2a544dca2f573d846e525ff65e153c261b16880d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Feb 2024 09:49:19 +0100 Subject: Fix documentation of `Action::RunWithHandle` --- runtime/src/window/action.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/src') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 532c1243..86d58528 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -98,7 +98,7 @@ pub enum Action { /// - **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. + /// Runs the closure with the native window handle of the window with the given [`Id`]. RunWithHandle(Id, Box) -> T + 'static>), /// Screenshot the viewport of the window. Screenshot(Id, Box T + 'static>), -- cgit