Remove generic parameter T from EventLoopWindowTarget (#3298)

This commit is contained in:
Mads Marquart 2024-01-13 21:36:53 +01:00 committed by GitHub
parent 169cd39f93
commit 22311802b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 174 additions and 210 deletions

View file

@ -74,12 +74,11 @@ impl PanicInfo {
}
#[derive(Debug)]
pub struct EventLoopWindowTarget<T: 'static> {
pub struct EventLoopWindowTarget {
mtm: MainThreadMarker,
p: PhantomData<T>,
}
impl<T: 'static> EventLoopWindowTarget<T> {
impl EventLoopWindowTarget {
#[inline]
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
monitor::available_monitors()
@ -131,7 +130,7 @@ impl<T: 'static> EventLoopWindowTarget<T> {
}
}
impl<T> EventLoopWindowTarget<T> {
impl EventLoopWindowTarget {
pub(crate) fn hide_application(&self) {
NSApplication::sharedApplication(self.mtm).hide(None)
}
@ -163,7 +162,7 @@ pub struct EventLoop<T: 'static> {
sender: mpsc::Sender<T>,
receiver: Rc<mpsc::Receiver<T>>,
window_target: Rc<RootWindowTarget<T>>,
window_target: Rc<RootWindowTarget>,
panic_info: Rc<PanicInfo>,
/// We make sure that the callback closure is dropped during a panic
@ -232,10 +231,7 @@ impl<T> EventLoop<T> {
sender,
receiver: Rc::new(receiver),
window_target: Rc::new(RootWindowTarget {
p: EventLoopWindowTarget {
mtm,
p: PhantomData,
},
p: EventLoopWindowTarget { mtm },
_marker: PhantomData,
}),
panic_info,
@ -243,13 +239,13 @@ impl<T> EventLoop<T> {
})
}
pub fn window_target(&self) -> &RootWindowTarget<T> {
pub fn window_target(&self) -> &RootWindowTarget {
&self.window_target
}
pub fn run<F>(mut self, callback: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootWindowTarget<T>),
F: FnMut(Event<T>, &RootWindowTarget),
{
self.run_on_demand(callback)
}
@ -260,7 +256,7 @@ impl<T> EventLoop<T> {
// redundant wake ups.
pub fn run_on_demand<F>(&mut self, callback: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootWindowTarget<T>),
F: FnMut(Event<T>, &RootWindowTarget),
{
if AppState::is_running() {
return Err(EventLoopError::AlreadyRunning);
@ -277,8 +273,8 @@ impl<T> EventLoop<T> {
let callback = unsafe {
mem::transmute::<
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget<T>)>>,
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget<T>)>>,
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget)>>,
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget)>>,
>(Rc::new(RefCell::new(callback)))
};
@ -344,7 +340,7 @@ impl<T> EventLoop<T> {
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, callback: F) -> PumpStatus
where
F: FnMut(Event<T>, &RootWindowTarget<T>),
F: FnMut(Event<T>, &RootWindowTarget),
{
// # Safety
// We are erasing the lifetime of the application callback here so that we
@ -357,8 +353,8 @@ impl<T> EventLoop<T> {
let callback = unsafe {
mem::transmute::<
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget<T>)>>,
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget<T>)>>,
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget)>>,
Rc<RefCell<dyn FnMut(Event<T>, &RootWindowTarget)>>,
>(Rc::new(RefCell::new(callback)))
};