PhantomData<*mut ()> in Window to ensure it is !Send
This commit is contained in:
parent
72302e9dd0
commit
86bf222601
|
@ -64,7 +64,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let window_handler = Box::new(build(&mut crate::Window(&mut window)));
|
let window_handler = Box::new(build(&mut crate::Window::new(&mut window)));
|
||||||
|
|
||||||
let retain_count_after_build: usize = unsafe {
|
let retain_count_after_build: usize = unsafe {
|
||||||
msg_send![window.ns_view, retainCount]
|
msg_send![window.ns_view, retainCount]
|
||||||
|
@ -190,7 +190,7 @@ impl WindowState {
|
||||||
|
|
||||||
pub(super) fn trigger_event(&mut self, event: Event){
|
pub(super) fn trigger_event(&mut self, event: Event){
|
||||||
self.window_handler.on_event(
|
self.window_handler.on_event(
|
||||||
&mut crate::Window(&mut self.window),
|
&mut crate::Window::new(&mut self.window),
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ unsafe extern "system" fn wnd_proc(
|
||||||
let window_state_ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA) as *mut RefCell<WindowState>;
|
let window_state_ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA) as *mut RefCell<WindowState>;
|
||||||
if !window_state_ptr.is_null() {
|
if !window_state_ptr.is_null() {
|
||||||
let mut window = Window { hwnd };
|
let mut window = Window { hwnd };
|
||||||
let mut window = crate::Window(&mut window);
|
let mut window = crate::Window::new(&mut window);
|
||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
WM_MOUSEMOVE => {
|
WM_MOUSEMOVE => {
|
||||||
|
@ -320,7 +320,7 @@ impl Window {
|
||||||
);
|
);
|
||||||
// todo: manage error ^
|
// todo: manage error ^
|
||||||
|
|
||||||
let handler = Box::new(build(&mut crate::Window(&mut Window { hwnd })));
|
let handler = Box::new(build(&mut crate::Window::new(&mut Window { hwnd })));
|
||||||
|
|
||||||
let window_state = Box::new(RefCell::new(WindowState {
|
let window_state = Box::new(RefCell::new(WindowState {
|
||||||
window_class,
|
window_class,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||||
|
|
||||||
use crate::WindowHandler;
|
use crate::WindowHandler;
|
||||||
|
@ -18,9 +20,20 @@ impl AppRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Window<'a>(pub(crate) &'a mut platform::Window);
|
pub struct Window<'a> {
|
||||||
|
window: &'a mut platform::Window,
|
||||||
|
// so that Window is !Send on all platforms
|
||||||
|
phantom: PhantomData<*mut ()>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Window<'a> {
|
impl<'a> Window<'a> {
|
||||||
|
pub(crate) fn new(window: &mut platform::Window) -> Window {
|
||||||
|
Window {
|
||||||
|
window,
|
||||||
|
phantom: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open<H, B>(
|
pub fn open<H, B>(
|
||||||
options: WindowOpenOptions,
|
options: WindowOpenOptions,
|
||||||
build: B
|
build: B
|
||||||
|
@ -35,6 +48,6 @@ impl<'a> Window<'a> {
|
||||||
|
|
||||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
self.0.raw_window_handle()
|
self.window.raw_window_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ impl Window {
|
||||||
new_physical_size: None,
|
new_physical_size: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut handler = build(&mut crate::Window(&mut window));
|
let mut handler = build(&mut crate::Window::new(&mut window));
|
||||||
|
|
||||||
let _ = tx.send(Ok(()));
|
let _ = tx.send(Ok(()));
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ impl Window {
|
||||||
let window_info = self.window_info;
|
let window_info = self.window_info;
|
||||||
|
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Window(WindowEvent::Resized(window_info))
|
Event::Window(WindowEvent::Resized(window_info))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ impl Window {
|
||||||
|
|
||||||
if wm_delete_window == data32[0] {
|
if wm_delete_window == data32[0] {
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Window(WindowEvent::WillClose)
|
Event::Window(WindowEvent::WillClose)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ impl Window {
|
||||||
let logical_pos = physical_pos.to_logical(&self.window_info);
|
let logical_pos = physical_pos.to_logical(&self.window_info);
|
||||||
|
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Mouse(MouseEvent::CursorMoved {
|
Event::Mouse(MouseEvent::CursorMoved {
|
||||||
position: logical_pos,
|
position: logical_pos,
|
||||||
}),
|
}),
|
||||||
|
@ -372,7 +372,7 @@ impl Window {
|
||||||
match detail {
|
match detail {
|
||||||
4 => {
|
4 => {
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Mouse(MouseEvent::WheelScrolled(ScrollDelta::Lines {
|
Event::Mouse(MouseEvent::WheelScrolled(ScrollDelta::Lines {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 1.0,
|
y: 1.0,
|
||||||
|
@ -381,7 +381,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
5 => {
|
5 => {
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Mouse(MouseEvent::WheelScrolled(ScrollDelta::Lines {
|
Event::Mouse(MouseEvent::WheelScrolled(ScrollDelta::Lines {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: -1.0,
|
y: -1.0,
|
||||||
|
@ -391,7 +391,7 @@ impl Window {
|
||||||
detail => {
|
detail => {
|
||||||
let button_id = mouse_id(detail);
|
let button_id = mouse_id(detail);
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Mouse(MouseEvent::ButtonPressed(button_id))
|
Event::Mouse(MouseEvent::ButtonPressed(button_id))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -405,7 +405,7 @@ impl Window {
|
||||||
if detail != 4 && detail != 5 {
|
if detail != 4 && detail != 5 {
|
||||||
let button_id = mouse_id(detail);
|
let button_id = mouse_id(detail);
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Mouse(MouseEvent::ButtonReleased(button_id))
|
Event::Mouse(MouseEvent::ButtonReleased(button_id))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ impl Window {
|
||||||
let event = unsafe { xcb::cast_event::<xcb::KeyPressEvent>(&event) };
|
let event = unsafe { xcb::cast_event::<xcb::KeyPressEvent>(&event) };
|
||||||
|
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Keyboard(convert_key_press_event(&event))
|
Event::Keyboard(convert_key_press_event(&event))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -427,7 +427,7 @@ impl Window {
|
||||||
let event = unsafe { xcb::cast_event::<xcb::KeyReleaseEvent>(&event) };
|
let event = unsafe { xcb::cast_event::<xcb::KeyReleaseEvent>(&event) };
|
||||||
|
|
||||||
handler.on_event(
|
handler.on_event(
|
||||||
&mut crate::Window(self),
|
&mut crate::Window::new(self),
|
||||||
Event::Keyboard(convert_key_release_event(&event))
|
Event::Keyboard(convert_key_release_event(&event))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue