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/Cargo.toml | 1 + runtime/src/window.rs | 15 +++++++++++++++ runtime/src/window/action.rs | 10 ++++++++++ winit/src/application.rs | 9 +++++++++ winit/src/multi_window.rs | 12 ++++++++++++ 5 files changed, 47 insertions(+) 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(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:?})"), } } diff --git a/winit/src/application.rs b/winit/src/application.rs index 24c98d46..f28aca32 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -23,6 +23,8 @@ use crate::{Clipboard, Error, Proxy, Settings}; use futures::channel::mpsc; +use winit::raw_window_handle::HasWindowHandle; + use std::mem::ManuallyDrop; use std::sync::Arc; @@ -783,6 +785,13 @@ pub fn run_command( .send_event(tag(window.id().into())) .expect("Send message to event loop"); } + window::Action::FetchNativeHandle(_id, tag) => { + proxy + .send_event(tag(&window + .window_handle() + .expect("Missing window handle"))) + .expect("Send message to event loop"); + } window::Action::Screenshot(_id, tag) => { let bytes = compositor.screenshot( renderer, diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 662adf5b..1b5fe375 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -22,6 +22,8 @@ use crate::runtime::Debug; use crate::style::application::StyleSheet; use crate::{Clipboard, Error, Proxy, Settings}; +use winit::raw_window_handle::HasWindowHandle; + use std::collections::HashMap; use std::mem::ManuallyDrop; use std::sync::Arc; @@ -1037,6 +1039,16 @@ fn run_command( .expect("Event loop doesn't exist."); } } + window::Action::FetchNativeHandle(id, tag) => { + if let Some(window) = window_manager.get_mut(id) { + proxy + .send_event(tag(&window + .raw + .window_handle() + .expect("Missing window handle."))) + .expect("Event loop doesn't exist."); + } + } window::Action::Screenshot(id, tag) => { if let Some(window) = window_manager.get_mut(id) { let bytes = compositor.screenshot( -- 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 +++++----- winit/src/application.rs | 17 +++++++++-------- winit/src/multi_window.rs | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 27 deletions(-) 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:?})"), } diff --git a/winit/src/application.rs b/winit/src/application.rs index f28aca32..6a176834 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -23,8 +23,6 @@ use crate::{Clipboard, Error, Proxy, Settings}; use futures::channel::mpsc; -use winit::raw_window_handle::HasWindowHandle; - use std::mem::ManuallyDrop; use std::sync::Arc; @@ -785,13 +783,16 @@ pub fn run_command( .send_event(tag(window.id().into())) .expect("Send message to event loop"); } - window::Action::FetchNativeHandle(_id, tag) => { - proxy - .send_event(tag(&window - .window_handle() - .expect("Missing window handle"))) - .expect("Send message to event loop"); + window::Action::RunWithHandle(_id, tag) => { + use window::raw_window_handle::HasWindowHandle; + + if let Ok(handle) = window.window_handle() { + proxy + .send_event(tag(&handle)) + .expect("Send message to event loop"); + } } + window::Action::Screenshot(_id, tag) => { let bytes = compositor.screenshot( renderer, diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 1b5fe375..23b2f3c4 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -22,8 +22,6 @@ use crate::runtime::Debug; use crate::style::application::StyleSheet; use crate::{Clipboard, Error, Proxy, Settings}; -use winit::raw_window_handle::HasWindowHandle; - use std::collections::HashMap; use std::mem::ManuallyDrop; use std::sync::Arc; @@ -1000,7 +998,7 @@ fn run_command( proxy .send_event(tag(mode)) - .expect("Event loop doesn't exist."); + .expect("Send message to event loop"); } } window::Action::ToggleMaximize(id) => { @@ -1036,17 +1034,19 @@ fn run_command( if let Some(window) = window_manager.get_mut(id) { proxy .send_event(tag(window.raw.id().into())) - .expect("Event loop doesn't exist."); + .expect("Send message to event loop"); } } - window::Action::FetchNativeHandle(id, tag) => { - if let Some(window) = window_manager.get_mut(id) { + window::Action::RunWithHandle(id, tag) => { + use window::raw_window_handle::HasWindowHandle; + + if let Some(handle) = window_manager + .get_mut(id) + .and_then(|window| window.raw.window_handle().ok()) + { proxy - .send_event(tag(&window - .raw - .window_handle() - .expect("Missing window handle."))) - .expect("Event loop doesn't exist."); + .send_event(tag(&handle)) + .expect("Send message to event loop"); } } window::Action::Screenshot(id, tag) => { -- 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(-) 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 From dea98005030bd39e5053fa5cbb87d65da24962b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Feb 2024 09:52:23 +0100 Subject: Update `CHANGELOG` --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c2fcaa..c62ab531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Cut functionality for `TextEditor`. [#2215](https://github.com/iced-rs/iced/pull/2215) - Disabled support for `Checkbox`. [#2109](https://github.com/iced-rs/iced/pull/2109) - `skip_taskbar` window setting for Windows. [#2211](https://github.com/iced-rs/iced/pull/2211) -- `fetch_maximized` and `fetch_minimized` window commands. [#2189](https://github.com/iced-rs/iced/pull/2189) +- `fetch_maximized` and `fetch_minimized` commands in `window`. [#2189](https://github.com/iced-rs/iced/pull/2189) +- `run_with_handle` command in `window`. [#2200](https://github.com/iced-rs/iced/pull/2200) - `text_shaping` method for `Tooltip`. [#2172](https://github.com/iced-rs/iced/pull/2172) - `hovered` styling for `Svg` widget. [#2163](https://github.com/iced-rs/iced/pull/2163) - Customizable style for `TextEditor`. [#2159](https://github.com/iced-rs/iced/pull/2159) -- cgit From 2a3778daa349043f5b69a1b264feb5f00d3dd772 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Feb 2024 10:32:47 +0100 Subject: Pin `web-sys` dependency to `0.3.67` for now Context: https://github.com/rustwasm/wasm-bindgen/issues/3834 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c9dee6b7..b1fa8634 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -156,7 +156,7 @@ xxhash-rust = { version = "0.8", features = ["xxh3"] } unicode-segmentation = "1.0" wasm-bindgen-futures = "0.4" wasm-timer = "0.2" -web-sys = "0.3" +web-sys = "=0.3.67" web-time = "0.2" wgpu = "0.19" winapi = "0.3" -- cgit