Merge pull request #2200 from dtzxporter/run-window-callback
Provide native window access, via "fetch_native_handle" method on window.
This commit is contained in:
commit
d3619b5f69
7 changed files with 55 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -20,3 +20,4 @@ iced_futures.workspace = true
|
|||
iced_futures.features = ["thread-pool"]
|
||||
|
||||
thiserror.workspace = true
|
||||
raw-window-handle.workspace = true
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ 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.
|
||||
///
|
||||
/// The resulting [`Subscription`] will produce items at a rate equal to the
|
||||
|
|
@ -170,6 +174,19 @@ pub fn change_icon<Message>(id: Id, icon: Icon) -> Command<Message> {
|
|||
Command::single(command::Action::Window(Action::ChangeIcon(id, icon)))
|
||||
}
|
||||
|
||||
/// 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 run_with_handle<Message>(
|
||||
id: Id,
|
||||
f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static,
|
||||
) -> Command<Message> {
|
||||
Command::single(command::Action::Window(Action::RunWithHandle(
|
||||
id,
|
||||
Box::new(f),
|
||||
)))
|
||||
}
|
||||
|
||||
/// Captures a [`Screenshot`] from the window.
|
||||
pub fn screenshot<Message>(
|
||||
id: Id,
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
/// Runs the closure with the native window handle of the window with the given [`Id`].
|
||||
RunWithHandle(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::RunWithHandle(id, o) => {
|
||||
Action::RunWithHandle(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::RunWithHandle(id, _) => {
|
||||
write!(f, "Action::RunWithHandle({id:?})")
|
||||
}
|
||||
Self::Screenshot(id, _) => write!(f, "Action::Screenshot({id:?})"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -783,6 +783,16 @@ pub fn run_command<A, C, E>(
|
|||
.send_event(tag(window.id().into()))
|
||||
.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,
|
||||
|
|
|
|||
|
|
@ -998,7 +998,7 @@ fn run_command<A, C, E>(
|
|||
|
||||
proxy
|
||||
.send_event(tag(mode))
|
||||
.expect("Event loop doesn't exist.");
|
||||
.expect("Send message to event loop");
|
||||
}
|
||||
}
|
||||
window::Action::ToggleMaximize(id) => {
|
||||
|
|
@ -1034,7 +1034,19 @@ fn run_command<A, C, E>(
|
|||
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::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(&handle))
|
||||
.expect("Send message to event loop");
|
||||
}
|
||||
}
|
||||
window::Action::Screenshot(id, tag) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue