use crate::{LockStateChecker, ModifierChecker};
use fidl_fuchsia_ui_input3::{LockState, Modifiers};
use lazy_static::lazy_static;
lazy_static! {
pub(crate) static ref QWERTY_MAP: Vec<Option<KeyLevels>> = vec![
None,
None,
None,
None,
Some(('a', Some('A'), true).into()),
Some(('b', Some('B'), true).into()),
Some(('c', Some('C'), true).into()),
Some(('d', Some('D'), true).into()),
Some(('e', Some('E'), true).into()),
Some(('f', Some('F'), true).into()),
Some(('g', Some('G'), true).into()),
Some(('h', Some('H'), true).into()),
Some(('i', Some('I'), true).into()),
Some(('j', Some('J'), true).into()),
Some(('k', Some('K'), true).into()),
Some(('l', Some('L'), true).into()),
Some(('m', Some('M'), true).into()),
Some(('n', Some('N'), true).into()),
Some(('o', Some('O'), true).into()),
Some(('p', Some('P'), true).into()),
Some(('q', Some('Q'), true).into()),
Some(('r', Some('R'), true).into()),
Some(('s', Some('S'), true).into()),
Some(('t', Some('T'), true).into()),
Some(('u', Some('U'), true).into()),
Some(('v', Some('V'), true).into()),
Some(('w', Some('W'), true).into()),
Some(('x', Some('X'), true).into()),
Some(('y', Some('Y'), true).into()),
Some(('z', Some('Z'), true).into()),
Some(('1', Some('!')).into()),
Some(('2', Some('@')).into()),
Some(('3', Some('#')).into()),
Some(('4', Some('$')).into()),
Some(('5', Some('%')).into()),
Some(('6', Some('^')).into()),
Some(('7', Some('&')).into()),
Some(('8', Some('*')).into()),
Some(('9', Some('(')).into()),
Some(('0', Some(')')).into()),
None,
None,
None,
None,
Some((' ', Some(' ')).into()),
Some(('-', Some('_')).into()),
Some(('=', Some('+')).into()),
Some(('[', Some('{')).into()),
Some((']', Some('}')).into()),
Some(('\\', Some('|')).into()),
None,
Some((';', Some(':')).into()),
Some(('\'', Some('"')).into()),
Some(('`', Some('~')).into()),
Some((',', Some('<')).into()),
Some(('.', Some('>')).into()),
Some(('/', Some('?')).into()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
Some(('/', None).into()),
Some(('*', None).into()),
Some(('-', None).into()),
Some(('+', None).into()),
None,
Some(('1', None).into()),
Some(('2', None).into()),
Some(('3', None).into()),
Some(('4', None).into()),
Some(('5', None).into()),
Some(('6', None).into()),
Some(('7', None).into()),
Some(('8', None).into()),
Some(('9', None).into()),
Some(('0', None).into()),
Some(('.', None).into()),
];
pub(crate) static ref DVORAK_MAP: Vec<Option<KeyLevels>> = vec![
None,
None,
None,
None,
Some(('a', Some('A'), true).into()),
Some(('x', Some('X'), true).into()),
Some(('j', Some('J'), true).into()),
Some(('e', Some('E'), true).into()),
Some(('.', Some('>')).into()),
Some(('u', Some('U'), true).into()),
Some(('i', Some('I'), true).into()),
Some(('d', Some('D'), true).into()),
Some(('c', Some('C'), true).into()),
Some(('h', Some('H'), true).into()),
Some(('t', Some('T'), true).into()),
Some(('n', Some('N'), true).into()),
Some(('m', Some('M'), true).into()),
Some(('b', Some('B'), true).into()),
Some(('r', Some('R'), true).into()),
Some(('l', Some('L'), true).into()),
Some(('\'', Some('"')).into()),
Some(('p', Some('P'), true).into()),
Some(('o', Some('O'), true).into()),
Some(('y', Some('Y'), true).into()),
Some(('g', Some('G'), true).into()),
Some(('k', Some('K'), true).into()),
Some((',', Some('<')).into()),
Some(('q', Some('Q'), true).into()),
Some(('f', Some('F'), true).into()),
Some((';', Some(':')).into()),
Some(('1', Some('!')).into()),
Some(('2', Some('@')).into()),
Some(('3', Some('#')).into()),
Some(('4', Some('$')).into()),
Some(('5', Some('%')).into()),
Some(('6', Some('^')).into()),
Some(('7', Some('&')).into()),
Some(('8', Some('*')).into()),
Some(('9', Some('(')).into()),
Some(('0', Some(')')).into()),
None,
None,
None,
None,
Some((' ', Some(' ')).into()),
Some(('[', Some('{')).into()),
Some((']', Some('}')).into()),
Some(('/', Some('?')).into()),
Some(('=', Some('+')).into()),
Some(('\\', Some('|')).into()),
None,
Some(('s', Some('S'), true).into()),
Some(('-', Some('_')).into()),
Some(('`', Some('~')).into()),
Some(('w', Some('W'), true).into()),
Some(('v', Some('V'), true).into()),
Some(('z', Some('Z'), true).into()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
Some(('/', None).into()),
Some(('*', None).into()),
Some(('-', None).into()),
Some(('+', None).into()),
None,
Some(('1', None).into()),
Some(('2', None).into()),
Some(('3', None).into()),
Some(('4', None).into()),
Some(('5', None).into()),
Some(('6', None).into()),
Some(('7', None).into()),
Some(('8', None).into()),
Some(('9', None).into()),
Some(('0', None).into()),
Some(('.', None).into()),
];
pub(crate) static ref FR_AZERTY_MAP: Vec<Option<KeyLevels>> = vec![
None,
None,
None,
None,
Some(('q', Some('Q'), true).into()),
Some(('b', Some('B'), true).into()),
Some(('c', Some('C'), true).into()),
Some(('d', Some('D'), true).into()),
Some(('e', Some('E'), true).into()),
Some(('f', Some('F'), true).into()),
Some(('g', Some('G'), true).into()),
Some(('h', Some('H'), true).into()),
Some(('i', Some('I'), true).into()),
Some(('j', Some('J'), true).into()),
Some(('k', Some('K'), true).into()),
Some(('l', Some('L'), true).into()),
Some((',', Some('?')).into()),
Some(('n', Some('N'), true).into()),
Some(('o', Some('O'), true).into()),
Some(('p', Some('P'), true).into()),
Some(('a', Some('A'), true).into()),
Some(('r', Some('R'), true).into()),
Some(('s', Some('S'), true).into()),
Some(('t', Some('T'), true).into()),
Some(('u', Some('U'), true).into()),
Some(('v', Some('V'), true).into()),
Some(('z', Some('Z'), true).into()),
Some(('x', Some('X'), true).into()),
Some(('y', Some('Y'), true).into()),
Some(('w', Some('W'), true).into()),
Some(('&', Some('1')).into()),
Some(('é', Some('2')).into()),
Some(('"', Some('3')).into()),
Some(('\'', Some('4')).into()),
Some(('(', Some('5')).into()),
Some(('-', Some('6')).into()),
Some(('è', Some('7')).into()),
Some(('—', Some('8')).into()),
Some(('ç', Some('9')).into()),
Some(('à', Some('0')).into()),
None,
None,
None,
None,
Some((' ', Some(' ')).into()),
Some((')', Some('°')).into()),
Some(('=', Some('+')).into()),
Some(('\u{0302}', Some('\u{0308}')).into()), Some(('$', Some('£')).into()),
Some(('\\', Some('|')).into()), None,
Some(('m', Some('M'), true).into()),
Some(('\'', Some('"')).into()),
Some(('²', None).into()),
Some((';', Some('.')).into()),
Some((':', Some('/')).into()),
Some(('!', Some('§')).into()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
Some(('/', None).into()),
Some(('*', None).into()),
Some(('-', None).into()),
Some(('+', None).into()),
None,
Some(('1', None).into()),
Some(('2', None).into()),
Some(('3', None).into()),
Some(('4', None).into()),
Some(('5', None).into()),
Some(('6', None).into()),
Some(('7', None).into()),
Some(('8', None).into()),
Some(('9', None).into()),
Some(('0', None).into()),
Some(('.', None).into()),
];
pub(crate) static ref COLEMAK_MAP: Vec<Option<KeyLevels>> = vec![
None,
None,
None,
None,
Some(('a', Some('A'), true).into()),
Some(('b', Some('B'), true).into()),
Some(('c', Some('C'), true).into()),
Some(('s', Some('S'), true).into()),
Some(('f', Some('F'), true).into()),
Some(('t', Some('T'), true).into()),
Some(('d', Some('D'), true).into()),
Some(('h', Some('H'), true).into()),
Some(('u', Some('U'), true).into()),
Some(('n', Some('N'), true).into()),
Some(('e', Some('E'), true).into()),
Some(('i', Some('I'), true).into()),
Some(('m', Some('M'), true).into()),
Some(('k', Some('K'), true).into()),
Some(('y', Some('Y'), true).into()),
Some((';', Some(':')).into()),
Some(('q', Some('Q'), true).into()),
Some(('p', Some('P'), true).into()),
Some(('r', Some('R'), true).into()),
Some(('g', Some('G'), true).into()),
Some(('l', Some('L'), true).into()),
Some(('v', Some('V'), true).into()),
Some(('w', Some('W'), true).into()),
Some(('x', Some('X'), true).into()),
Some(('j', Some('J'), true).into()),
Some(('z', Some('Z'), true).into()),
Some(('1', Some('!')).into()),
Some(('2', Some('@')).into()),
Some(('3', Some('#')).into()),
Some(('4', Some('$')).into()),
Some(('5', Some('%')).into()),
Some(('6', Some('^')).into()),
Some(('7', Some('&')).into()),
Some(('8', Some('*')).into()),
Some(('9', Some('(')).into()),
Some(('0', Some(')')).into()),
None,
None,
None,
None,
Some((' ', Some(' ')).into()),
Some(('-', Some('_')).into()),
Some(('=', Some('+')).into()),
Some(('[', Some('{')).into()),
Some((']', Some('}')).into()),
Some(('\\', Some('|')).into()),
None,
Some(('o', Some('O'), true).into()),
Some(('\'', Some('"')).into()),
Some(('`', Some('~')).into()),
Some((',', Some('<')).into()),
Some(('.', Some('>')).into()),
Some(('/', Some('?')).into()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
Some(('/', None).into()),
Some(('*', None).into()),
Some(('-', None).into()),
Some(('+', None).into()),
None,
Some(('1', None).into()),
Some(('2', None).into()),
Some(('3', None).into()),
Some(('4', None).into()),
Some(('5', None).into()),
Some(('6', None).into()),
Some(('7', None).into()),
Some(('8', None).into()),
Some(('9', None).into()),
Some(('0', None).into()),
Some(('.', None).into()),
];
}
pub struct KeyLevels {
pub(crate) ch: char,
pub(crate) shift_ch: Option<char>,
is_letter: bool,
}
impl From<(char, Option<char>)> for KeyLevels {
fn from(s: (char, Option<char>)) -> Self {
KeyLevels { ch: s.0, shift_ch: s.1, is_letter: false }
}
}
impl From<(char, Option<char>, bool)> for KeyLevels {
fn from(s: (char, Option<char>, bool)) -> Self {
KeyLevels { ch: s.0, shift_ch: s.1, is_letter: s.2 }
}
}
impl KeyLevels {
pub fn get_key(&self, m: &impl ModifierChecker, l: &impl LockStateChecker) -> Option<char> {
if (l.test(LockState::CAPS_LOCK) && self.is_letter) || m.test(Modifiers::SHIFT) {
return self.shift_ch;
}
Some(self.ch)
}
}