Skip to content

Commit 85989f6

Browse files
committed
Allow not preventing default event behaviors on wasm (#7304)
# Objective On wasm, bevy applications currently prevent any of the normal browser hotkeys from working normally (Ctrl+R, F12, F5, Ctrl+F5, tab, etc.). Some of those events you may want to override, perhaps you can hold the tab key for showing in-game stats? However, if you want to make a well-behaved game, you probably don't want to needlessly prevent that behavior unless you have a good reason. Secondary motivation: Also, consider the workaround presented here to get audio working: https://developer.chrome.com/blog/web-audio-autoplay/#moving-forward ; It won't work (for keydown events) if we stop event propagation. ## Solution - Winit has a field that allows it to not stop event propagation, expose it on the window settings to allow the user to choose the desired behavior. Default to `true` for backwards compatibility. --- ## Changelog - Added `Window::prevent_default_event_handling` . This allows bevy apps to not override default browser behavior on hotkeys like F5, F12, Ctrl+R etc.
1 parent 0332e08 commit 85989f6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/winit_windows.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ impl WinitWindows {
110110
panic!("Cannot find element: {}.", selector);
111111
}
112112
}
113+
114+
winit_window_builder =
115+
winit_window_builder.with_prevent_default(window.prevent_default_event_handling)
113116
}
114117

115118
let winit_window = winit_window_builder.build(event_loop).unwrap();

0 commit comments

Comments
 (0)