inputd: Implement keymap

This commit is contained in:
Wildan M
2026-01-14 11:35:48 +07:00
parent 6091b46620
commit 3d04f523b4
14 changed files with 645 additions and 1302 deletions
+439
View File
@@ -0,0 +1,439 @@
use std::collections::HashMap;
use std::fmt::Display;
use std::str::FromStr;
mod keymaps {
pub static US: [(u8, [char; 2]); 53] = [
(orbclient::K_ESC, ['\x1B', '\x1B']),
(orbclient::K_1, ['1', '!']),
(orbclient::K_2, ['2', '@']),
(orbclient::K_3, ['3', '#']),
(orbclient::K_4, ['4', '$']),
(orbclient::K_5, ['5', '%']),
(orbclient::K_6, ['6', '^']),
(orbclient::K_7, ['7', '&']),
(orbclient::K_8, ['8', '*']),
(orbclient::K_9, ['9', '(']),
(orbclient::K_0, ['0', ')']),
(orbclient::K_MINUS, ['-', '_']),
(orbclient::K_EQUALS, ['=', '+']),
(orbclient::K_BKSP, ['\x7F', '\x7F']),
(orbclient::K_TAB, ['\t', '\t']),
(orbclient::K_Q, ['q', 'Q']),
(orbclient::K_W, ['w', 'W']),
(orbclient::K_E, ['e', 'E']),
(orbclient::K_R, ['r', 'R']),
(orbclient::K_T, ['t', 'T']),
(orbclient::K_Y, ['y', 'Y']),
(orbclient::K_U, ['u', 'U']),
(orbclient::K_I, ['i', 'I']),
(orbclient::K_O, ['o', 'O']),
(orbclient::K_P, ['p', 'P']),
(orbclient::K_BRACE_OPEN, ['[', '{']),
(orbclient::K_BRACE_CLOSE, [']', '}']),
(orbclient::K_ENTER, ['\n', '\n']),
(orbclient::K_CTRL, ['\0', '\0']),
(orbclient::K_A, ['a', 'A']),
(orbclient::K_S, ['s', 'S']),
(orbclient::K_D, ['d', 'D']),
(orbclient::K_F, ['f', 'F']),
(orbclient::K_G, ['g', 'G']),
(orbclient::K_H, ['h', 'H']),
(orbclient::K_J, ['j', 'J']),
(orbclient::K_K, ['k', 'K']),
(orbclient::K_L, ['l', 'L']),
(orbclient::K_SEMICOLON, [';', ':']),
(orbclient::K_QUOTE, ['\'', '"']),
(orbclient::K_TICK, ['`', '~']),
(orbclient::K_BACKSLASH, ['\\', '|']),
(orbclient::K_Z, ['z', 'Z']),
(orbclient::K_X, ['x', 'X']),
(orbclient::K_C, ['c', 'C']),
(orbclient::K_V, ['v', 'V']),
(orbclient::K_B, ['b', 'B']),
(orbclient::K_N, ['n', 'N']),
(orbclient::K_M, ['m', 'M']),
(orbclient::K_COMMA, [',', '<']),
(orbclient::K_PERIOD, ['.', '>']),
(orbclient::K_SLASH, ['/', '?']),
(orbclient::K_SPACE, [' ', ' ']),
];
pub static GB: [(u8, [char; 2]); 54] = [
(orbclient::K_ESC, ['\x1B', '\x1B']),
(orbclient::K_1, ['1', '!']),
(orbclient::K_2, ['2', '"']),
(orbclient::K_3, ['3', '£']),
(orbclient::K_4, ['4', '$']),
(orbclient::K_5, ['5', '%']),
(orbclient::K_6, ['6', '^']),
(orbclient::K_7, ['7', '&']),
(orbclient::K_8, ['8', '*']),
(orbclient::K_9, ['9', '(']),
(orbclient::K_0, ['0', ')']),
(orbclient::K_MINUS, ['-', '_']),
(orbclient::K_EQUALS, ['=', '+']),
(orbclient::K_BKSP, ['\x7F', '\x7F']),
(orbclient::K_TAB, ['\t', '\t']),
(orbclient::K_Q, ['q', 'Q']),
(orbclient::K_W, ['w', 'W']),
(orbclient::K_E, ['e', 'E']),
(orbclient::K_R, ['r', 'R']),
(orbclient::K_T, ['t', 'T']),
(orbclient::K_Y, ['y', 'Y']),
(orbclient::K_U, ['u', 'U']),
(orbclient::K_I, ['i', 'I']),
(orbclient::K_O, ['o', 'O']),
(orbclient::K_P, ['p', 'P']),
(orbclient::K_BRACE_OPEN, ['[', '{']),
(orbclient::K_BRACE_CLOSE, [']', '}']),
(orbclient::K_ENTER, ['\n', '\n']),
(orbclient::K_CTRL, ['\0', '\0']),
(orbclient::K_A, ['a', 'A']),
(orbclient::K_S, ['s', 'S']),
(orbclient::K_D, ['d', 'D']),
(orbclient::K_F, ['f', 'F']),
(orbclient::K_G, ['g', 'G']),
(orbclient::K_H, ['h', 'H']),
(orbclient::K_J, ['j', 'J']),
(orbclient::K_K, ['k', 'K']),
(orbclient::K_L, ['l', 'L']),
(orbclient::K_SEMICOLON, [';', ':']),
(orbclient::K_QUOTE, ['\'', '@']),
(orbclient::K_TICK, ['`', '¬']),
(orbclient::K_BACKSLASH, ['#', '~']),
(orbclient::K_Z, ['z', 'Z']),
(orbclient::K_X, ['x', 'X']),
(orbclient::K_C, ['c', 'C']),
(orbclient::K_V, ['v', 'V']),
(orbclient::K_B, ['b', 'B']),
(orbclient::K_N, ['n', 'N']),
(orbclient::K_M, ['m', 'M']),
(orbclient::K_COMMA, [',', '<']),
(orbclient::K_PERIOD, ['.', '>']),
(orbclient::K_SLASH, ['/', '?']),
(orbclient::K_SPACE, [' ', ' ']),
// UK Backslash, doesn't exist on US keyboard
(0x56, ['\\', '|']),
];
pub static DVORAK: [(u8, [char; 2]); 53] = [
(orbclient::K_ESC, ['\x1B', '\x1B']),
(orbclient::K_1, ['1', '!']),
(orbclient::K_2, ['2', '@']),
(orbclient::K_3, ['3', '#']),
(orbclient::K_4, ['4', '$']),
(orbclient::K_5, ['5', '%']),
(orbclient::K_6, ['6', '^']),
(orbclient::K_7, ['7', '&']),
(orbclient::K_8, ['8', '*']),
(orbclient::K_9, ['9', '(']),
(orbclient::K_0, ['0', ')']),
(orbclient::K_MINUS, ['[', '{']),
(orbclient::K_EQUALS, [']', '}']),
(orbclient::K_BKSP, ['\x7F', '\x7F']),
(orbclient::K_TAB, ['\t', '\t']),
(orbclient::K_Q, ['\'', '"']),
(orbclient::K_W, [',', '<']),
(orbclient::K_E, ['.', '>']),
(orbclient::K_R, ['p', 'P']),
(orbclient::K_T, ['y', 'Y']),
(orbclient::K_Y, ['f', 'F']),
(orbclient::K_U, ['g', 'G']),
(orbclient::K_I, ['c', 'C']),
(orbclient::K_O, ['r', 'R']),
(orbclient::K_P, ['l', 'L']),
(orbclient::K_BRACE_OPEN, ['/', '?']),
(orbclient::K_BRACE_CLOSE, ['=', '+']),
(orbclient::K_ENTER, ['\n', '\n']),
(orbclient::K_CTRL, ['\0', '\0']),
(orbclient::K_A, ['a', 'A']),
(orbclient::K_S, ['o', 'O']),
(orbclient::K_D, ['e', 'E']),
(orbclient::K_F, ['u', 'U']),
(orbclient::K_G, ['i', 'I']),
(orbclient::K_H, ['d', 'D']),
(orbclient::K_J, ['h', 'H']),
(orbclient::K_K, ['t', 'T']),
(orbclient::K_L, ['n', 'N']),
(orbclient::K_SEMICOLON, ['s', 'S']),
(orbclient::K_QUOTE, ['-', '_']),
(orbclient::K_TICK, ['`', '~']),
(orbclient::K_BACKSLASH, ['\\', '|']),
(orbclient::K_Z, [';', ':']),
(orbclient::K_X, ['q', 'Q']),
(orbclient::K_C, ['j', 'J']),
(orbclient::K_V, ['k', 'K']),
(orbclient::K_B, ['x', 'X']),
(orbclient::K_N, ['b', 'B']),
(orbclient::K_M, ['m', 'M']),
(orbclient::K_COMMA, ['w', 'W']),
(orbclient::K_PERIOD, ['v', 'V']),
(orbclient::K_SLASH, ['z', 'Z']),
(orbclient::K_SPACE, [' ', ' ']),
];
pub static AZERTY: [(u8, [char; 2]); 53] = [
(orbclient::K_ESC, ['\x1B', '\x1B']),
(orbclient::K_1, ['&', '1']),
(orbclient::K_2, ['é', '2']),
(orbclient::K_3, ['"', '3']),
(orbclient::K_4, ['\'', '4']),
(orbclient::K_5, ['(', '5']),
(orbclient::K_6, ['|', '6']),
(orbclient::K_7, ['è', '7']),
(orbclient::K_8, ['_', '8']),
(orbclient::K_9, ['ç', '9']),
(orbclient::K_0, ['à', '0']),
(orbclient::K_MINUS, [')', '°']),
(orbclient::K_EQUALS, ['=', '+']),
(orbclient::K_BKSP, ['\x7F', '\x7F']),
(orbclient::K_TAB, ['\t', '\t']),
(orbclient::K_Q, ['a', 'A']),
(orbclient::K_W, ['z', 'Z']),
(orbclient::K_E, ['e', 'E']),
(orbclient::K_R, ['r', 'R']),
(orbclient::K_T, ['t', 'T']),
(orbclient::K_Y, ['y', 'Y']),
(orbclient::K_U, ['u', 'U']),
(orbclient::K_I, ['i', 'I']),
(orbclient::K_O, ['o', 'O']),
(orbclient::K_P, ['p', 'P']),
(orbclient::K_BRACE_OPEN, ['^', '¨']),
(orbclient::K_BRACE_CLOSE, ['$', '£']),
(orbclient::K_ENTER, ['\n', '\n']),
(orbclient::K_CTRL, ['\0', '\0']),
(orbclient::K_A, ['q', 'Q']),
(orbclient::K_S, ['s', 'S']),
(orbclient::K_D, ['d', 'D']),
(orbclient::K_F, ['f', 'F']),
(orbclient::K_G, ['g', 'G']),
(orbclient::K_H, ['h', 'H']),
(orbclient::K_J, ['j', 'J']),
(orbclient::K_K, ['k', 'K']),
(orbclient::K_L, ['l', 'L']),
(orbclient::K_SEMICOLON, ['m', 'M']),
(orbclient::K_QUOTE, ['ù', '%']),
(orbclient::K_TICK, ['*', 'µ']),
(orbclient::K_BACKSLASH, ['ê', 'Ê']),
(orbclient::K_Z, ['w', 'W']),
(orbclient::K_X, ['x', 'X']),
(orbclient::K_C, ['c', 'C']),
(orbclient::K_V, ['v', 'V']),
(orbclient::K_B, ['b', 'B']),
(orbclient::K_N, ['n', 'N']),
(orbclient::K_M, [',', '?']),
(orbclient::K_COMMA, [';', '.']),
(orbclient::K_PERIOD, [':', '/']),
(orbclient::K_SLASH, ['!', '§']),
(orbclient::K_SPACE, [' ', ' ']),
];
pub static BEPO: [(u8, [char; 2]); 53] = [
(orbclient::K_ESC, ['\x1B', '\x1B']),
(orbclient::K_1, ['"', '1']),
(orbclient::K_2, ['«', '2']),
(orbclient::K_3, ['»', '3']),
(orbclient::K_4, ['(', '4']),
(orbclient::K_5, [')', '5']),
(orbclient::K_6, ['@', '6']),
(orbclient::K_7, ['+', '7']),
(orbclient::K_8, ['-', '8']),
(orbclient::K_9, ['/', '9']),
(orbclient::K_0, ['*', '0']),
(orbclient::K_MINUS, ['=', '°']),
(orbclient::K_EQUALS, ['%', '`']),
(orbclient::K_BKSP, ['\x7F', '\x7F']),
(orbclient::K_TAB, ['\t', '\t']),
(orbclient::K_Q, ['b', 'B']),
(orbclient::K_W, ['é', 'É']),
(orbclient::K_E, ['p', 'P']),
(orbclient::K_R, ['o', 'O']),
(orbclient::K_T, ['è', 'È']),
(orbclient::K_Y, ['^', '!']),
(orbclient::K_U, ['v', 'V']),
(orbclient::K_I, ['d', 'D']),
(orbclient::K_O, ['l', 'L']),
(orbclient::K_P, ['j', 'J']),
(orbclient::K_BRACE_OPEN, ['z', 'Z']),
(orbclient::K_BRACE_CLOSE, ['w', 'W']),
(orbclient::K_ENTER, ['\n', '\n']),
(orbclient::K_CTRL, ['\0', '\0']),
(orbclient::K_A, ['a', 'A']),
(orbclient::K_S, ['u', 'U']),
(orbclient::K_D, ['i', 'I']),
(orbclient::K_F, ['e', 'E']),
(orbclient::K_G, [',', ';']),
(orbclient::K_H, ['c', 'C']),
(orbclient::K_J, ['t', 'T']),
(orbclient::K_K, ['s', 'S']),
(orbclient::K_L, ['r', 'R']),
(orbclient::K_SEMICOLON, ['n', 'N']),
(orbclient::K_QUOTE, ['m', 'M']),
(orbclient::K_TICK, ['ç', 'Ç']),
(orbclient::K_BACKSLASH, ['ê', 'Ê']),
(orbclient::K_Z, ['à', 'À']),
(orbclient::K_X, ['y', 'Y']),
(orbclient::K_C, ['x', 'X']),
(orbclient::K_V, ['.', ':']),
(orbclient::K_B, ['k', 'K']),
(orbclient::K_N, ['\'', '?']),
(orbclient::K_M, ['q', 'Q']),
(orbclient::K_COMMA, ['g', 'G']),
(orbclient::K_PERIOD, ['h', 'H']),
(orbclient::K_SLASH, ['f', 'F']),
(orbclient::K_SPACE, [' ', ' ']),
];
pub static IT: [(u8, [char; 2]); 53] = [
(orbclient::K_ESC, ['\x1B', '\x1B']),
(orbclient::K_1, ['1', '!']),
(orbclient::K_2, ['2', '"']),
(orbclient::K_3, ['3', '£']),
(orbclient::K_4, ['4', '$']),
(orbclient::K_5, ['5', '%']),
(orbclient::K_6, ['6', '&']),
(orbclient::K_7, ['7', '/']),
(orbclient::K_8, ['8', '(']),
(orbclient::K_9, ['9', ')']),
(orbclient::K_0, ['0', '=']),
(orbclient::K_MINUS, ['?', '\'']),
(orbclient::K_EQUALS, ['ì', '^']),
(orbclient::K_BKSP, ['\x7F', '\x7F']),
(orbclient::K_TAB, ['\t', '\t']),
(orbclient::K_Q, ['q', 'Q']),
(orbclient::K_W, ['w', 'W']),
(orbclient::K_E, ['e', 'E']),
(orbclient::K_R, ['r', 'R']),
(orbclient::K_T, ['t', 'T']),
(orbclient::K_Y, ['y', 'Y']),
(orbclient::K_U, ['u', 'U']),
(orbclient::K_I, ['i', 'I']),
(orbclient::K_O, ['o', 'O']),
(orbclient::K_P, ['p', 'P']),
(orbclient::K_BRACE_OPEN, ['è', 'é']),
(orbclient::K_BRACE_CLOSE, ['+', '*']),
(orbclient::K_ENTER, ['\n', '\n']),
(orbclient::K_CTRL, ['\x20', '\x20']),
(orbclient::K_A, ['a', 'A']),
(orbclient::K_S, ['s', 'S']),
(orbclient::K_D, ['d', 'D']),
(orbclient::K_F, ['f', 'F']),
(orbclient::K_G, ['g', 'G']),
(orbclient::K_H, ['h', 'H']),
(orbclient::K_J, ['j', 'J']),
(orbclient::K_K, ['k', 'K']),
(orbclient::K_L, ['l', 'L']),
(orbclient::K_SEMICOLON, ['ò', 'ç']),
(orbclient::K_QUOTE, ['à', '°']),
(orbclient::K_TICK, ['ù', '§']),
(orbclient::K_BACKSLASH, ['<', '>']),
(orbclient::K_Z, ['z', 'Z']),
(orbclient::K_X, ['x', 'X']),
(orbclient::K_C, ['c', 'C']),
(orbclient::K_V, ['v', 'V']),
(orbclient::K_B, ['b', 'B']),
(orbclient::K_N, ['n', 'N']),
(orbclient::K_M, ['m', 'M']),
(orbclient::K_COMMA, [',', ';']),
(orbclient::K_PERIOD, ['.', ':']),
(orbclient::K_SLASH, ['-', '_']),
(orbclient::K_SPACE, [' ', ' ']),
];
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(usize)]
pub enum KeymapKind {
US = 0,
GB,
Dvorak,
Azerty,
Bepo,
IT,
}
impl From<usize> for KeymapKind {
fn from(value: usize) -> Self {
if value > (KeymapKind::IT as usize) {
KeymapKind::US
} else {
// SAFETY: Checked above
unsafe { std::mem::transmute(value) }
}
}
}
#[allow(missing_copy_implementations)]
#[derive(Debug, PartialEq, Eq)]
pub struct ParseKeymapError(());
impl FromStr for KeymapKind {
type Err = ParseKeymapError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let keymap = match s {
"dvorak" => KeymapKind::Dvorak,
"us" => KeymapKind::US,
"gb" => KeymapKind::GB,
"azerty" => KeymapKind::Azerty,
"bepo" => KeymapKind::Bepo,
"it" => KeymapKind::IT,
&_ => return Err(ParseKeymapError(())),
};
Ok(keymap)
}
}
impl Display for KeymapKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match *self {
KeymapKind::US => "us",
KeymapKind::GB => "gb",
KeymapKind::Dvorak => "dvorak",
KeymapKind::Azerty => "azerty",
KeymapKind::Bepo => "bepo",
KeymapKind::IT => "it",
};
f.write_str(s);
Ok(())
}
}
pub struct KeymapData {
pub keymap_hash: HashMap<u8, [char; 2]>,
pub kind: KeymapKind,
}
impl KeymapData {
pub fn new(kind: KeymapKind) -> Self {
let keymap_hash = match kind {
KeymapKind::US => HashMap::from(keymaps::US),
KeymapKind::GB => HashMap::from(keymaps::GB),
KeymapKind::Dvorak => HashMap::from(keymaps::DVORAK),
KeymapKind::Azerty => HashMap::from(keymaps::AZERTY),
KeymapKind::Bepo => HashMap::from(keymaps::BEPO),
KeymapKind::IT => HashMap::from(keymaps::IT),
};
Self { keymap_hash, kind }
}
pub fn get_kind(&self) -> KeymapKind {
self.kind
}
// TODO: AltGr, Numlock
pub fn get_char(&self, scancode: u8, shift: bool) -> char {
if let Some(c) = self.keymap_hash.get(&scancode) {
if shift {
c[1]
} else {
c[0]
}
} else {
'\0'
}
}
}
+36 -2
View File
@@ -23,7 +23,7 @@ fn read_to_slice<T: Copy>(
}
}
unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
pub unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
slice::from_raw_parts((p as *const T) as *const u8, size_of::<T>())
}
@@ -111,10 +111,37 @@ impl ConsumerHandle {
#[derive(Debug, Clone)]
#[repr(C)]
pub struct ControlEvent {
pub kind: usize,
pub data: usize,
}
impl From<VtActivate> for ControlEvent {
fn from(value: VtActivate) -> Self {
ControlEvent {
kind: 1,
data: value.vt,
}
}
}
impl From<KeymapActivate> for ControlEvent {
fn from(value: KeymapActivate) -> Self {
ControlEvent {
kind: 2,
data: value.keymap,
}
}
}
pub struct VtActivate {
pub vt: usize,
}
pub struct KeymapActivate {
pub keymap: usize,
}
pub struct DisplayHandle(File);
impl DisplayHandle {
@@ -160,8 +187,15 @@ impl ControlHandle {
Ok(Self(File::open(path)?))
}
/// Sent to Handle::Display
pub fn activate_vt(&mut self, vt: usize) -> io::Result<usize> {
let cmd = VtActivate { vt };
let cmd = ControlEvent::from(VtActivate { vt });
self.0.write(unsafe { any_as_u8_slice(&cmd) })
}
/// Sent to Handle::Producer
pub fn activate_keymap(&mut self, keymap: usize) -> io::Result<usize> {
let cmd = ControlEvent::from(KeymapActivate { keymap });
self.0.write(unsafe { any_as_u8_slice(&cmd) })
}
}
+109 -31
View File
@@ -12,13 +12,15 @@
//! events are available.
use core::mem::size_of;
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet};
use std::mem::transmute;
use std::sync::atomic::{AtomicUsize, Ordering};
use inputd::{VtActivate, VtEvent, VtEventKind};
use inputd::{ControlEvent, VtEvent, VtEventKind};
use libredox::errno::ESTALE;
use log::warn;
use redox_scheme::scheme::SchemeSync;
use redox_scheme::{CallerCtx, OpenResult, RequestKind, Response, SignalBehavior, Socket};
@@ -26,6 +28,12 @@ use orbclient::{Event, EventOption};
use syscall::schemev2::NewFdFlags;
use syscall::{Error as SysError, EventFlags, EINVAL};
pub mod keymap;
use keymap::KeymapKind;
use crate::keymap::KeymapData;
enum Handle {
Producer,
Consumer {
@@ -58,6 +66,9 @@ struct InputScheme {
vts: BTreeSet<usize>,
super_key: bool,
active_vt: Option<usize>,
active_keymap: KeymapData,
lshift: bool,
rshift: bool,
has_new_events: bool,
}
@@ -74,7 +85,10 @@ impl InputScheme {
vts: BTreeSet::new(),
super_key: false,
active_vt: None,
// TODO: configurable init?
active_keymap: KeymapData::new(KeymapKind::US),
lshift: false,
rshift: false,
has_new_events: false,
}
}
@@ -121,6 +135,20 @@ impl InputScheme {
self.active_vt = Some(new_active);
}
fn switch_keymap(&mut self, new_active: usize) {
if new_active == self.active_keymap.get_kind() as usize {
return;
}
log::debug!(
"switching from keymap #{} to keymap #{}",
self.active_keymap.get_kind(),
KeymapKind::from(new_active),
);
self.active_keymap = KeymapData::new(new_active.into());
}
}
impl SchemeSync for InputScheme {
@@ -308,15 +336,21 @@ impl SchemeSync for InputScheme {
match handle {
Handle::Control => {
if buf.len() != size_of::<VtActivate>() {
if buf.len() != size_of::<ControlEvent>() {
log::error!("control tried to write incorrectly sized command");
return Err(SysError::new(EINVAL));
}
// SAFETY: We have verified the size of the buffer above.
let cmd = unsafe { &*buf.as_ptr().cast::<VtActivate>() };
let cmd = unsafe { &*buf.as_ptr().cast::<ControlEvent>() };
self.switch_vt(cmd.vt);
match cmd.kind {
1 => self.switch_vt(cmd.data),
2 => self.switch_keymap(cmd.data),
k => {
log::warn!("unknown control {}", k);
}
}
return Ok(buf.len());
}
@@ -336,38 +370,42 @@ impl SchemeSync for InputScheme {
return Ok(1);
}
let events = unsafe {
let mut events = Cow::from(unsafe {
core::slice::from_raw_parts(
buf.as_ptr() as *const Event,
buf.len() / size_of::<Event>(),
)
};
});
for event in events.iter() {
for i in 0..events.len() {
let mut new_active_opt = None;
match event.to_option() {
EventOption::Key(key_event) => match key_event.scancode {
f @ 0x3B..=0x44 if self.super_key => {
// F1 through F10
match events[i].to_option() {
EventOption::Key(mut key_event) => match key_event.scancode {
f @ orbclient::K_F1..=orbclient::K_F10 if self.super_key => {
new_active_opt = Some((f - 0x3A) as usize);
}
0x57 if self.super_key => {
// F11
orbclient::K_F11 if self.super_key => {
new_active_opt = Some(11);
}
0x58 if self.super_key => {
// F12
orbclient::K_F12 if self.super_key => {
new_active_opt = Some(12);
}
0x5B => {
// Super
orbclient::K_SUPER => {
self.super_key = key_event.pressed;
}
orbclient::K_LEFT_SHIFT => {
self.lshift = key_event.pressed;
}
orbclient::K_RIGHT_SHIFT => {
self.rshift = key_event.pressed;
}
_ => (),
key => {
let shift = self.lshift | self.rshift;
let ev = self.active_keymap.get_char(key, shift);
key_event.character = ev;
events.to_mut()[i] = key_event.to_event();
}
},
EventOption::Resize(resize_event) => {
@@ -408,6 +446,13 @@ impl SchemeSync for InputScheme {
let handle = self.handles.get_mut(&id).ok_or(SysError::new(EINVAL))?;
assert!(matches!(handle, Handle::Producer));
let buf = unsafe {
core::slice::from_raw_parts(
(events.as_ptr()) as *const u8,
events.len() * size_of::<Event>(),
)
};
if let Some(active_vt) = self.active_vt {
for handle in self.handles.values_mut() {
match handle {
@@ -571,33 +616,66 @@ fn daemon_runner(daemon: daemon::Daemon) -> ! {
unreachable!();
}
fn main() {
common::setup_logging(
"input",
"inputd",
"inputd",
common::output_level(),
common::file_level(),
);
const HELP: &str = r#"
inputd [-K keymap|-A vt|--keymaps]
-A vt : set current virtual display
-K keymap : set keyboard mapping
--keymaps : list available keyboard mappings
"#;
fn main() {
let mut args = std::env::args().skip(1);
if let Some(val) = args.next() {
// TODO: Get current VT or keymap
match val.as_ref() {
// Activates a VT.
"-A" => {
let vt = args.next().unwrap().parse::<usize>().unwrap();
let mut handle =
inputd::ControlHandle::new().expect("inputd: failed to open display handle");
inputd::ControlHandle::new().expect("inputd: failed to open control handle");
handle
.activate_vt(vt)
.expect("inputd: failed to activate VT");
}
// Activates a keymap.
"-K" => {
let vt = args
.next()
.unwrap()
.to_ascii_lowercase()
.parse::<KeymapKind>()
.expect("inputd: unrecognized keymap code (see: inputd --keymaps)");
let mut handle =
inputd::ControlHandle::new().expect("inputd: failed to open control handle");
handle
.activate_keymap(vt as usize)
.expect("inputd: failed to activate keymap");
}
// List available keymaps
"--keymaps" => {
// TODO: configurable KeymapKind using files
for key in vec!["dvorak", "us", "gb", "azerty", "bepo", "it"] {
println!("{}", key);
}
}
"--help" => {
println!("{}", HELP);
}
_ => panic!("inputd: invalid argument: {}", val),
}
} else {
common::setup_logging(
"input",
"inputd",
"inputd",
common::output_level(),
common::file_level(),
);
daemon::Daemon::new(daemon_runner);
}
}