use super::accessibility::AccessibilityActionRequest;
pub(super) const CONTROL_BITS: u8 = 0b0000_0011;
pub(super) const CONTROL_LEFT: u8 = 0b0000_0001;
pub(super) const CONTROL_RIGHT: u8 = 0b0000_0010;
pub(super) const SHIFT_BITS: u8 = 0b0000_1100;
pub(super) const SHIFT_LEFT: u8 = 0b0000_0100;
pub(super) const SHIFT_RIGHT: u8 = 0b0000_1000;
pub(super) const ALT_BITS: u8 = 0b0011_0000;
pub(super) const ALT_LEFT: u8 = 0b0001_0000;
pub(super) const ALT_RIGHT: u8 = 0b0010_0000;
pub(super) const META_BITS: u8 = 0b1100_0000;
pub(super) const META_LEFT: u8 = 0b0100_0000;
pub(super) const META_RIGHT: u8 = 0b1000_0000;
const WHEEL_FLAG_CONTROL: usize = 0x0008;
const WHEEL_FLAG_SHIFT: usize = 0x0004;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct ModifierState {
bits: u8,
}
impl ModifierState {
pub const NONE: Self = Self { bits: 0 };
pub const CONTROL: Self = Self { bits: CONTROL_LEFT };
pub const SHIFT: Self = Self { bits: SHIFT_LEFT };
pub const ALT: Self = Self { bits: ALT_LEFT };
pub const META: Self = Self { bits: META_LEFT };
#[must_use]
pub const fn ctrl(self) -> bool {
self.bits & CONTROL_BITS != 0
}
#[must_use]
pub const fn shift(self) -> bool {
self.bits & SHIFT_BITS != 0
}
#[must_use]
pub const fn alt(self) -> bool {
self.bits & ALT_BITS != 0
}
#[must_use]
pub const fn meta(self) -> bool {
self.bits & META_BITS != 0
}
pub(super) const fn set_bits(self, mask: u8, pressed: bool) -> Self {
let bits = if pressed {
self.bits | mask
} else {
self.bits & !mask
};
Self { bits }
}
pub(super) const fn with_wheel_message_flags(self, wparam: usize) -> Self {
let flags = wparam & 0xffff;
let mut state = self.set_bits(CONTROL_BITS | SHIFT_BITS, false);
if flags & WHEEL_FLAG_CONTROL != 0 {
state = state.set_bits(CONTROL_BITS, true);
}
if flags & WHEEL_FLAG_SHIFT != 0 {
state = state.set_bits(SHIFT_BITS, true);
}
state
}
}
impl core::ops::BitOr for ModifierState {
type Output = Self;
fn bitor(self, other: Self) -> Self {
Self {
bits: self.bits | other.bits,
}
}
}
impl core::ops::BitOrAssign for ModifierState {
fn bitor_assign(&mut self, other: Self) {
self.bits |= other.bits;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseButton {
Left,
Right,
Middle,
X1,
X2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompositionPhase {
Started,
Updated,
Committed,
Canceled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WindowEvent {
CloseRequested,
Destroyed,
FocusGained,
FocusLost,
PointerMove {
x: i32,
y: i32,
},
PointerDown {
x: i32,
y: i32,
button: MouseButton,
},
PointerUp {
x: i32,
y: i32,
button: MouseButton,
},
PointerWheel {
x: i32,
y: i32,
delta_x: i16,
delta_y: i16,
modifiers: ModifierState,
},
KeyDown {
virtual_key: u32,
repeated: bool,
modifiers: ModifierState,
},
KeyUp {
virtual_key: u32,
modifiers: ModifierState,
},
TextInput {
character: char,
},
TextComposition {
phase: CompositionPhase,
text: String,
},
Resized {
width: u32,
height: u32,
},
DpiChanged {
dpi: u32,
},
AccessibilityAction {
request: AccessibilityActionRequest,
},
}