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

@ -158,7 +158,7 @@ pub(crate) enum ProcResult {
pub struct EventLoop<T: 'static> {
user_event_sender: Sender<T>,
user_event_receiver: Receiver<T>,
window_target: RootELW<T>,
window_target: RootELW,
msg_hook: Option<Box<dyn FnMut(*const c_void) -> bool + 'static>>,
}
@ -178,11 +178,10 @@ impl Default for PlatformSpecificEventLoopAttributes {
}
}
pub struct EventLoopWindowTarget<T: 'static> {
pub struct EventLoopWindowTarget {
thread_id: u32,
thread_msg_target: HWND,
pub(crate) runner_shared: EventLoopRunnerShared<UserEventPlaceholder>,
_marker: PhantomData<T>,
}
impl<T: 'static> EventLoop<T> {
@ -223,7 +222,6 @@ impl<T: 'static> EventLoop<T> {
thread_id,
thread_msg_target,
runner_shared,
_marker: PhantomData,
},
_marker: PhantomData,
},
@ -231,20 +229,20 @@ impl<T: 'static> EventLoop<T> {
})
}
pub fn window_target(&self) -> &RootELW<T> {
pub fn window_target(&self) -> &RootELW {
&self.window_target
}
pub fn run<F>(mut self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
self.run_on_demand(event_handler)
}
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
{
let runner = &self.window_target.p.runner_shared;
@ -309,7 +307,7 @@ impl<T: 'static> EventLoop<T> {
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, mut event_handler: F) -> PumpStatus
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
{
let runner = &self.window_target.p.runner_shared;
@ -529,7 +527,7 @@ impl<T: 'static> EventLoop<T> {
}
}
impl<T> EventLoopWindowTarget<T> {
impl EventLoopWindowTarget {
#[inline(always)]
pub(crate) fn create_thread_executor(&self) -> EventLoopThreadExecutor {
EventLoopThreadExecutor {
@ -983,7 +981,7 @@ unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) {
//
// Returning 0 tells the Win32 API that the message has been processed.
// FIXME: detect WM_DWMCOMPOSITIONCHANGED and call DwmEnableBlurBehindWindow if necessary
pub(super) unsafe extern "system" fn public_window_callback<T: 'static>(
pub(super) unsafe extern "system" fn public_window_callback(
window: HWND,
msg: u32,
wparam: WPARAM,
@ -994,7 +992,7 @@ pub(super) unsafe extern "system" fn public_window_callback<T: 'static>(
let userdata_ptr = match (userdata, msg) {
(0, WM_NCCREATE) => {
let createstruct = unsafe { &mut *(lparam as *mut CREATESTRUCTW) };
let initdata = unsafe { &mut *(createstruct.lpCreateParams as *mut InitData<'_, T>) };
let initdata = unsafe { &mut *(createstruct.lpCreateParams as *mut InitData<'_>) };
let result = match unsafe { initdata.on_nccreate(window) } {
Some(userdata) => unsafe {
@ -1012,7 +1010,7 @@ pub(super) unsafe extern "system" fn public_window_callback<T: 'static>(
(_, WM_CREATE) => unsafe {
let createstruct = &mut *(lparam as *mut CREATESTRUCTW);
let initdata = createstruct.lpCreateParams;
let initdata = &mut *(initdata as *mut InitData<'_, T>);
let initdata = &mut *(initdata as *mut InitData<'_>);
initdata.on_create();
return DefWindowProcW(window, msg, wparam, lparam);

View file

@ -237,7 +237,7 @@ impl WinCursor {
}
}
pub(crate) fn build<T>(cursor: OnlyCursorImageBuilder, _: &EventLoopWindowTarget<T>) -> Self {
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &EventLoopWindowTarget) -> Self {
match Self::new(&cursor.0) {
Ok(cursor) => cursor,
Err(err) => {

View file

@ -96,8 +96,8 @@ pub(crate) struct Window {
}
impl Window {
pub(crate) fn new<T: 'static>(
event_loop: &EventLoopWindowTarget<T>,
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
w_attr: WindowAttributes,
pl_attr: PlatformSpecificWindowBuilderAttributes,
) -> Result<Window, RootOsError> {
@ -1074,9 +1074,9 @@ impl Drop for Window {
}
}
pub(super) struct InitData<'a, T: 'static> {
pub(super) struct InitData<'a> {
// inputs
pub event_loop: &'a EventLoopWindowTarget<T>,
pub event_loop: &'a EventLoopWindowTarget,
pub attributes: WindowAttributes,
pub pl_attribs: PlatformSpecificWindowBuilderAttributes,
pub window_flags: WindowFlags,
@ -1084,7 +1084,7 @@ pub(super) struct InitData<'a, T: 'static> {
pub window: Option<Window>,
}
impl<'a, T: 'static> InitData<'a, T> {
impl<'a> InitData<'a> {
unsafe fn create_window(&self, window: HWND) -> Window {
// Register for touch events if applicable
{
@ -1269,18 +1269,15 @@ impl<'a, T: 'static> InitData<'a, T> {
}
}
}
unsafe fn init<T>(
unsafe fn init(
attributes: WindowAttributes,
pl_attribs: PlatformSpecificWindowBuilderAttributes,
event_loop: &EventLoopWindowTarget<T>,
) -> Result<Window, RootOsError>
where
T: 'static,
{
event_loop: &EventLoopWindowTarget,
) -> Result<Window, RootOsError> {
let title = util::encode_wide(&attributes.title);
let class_name = util::encode_wide(&pl_attribs.class_name);
unsafe { register_window_class::<T>(&class_name) };
unsafe { register_window_class(&class_name) };
let mut window_flags = WindowFlags::empty();
window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations);
@ -1375,11 +1372,11 @@ where
Ok(initdata.window.unwrap())
}
unsafe fn register_window_class<T: 'static>(class_name: &[u16]) {
unsafe fn register_window_class(class_name: &[u16]) {
let class = WNDCLASSEXW {
cbSize: mem::size_of::<WNDCLASSEXW>() as u32,
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(super::event_loop::public_window_callback::<T>),
lpfnWndProc: Some(super::event_loop::public_window_callback),
cbClsExtra: 0,
cbWndExtra: 0,
hInstance: util::get_instance_handle(),