diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index ec29a7e9692aa..2c0aad00b756c 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -158,6 +158,13 @@ pub struct Window { /// /// This value has no effect on non-web platforms. pub fit_canvas_to_parent: bool, + /// Whether or not to stop events from propagating out of the canvas element + /// + /// When `true`, this will prevent common browser hotkeys like F5, F12, Ctrl+R, tab, etc. + /// from performing their default behavior while the bevy app has focus. + /// + /// This value has no effect on non-web platforms. + pub prevent_default_event_handling: bool, /// Stores internal state that isn't directly accessible. pub internal: InternalWindowState, } @@ -180,6 +187,7 @@ impl Default for Window { focused: true, always_on_top: false, fit_canvas_to_parent: false, + prevent_default_event_handling: true, canvas: None, } } diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 2f7dda6702f7b..25ac5e40b780a 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -110,6 +110,9 @@ impl WinitWindows { panic!("Cannot find element: {}.", selector); } } + + winit_window_builder = + winit_window_builder.with_prevent_default(window.prevent_default_event_handling) } let winit_window = winit_window_builder.build(event_loop).unwrap(); diff --git a/examples/window/window_settings.rs b/examples/window/window_settings.rs index 53ceccb1eb50b..7d914081cfec1 100644 --- a/examples/window/window_settings.rs +++ b/examples/window/window_settings.rs @@ -16,6 +16,8 @@ fn main() { present_mode: PresentMode::AutoVsync, // Tells wasm to resize the window according to the available canvas fit_canvas_to_parent: true, + // Tells wasm not to override default event handling, like F5, Ctrl+R etc. + prevent_default_event_handling: false, ..default() }), ..default()