keybindings_parser/
masks.rs

1#[derive(Debug, PartialEq, Clone, Copy)]
2pub struct ModMask(u16);
3impl ModMask {
4    pub const NONE: Self = Self(0);
5    pub const SHIFT: Self = Self(1 << 0);
6    pub const CAPS_LOCK: Self = Self(1 << 1);
7    pub const CONTROL: Self = Self(1 << 2);
8    pub const MOD1: Self = Self(1 << 3); // alt
9    pub const MOD2: Self = Self(1 << 4); // num lock
10    pub const MOD3: Self = Self(1 << 5); // not exist anymore (AltGr?)
11    pub const MOD4: Self = Self(1 << 6); // super/win/cmd
12    pub const MOD5: Self = Self(1 << 7); // scroll lock
13    pub const ANY: Self = Self(1 << 15);
14}
15
16impl From<ModMask> for u16 {
17    #[inline]
18    fn from(input: ModMask) -> Self {
19        input.0
20    }
21}
22impl From<ModMask> for Option<u16> {
23    #[inline]
24    fn from(input: ModMask) -> Self {
25        Some(input.0)
26    }
27}
28impl From<ModMask> for u32 {
29    #[inline]
30    fn from(input: ModMask) -> Self {
31        u32::from(input.0)
32    }
33}
34impl From<ModMask> for Option<u32> {
35    #[inline]
36    fn from(input: ModMask) -> Self {
37        Some(u32::from(input.0))
38    }
39}
40impl From<u8> for ModMask {
41    #[inline]
42    fn from(value: u8) -> Self {
43        Self(value.into())
44    }
45}
46impl From<u16> for ModMask {
47    #[inline]
48    fn from(value: u16) -> Self {
49        Self(value)
50    }
51}
52
53impl std::ops::BitOr for ModMask {
54    type Output = Self;
55    fn bitor(self, rhs: Self) -> Self::Output {
56        Self(self.0 | rhs.0)
57    }
58}
59
60impl std::ops::BitOrAssign for ModMask {
61    fn bitor_assign(&mut self, rhs: Self) {
62        *self = Self(self.0 | rhs.0);
63    }
64}
65
66impl std::ops::BitAnd for ModMask {
67    type Output = Self;
68
69    fn bitand(self, rhs: Self) -> Self {
70        Self(self.0 & rhs.0)
71    }
72}