Commit febfbfed authored by Waylon Cude's avatar Waylon Cude Committed by Jeremy Soller

Added dvorak keymap (#752)

Keymaps are passed as arguments to ps2d.
To select the dvorak keymap use `ps2d dvorak`,
otherwise the kymap will default to english.
parent 08557a7c
static ENGLISH: [[char; 2]; 58] = [
['\0', '\0'],
['\x1B', '\x1B'],
['1', '!'],
['2', '@'],
['3', '#'],
['4', '$'],
['5', '%'],
['6', '^'],
['7', '&'],
['8', '*'],
['9', '('],
['0', ')'],
['-', '_'],
['=', '+'],
['\x7F', '\x7F'],
['\t', '\t'],
['q', 'Q'],
['w', 'W'],
['e', 'E'],
['r', 'R'],
['t', 'T'],
['y', 'Y'],
['u', 'U'],
['i', 'I'],
['o', 'O'],
['p', 'P'],
['[', '{'],
[']', '}'],
['\n', '\n'],
['\0', '\0'],
['a', 'A'],
['s', 'S'],
['d', 'D'],
['f', 'F'],
['g', 'G'],
['h', 'H'],
['j', 'J'],
['k', 'K'],
['l', 'L'],
[';', ':'],
['\'', '"'],
['`', '~'],
['\0', '\0'],
['\\', '|'],
['z', 'Z'],
['x', 'X'],
['c', 'C'],
['v', 'V'],
['b', 'B'],
['n', 'N'],
['m', 'M'],
[',', '<'],
['.', '>'],
['/', '?'],
['\0', '\0'],
['\0', '\0'],
['\0', '\0'],
[' ', ' ']
];
pub mod english {
static ENGLISH: [[char; 2]; 58] = [
['\0', '\0'],
['\x1B', '\x1B'],
['1', '!'],
['2', '@'],
['3', '#'],
['4', '$'],
['5', '%'],
['6', '^'],
['7', '&'],
['8', '*'],
['9', '('],
['0', ')'],
['-', '_'],
['=', '+'],
['\x7F', '\x7F'],
['\t', '\t'],
['q', 'Q'],
['w', 'W'],
['e', 'E'],
['r', 'R'],
['t', 'T'],
['y', 'Y'],
['u', 'U'],
['i', 'I'],
['o', 'O'],
['p', 'P'],
['[', '{'],
[']', '}'],
['\n', '\n'],
['\0', '\0'],
['a', 'A'],
['s', 'S'],
['d', 'D'],
['f', 'F'],
['g', 'G'],
['h', 'H'],
['j', 'J'],
['k', 'K'],
['l', 'L'],
[';', ':'],
['\'', '"'],
['`', '~'],
['\0', '\0'],
['\\', '|'],
['z', 'Z'],
['x', 'X'],
['c', 'C'],
['v', 'V'],
['b', 'B'],
['n', 'N'],
['m', 'M'],
[',', '<'],
['.', '>'],
['/', '?'],
['\0', '\0'],
['\0', '\0'],
['\0', '\0'],
[' ', ' ']
];
pub fn get_char(scancode: u8, shift: bool) -> char {
if let Some(c) = ENGLISH.get(scancode as usize) {
if shift {
c[1]
pub fn get_char(scancode: u8, shift: bool) -> char {
if let Some(c) = ENGLISH.get(scancode as usize) {
if shift {
c[1]
} else {
c[0]
}
} else {
c[0]
'\0'
}
}
}
pub mod dvorak {
static DVORAK: [[char; 2]; 58] = [
['\0', '\0'],
['\x1B', '\x1B'],
['1', '!'],
['2', '@'],
['3', '#'],
['4', '$'],
['5', '%'],
['6', '^'],
['7', '&'],
['8', '*'],
['9', '('],
['0', ')'],
['[', '{'],
[']', '}'],
['\x7F', '\x7F'],
['\t', '\t'],
['\'', '"'],
[',', '<'],
['.', '>'],
['p', 'P'],
['y', 'Y'],
['f', 'F'],
['g', 'G'],
['c', 'C'],
['r', 'R'],
['l', 'L'],
['/', '?'],
['=', '+'],
['\n', '\n'],
['\0', '\0'],
['a', 'A'],
['o', 'O'],
['e', 'E'],
['u', 'U'],
['i', 'I'],
['d', 'D'],
['h', 'H'],
['t', 'T'],
['n', 'N'],
['s', 'S'],
['-', '_'],
['`', '~'],
['\0', '\0'],
['\\', '|'],
[';', ':'],
['q', 'Q'],
['j', 'J'],
['k', 'K'],
['x', 'X'],
['b', 'B'],
['m', 'M'],
['w', 'W'],
['v', 'V'],
['z', 'Z'],
['\0', '\0'],
['\0', '\0'],
['\0', '\0'],
[' ', ' ']
];
pub fn get_char(scancode: u8, shift: bool) -> char {
if let Some(c) = DVORAK.get(scancode as usize) {
if shift {
c[1]
} else {
c[0]
}
} else {
'\0'
}
} else {
'\0'
}
}
......@@ -7,6 +7,7 @@ extern crate io;
extern crate orbclient;
extern crate syscall;
use std::env;
use std::fs::File;
use std::io::{Read, Write, Result};
use std::os::unix::io::AsRawFd;
......@@ -32,24 +33,27 @@ bitflags! {
}
}
struct Ps2d {
struct Ps2d<'a> {
input: File,
lshift: bool,
rshift: bool,
packets: [u8; 4],
packet_i: usize,
extra_packet: bool
extra_packet: bool,
//Keymap function
get_char: &'a Fn(u8,bool) -> char
}
impl Ps2d {
fn new(input: File, extra_packet: bool) -> Self {
impl<'a> Ps2d<'a> {
fn new(input: File, extra_packet: bool, keymap: &'a Fn(u8,bool) -> char) -> Self {
Ps2d {
input: input,
lshift: false,
rshift: false,
packets: [0; 4],
packet_i: 0,
extra_packet: extra_packet
extra_packet: extra_packet,
get_char: keymap
}
}
......@@ -68,7 +72,7 @@ impl Ps2d {
}
self.input.write(&KeyEvent {
character: keymap::get_char(scancode, self.lshift || self.rshift),
character: (self.get_char)(scancode, self.lshift || self.rshift),
scancode: scancode,
pressed: pressed
}.to_event()).expect("ps2d: failed to write key event");
......@@ -128,8 +132,15 @@ fn main() {
let input = File::open("display:input").expect("ps2d: failed to open display:input");
let extra_packet = controller::Ps2::new().init();
let mut ps2d = Ps2d::new(input, extra_packet);
let keymap = match env::args().skip(1).next() {
Some(k) => match k.to_lowercase().as_ref() {
"dvorak" => (keymap::dvorak::get_char),
"english" => (keymap::english::get_char),
&_ => (keymap::english::get_char)
},
None => (keymap::english::get_char)
};
let mut ps2d = Ps2d::new(input, extra_packet,&keymap);
let mut event_queue = EventQueue::<(bool, u8)>::new().expect("ps2d: failed to create event queue");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment