2023-03-01 22:45:04 +00:00
|
|
|
use bevy_a11y::AccessibilityRequested;
|
2023-01-19 00:38:28 +00:00
|
|
|
use bevy_ecs::{
|
|
|
|
entity::Entity,
|
|
|
|
event::EventWriter,
|
|
|
|
prelude::{Changed, Component, Resource},
|
2023-02-04 20:53:37 +00:00
|
|
|
removal_detection::RemovedComponents,
|
2023-03-01 22:45:04 +00:00
|
|
|
system::{Commands, NonSendMut, Query, ResMut},
|
2023-01-19 00:38:28 +00:00
|
|
|
world::Mut,
|
|
|
|
};
|
|
|
|
use bevy_utils::{
|
|
|
|
tracing::{error, info, warn},
|
2024-01-15 15:51:17 +00:00
|
|
|
EntityHashMap,
|
2023-01-19 00:38:28 +00:00
|
|
|
};
|
|
|
|
use bevy_window::{RawHandleWrapper, Window, WindowClosed, WindowCreated};
|
|
|
|
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
|
|
|
|
|
|
|
use winit::{
|
2023-01-29 20:27:29 +00:00
|
|
|
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize},
|
2023-01-19 00:38:28 +00:00
|
|
|
event_loop::EventLoopWindowTarget,
|
|
|
|
};
|
|
|
|
|
2023-02-03 16:41:39 +00:00
|
|
|
use crate::{
|
2023-03-01 22:45:04 +00:00
|
|
|
accessibility::{AccessKitAdapters, WinitActionHandlers},
|
2023-07-23 01:02:40 +00:00
|
|
|
converters::{
|
|
|
|
self, convert_enabled_buttons, convert_window_level, convert_window_theme,
|
|
|
|
convert_winit_theme,
|
|
|
|
},
|
Update winit dependency to 0.29 (#10702)
# Objective
- Update winit dependency to 0.29
## Changelog
### KeyCode changes
- Removed `ScanCode`, as it was [replaced by
KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292).
- `ReceivedCharacter.char` is now a `SmolStr`, [relevant
doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text).
- Changed most `KeyCode` values, and added more.
KeyCode has changed meaning. With this PR, it refers to physical
position on keyboard rather than the printed letter on keyboard keys.
In practice this means:
- On QWERTY keyboard layouts, nothing changes
- On any other keyboard layout, `KeyCode` no longer reflects the label
on key.
- This is "good". In bevy 0.12, when you used WASD for movement, users
with non-QWERTY keyboards couldn't play your game! This was especially
bad for non-latin keyboards. Now, WASD represents the physical keys. A
French player will press the ZQSD keys, which are near each other,
Kyrgyz players will use "Цфыв".
- This is "bad" as well. You can't know in advance what the label of the
key for input is. Your UI says "press WASD to move", even if in reality,
they should be pressing "ZQSD" or "Цфыв". You also no longer can use
`KeyCode` for text inputs. In any case, it was a pretty bad API for text
input. You should use `ReceivedCharacter` now instead.
### Other changes
- Use `web-time` rather than `instant` crate.
(https://github.com/rust-windowing/winit/pull/2836)
- winit did split `run_return` in `run_onDemand` and `pump_events`, I
did the same change in bevy_winit and used `pump_events`.
- Removed `return_from_run` from `WinitSettings` as `winit::run` now
returns on supported platforms.
- I left the example "return_after_run" as I think it's still useful.
- This winit change is done partly to allow to create a new window after
quitting all windows: https://github.com/emilk/egui/issues/1918 ; this
PR doesn't address.
- added `width` and `height` properties in the `canvas` from wasm
example
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1420567168)
## Known regressions (important follow ups?)
- Provide an API for reacting when a specific key from current layout
was released.
- possible solutions: use winit::Key from winit::KeyEvent ; mapping
between KeyCode and Key ; or .
- We don't receive characters through alt+numpad (e.g. alt + 151 = "ù")
anymore ; reproduced on winit example "ime". maybe related to
https://github.com/rust-windowing/winit/issues/2945
- (windows) Window content doesn't refresh at all when resizing. By
reading https://github.com/rust-windowing/winit/issues/2900 ; I suspect
we should just fire a `window.request_redraw();` from `AboutToWait`, and
handle actual redrawing within `RedrawRequested`. I'm not sure how to
move all that code so I'd appreciate it to be a follow up.
- (windows) unreleased winit fix for using set_control_flow in
AboutToWait https://github.com/rust-windowing/winit/issues/3215 ; ⚠️ I'm
not sure what the implications are, but that feels bad 🤔
## Follow up
I'd like to avoid bloating this PR, here are a few follow up tasks
worthy of a separate PR, or new issue to track them once this PR is
closed, as they would either complicate reviews, or at risk of being
controversial:
- remove CanvasParentResizePlugin
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1417068856)
- avoid mentionning explicitly winit in docs from bevy_window ?
- NamedKey integration on bevy_input:
https://github.com/rust-windowing/winit/pull/3143 introduced a new
NamedKey variant. I implemented it only on the converters but we'd
benefit making the same changes to bevy_input.
- Add more info in KeyboardInput
https://github.com/bevyengine/bevy/pull/10702#pullrequestreview-1748336313
- https://github.com/bevyengine/bevy/pull/9905 added a workaround on a
bug allegedly fixed by winit 0.29. We should check if it's still
necessary.
- update to raw_window_handle 0.6
- blocked by wgpu
- Rename `KeyCode` to `PhysicalKeyCode`
https://github.com/bevyengine/bevy/pull/10702#discussion_r1404595015
- remove `instant` dependency, [replaced
by](https://github.com/rust-windowing/winit/pull/2836) `web_time`), we'd
need to update to :
- fastrand >= 2.0
- [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7
- [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0
- Verify license, see
[discussion](https://github.com/bevyengine/bevy/pull/8745#discussion_r1402439800)
- we might be missing a short notice or description of changes made
- Consider using https://github.com/rust-windowing/cursor-icon directly
rather than vendoring it in bevy.
- investigate [this
unwrap](https://github.com/bevyengine/bevy/pull/8745#discussion_r1387044986)
(`winit_window.canvas().unwrap();`)
- Use more good things about winit's update
- https://github.com/bevyengine/bevy/pull/10689#issuecomment-1823560428
## Migration Guide
This PR should have one.
2023-12-21 07:40:47 +00:00
|
|
|
get_best_videomode, get_fitting_videomode, WindowAndInputEventWriters, WinitWindows,
|
2023-02-03 16:41:39 +00:00
|
|
|
};
|
2023-01-19 00:38:28 +00:00
|
|
|
|
2023-07-31 21:41:59 +00:00
|
|
|
/// Creates new windows on the [`winit`] backend for each entity with a newly-added
|
|
|
|
/// [`Window`] component.
|
2023-01-19 00:38:28 +00:00
|
|
|
///
|
2023-07-31 21:41:59 +00:00
|
|
|
/// If any of these entities are missing required components, those will be added with their
|
|
|
|
/// default values.
|
2023-03-01 22:45:04 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2023-07-31 21:41:59 +00:00
|
|
|
pub(crate) fn create_windows<'a>(
|
2023-01-19 00:38:28 +00:00
|
|
|
event_loop: &EventLoopWindowTarget<()>,
|
2023-07-31 21:41:59 +00:00
|
|
|
mut commands: Commands,
|
2023-01-19 00:38:28 +00:00
|
|
|
created_windows: impl Iterator<Item = (Entity, Mut<'a, Window>)>,
|
|
|
|
mut event_writer: EventWriter<WindowCreated>,
|
|
|
|
mut winit_windows: NonSendMut<WinitWindows>,
|
2023-03-01 22:45:04 +00:00
|
|
|
mut adapters: NonSendMut<AccessKitAdapters>,
|
|
|
|
mut handlers: ResMut<WinitActionHandlers>,
|
2023-09-02 18:35:06 +00:00
|
|
|
accessibility_requested: ResMut<AccessibilityRequested>,
|
2023-01-19 00:38:28 +00:00
|
|
|
) {
|
2023-02-07 14:18:13 +00:00
|
|
|
for (entity, mut window) in created_windows {
|
2023-01-19 00:38:28 +00:00
|
|
|
if winit_windows.get_window(entity).is_some() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
info!(
|
|
|
|
"Creating new window {:?} ({:?})",
|
2023-02-07 14:18:13 +00:00
|
|
|
window.title.as_str(),
|
2023-01-19 00:38:28 +00:00
|
|
|
entity
|
|
|
|
);
|
|
|
|
|
2023-03-01 22:45:04 +00:00
|
|
|
let winit_window = winit_windows.create_window(
|
|
|
|
event_loop,
|
|
|
|
entity,
|
|
|
|
&window,
|
|
|
|
&mut adapters,
|
|
|
|
&mut handlers,
|
2023-09-02 18:35:06 +00:00
|
|
|
&accessibility_requested,
|
2023-03-01 22:45:04 +00:00
|
|
|
);
|
2023-06-05 21:04:22 +00:00
|
|
|
|
|
|
|
if let Some(theme) = winit_window.theme() {
|
|
|
|
window.window_theme = Some(convert_winit_theme(theme));
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
window
|
2023-01-19 00:38:28 +00:00
|
|
|
.resolution
|
2023-12-14 14:56:40 +00:00
|
|
|
.set_scale_factor(winit_window.scale_factor() as f32);
|
2023-01-19 00:38:28 +00:00
|
|
|
commands
|
|
|
|
.entity(entity)
|
|
|
|
.insert(RawHandleWrapper {
|
|
|
|
window_handle: winit_window.raw_window_handle(),
|
|
|
|
display_handle: winit_window.raw_display_handle(),
|
|
|
|
})
|
2023-02-07 14:18:13 +00:00
|
|
|
.insert(CachedWindow {
|
|
|
|
window: window.clone(),
|
2023-01-19 00:38:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
event_writer.send(WindowCreated { window: entity });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Cache for closing windows so we can get better debug information.
|
|
|
|
#[derive(Debug, Clone, Resource)]
|
2024-01-15 15:51:17 +00:00
|
|
|
pub struct WindowTitleCache(EntityHashMap<Entity, String>);
|
2023-01-19 00:38:28 +00:00
|
|
|
|
2023-07-31 21:41:59 +00:00
|
|
|
pub(crate) fn despawn_windows(
|
2023-02-04 20:53:37 +00:00
|
|
|
mut closed: RemovedComponents<Window>,
|
2023-01-31 01:47:00 +00:00
|
|
|
window_entities: Query<&Window>,
|
2023-01-19 00:38:28 +00:00
|
|
|
mut close_events: EventWriter<WindowClosed>,
|
|
|
|
mut winit_windows: NonSendMut<WinitWindows>,
|
|
|
|
) {
|
2023-09-15 12:37:20 +00:00
|
|
|
for window in closed.read() {
|
2023-01-19 00:38:28 +00:00
|
|
|
info!("Closing window {:?}", window);
|
2023-01-31 01:47:00 +00:00
|
|
|
// Guard to verify that the window is in fact actually gone,
|
|
|
|
// rather than having the component added and removed in the same frame.
|
|
|
|
if !window_entities.contains(window) {
|
|
|
|
winit_windows.remove_window(window);
|
|
|
|
close_events.send(WindowClosed { window });
|
|
|
|
}
|
2023-01-19 00:38:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
/// The cached state of the window so we can check which properties were changed from within the app.
|
2023-01-19 00:38:28 +00:00
|
|
|
#[derive(Debug, Clone, Component)]
|
2023-02-07 14:18:13 +00:00
|
|
|
pub struct CachedWindow {
|
|
|
|
pub window: Window,
|
2023-01-19 00:38:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 21:41:59 +00:00
|
|
|
/// Propagates changes from [`Window`] entities to the [`winit`] backend.
|
|
|
|
///
|
|
|
|
/// # Notes
|
|
|
|
///
|
|
|
|
/// - [`Window::present_mode`] and [`Window::composite_alpha_mode`] changes are handled by the `bevy_render` crate.
|
|
|
|
/// - [`Window::transparent`] cannot be changed after the window is created.
|
|
|
|
/// - [`Window::canvas`] cannot be changed after the window is created.
|
|
|
|
/// - [`Window::focused`] cannot be manually changed to `false` after the window is created.
|
|
|
|
pub(crate) fn changed_windows(
|
2023-02-07 14:18:13 +00:00
|
|
|
mut changed_windows: Query<(Entity, &mut Window, &mut CachedWindow), Changed<Window>>,
|
2023-01-19 00:38:28 +00:00
|
|
|
winit_windows: NonSendMut<WinitWindows>,
|
Update winit dependency to 0.29 (#10702)
# Objective
- Update winit dependency to 0.29
## Changelog
### KeyCode changes
- Removed `ScanCode`, as it was [replaced by
KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292).
- `ReceivedCharacter.char` is now a `SmolStr`, [relevant
doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text).
- Changed most `KeyCode` values, and added more.
KeyCode has changed meaning. With this PR, it refers to physical
position on keyboard rather than the printed letter on keyboard keys.
In practice this means:
- On QWERTY keyboard layouts, nothing changes
- On any other keyboard layout, `KeyCode` no longer reflects the label
on key.
- This is "good". In bevy 0.12, when you used WASD for movement, users
with non-QWERTY keyboards couldn't play your game! This was especially
bad for non-latin keyboards. Now, WASD represents the physical keys. A
French player will press the ZQSD keys, which are near each other,
Kyrgyz players will use "Цфыв".
- This is "bad" as well. You can't know in advance what the label of the
key for input is. Your UI says "press WASD to move", even if in reality,
they should be pressing "ZQSD" or "Цфыв". You also no longer can use
`KeyCode` for text inputs. In any case, it was a pretty bad API for text
input. You should use `ReceivedCharacter` now instead.
### Other changes
- Use `web-time` rather than `instant` crate.
(https://github.com/rust-windowing/winit/pull/2836)
- winit did split `run_return` in `run_onDemand` and `pump_events`, I
did the same change in bevy_winit and used `pump_events`.
- Removed `return_from_run` from `WinitSettings` as `winit::run` now
returns on supported platforms.
- I left the example "return_after_run" as I think it's still useful.
- This winit change is done partly to allow to create a new window after
quitting all windows: https://github.com/emilk/egui/issues/1918 ; this
PR doesn't address.
- added `width` and `height` properties in the `canvas` from wasm
example
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1420567168)
## Known regressions (important follow ups?)
- Provide an API for reacting when a specific key from current layout
was released.
- possible solutions: use winit::Key from winit::KeyEvent ; mapping
between KeyCode and Key ; or .
- We don't receive characters through alt+numpad (e.g. alt + 151 = "ù")
anymore ; reproduced on winit example "ime". maybe related to
https://github.com/rust-windowing/winit/issues/2945
- (windows) Window content doesn't refresh at all when resizing. By
reading https://github.com/rust-windowing/winit/issues/2900 ; I suspect
we should just fire a `window.request_redraw();` from `AboutToWait`, and
handle actual redrawing within `RedrawRequested`. I'm not sure how to
move all that code so I'd appreciate it to be a follow up.
- (windows) unreleased winit fix for using set_control_flow in
AboutToWait https://github.com/rust-windowing/winit/issues/3215 ; ⚠️ I'm
not sure what the implications are, but that feels bad 🤔
## Follow up
I'd like to avoid bloating this PR, here are a few follow up tasks
worthy of a separate PR, or new issue to track them once this PR is
closed, as they would either complicate reviews, or at risk of being
controversial:
- remove CanvasParentResizePlugin
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1417068856)
- avoid mentionning explicitly winit in docs from bevy_window ?
- NamedKey integration on bevy_input:
https://github.com/rust-windowing/winit/pull/3143 introduced a new
NamedKey variant. I implemented it only on the converters but we'd
benefit making the same changes to bevy_input.
- Add more info in KeyboardInput
https://github.com/bevyengine/bevy/pull/10702#pullrequestreview-1748336313
- https://github.com/bevyengine/bevy/pull/9905 added a workaround on a
bug allegedly fixed by winit 0.29. We should check if it's still
necessary.
- update to raw_window_handle 0.6
- blocked by wgpu
- Rename `KeyCode` to `PhysicalKeyCode`
https://github.com/bevyengine/bevy/pull/10702#discussion_r1404595015
- remove `instant` dependency, [replaced
by](https://github.com/rust-windowing/winit/pull/2836) `web_time`), we'd
need to update to :
- fastrand >= 2.0
- [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7
- [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0
- Verify license, see
[discussion](https://github.com/bevyengine/bevy/pull/8745#discussion_r1402439800)
- we might be missing a short notice or description of changes made
- Consider using https://github.com/rust-windowing/cursor-icon directly
rather than vendoring it in bevy.
- investigate [this
unwrap](https://github.com/bevyengine/bevy/pull/8745#discussion_r1387044986)
(`winit_window.canvas().unwrap();`)
- Use more good things about winit's update
- https://github.com/bevyengine/bevy/pull/10689#issuecomment-1823560428
## Migration Guide
This PR should have one.
2023-12-21 07:40:47 +00:00
|
|
|
mut event_writers: WindowAndInputEventWriters<'_>,
|
2023-01-19 00:38:28 +00:00
|
|
|
) {
|
2023-02-07 14:18:13 +00:00
|
|
|
for (entity, mut window, mut cache) in &mut changed_windows {
|
2023-01-19 00:38:28 +00:00
|
|
|
if let Some(winit_window) = winit_windows.get_window(entity) {
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.title != cache.window.title {
|
2023-01-19 00:38:28 +00:00
|
|
|
winit_window.set_title(window.title.as_str());
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.mode != cache.window.mode {
|
2023-01-19 00:38:28 +00:00
|
|
|
let new_mode = match window.mode {
|
|
|
|
bevy_window::WindowMode::BorderlessFullscreen => {
|
|
|
|
Some(winit::window::Fullscreen::Borderless(None))
|
|
|
|
}
|
|
|
|
bevy_window::WindowMode::Fullscreen => {
|
|
|
|
Some(winit::window::Fullscreen::Exclusive(get_best_videomode(
|
|
|
|
&winit_window.current_monitor().unwrap(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
bevy_window::WindowMode::SizedFullscreen => {
|
|
|
|
Some(winit::window::Fullscreen::Exclusive(get_fitting_videomode(
|
|
|
|
&winit_window.current_monitor().unwrap(),
|
|
|
|
window.width() as u32,
|
|
|
|
window.height() as u32,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
bevy_window::WindowMode::Windowed => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
if winit_window.fullscreen() != new_mode {
|
|
|
|
winit_window.set_fullscreen(new_mode);
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.resolution != cache.window.resolution {
|
2023-01-19 00:38:28 +00:00
|
|
|
let physical_size = PhysicalSize::new(
|
|
|
|
window.resolution.physical_width(),
|
|
|
|
window.resolution.physical_height(),
|
|
|
|
);
|
Update winit dependency to 0.29 (#10702)
# Objective
- Update winit dependency to 0.29
## Changelog
### KeyCode changes
- Removed `ScanCode`, as it was [replaced by
KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292).
- `ReceivedCharacter.char` is now a `SmolStr`, [relevant
doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text).
- Changed most `KeyCode` values, and added more.
KeyCode has changed meaning. With this PR, it refers to physical
position on keyboard rather than the printed letter on keyboard keys.
In practice this means:
- On QWERTY keyboard layouts, nothing changes
- On any other keyboard layout, `KeyCode` no longer reflects the label
on key.
- This is "good". In bevy 0.12, when you used WASD for movement, users
with non-QWERTY keyboards couldn't play your game! This was especially
bad for non-latin keyboards. Now, WASD represents the physical keys. A
French player will press the ZQSD keys, which are near each other,
Kyrgyz players will use "Цфыв".
- This is "bad" as well. You can't know in advance what the label of the
key for input is. Your UI says "press WASD to move", even if in reality,
they should be pressing "ZQSD" or "Цфыв". You also no longer can use
`KeyCode` for text inputs. In any case, it was a pretty bad API for text
input. You should use `ReceivedCharacter` now instead.
### Other changes
- Use `web-time` rather than `instant` crate.
(https://github.com/rust-windowing/winit/pull/2836)
- winit did split `run_return` in `run_onDemand` and `pump_events`, I
did the same change in bevy_winit and used `pump_events`.
- Removed `return_from_run` from `WinitSettings` as `winit::run` now
returns on supported platforms.
- I left the example "return_after_run" as I think it's still useful.
- This winit change is done partly to allow to create a new window after
quitting all windows: https://github.com/emilk/egui/issues/1918 ; this
PR doesn't address.
- added `width` and `height` properties in the `canvas` from wasm
example
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1420567168)
## Known regressions (important follow ups?)
- Provide an API for reacting when a specific key from current layout
was released.
- possible solutions: use winit::Key from winit::KeyEvent ; mapping
between KeyCode and Key ; or .
- We don't receive characters through alt+numpad (e.g. alt + 151 = "ù")
anymore ; reproduced on winit example "ime". maybe related to
https://github.com/rust-windowing/winit/issues/2945
- (windows) Window content doesn't refresh at all when resizing. By
reading https://github.com/rust-windowing/winit/issues/2900 ; I suspect
we should just fire a `window.request_redraw();` from `AboutToWait`, and
handle actual redrawing within `RedrawRequested`. I'm not sure how to
move all that code so I'd appreciate it to be a follow up.
- (windows) unreleased winit fix for using set_control_flow in
AboutToWait https://github.com/rust-windowing/winit/issues/3215 ; ⚠️ I'm
not sure what the implications are, but that feels bad 🤔
## Follow up
I'd like to avoid bloating this PR, here are a few follow up tasks
worthy of a separate PR, or new issue to track them once this PR is
closed, as they would either complicate reviews, or at risk of being
controversial:
- remove CanvasParentResizePlugin
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1417068856)
- avoid mentionning explicitly winit in docs from bevy_window ?
- NamedKey integration on bevy_input:
https://github.com/rust-windowing/winit/pull/3143 introduced a new
NamedKey variant. I implemented it only on the converters but we'd
benefit making the same changes to bevy_input.
- Add more info in KeyboardInput
https://github.com/bevyengine/bevy/pull/10702#pullrequestreview-1748336313
- https://github.com/bevyengine/bevy/pull/9905 added a workaround on a
bug allegedly fixed by winit 0.29. We should check if it's still
necessary.
- update to raw_window_handle 0.6
- blocked by wgpu
- Rename `KeyCode` to `PhysicalKeyCode`
https://github.com/bevyengine/bevy/pull/10702#discussion_r1404595015
- remove `instant` dependency, [replaced
by](https://github.com/rust-windowing/winit/pull/2836) `web_time`), we'd
need to update to :
- fastrand >= 2.0
- [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7
- [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0
- Verify license, see
[discussion](https://github.com/bevyengine/bevy/pull/8745#discussion_r1402439800)
- we might be missing a short notice or description of changes made
- Consider using https://github.com/rust-windowing/cursor-icon directly
rather than vendoring it in bevy.
- investigate [this
unwrap](https://github.com/bevyengine/bevy/pull/8745#discussion_r1387044986)
(`winit_window.canvas().unwrap();`)
- Use more good things about winit's update
- https://github.com/bevyengine/bevy/pull/10689#issuecomment-1823560428
## Migration Guide
This PR should have one.
2023-12-21 07:40:47 +00:00
|
|
|
if let Some(size_now) = winit_window.request_inner_size(physical_size) {
|
|
|
|
crate::react_to_resize(&mut window, size_now, &mut event_writers, entity);
|
|
|
|
}
|
2023-01-19 00:38:28 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.physical_cursor_position() != cache.window.physical_cursor_position() {
|
2023-01-20 14:25:24 +00:00
|
|
|
if let Some(physical_position) = window.physical_cursor_position() {
|
2023-08-17 16:59:07 +00:00
|
|
|
let position = PhysicalPosition::new(physical_position.x, physical_position.y);
|
2023-01-19 00:38:28 +00:00
|
|
|
|
|
|
|
if let Err(err) = winit_window.set_cursor_position(position) {
|
|
|
|
error!("could not set cursor position: {:?}", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.cursor.icon != cache.window.cursor.icon {
|
2023-01-19 00:38:28 +00:00
|
|
|
winit_window.set_cursor_icon(converters::convert_cursor_icon(window.cursor.icon));
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.cursor.grab_mode != cache.window.cursor.grab_mode {
|
2023-01-19 00:38:28 +00:00
|
|
|
crate::winit_windows::attempt_grab(winit_window, window.cursor.grab_mode);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.cursor.visible != cache.window.cursor.visible {
|
2023-01-19 00:38:28 +00:00
|
|
|
winit_window.set_cursor_visible(window.cursor.visible);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.cursor.hit_test != cache.window.cursor.hit_test {
|
2023-01-19 00:38:28 +00:00
|
|
|
if let Err(err) = winit_window.set_cursor_hittest(window.cursor.hit_test) {
|
2023-02-07 14:18:13 +00:00
|
|
|
window.cursor.hit_test = cache.window.cursor.hit_test;
|
2023-01-19 00:38:28 +00:00
|
|
|
warn!(
|
|
|
|
"Could not set cursor hit test for window {:?}: {:?}",
|
|
|
|
window.title, err
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.decorations != cache.window.decorations
|
2023-01-19 00:38:28 +00:00
|
|
|
&& window.decorations != winit_window.is_decorated()
|
|
|
|
{
|
|
|
|
winit_window.set_decorations(window.decorations);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.resizable != cache.window.resizable
|
2023-01-19 00:38:28 +00:00
|
|
|
&& window.resizable != winit_window.is_resizable()
|
|
|
|
{
|
|
|
|
winit_window.set_resizable(window.resizable);
|
|
|
|
}
|
|
|
|
|
2023-07-23 01:02:40 +00:00
|
|
|
if window.enabled_buttons != cache.window.enabled_buttons {
|
|
|
|
winit_window.set_enabled_buttons(convert_enabled_buttons(window.enabled_buttons));
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.resize_constraints != cache.window.resize_constraints {
|
2023-01-19 00:38:28 +00:00
|
|
|
let constraints = window.resize_constraints.check_constraints();
|
|
|
|
let min_inner_size = LogicalSize {
|
|
|
|
width: constraints.min_width,
|
|
|
|
height: constraints.min_height,
|
|
|
|
};
|
|
|
|
let max_inner_size = LogicalSize {
|
|
|
|
width: constraints.max_width,
|
|
|
|
height: constraints.max_height,
|
|
|
|
};
|
|
|
|
|
|
|
|
winit_window.set_min_inner_size(Some(min_inner_size));
|
|
|
|
if constraints.max_width.is_finite() && constraints.max_height.is_finite() {
|
|
|
|
winit_window.set_max_inner_size(Some(max_inner_size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.position != cache.window.position {
|
2023-01-19 00:38:28 +00:00
|
|
|
if let Some(position) = crate::winit_window_position(
|
|
|
|
&window.position,
|
|
|
|
&window.resolution,
|
|
|
|
winit_window.available_monitors(),
|
|
|
|
winit_window.primary_monitor(),
|
|
|
|
winit_window.current_monitor(),
|
|
|
|
) {
|
|
|
|
let should_set = match winit_window.outer_position() {
|
|
|
|
Ok(current_position) => current_position != position,
|
|
|
|
_ => true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if should_set {
|
|
|
|
winit_window.set_outer_position(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(maximized) = window.internal.take_maximize_request() {
|
|
|
|
winit_window.set_maximized(maximized);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(minimized) = window.internal.take_minimize_request() {
|
|
|
|
winit_window.set_minimized(minimized);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.focused != cache.window.focused && window.focused {
|
2023-01-19 00:38:28 +00:00
|
|
|
winit_window.focus_window();
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.window_level != cache.window.window_level {
|
2023-02-03 16:41:39 +00:00
|
|
|
winit_window.set_window_level(convert_window_level(window.window_level));
|
2023-01-19 00:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Currently unsupported changes
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.transparent != cache.window.transparent {
|
|
|
|
window.transparent = cache.window.transparent;
|
2023-01-19 00:38:28 +00:00
|
|
|
warn!(
|
|
|
|
"Winit does not currently support updating transparency after window creation."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.canvas != cache.window.canvas {
|
|
|
|
window.canvas = cache.window.canvas.clone();
|
2023-01-19 00:38:28 +00:00
|
|
|
warn!(
|
|
|
|
"Bevy currently doesn't support modifying the window canvas after initialization."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.ime_enabled != cache.window.ime_enabled {
|
2023-01-29 20:27:29 +00:00
|
|
|
winit_window.set_ime_allowed(window.ime_enabled);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
if window.ime_position != cache.window.ime_position {
|
Update winit dependency to 0.29 (#10702)
# Objective
- Update winit dependency to 0.29
## Changelog
### KeyCode changes
- Removed `ScanCode`, as it was [replaced by
KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292).
- `ReceivedCharacter.char` is now a `SmolStr`, [relevant
doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text).
- Changed most `KeyCode` values, and added more.
KeyCode has changed meaning. With this PR, it refers to physical
position on keyboard rather than the printed letter on keyboard keys.
In practice this means:
- On QWERTY keyboard layouts, nothing changes
- On any other keyboard layout, `KeyCode` no longer reflects the label
on key.
- This is "good". In bevy 0.12, when you used WASD for movement, users
with non-QWERTY keyboards couldn't play your game! This was especially
bad for non-latin keyboards. Now, WASD represents the physical keys. A
French player will press the ZQSD keys, which are near each other,
Kyrgyz players will use "Цфыв".
- This is "bad" as well. You can't know in advance what the label of the
key for input is. Your UI says "press WASD to move", even if in reality,
they should be pressing "ZQSD" or "Цфыв". You also no longer can use
`KeyCode` for text inputs. In any case, it was a pretty bad API for text
input. You should use `ReceivedCharacter` now instead.
### Other changes
- Use `web-time` rather than `instant` crate.
(https://github.com/rust-windowing/winit/pull/2836)
- winit did split `run_return` in `run_onDemand` and `pump_events`, I
did the same change in bevy_winit and used `pump_events`.
- Removed `return_from_run` from `WinitSettings` as `winit::run` now
returns on supported platforms.
- I left the example "return_after_run" as I think it's still useful.
- This winit change is done partly to allow to create a new window after
quitting all windows: https://github.com/emilk/egui/issues/1918 ; this
PR doesn't address.
- added `width` and `height` properties in the `canvas` from wasm
example
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1420567168)
## Known regressions (important follow ups?)
- Provide an API for reacting when a specific key from current layout
was released.
- possible solutions: use winit::Key from winit::KeyEvent ; mapping
between KeyCode and Key ; or .
- We don't receive characters through alt+numpad (e.g. alt + 151 = "ù")
anymore ; reproduced on winit example "ime". maybe related to
https://github.com/rust-windowing/winit/issues/2945
- (windows) Window content doesn't refresh at all when resizing. By
reading https://github.com/rust-windowing/winit/issues/2900 ; I suspect
we should just fire a `window.request_redraw();` from `AboutToWait`, and
handle actual redrawing within `RedrawRequested`. I'm not sure how to
move all that code so I'd appreciate it to be a follow up.
- (windows) unreleased winit fix for using set_control_flow in
AboutToWait https://github.com/rust-windowing/winit/issues/3215 ; ⚠️ I'm
not sure what the implications are, but that feels bad 🤔
## Follow up
I'd like to avoid bloating this PR, here are a few follow up tasks
worthy of a separate PR, or new issue to track them once this PR is
closed, as they would either complicate reviews, or at risk of being
controversial:
- remove CanvasParentResizePlugin
(https://github.com/bevyengine/bevy/pull/10702#discussion_r1417068856)
- avoid mentionning explicitly winit in docs from bevy_window ?
- NamedKey integration on bevy_input:
https://github.com/rust-windowing/winit/pull/3143 introduced a new
NamedKey variant. I implemented it only on the converters but we'd
benefit making the same changes to bevy_input.
- Add more info in KeyboardInput
https://github.com/bevyengine/bevy/pull/10702#pullrequestreview-1748336313
- https://github.com/bevyengine/bevy/pull/9905 added a workaround on a
bug allegedly fixed by winit 0.29. We should check if it's still
necessary.
- update to raw_window_handle 0.6
- blocked by wgpu
- Rename `KeyCode` to `PhysicalKeyCode`
https://github.com/bevyengine/bevy/pull/10702#discussion_r1404595015
- remove `instant` dependency, [replaced
by](https://github.com/rust-windowing/winit/pull/2836) `web_time`), we'd
need to update to :
- fastrand >= 2.0
- [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7
- [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0
- Verify license, see
[discussion](https://github.com/bevyengine/bevy/pull/8745#discussion_r1402439800)
- we might be missing a short notice or description of changes made
- Consider using https://github.com/rust-windowing/cursor-icon directly
rather than vendoring it in bevy.
- investigate [this
unwrap](https://github.com/bevyengine/bevy/pull/8745#discussion_r1387044986)
(`winit_window.canvas().unwrap();`)
- Use more good things about winit's update
- https://github.com/bevyengine/bevy/pull/10689#issuecomment-1823560428
## Migration Guide
This PR should have one.
2023-12-21 07:40:47 +00:00
|
|
|
winit_window.set_ime_cursor_area(
|
|
|
|
LogicalPosition::new(window.ime_position.x, window.ime_position.y),
|
|
|
|
PhysicalSize::new(10, 10),
|
|
|
|
);
|
2023-01-29 20:27:29 +00:00
|
|
|
}
|
|
|
|
|
2023-06-05 21:04:22 +00:00
|
|
|
if window.window_theme != cache.window.window_theme {
|
|
|
|
winit_window.set_theme(window.window_theme.map(convert_window_theme));
|
|
|
|
}
|
|
|
|
|
2023-08-20 22:42:07 +00:00
|
|
|
if window.visible != cache.window.visible {
|
|
|
|
winit_window.set_visible(window.visible);
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:18:13 +00:00
|
|
|
cache.window = window.clone();
|
2023-01-19 00:38:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|