Rename fetch_native_handle to run_with_handle in window
This commit is contained in:
parent
7105992228
commit
f18a81451f
4 changed files with 30 additions and 27 deletions
|
|
@ -15,6 +15,8 @@ use crate::core::{Point, Size};
|
||||||
use crate::futures::event;
|
use crate::futures::event;
|
||||||
use crate::futures::Subscription;
|
use crate::futures::Subscription;
|
||||||
|
|
||||||
|
pub use raw_window_handle;
|
||||||
|
|
||||||
use raw_window_handle::WindowHandle;
|
use raw_window_handle::WindowHandle;
|
||||||
|
|
||||||
/// Subscribes to the frames of the window of the running application.
|
/// Subscribes to the frames of the window of the running application.
|
||||||
|
|
@ -172,14 +174,14 @@ pub fn change_icon<Message>(id: Id, icon: Icon) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::ChangeIcon(id, icon)))
|
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.
|
/// Note that if the window closes before this call is processed the callback will not be run.
|
||||||
pub fn fetch_native_handle<Message>(
|
pub fn run_with_handle<Message>(
|
||||||
id: Id,
|
id: Id,
|
||||||
f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static,
|
f: impl FnOnce(&WindowHandle<'_>) -> Message + 'static,
|
||||||
) -> Command<Message> {
|
) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::FetchNativeHandle(
|
Command::single(command::Action::Window(Action::RunWithHandle(
|
||||||
id,
|
id,
|
||||||
Box::new(f),
|
Box::new(f),
|
||||||
)))
|
)))
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ pub enum Action<T> {
|
||||||
/// said, it's usually in the same ballpark as on Windows.
|
/// said, it's usually in the same ballpark as on Windows.
|
||||||
ChangeIcon(Id, Icon),
|
ChangeIcon(Id, Icon),
|
||||||
/// Requests access to the windows native handle.
|
/// Requests access to the windows native handle.
|
||||||
FetchNativeHandle(Id, Box<dyn FnOnce(&WindowHandle<'_>) -> T + 'static>),
|
RunWithHandle(Id, Box<dyn FnOnce(&WindowHandle<'_>) -> T + 'static>),
|
||||||
/// Screenshot the viewport of the window.
|
/// Screenshot the viewport of the window.
|
||||||
Screenshot(Id, Box<dyn FnOnce(Screenshot) -> T + 'static>),
|
Screenshot(Id, Box<dyn FnOnce(Screenshot) -> T + 'static>),
|
||||||
}
|
}
|
||||||
|
|
@ -145,8 +145,8 @@ impl<T> Action<T> {
|
||||||
Action::FetchId(id, Box::new(move |s| f(o(s))))
|
Action::FetchId(id, Box::new(move |s| f(o(s))))
|
||||||
}
|
}
|
||||||
Self::ChangeIcon(id, icon) => Action::ChangeIcon(id, icon),
|
Self::ChangeIcon(id, icon) => Action::ChangeIcon(id, icon),
|
||||||
Self::FetchNativeHandle(id, o) => {
|
Self::RunWithHandle(id, o) => {
|
||||||
Action::FetchNativeHandle(id, Box::new(move |s| f(o(s))))
|
Action::RunWithHandle(id, Box::new(move |s| f(o(s))))
|
||||||
}
|
}
|
||||||
Self::Screenshot(id, tag) => Action::Screenshot(
|
Self::Screenshot(id, tag) => Action::Screenshot(
|
||||||
id,
|
id,
|
||||||
|
|
@ -204,8 +204,8 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
Self::ChangeIcon(id, _icon) => {
|
Self::ChangeIcon(id, _icon) => {
|
||||||
write!(f, "Action::ChangeIcon({id:?})")
|
write!(f, "Action::ChangeIcon({id:?})")
|
||||||
}
|
}
|
||||||
Self::FetchNativeHandle(id, _) => {
|
Self::RunWithHandle(id, _) => {
|
||||||
write!(f, "Action::RequestNativeHandle({id:?})")
|
write!(f, "Action::RunWithHandle({id:?})")
|
||||||
}
|
}
|
||||||
Self::Screenshot(id, _) => write!(f, "Action::Screenshot({id:?})"),
|
Self::Screenshot(id, _) => write!(f, "Action::Screenshot({id:?})"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ use crate::{Clipboard, Error, Proxy, Settings};
|
||||||
|
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
|
|
||||||
use winit::raw_window_handle::HasWindowHandle;
|
|
||||||
|
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
@ -785,13 +783,16 @@ pub fn run_command<A, C, E>(
|
||||||
.send_event(tag(window.id().into()))
|
.send_event(tag(window.id().into()))
|
||||||
.expect("Send message to event loop");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
window::Action::FetchNativeHandle(_id, tag) => {
|
window::Action::RunWithHandle(_id, tag) => {
|
||||||
proxy
|
use window::raw_window_handle::HasWindowHandle;
|
||||||
.send_event(tag(&window
|
|
||||||
.window_handle()
|
if let Ok(handle) = window.window_handle() {
|
||||||
.expect("Missing window handle")))
|
proxy
|
||||||
.expect("Send message to event loop");
|
.send_event(tag(&handle))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window::Action::Screenshot(_id, tag) => {
|
window::Action::Screenshot(_id, tag) => {
|
||||||
let bytes = compositor.screenshot(
|
let bytes = compositor.screenshot(
|
||||||
renderer,
|
renderer,
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ use crate::runtime::Debug;
|
||||||
use crate::style::application::StyleSheet;
|
use crate::style::application::StyleSheet;
|
||||||
use crate::{Clipboard, Error, Proxy, Settings};
|
use crate::{Clipboard, Error, Proxy, Settings};
|
||||||
|
|
||||||
use winit::raw_window_handle::HasWindowHandle;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -1000,7 +998,7 @@ fn run_command<A, C, E>(
|
||||||
|
|
||||||
proxy
|
proxy
|
||||||
.send_event(tag(mode))
|
.send_event(tag(mode))
|
||||||
.expect("Event loop doesn't exist.");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window::Action::ToggleMaximize(id) => {
|
window::Action::ToggleMaximize(id) => {
|
||||||
|
|
@ -1036,17 +1034,19 @@ fn run_command<A, C, E>(
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
proxy
|
proxy
|
||||||
.send_event(tag(window.raw.id().into()))
|
.send_event(tag(window.raw.id().into()))
|
||||||
.expect("Event loop doesn't exist.");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window::Action::FetchNativeHandle(id, tag) => {
|
window::Action::RunWithHandle(id, tag) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
use window::raw_window_handle::HasWindowHandle;
|
||||||
|
|
||||||
|
if let Some(handle) = window_manager
|
||||||
|
.get_mut(id)
|
||||||
|
.and_then(|window| window.raw.window_handle().ok())
|
||||||
|
{
|
||||||
proxy
|
proxy
|
||||||
.send_event(tag(&window
|
.send_event(tag(&handle))
|
||||||
.raw
|
.expect("Send message to event loop");
|
||||||
.window_handle()
|
|
||||||
.expect("Missing window handle.")))
|
|
||||||
.expect("Event loop doesn't exist.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window::Action::Screenshot(id, tag) => {
|
window::Action::Screenshot(id, tag) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue