Make EventLoopWindowTarget independent of the user type on Orbital (#3055)

This commit is contained in:
Mads Marquart 2023-08-30 16:43:28 +02:00 committed by GitHub
parent 477619c0a7
commit 6dfc78fb50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
marker::PhantomData,
mem, slice, mem, slice,
sync::{mpsc, Arc, Mutex}, sync::{mpsc, Arc, Mutex},
time::Instant, time::Instant,
@ -267,6 +268,8 @@ impl EventState {
pub struct EventLoop<T: 'static> { pub struct EventLoop<T: 'static> {
windows: Vec<(Arc<RedoxSocket>, EventState)>, windows: Vec<(Arc<RedoxSocket>, EventState)>,
window_target: event_loop::EventLoopWindowTarget<T>, window_target: event_loop::EventLoopWindowTarget<T>,
user_events_sender: mpsc::Sender<T>,
user_events_receiver: mpsc::Receiver<T>,
} }
impl<T: 'static> EventLoop<T> { impl<T: 'static> EventLoop<T> {
@ -298,16 +301,17 @@ impl<T: 'static> EventLoop<T> {
windows: Vec::new(), windows: Vec::new(),
window_target: event_loop::EventLoopWindowTarget { window_target: event_loop::EventLoopWindowTarget {
p: EventLoopWindowTarget { p: EventLoopWindowTarget {
user_events_sender,
user_events_receiver,
creates: Mutex::new(VecDeque::new()), creates: Mutex::new(VecDeque::new()),
redraws: Arc::new(Mutex::new(VecDeque::new())), redraws: Arc::new(Mutex::new(VecDeque::new())),
destroys: Arc::new(Mutex::new(VecDeque::new())), destroys: Arc::new(Mutex::new(VecDeque::new())),
event_socket, event_socket,
wake_socket, wake_socket,
p: PhantomData,
}, },
_marker: std::marker::PhantomData, _marker: PhantomData,
}, },
user_events_sender,
user_events_receiver,
}) })
} }
@ -594,7 +598,7 @@ impl<T: 'static> EventLoop<T> {
i += 1; i += 1;
} }
while let Ok(event) = self.window_target.p.user_events_receiver.try_recv() { while let Ok(event) = self.user_events_receiver.try_recv() {
event_handler( event_handler(
event::Event::UserEvent(event), event::Event::UserEvent(event),
&self.window_target, &self.window_target,
@ -707,7 +711,7 @@ impl<T: 'static> EventLoop<T> {
pub fn create_proxy(&self) -> EventLoopProxy<T> { pub fn create_proxy(&self) -> EventLoopProxy<T> {
EventLoopProxy { EventLoopProxy {
user_events_sender: self.window_target.p.user_events_sender.clone(), user_events_sender: self.user_events_sender.clone(),
wake_socket: self.window_target.p.wake_socket.clone(), wake_socket: self.window_target.p.wake_socket.clone(),
} }
} }
@ -742,13 +746,12 @@ impl<T> Clone for EventLoopProxy<T> {
impl<T> Unpin for EventLoopProxy<T> {} impl<T> Unpin for EventLoopProxy<T> {}
pub struct EventLoopWindowTarget<T: 'static> { pub struct EventLoopWindowTarget<T: 'static> {
pub(super) user_events_sender: mpsc::Sender<T>,
pub(super) user_events_receiver: mpsc::Receiver<T>,
pub(super) creates: Mutex<VecDeque<Arc<RedoxSocket>>>, pub(super) creates: Mutex<VecDeque<Arc<RedoxSocket>>>,
pub(super) redraws: Arc<Mutex<VecDeque<WindowId>>>, pub(super) redraws: Arc<Mutex<VecDeque<WindowId>>>,
pub(super) destroys: Arc<Mutex<VecDeque<WindowId>>>, pub(super) destroys: Arc<Mutex<VecDeque<WindowId>>>,
pub(super) event_socket: Arc<RedoxSocket>, pub(super) event_socket: Arc<RedoxSocket>,
pub(super) wake_socket: Arc<TimeSocket>, pub(super) wake_socket: Arc<TimeSocket>,
p: PhantomData<T>,
} }
impl<T: 'static> EventLoopWindowTarget<T> { impl<T: 'static> EventLoopWindowTarget<T> {