From e02854452ed6f9509cc2dd24d232143220e2394d Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Tue, 8 Dec 2020 19:30:50 -0600 Subject: [PATCH] remove WindowHandle --- examples/open_window.rs | 2 +- src/macos/window.rs | 24 +++++++++--------------- src/win/window.rs | 12 +++--------- src/window.rs | 24 +----------------------- src/x11/window.rs | 10 +++------- 5 files changed, 17 insertions(+), 55 deletions(-) diff --git a/examples/open_window.rs b/examples/open_window.rs index 7e4ad29..97994ad 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -39,7 +39,7 @@ fn main() { let (mut tx, rx) = RingBuffer::new(128).split(); - let (_handle, opt_app_runner) = Window::open( + let opt_app_runner = Window::open( window_open_options, |_| OpenWindowExample { rx } ); diff --git a/src/macos/window.rs b/src/macos/window.rs index 25613f5..3fe4c22 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -29,15 +29,6 @@ pub(super) const WINDOW_STATE_IVAR_NAME: &str = "WINDOW_STATE_IVAR_NAME"; pub(super) const FRAME_TIMER_IVAR_NAME: &str = "FRAME_TIMER"; -pub struct Window { - /// Only set if we created the parent window, i.e. we are running in - /// parentless mode - ns_window: Option, - /// Our subclassed NSView - ns_view: id, -} - - pub struct AppRunner; impl AppRunner { @@ -51,14 +42,19 @@ impl AppRunner { } -pub struct WindowHandle; - +pub struct Window { + /// Only set if we created the parent window, i.e. we are running in + /// parentless mode + ns_window: Option, + /// Our subclassed NSView + ns_view: id, +} impl Window { pub fn open( options: WindowOpenOptions, build: B - ) -> (crate::WindowHandle, Option) + ) -> Option where H: WindowHandler + 'static, B: FnOnce(&mut crate::Window) -> H, B: Send + 'static @@ -201,9 +197,7 @@ impl Window { ) } - let window_handle = crate::WindowHandle(WindowHandle); - - (window_handle, opt_app_runner) + opt_app_runner } } diff --git a/src/win/window.rs b/src/win/window.rs index b3fca82..b7574d6 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -195,8 +195,6 @@ pub struct Window { hwnd: HWND, } -pub struct WindowHandle; - pub struct AppRunner { hwnd: HWND, } @@ -224,7 +222,7 @@ impl Window { pub fn open( options: WindowOpenOptions, build: B - ) -> (crate::WindowHandle, Option) + ) -> Option where H: WindowHandler + 'static, B: FnOnce(&mut crate::Window) -> H, B: Send + 'static @@ -301,15 +299,11 @@ impl Window { SetWindowLongPtrA(hwnd, GWLP_USERDATA, Box::into_raw(window_state) as *const _ as _); SetTimer(hwnd, WIN_FRAME_TIMER, 15, None); - let window_handle = crate::WindowHandle(WindowHandle); - - let opt_app_runner = if let crate::Parent::None = options.parent { + if let crate::Parent::None = options.parent { Some(crate::AppRunner(AppRunner { hwnd })) } else { None - }; - - (window_handle, opt_app_runner) + } } } } diff --git a/src/window.rs b/src/window.rs index be6c89c..a88af7b 100644 --- a/src/window.rs +++ b/src/window.rs @@ -18,15 +18,13 @@ impl AppRunner { } } -pub struct WindowHandle(pub(crate) platform::WindowHandle); - pub struct Window<'a>(pub(crate) &'a mut platform::Window); impl<'a> Window<'a> { pub fn open( options: WindowOpenOptions, build: B - ) -> (WindowHandle, Option) + ) -> Option where H: WindowHandler + 'static, B: FnOnce(&mut Window) -> H, B: Send + 'static @@ -40,23 +38,3 @@ unsafe impl<'a> HasRawWindowHandle for Window<'a> { self.0.raw_window_handle() } } - -// Compile-time API assertions -#[doc(hidden)] -mod assertions { - use crate::{WindowHandle, WindowHandler, Event, Window}; - - struct TestWindowHandler { - #[allow(dead_code)] - ptr: *mut ::std::ffi::c_void, - } - - impl WindowHandler for TestWindowHandler { - fn on_event(&mut self, _: &mut Window, _: Event) {} - fn on_frame(&mut self) {} - } - - // Assert that WindowHandle is Send even if WindowHandler isn't - static_assertions::assert_not_impl_any!(TestWindowHandler: Send); - static_assertions::assert_impl_all!(WindowHandle: Send); -} diff --git a/src/x11/window.rs b/src/x11/window.rs index e44cbec..224d8d3 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -49,7 +49,7 @@ impl Window { pub fn open( options: WindowOpenOptions, build: B - ) -> (crate::WindowHandle, Option) + ) -> Option where H: WindowHandler, B: FnOnce(&mut crate::Window) -> H, B: Send + 'static @@ -67,15 +67,11 @@ impl Window { // FIXME: placeholder types for returning errors in the future let _ = rx.recv(); - let window_handle = crate::WindowHandle(WindowHandle); - - let opt_app_runner = if is_not_parented { + if is_not_parented { Some(crate::AppRunner(AppRunner { thread })) } else { None - }; - - (window_handle, opt_app_runner) + } } fn window_thread(