use bitflags::bitflags;
pub use floem_winit::keyboard::{
Key, KeyCode, KeyLocation, ModifiersState, NamedKey, NativeKey, PhysicalKey,
};
#[cfg(not(target_arch = "wasm32"))]
pub use floem_winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct KeyEvent {
pub key: floem_winit::event::KeyEvent,
pub modifiers: Modifiers,
}
bitflags! {
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Modifiers: u32 {
const SHIFT = 0b100;
const CONTROL = 0b100 << 3;
const ALT = 0b100 << 6;
const META = 0b100 << 9;
const ALTGR = 0b100 << 12;
}
}
impl Modifiers {
pub fn shift(&self) -> bool {
self.intersects(Self::SHIFT)
}
pub fn control(&self) -> bool {
self.intersects(Self::CONTROL)
}
pub fn alt(&self) -> bool {
self.intersects(Self::ALT)
}
pub fn meta(&self) -> bool {
self.intersects(Self::META)
}
pub fn altgr(&self) -> bool {
self.intersects(Self::ALTGR)
}
}
impl From<ModifiersState> for Modifiers {
fn from(value: ModifiersState) -> Self {
let mut modifiers = Modifiers::empty();
if value.shift_key() {
modifiers.set(Modifiers::SHIFT, true);
}
if value.alt_key() {
modifiers.set(Modifiers::ALT, true);
}
if value.control_key() {
modifiers.set(Modifiers::CONTROL, true);
}
if value.super_key() {
modifiers.set(Modifiers::META, true);
}
modifiers
}
}