use winit::keyboard::{Key, KeyLocation};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(
clippy::struct_excessive_bools,
reason = "one flag per physical modifier key, mirroring winit's own \
modifiers state; a browser app constructs this by field name \
across the crate boundary, so reshaping it into flags is out \
of scope for a lint fix"
)]
pub struct KeyModifiers {
pub ctrl: bool,
pub shift: bool,
pub alt: bool,
pub meta: bool,
}
#[cfg(target_os = "linux")]
#[must_use]
pub fn keysym_key(keysym: u32) -> Option<(Key, KeyLocation)> {
Some(winit::platform::scancode::keysym_to_key(keysym))
}
#[cfg(not(target_os = "linux"))]
#[must_use]
pub const fn keysym_key(_keysym: u32) -> Option<(Key, KeyLocation)> {
None
}
#[cfg(all(test, target_os = "linux"))]
mod tests {
use super::*;
use winit::keyboard::NamedKey;
#[test]
fn a_named_keysym_names_the_key_winit_names() {
let (key, _) = keysym_key(0xff0d).expect("no host lacks keysyms here");
assert_eq!(key, Key::Named(NamedKey::Enter));
}
#[test]
fn a_typed_character_is_no_named_key() {
let (key, _) = keysym_key(u32::from('с')).expect("no host lacks keysyms here");
assert!(matches!(key, Key::Unidentified(_)), "{key:?}");
}
}