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

Update to winit 0.27. Handle new window events (IME and Occluded) #904

Closed
wants to merge 5 commits into from

Conversation

hugcis
Copy link

@hugcis hugcis commented Jan 23, 2023

Motivation

This pull request addresses issue #903 and updates the nannou and nannou_egui libraries to be compatible with winit version 0.27+.

One breaking change in winit 0.27 is the removal of the WindowAttributes field on WindowBuilder. As a result, additional fields were added to nannou::window::Builder to track properties such as inner_size and min_inner_size before building the window.

The winit update also introduces two new events: IME and Occluded.

  • The IME event corresponds to a "composition event" (e.g., a series of keyboard events that should be combined in a single produced character, like accented characters) and will only be created if Window::set_ime_allowed is called. I ignored the event because the added complexity would outweigh the benefits, but I may be wrong.
  • The Occluded event is a macOS-only (for now) event that fires only when the current window is completely hidden from view. It contains a bool which I believe indicates if the window is hidden or not (this is not documented in winit). This event can be useful to save computations when the window is not visible.

Summary of changes:

  • Update to winit 0.27. Update window.rs to deal with a few breaking changes.
  • Handle new events IME (ignored) and Occluded (handled).
  • Update examples to handle new Occluded events.
  • Update changelog.

The commit updates nannou and nannou_egui to use winit to 0.27+. The
window attribute of the WindowBuilder is now private, we use the
WindowBuilder methods to properly build the window in window.rs.

Because the properties of the `Window` currently being built cannot be
accessed from the `WindowBuilder` anymore, some additional properties
have to be stored in the `Builder` struct which are mirrors of the
`Window`'s properties. These properties allow checking if a value and
what it was set to. `Builder` now has `fullscreen` `size`, `min_size`,
and `max_size` as new properties.

The `set_cursor_grab` has also been updated with the new winit enum
`CursorGrabMode`. If the cursor should be grabbed, we first try to
confine it, then try to lock it (see
https://docs.rs/winit/latest/winit/window/enum.CursorGrabMode.html).
The Ime event corresponds to a "composition event". It will never be
sent if `Window::set_ime_allowed` is not called. These events are
stateful, they first need to be enabled and successive events need to be
combined. This should be a separate feature since it will require some
extra work to handle.

The occluded event is handled a function can be used to take advantage
of it. For example, costly rendering can be avoided if the window is
occluded (hidden from view).
@mitchmindtree
Copy link
Member

Hey thanks so much for the PR @hugcis!

I actually began addressing this update over the weekend as a part of an update to wgpu 0.14 and egui 0.20 😅 you can find my WIP branch here.

I plan to resume work on this over the coming weekend, though we're encountering some issues with the way egui's new egui_wgpu crate's fragment shader behaves.

@hugcis
Copy link
Author

hugcis commented Jan 23, 2023

Hey @mitchmindtree,

No problem, I am happy to help with nannou! I see you are using an unmerged PR of winit (rust-windowing/winit#2613), which allows skipping some of the workarounds I had to make to update to 0.27.

It probably makes more sense to update winit with wgpu and egui in one go.

@archshift
Copy link

Any plans to revisit this?

@mitchmindtree
Copy link
Member

I think this has for the most part been addressed by #940 which updates to winit 0.28 (minus the extra functions for handling new events like occluded), however as the new plan is to orient toward a set of bevy plugins (see #946) hopefully we can lean into using bevy's event abstractions instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants