diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e62cb684e..e3298ebeee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- On Android, ignoring volume up/down key events since most applications should not override the default behavior. - On macOS, fix creating new windows when the application has a main menu. - On Windows, fix fractional deltas for mouse wheel device events. - On macOS, fix segmentation fault after dropping the main window. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 4dc3bb4aff..f55880e918 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -8,7 +8,7 @@ use crate::{ }; use ndk::{ configuration::Configuration, - event::{InputEvent, KeyAction, MotionAction}, + event::{InputEvent, KeyAction, Keycode, MotionAction}, looper::{ForeignLooper, Poll, ThreadLooper}, }; use ndk_glue::{Event, Rect}; @@ -245,26 +245,35 @@ impl EventLoop { KeyAction::Up => event::ElementState::Released, _ => event::ElementState::Released, }; - #[allow(deprecated)] - let event = event::Event::WindowEvent { - window_id, - event: event::WindowEvent::KeyboardInput { - device_id, - input: event::KeyboardInput { - scancode: key.scan_code() as u32, - state, - virtual_keycode: None, - modifiers: event::ModifiersState::default(), - }, - is_synthetic: false, - }, - }; - call_event_handler!( - event_handler, - self.window_target(), - control_flow, - event - ); + + match key.key_code() { + Keycode::VolumeUp | Keycode::VolumeDown => { + handled = false + } + _ => { + #[allow(deprecated)] + let event = event::Event::WindowEvent { + window_id, + event: event::WindowEvent::KeyboardInput { + device_id, + input: event::KeyboardInput { + scancode: key.scan_code() as u32, + state, + virtual_keycode: None, + modifiers: + event::ModifiersState::default(), + }, + is_synthetic: false, + }, + }; + call_event_handler!( + event_handler, + self.window_target(), + control_flow, + event + ); + } + } } }; input_queue.finish_event(event, handled);