Skip to content

Commit

Permalink
Make EventLoopWindowTarget independent of the user type on Orbital (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm authored Aug 30, 2023
1 parent 477619c commit 6dfc78f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/platform_impl/orbital/event_loop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::VecDeque,
marker::PhantomData,
mem, slice,
sync::{mpsc, Arc, Mutex},
time::Instant,
Expand Down Expand Up @@ -267,6 +268,8 @@ impl EventState {
pub struct EventLoop<T: 'static> {
windows: Vec<(Arc<RedoxSocket>, EventState)>,
window_target: event_loop::EventLoopWindowTarget<T>,
user_events_sender: mpsc::Sender<T>,
user_events_receiver: mpsc::Receiver<T>,
}

impl<T: 'static> EventLoop<T> {
Expand Down Expand Up @@ -298,16 +301,17 @@ impl<T: 'static> EventLoop<T> {
windows: Vec::new(),
window_target: event_loop::EventLoopWindowTarget {
p: EventLoopWindowTarget {
user_events_sender,
user_events_receiver,
creates: Mutex::new(VecDeque::new()),
redraws: Arc::new(Mutex::new(VecDeque::new())),
destroys: Arc::new(Mutex::new(VecDeque::new())),
event_socket,
wake_socket,
p: PhantomData,
},
_marker: std::marker::PhantomData,
_marker: PhantomData,
},
user_events_sender,
user_events_receiver,
})
}

Expand Down Expand Up @@ -594,7 +598,7 @@ impl<T: 'static> EventLoop<T> {
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::Event::UserEvent(event),
&self.window_target,
Expand Down Expand Up @@ -707,7 +711,7 @@ impl<T: 'static> EventLoop<T> {

pub fn create_proxy(&self) -> EventLoopProxy<T> {
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(),
}
}
Expand Down Expand Up @@ -742,13 +746,12 @@ impl<T> Clone for EventLoopProxy<T> {
impl<T> Unpin for EventLoopProxy<T> {}

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) redraws: Arc<Mutex<VecDeque<WindowId>>>,
pub(super) destroys: Arc<Mutex<VecDeque<WindowId>>>,
pub(super) event_socket: Arc<RedoxSocket>,
pub(super) wake_socket: Arc<TimeSocket>,
p: PhantomData<T>,
}

impl<T: 'static> EventLoopWindowTarget<T> {
Expand Down

0 comments on commit 6dfc78f

Please sign in to comment.