mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
child window created using a winapi::HWND instead of a WindowProxy
This commit is contained in:
parent
2b25bf1480
commit
3e2154a922
|
@ -1,50 +1,64 @@
|
||||||
#![cfg(target_os = "windows")]
|
|
||||||
|
|
||||||
extern crate winit;
|
|
||||||
use std::thread;
|
|
||||||
use winit::os::windows::WindowBuilderExt;
|
|
||||||
|
|
||||||
fn resize_callback(width: u32, height: u32) {
|
|
||||||
println!("Window resized to {}x{}", width, height);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Creates a main window and a child within it and handle their events separetely.
|
|
||||||
* Currently windows only
|
|
||||||
*/
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let window = winit::WindowBuilder::new()
|
child_window_exemple::child_window();
|
||||||
.with_title("A fantastic window!")
|
}
|
||||||
.with_window_resize_callback(resize_callback)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let proxy = window.create_window_proxy();
|
#[cfg(windows)]
|
||||||
thread::spawn(move || {
|
mod child_window_exemple {
|
||||||
|
|
||||||
|
extern crate winit;
|
||||||
|
extern crate winapi;
|
||||||
|
use std::thread;
|
||||||
|
use self::winit::os::windows::{WindowBuilderExt, WindowExt};
|
||||||
|
|
||||||
|
fn resize_callback(width: u32, height: u32) {
|
||||||
|
println!("Window resized to {}x{}", width, height);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a main window and a child within it and handle their events separetely.
|
||||||
|
* Currently windows only
|
||||||
|
*/
|
||||||
|
pub fn child_window() {
|
||||||
|
let window = winit::WindowBuilder::new()
|
||||||
|
.with_title("A fantastic window!")
|
||||||
|
.with_window_resize_callback(resize_callback)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let parent = window.get_hwnd() as winapi::HWND;
|
||||||
let child = winit::WindowBuilder::new()
|
let child = winit::WindowBuilder::new()
|
||||||
.with_title("child window!")
|
.with_title("child window!")
|
||||||
.with_window_resize_callback(resize_callback)
|
.with_window_resize_callback(resize_callback)
|
||||||
.with_decorations(false)
|
.with_decorations(false)
|
||||||
.with_dimensions(100, 100)
|
.with_dimensions(100, 100)
|
||||||
.with_parent_window(proxy)
|
.with_parent_window(parent)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for event in child.wait_events() {
|
let child_thread = thread::spawn(move || {
|
||||||
println!("child {:?}", event);
|
for event in child.wait_events() {
|
||||||
|
println!("child {:?}", event);
|
||||||
|
|
||||||
|
match event {
|
||||||
|
winit::Event::Closed => break,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for event in window.wait_events() {
|
||||||
|
println!("parent {:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
winit::Event::Closed => break,
|
winit::Event::Closed => break,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
for event in window.wait_events() {
|
child_thread.join().unwrap();
|
||||||
println!("parent {:?}", event);
|
|
||||||
|
|
||||||
match event {
|
|
||||||
winit::Event::Closed => break,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
mod child_window_exemple {
|
||||||
|
pub fn child_window() {}
|
||||||
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
use libc;
|
use libc;
|
||||||
use Window;
|
use Window;
|
||||||
use WindowBuilder;
|
use WindowBuilder;
|
||||||
use window;
|
|
||||||
use winapi;
|
use winapi;
|
||||||
use platform;
|
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to Windows.
|
/// Additional methods on `Window` that are specific to Windows.
|
||||||
pub trait WindowExt {
|
pub trait WindowExt {
|
||||||
|
@ -26,22 +24,14 @@ impl WindowExt for Window {
|
||||||
|
|
||||||
/// Additional methods on `WindowBuilder` that are specific to Windows.
|
/// Additional methods on `WindowBuilder` that are specific to Windows.
|
||||||
pub trait WindowBuilderExt {
|
pub trait WindowBuilderExt {
|
||||||
fn with_parent_window(self, parent: window::WindowProxy) -> WindowBuilder;
|
fn with_parent_window(self, parent: winapi::HWND) -> WindowBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowBuilderExt for WindowBuilder {
|
impl WindowBuilderExt for WindowBuilder {
|
||||||
/// Sets a parent to the window to be created
|
/// Sets a parent to the window to be created
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_parent_window(mut self, parent: window::WindowProxy) -> WindowBuilder {
|
fn with_parent_window(mut self, parent: winapi::HWND) -> WindowBuilder {
|
||||||
self.platform_specific.parent = Some(parent);
|
self.platform_specific.parent = Some(parent);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowBuilderExt {
|
|
||||||
/// Creates a new WindowProxy from a winapi::HWND
|
|
||||||
#[inline]
|
|
||||||
pub fn create_window_proxy_from_handle(handle: winapi::HWND) -> window::WindowProxy {
|
|
||||||
window::WindowProxy::create_proxy(platform::WindowProxy{hwnd: handle})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pl_attribs: PlatformS
|
||||||
style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN,
|
style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN,
|
||||||
x.unwrap_or(winapi::CW_USEDEFAULT), y.unwrap_or(winapi::CW_USEDEFAULT),
|
x.unwrap_or(winapi::CW_USEDEFAULT), y.unwrap_or(winapi::CW_USEDEFAULT),
|
||||||
width.unwrap_or(winapi::CW_USEDEFAULT), height.unwrap_or(winapi::CW_USEDEFAULT),
|
width.unwrap_or(winapi::CW_USEDEFAULT), height.unwrap_or(winapi::CW_USEDEFAULT),
|
||||||
pl_attribs.parent.map_or(ptr::null_mut(), |v| v.get_proxy_data().hwnd),
|
pl_attribs.parent.unwrap_or(ptr::null_mut()),
|
||||||
ptr::null_mut(), kernel32::GetModuleHandleW(ptr::null()),
|
ptr::null_mut(), kernel32::GetModuleHandleW(ptr::null()),
|
||||||
ptr::null_mut());
|
ptr::null_mut());
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,14 @@ use CursorState;
|
||||||
|
|
||||||
use WindowAttributes;
|
use WindowAttributes;
|
||||||
|
|
||||||
use window;
|
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
pub parent: Option<window::WindowProxy>,
|
pub parent: Option<winapi::HWND>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for PlatformSpecificWindowBuilderAttributes {}
|
||||||
|
unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PlatformSpecificHeadlessBuilderAttributes;
|
pub struct PlatformSpecificHeadlessBuilderAttributes;
|
||||||
|
|
||||||
|
|
|
@ -372,19 +372,8 @@ impl WindowProxy {
|
||||||
pub fn wakeup_event_loop(&self) {
|
pub fn wakeup_event_loop(&self) {
|
||||||
self.proxy.wakeup_event_loop();
|
self.proxy.wakeup_event_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the platform specific proxy data
|
|
||||||
#[inline]
|
|
||||||
pub fn get_proxy_data(&self) -> &platform::WindowProxy {
|
|
||||||
&self.proxy
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a WindowProxy by directly setting its platform specific data
|
|
||||||
#[inline]
|
|
||||||
pub fn create_proxy(data: platform::WindowProxy) -> WindowProxy {
|
|
||||||
WindowProxy {proxy: data}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator for the `poll_events` function.
|
/// An iterator for the `poll_events` function.
|
||||||
pub struct PollEventsIterator<'a>(platform::PollEventsIterator<'a>);
|
pub struct PollEventsIterator<'a>(platform::PollEventsIterator<'a>);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue