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

@ -46,18 +46,18 @@ pub trait EventHandler: Debug {
fn handle_user_events(&mut self);
}
pub(crate) type Callback<T> = RefCell<dyn FnMut(Event<T>, &RootWindowTarget<T>)>;
pub(crate) type Callback<T> = RefCell<dyn FnMut(Event<T>, &RootWindowTarget)>;
struct EventLoopHandler<T: 'static> {
callback: Weak<Callback<T>>,
window_target: Rc<RootWindowTarget<T>>,
window_target: Rc<RootWindowTarget>,
receiver: Rc<mpsc::Receiver<T>>,
}
impl<T> EventLoopHandler<T> {
fn with_callback<F>(&mut self, f: F)
where
F: FnOnce(&mut EventLoopHandler<T>, RefMut<'_, dyn FnMut(Event<T>, &RootWindowTarget<T>)>),
F: FnOnce(&mut EventLoopHandler<T>, RefMut<'_, dyn FnMut(Event<T>, &RootWindowTarget)>),
{
// `NSApplication` and our `HANDLER` are global state and so it's possible
// that we could get a delegate callback after the application has exit an
@ -375,7 +375,7 @@ impl AppState {
/// a call to `clear_callback` before returning to avoid undefined behaviour.
pub unsafe fn set_callback<T>(
callback: Weak<Callback<T>>,
window_target: Rc<RootWindowTarget<T>>,
window_target: Rc<RootWindowTarget>,
receiver: Rc<mpsc::Receiver<T>>,
) {
*HANDLER.callback.lock().unwrap() = Some(Box::new(EventLoopHandler {

View file

@ -24,10 +24,7 @@ unsafe impl Send for CustomCursor {}
unsafe impl Sync for CustomCursor {}
impl CustomCursor {
pub(crate) fn build<T>(
cursor: OnlyCursorImageBuilder,
_: &EventLoopWindowTarget<T>,
) -> CustomCursor {
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &EventLoopWindowTarget) -> CustomCursor {
Self(cursor_from_image(&cursor.0))
}
}

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)))
};

View file

@ -69,8 +69,8 @@ impl Drop for Window {
}
impl Window {
pub(crate) fn new<T: 'static>(
_window_target: &EventLoopWindowTarget<T>,
pub(crate) fn new(
_window_target: &EventLoopWindowTarget,
attributes: WindowAttributes,
pl_attribs: PlatformSpecificWindowBuilderAttributes,
) -> Result<Self, RootOsError> {