Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Make EventLoopWindowTarget independent of UserEvent type #3061

Merged
merged 4 commits into from
Jan 4, 2024

Conversation

nerditation
Copy link
Contributor

the EventLoopWindowTarget is needed for window creation. conceptually, only EventLoop and EventLoopProxy need to be parameterized, and all other parts of the backend should be agnostic about the user event type, parallel to how Event<T> is parameterized, but WindowEvent is not.

this change removes the dependency on the type of user events from the EventLoopWindowTarget for the Windows backend, but keep a phantom data to keep the API intact. to achieve this, I moved the Receiver end of the mpsc channel from ThreadMsgTargetData into EventLoop itself, so the UserEvent is only passed between EventLoop and EventLoopProxy, all other part of the backend just use unit type as a placeholder for user events.

it's similar to the macos backend where an erased EventHandler trait object is used so all component except EventLoop and EventLoopProxy need to be parameterized. however EventLoop of the Windows backend already use an Box<dyn FnMut> to wrap the user provided event handler callback, so no need for an dedicated trait object, I just modified the wrapper to replace the placeholder user event with real value pulled from the channel. I find this is the approach which need minimum change to be made to existing code. but it does the job and could serve as a starting point to future Windows backend re-works.

  • Tested on all platforms changed
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

@madsmtm madsmtm added DS - windows S - maintenance Repaying technical debt labels Aug 28, 2023
@madsmtm madsmtm changed the title make EventLoopWindowTarget independent of UserEvent type Windows: Make EventLoopWindowTarget independent of UserEvent type Aug 28, 2023
Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the rest, indeed there are room for future improvement, but the idea looks fine to my eyes for now. Would like a Windows expert to have a look first though.

src/platform_impl/windows/event_loop.rs Outdated Show resolved Hide resolved
src/platform_impl/windows/event_loop.rs Show resolved Hide resolved
src/platform_impl/windows/event_loop.rs Outdated Show resolved Hide resolved
@madsmtm
Copy link
Member

madsmtm commented Dec 24, 2023

@msiglreith @maroider last call for getting a review here, otherwise I'll merge this soon, I'd like to progress on #3053.

the `EventLoopWindowTarget` is needed for window creation. conceptually,
only `EventLoop` and `EventLoopProxy` need to be parameterized, and all
other parts of the backend should be agnostic about the user event type,
parallel to how `Event<T>` is parameterized, but `WindowEvent` is not.

this change removes the dependency on the type of user events from the
`EventLoopWindowTarget` for the Windows backend, but keep a phantom data
to keep the API intact. to achieve this, I moved the `Receiver` end of
the mpsc channel from `ThreadMsgTargetData` into `EventLoop` itself, so
the `UserEvent` is only passed between `EventLoop` and `EventLoopProxy`,
all other part of the backend just use unit type as a placeholder for
user events.

it's similar to the macos backend where an erased `EventHandler` trait
object is used so all component except `EventLoop` and `EventLoopProxy`
need to be parameterized. however `EventLoop` of the Windows backend
already use an `Box<dyn FnMut>` to wrap the user provided event handler
callback, so no need for an dedicated trait object, I just modified the
wrapper to replace the placeholder user event with real value pulled
from the channel. I find this is the approach which need minimum change
to be made to existing code. but it does the job and could serve as a
starting point to future Windows backend re-works.
this field is transitional and her to keep API compatibility only.
the correct variance and such is already ensured by the top-level
`EventLoopWindowTarget`, just use `PhantomData<T>` here.
@madsmtm madsmtm force-pushed the non-generic-ELWT-windows branch from dac99dd to e0dab55 Compare January 4, 2024 15:33
@madsmtm madsmtm merged commit dd12746 into rust-windowing:master Jan 4, 2024
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DS - windows S - maintenance Repaying technical debt
Development

Successfully merging this pull request may close these issues.

2 participants