autocommit 2022-03-13 22:20:31 CET
This commit is contained in:
parent
156bd5b042
commit
a15a02a95c
38 changed files with 63 additions and 66 deletions
18
jay-config/src/keyboard/keymap.rs
Normal file
18
jay-config/src/keyboard/keymap.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use bincode::{Decode, Encode};
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct Keymap(pub u64);
|
||||
|
||||
impl Keymap {
|
||||
pub const INVALID: Self = Self(0);
|
||||
|
||||
pub fn is_invalid(self) -> bool {
|
||||
self == Self::INVALID
|
||||
}
|
||||
|
||||
pub fn parse(self, keymap: &str) -> Self {
|
||||
let mut res = Self::INVALID;
|
||||
(|| res = get!().parse_keymap(keymap))();
|
||||
res
|
||||
}
|
||||
}
|
||||
40
jay-config/src/keyboard/mod.rs
Normal file
40
jay-config/src/keyboard/mod.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use crate::keyboard::mods::Modifiers;
|
||||
use crate::keyboard::syms::KeySym;
|
||||
use bincode::{Decode, Encode};
|
||||
use std::ops::{BitOr, BitOrAssign};
|
||||
|
||||
pub mod keymap;
|
||||
pub mod mods;
|
||||
pub mod syms;
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct ModifiedKeySym {
|
||||
pub mods: Modifiers,
|
||||
pub sym: KeySym,
|
||||
}
|
||||
|
||||
impl From<KeySym> for ModifiedKeySym {
|
||||
fn from(sym: KeySym) -> Self {
|
||||
Self {
|
||||
mods: Modifiers(0),
|
||||
sym,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<Modifiers> for ModifiedKeySym {
|
||||
type Output = ModifiedKeySym;
|
||||
|
||||
fn bitor(self, rhs: Modifiers) -> Self::Output {
|
||||
ModifiedKeySym {
|
||||
mods: self.mods | rhs,
|
||||
sym: self.sym,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOrAssign<Modifiers> for ModifiedKeySym {
|
||||
fn bitor_assign(&mut self, rhs: Modifiers) {
|
||||
self.mods |= rhs;
|
||||
}
|
||||
}
|
||||
60
jay-config/src/keyboard/mods.rs
Normal file
60
jay-config/src/keyboard/mods.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
use crate::keyboard::syms::KeySym;
|
||||
use crate::ModifiedKeySym;
|
||||
use bincode::{Decode, Encode};
|
||||
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Default, Hash, Debug)]
|
||||
pub struct Modifiers(pub u32);
|
||||
|
||||
pub const SHIFT: Modifiers = Modifiers(1 << 0);
|
||||
pub const LOCK: Modifiers = Modifiers(1 << 1);
|
||||
pub const CTRL: Modifiers = Modifiers(1 << 2);
|
||||
pub const MOD1: Modifiers = Modifiers(1 << 3);
|
||||
pub const MOD2: Modifiers = Modifiers(1 << 4);
|
||||
pub const MOD3: Modifiers = Modifiers(1 << 5);
|
||||
pub const MOD4: Modifiers = Modifiers(1 << 6);
|
||||
pub const MOD5: Modifiers = Modifiers(1 << 7);
|
||||
|
||||
pub const CAPS: Modifiers = LOCK;
|
||||
pub const ALT: Modifiers = MOD1;
|
||||
pub const NUM: Modifiers = MOD2;
|
||||
pub const LOGO: Modifiers = MOD4;
|
||||
|
||||
impl BitOr for Modifiers {
|
||||
type Output = Self;
|
||||
|
||||
fn bitor(self, rhs: Self) -> Self::Output {
|
||||
Self(self.0 | rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<KeySym> for Modifiers {
|
||||
type Output = ModifiedKeySym;
|
||||
|
||||
fn bitor(self, rhs: KeySym) -> Self::Output {
|
||||
ModifiedKeySym {
|
||||
mods: self,
|
||||
sym: rhs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd for Modifiers {
|
||||
type Output = Self;
|
||||
|
||||
fn bitand(self, rhs: Self) -> Self::Output {
|
||||
Self(self.0 & rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOrAssign for Modifiers {
|
||||
fn bitor_assign(&mut self, rhs: Self) {
|
||||
self.0 |= rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAndAssign for Modifiers {
|
||||
fn bitand_assign(&mut self, rhs: Self) {
|
||||
self.0 &= rhs.0
|
||||
}
|
||||
}
|
||||
2556
jay-config/src/keyboard/syms.rs
Normal file
2556
jay-config/src/keyboard/syms.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue