vietc/engine/src/input_method.rs
Khoa Vo d4102088b8 fix: X11 key lookup, bamboo engine port, uinput injection overhaul
- Fix Xutf8LookupString signature (missing XIC param caused all keys to map to \0)
- Port bamboo-core Vietnamese engine to Rust (bamboo.rs, input_method.rs)
- Flexible backtracking for mark/tone keys (scan up to 5 chars back)
- Correct tone placement for io, uâ, yê clusters
- Evdev capture preferred over X11 XRecord (more reliable)
- Uinput injection with correct Linux keycodes
- Vietnamese Unicode via clipboard paste + trailing ASCII via uinput
- Persistent X11 connection for Ctrl+V (no per-call dlopen overhead)
- Consume stale VNI/Telex control keys when no match found
- Fix execute_commands backspace count for evdev grabbing path
- Add vietc-uinputd privileged injection daemon
- AppImage: bundle uinputd, preserve LD_LIBRARY_PATH, fix xrecord build flags
- Remove old generated test files, add 63 focused engine tests
2026-06-26 15:20:03 +07:00

71 lines
2.1 KiB
Rust

use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InputMethod {
Telex,
Vni,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RuleEffect {
Appending(char),
MarkTransformation { base: char, marked: char },
ToneTransformation { tone: char, name: &'static str },
}
#[derive(Debug, Clone)]
pub struct InputMethodRules {
pub method: InputMethod,
pub tone_keys: HashMap<char, (char, &'static str)>,
pub mark_rules: Vec<(String, String)>,
pub special_rules: Vec<RuleEffect>,
}
fn tone_map(entries: &[(char, char, &'static str)]) -> HashMap<char, (char, &'static str)> {
entries.iter().map(|&(k, t, n)| (k, (t, n))).collect()
}
pub fn get_rules(method: InputMethod) -> InputMethodRules {
match method {
InputMethod::Telex => InputMethodRules {
method,
tone_keys: tone_map(&[
('f', 'f', "huyen"),
('s', 's', "sac"),
('r', 'r', "hoi"),
('x', 'x', "nga"),
('j', 'j', "nang"),
]),
mark_rules: vec![
("aw".into(), "ă".into()),
("aa".into(), "â".into()),
("ee".into(), "ê".into()),
("oo".into(), "ô".into()),
("ow".into(), "ơ".into()),
("uw".into(), "ư".into()),
("dd".into(), "đ".into()),
],
special_rules: vec![],
},
InputMethod::Vni => InputMethodRules {
method,
tone_keys: tone_map(&[
('1', '1', "sac"),
('2', '2', "huyen"),
('3', '3', "hoi"),
('4', '4', "nga"),
('5', '5', "nang"),
]),
mark_rules: vec![
("a6".into(), "â".into()),
("e6".into(), "ê".into()),
("o6".into(), "ô".into()),
("o7".into(), "ơ".into()),
("u7".into(), "ư".into()),
("a8".into(), "ă".into()),
("d9".into(), "đ".into()),
],
special_rules: vec![],
},
}
}