diff --git a/ableos/src/keyboard/abstractions/custom_layout.rs b/ableos/src/keyboard/abstractions/custom_layout.rs index 25e34105b..0c42378ea 100644 --- a/ableos/src/keyboard/abstractions/custom_layout.rs +++ b/ableos/src/keyboard/abstractions/custom_layout.rs @@ -1,4 +1,6 @@ -use crate::{LayoutEntry, KeyCode, KeyboardLayout, Modifiers, HandleControl, DecodedKey, LayoutEntryKind}; +use crate::{ + DecodedKey, HandleControl, KeyCode, KeyboardLayout, LayoutEntry, LayoutEntryKind, Modifiers, +}; // Do not edit this file directly. Instead, create a `Keyboard` and modify that. @@ -10,8 +12,8 @@ impl Default for CustomLayout { Self::new_us104key() } } +#[rustfmt::skip] impl CustomLayout { - #[rustfmt::skip] pub fn new_us104key() -> Self { let mut mapping = Self { mapping: [LayoutEntry::default(); 256], @@ -30,72 +32,71 @@ impl CustomLayout { mapping.set(KeyCode::Key9, LayoutEntry::regular().unshifted('9').shifted('(')); mapping.set(KeyCode::Minus, LayoutEntry::regular().unshifted('-').shifted('_')); mapping.set(KeyCode::Equals, LayoutEntry::regular().unshifted('=').shifted('+')); - mapping.set(KeyCode::Backspace, LayoutEntry::regular().unshifted('\x08')); - mapping.set(KeyCode::Tab, LayoutEntry::regular().unshifted('\x09')); - mapping.set(KeyCode::Q, LayoutEntry::regular().unshifted('q').shifted('Q').locked('Q').locked_shifted('q').raw_unicode('\u{0011}')); - mapping.set(KeyCode::W, LayoutEntry::regular().unshifted('w').shifted('W').locked('W').locked_shifted('w').raw_unicode('\u{0017}')); - mapping.set(KeyCode::E, LayoutEntry::regular().unshifted('e').shifted('E').locked('E').locked_shifted('e').raw_unicode('\u{0005}')); - mapping.set(KeyCode::R, LayoutEntry::regular().unshifted('r').shifted('R').locked('R').locked_shifted('r').raw_unicode('\u{0012}')); - mapping.set(KeyCode::T, LayoutEntry::regular().unshifted('t').shifted('T').locked('T').locked_shifted('t').raw_unicode('\u{0014}')); - mapping.set(KeyCode::Y, LayoutEntry::regular().unshifted('y').shifted('Y').locked('Y').locked_shifted('y').raw_unicode('\u{0019}')); - mapping.set(KeyCode::U, LayoutEntry::regular().unshifted('u').shifted('U').locked('U').locked_shifted('u').raw_unicode('\u{0015}')); - mapping.set(KeyCode::I, LayoutEntry::regular().unshifted('i').shifted('I').locked('I').locked_shifted('i').raw_unicode('\u{0009}')); - mapping.set(KeyCode::O, LayoutEntry::regular().unshifted('o').shifted('O').locked('O').locked_shifted('o').raw_unicode('\u{000F}')); - mapping.set(KeyCode::P, LayoutEntry::regular().unshifted('p').shifted('P').locked('P').locked_shifted('p').raw_unicode('\u{0010}')); - mapping.set(KeyCode::A, LayoutEntry::regular().unshifted('a').shifted('A').locked('A').locked_shifted('a').raw_unicode('\u{0001}')); - mapping.set(KeyCode::S, LayoutEntry::regular().unshifted('s').shifted('S').locked('S').locked_shifted('s').raw_unicode('\u{0013}')); - mapping.set(KeyCode::D, LayoutEntry::regular().unshifted('d').shifted('D').locked('D').locked_shifted('d').raw_unicode('\u{0004}')); - mapping.set(KeyCode::F, LayoutEntry::regular().unshifted('f').shifted('F').locked('F').locked_shifted('f').raw_unicode('\u{0006}')); - mapping.set(KeyCode::G, LayoutEntry::regular().unshifted('g').shifted('G').locked('G').locked_shifted('g').raw_unicode('\u{0007}')); - mapping.set(KeyCode::H, LayoutEntry::regular().unshifted('h').shifted('H').locked('H').locked_shifted('h').raw_unicode('\u{0008}')); - mapping.set(KeyCode::J, LayoutEntry::regular().unshifted('j').shifted('J').locked('J').locked_shifted('j').raw_unicode('\u{000A}')); - mapping.set(KeyCode::K, LayoutEntry::regular().unshifted('k').shifted('K').locked('K').locked_shifted('k').raw_unicode('\u{000B}')); - mapping.set(KeyCode::L, LayoutEntry::regular().unshifted('l').shifted('L').locked('L').locked_shifted('l').raw_unicode('\u{000C}')); - mapping.set(KeyCode::Z, LayoutEntry::regular().unshifted('z').shifted('Z').locked('Z').locked_shifted('z').raw_unicode('\u{001A}')); - mapping.set(KeyCode::X, LayoutEntry::regular().unshifted('x').shifted('X').locked('X').locked_shifted('x').raw_unicode('\u{0018}')); - mapping.set(KeyCode::C, LayoutEntry::regular().unshifted('c').shifted('C').locked('C').locked_shifted('c').raw_unicode('\u{0003}')); - mapping.set(KeyCode::V, LayoutEntry::regular().unshifted('v').shifted('V').locked('V').locked_shifted('v').raw_unicode('\u{0016}')); - mapping.set(KeyCode::B, LayoutEntry::regular().unshifted('b').shifted('B').locked('B').locked_shifted('b').raw_unicode('\u{0002}')); - mapping.set(KeyCode::N, LayoutEntry::regular().unshifted('n').shifted('N').locked('N').locked_shifted('n').raw_unicode('\u{000E}')); - mapping.set(KeyCode::M, LayoutEntry::regular().unshifted('m').shifted('M').locked('M').locked_shifted('m').raw_unicode('\u{000D}')); + mapping.set(KeyCode::Backspace, LayoutEntry::regular().all('\x08')); + mapping.set(KeyCode::Tab, LayoutEntry::regular().all('\x09')); + mapping.set(KeyCode::Q, LayoutEntry::alphabet().low('q').high('Q').raw_unicode('\u{0011}')); + mapping.set(KeyCode::W, LayoutEntry::alphabet().low('w').high('W').raw_unicode('\u{0017}')); + mapping.set(KeyCode::E, LayoutEntry::alphabet().low('e').high('E').raw_unicode('\u{0005}')); + mapping.set(KeyCode::R, LayoutEntry::alphabet().low('r').high('R').raw_unicode('\u{0012}')); + mapping.set(KeyCode::T, LayoutEntry::alphabet().low('t').high('T').raw_unicode('\u{0014}')); + mapping.set(KeyCode::Y, LayoutEntry::alphabet().low('y').high('Y').raw_unicode('\u{0019}')); + mapping.set(KeyCode::U, LayoutEntry::alphabet().low('u').high('U').raw_unicode('\u{0015}')); + mapping.set(KeyCode::I, LayoutEntry::alphabet().low('i').high('I').raw_unicode('\u{0009}')); + mapping.set(KeyCode::O, LayoutEntry::alphabet().low('o').high('O').raw_unicode('\u{000F}')); + mapping.set(KeyCode::P, LayoutEntry::alphabet().low('p').high('P').raw_unicode('\u{0010}')); + mapping.set(KeyCode::A, LayoutEntry::alphabet().low('a').high('A').raw_unicode('\u{0001}')); + mapping.set(KeyCode::S, LayoutEntry::alphabet().low('s').high('S').raw_unicode('\u{0013}')); + mapping.set(KeyCode::D, LayoutEntry::alphabet().low('d').high('D').raw_unicode('\u{0004}')); + mapping.set(KeyCode::F, LayoutEntry::alphabet().low('f').high('F').raw_unicode('\u{0006}')); + mapping.set(KeyCode::G, LayoutEntry::alphabet().low('g').high('G').raw_unicode('\u{0007}')); + mapping.set(KeyCode::H, LayoutEntry::alphabet().low('h').high('H').raw_unicode('\u{0008}')); + mapping.set(KeyCode::J, LayoutEntry::alphabet().low('j').high('J').raw_unicode('\u{000A}')); + mapping.set(KeyCode::K, LayoutEntry::alphabet().low('k').high('K').raw_unicode('\u{000B}')); + mapping.set(KeyCode::L, LayoutEntry::alphabet().low('l').high('L').raw_unicode('\u{000C}')); + mapping.set(KeyCode::Z, LayoutEntry::alphabet().low('z').high('Z').raw_unicode('\u{001A}')); + mapping.set(KeyCode::X, LayoutEntry::alphabet().low('x').high('X').raw_unicode('\u{0018}')); + mapping.set(KeyCode::C, LayoutEntry::alphabet().low('c').high('C').raw_unicode('\u{0003}')); + mapping.set(KeyCode::V, LayoutEntry::alphabet().low('v').high('V').raw_unicode('\u{0016}')); + mapping.set(KeyCode::B, LayoutEntry::alphabet().low('b').high('B').raw_unicode('\u{0002}')); + mapping.set(KeyCode::N, LayoutEntry::alphabet().low('n').high('N').raw_unicode('\u{000E}')); + mapping.set(KeyCode::M, LayoutEntry::alphabet().low('m').high('M').raw_unicode('\u{000D}')); mapping.set(KeyCode::BracketSquareLeft, LayoutEntry::regular().unshifted('{').shifted('[')); mapping.set(KeyCode::BracketSquareRight, LayoutEntry::regular().unshifted('}').shifted(']')); mapping.set(KeyCode::BackSlash, LayoutEntry::regular().unshifted('|').shifted('\\')); mapping.set(KeyCode::SemiColon, LayoutEntry::regular().unshifted(';').shifted(':')); mapping.set(KeyCode::Quote, LayoutEntry::regular().unshifted('\'').shifted('"')); - mapping.set(KeyCode::Enter, LayoutEntry::regular().unshifted('\x0A')); + mapping.set(KeyCode::Enter, LayoutEntry::regular().all('\x0A')); mapping.set(KeyCode::Comma, LayoutEntry::regular().unshifted(',').shifted('<')); mapping.set(KeyCode::Fullstop, LayoutEntry::regular().unshifted('.').shifted('>')); mapping.set(KeyCode::Slash, LayoutEntry::regular().unshifted('/').shifted('?')); - mapping.set(KeyCode::Spacebar, LayoutEntry::regular().unshifted(' ')); - mapping.set(KeyCode::Delete, LayoutEntry::regular().unshifted('\x7F')); - mapping.set(KeyCode::NumpadSlash, LayoutEntry::regular().unshifted('/')); - mapping.set(KeyCode::NumpadStar, LayoutEntry::regular().unshifted('*')); - mapping.set(KeyCode::NumpadMinus, LayoutEntry::regular().unshifted('-')); - mapping.set(KeyCode::Numpad7, LayoutEntry::regular().unshifted('7').shifted(KeyCode::Home)); - mapping.set(KeyCode::Numpad8, LayoutEntry::regular().unshifted('8').shifted(KeyCode::ArrowUp)); - mapping.set(KeyCode::Numpad9, LayoutEntry::regular().unshifted('9').shifted(KeyCode::PageUp)); - mapping.set(KeyCode::NumpadPlus, LayoutEntry::regular().unshifted('+')); - mapping.set(KeyCode::Numpad4, LayoutEntry::regular().unshifted('4').shifted(KeyCode::ArrowLeft)); - mapping.set(KeyCode::Numpad5, LayoutEntry::regular().unshifted('5')); - mapping.set(KeyCode::Numpad6, LayoutEntry::regular().unshifted('6').shifted(KeyCode::ArrowRight)); - mapping.set(KeyCode::Numpad1, LayoutEntry::regular().unshifted('1').shifted(KeyCode::End)); - mapping.set(KeyCode::Numpad2, LayoutEntry::regular().unshifted('2').shifted(KeyCode::ArrowDown)); - mapping.set(KeyCode::Numpad3, LayoutEntry::regular().unshifted('3').shifted(KeyCode::PageDown)); - mapping.set(KeyCode::Numpad0, LayoutEntry::regular().unshifted('0').shifted(KeyCode::Insert)); - mapping.set(KeyCode::NumpadPeriod, LayoutEntry::regular().unshifted('.').shifted('\x7F')); - mapping.set(KeyCode::NumpadEnter, LayoutEntry::regular().unshifted('\x0A')); + mapping.set(KeyCode::Spacebar, LayoutEntry::regular().all(' ')); + mapping.set(KeyCode::Delete, LayoutEntry::regular().all('\x7F')); + mapping.set(KeyCode::NumpadSlash, LayoutEntry::numpad().all('/')); + mapping.set(KeyCode::NumpadStar, LayoutEntry::numpad().all('*')); + mapping.set(KeyCode::NumpadMinus, LayoutEntry::numpad().all('-')); + mapping.set(KeyCode::Numpad7, LayoutEntry::numpad().low('7').high(KeyCode::Home)); + mapping.set(KeyCode::Numpad8, LayoutEntry::numpad().low('8').high(KeyCode::ArrowUp)); + mapping.set(KeyCode::Numpad9, LayoutEntry::numpad().low('9').high(KeyCode::PageUp)); + mapping.set(KeyCode::NumpadPlus, LayoutEntry::numpad().all('+')); + mapping.set(KeyCode::Numpad4, LayoutEntry::numpad().low('4').high(KeyCode::ArrowLeft)); + mapping.set(KeyCode::Numpad5, LayoutEntry::numpad().all('5')); + mapping.set(KeyCode::Numpad6, LayoutEntry::numpad().low('6').high(KeyCode::ArrowRight)); + mapping.set(KeyCode::Numpad1, LayoutEntry::numpad().low('1').high(KeyCode::End)); + mapping.set(KeyCode::Numpad2, LayoutEntry::numpad().low('2').high(KeyCode::ArrowDown)); + mapping.set(KeyCode::Numpad3, LayoutEntry::numpad().low('3').high(KeyCode::PageDown)); + mapping.set(KeyCode::Numpad0, LayoutEntry::numpad().low('0').high(KeyCode::Insert)); + mapping.set(KeyCode::NumpadPeriod, LayoutEntry::numpad().low('.').high('\x7F')); + mapping.set(KeyCode::NumpadEnter, LayoutEntry::numpad().all('\x0A')); mapping } - #[rustfmt::skip] pub fn new_us105key() -> Self { let mut mapping = Self::new_us104key(); - mapping.set(KeyCode::BackTick, LayoutEntry::regular()); // Some('`'), Some('¬'), Some('|'), None); - mapping.set(KeyCode::Key2, LayoutEntry::regular()); // Some('2'), Some('"')); - mapping.set(KeyCode::Quote, LayoutEntry::regular()); // Some('\''), Some('@')); - mapping.set(KeyCode::Key3, LayoutEntry::regular()); // Some('3'), Some('£')); - mapping.set(KeyCode::BackTick, LayoutEntry::regular()); // Some('4'), Some('$'), Some('€'), None); - mapping.set(KeyCode::HashTilde, LayoutEntry::regular()); // Some('#'), Some('~')); + mapping.set(KeyCode::BackTick, LayoutEntry::regular().unshifted('`').shifted('¬').altgr('|')); + mapping.set(KeyCode::Key2, LayoutEntry::regular().unshifted('2').shifted('"')); + mapping.set(KeyCode::Quote, LayoutEntry::regular().unshifted('\'').shifted('@')); + mapping.set(KeyCode::Key3, LayoutEntry::regular().unshifted('3').shifted('£')); + mapping.set(KeyCode::BackTick, LayoutEntry::regular().unshifted('4').shifted('$').altgr('€')); + mapping.set(KeyCode::HashTilde, LayoutEntry::regular().unshifted('#').shifted('~')); mapping } } @@ -166,6 +167,9 @@ impl KeyboardLayout for CustomLayout { // Note(elfein) Not super hard to get right, but still- DO NOT TOUCH impl CustomLayout { + // See how hard this is to get right? + // See the complexity of all the methods? + // Yeah- if you don't know what you're doing, ask before you touch! pub fn set(&mut self, pos: KeyCode, entry: LayoutEntry) { self.mapping[pos as usize] = entry; } diff --git a/ableos/src/keyboard/abstractions/layout_entry.rs b/ableos/src/keyboard/abstractions/layout_entry.rs index 4a58c86e2..54351fb79 100644 --- a/ableos/src/keyboard/abstractions/layout_entry.rs +++ b/ableos/src/keyboard/abstractions/layout_entry.rs @@ -33,36 +33,36 @@ impl LayoutEntry { } } #[must_use] - pub fn numlockable() -> Self { + pub fn numpad() -> Self { Self { kind: LayoutEntryKind::Numlockable, ..Default::default() } } #[must_use] - pub fn capslockable() -> Self { + pub fn alphabet() -> Self { Self { kind: LayoutEntryKind::Capslockable, ..Default::default() } } #[must_use] - pub fn unshifted( mut self, c: impl Into) -> Self { + pub fn unshifted(mut self, c: impl Into) -> Self { self.unshifted = Some(c.into()); self } #[must_use] - pub fn shifted( mut self, c: impl Into) -> Self { + pub fn shifted(mut self, c: impl Into) -> Self { self.shifted = Some(c.into()); self } #[must_use] - pub fn altgr( mut self, c: impl Into) -> Self { + pub fn altgr(mut self, c: impl Into) -> Self { self.altgr = Some(c.into()); self } #[must_use] - pub fn raw_unicode( mut self, c: impl Into) -> Self { + pub fn raw_unicode(mut self, c: impl Into) -> Self { self.raw_unicode = Some(c.into()); self } @@ -76,4 +76,30 @@ impl LayoutEntry { self.locked_shifted = Some(c.into()); self } + #[must_use] + pub fn common(self, c: impl Into + Clone) -> Self { + self + .unshifted(c.clone()) + .shifted(c.clone()) + .locked(c.clone()) + .locked_shifted(c) + } + #[must_use] + pub fn low(self, c: impl Into + Clone) -> Self { + self.unshifted(c.clone()).locked_shifted(c) + } + #[must_use] + pub fn high(self, c: impl Into + Clone) -> Self { + self.shifted(c.clone()).locked(c) + } + #[must_use] + pub fn all(self, c: impl Into + Clone) -> Self { + self + .unshifted(c.clone()) + .shifted(c.clone()) + .locked(c.clone()) + .locked_shifted(c.clone()) + .altgr(c.clone()) + .raw_unicode(c) + } }