2016-04-04 10:14:57 +00:00
|
|
|
|
|
|
|
use gdk;
|
|
|
|
use gdk::EventKey;
|
|
|
|
use phf;
|
|
|
|
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/key_map_table.rs"));
|
|
|
|
|
|
|
|
|
2016-05-04 14:59:51 +00:00
|
|
|
pub fn keyval_to_input_string(val: &str, state: gdk::ModifierType) -> String {
|
2016-04-04 10:14:57 +00:00
|
|
|
let mut input = String::from("<");
|
|
|
|
if state.contains(gdk::enums::modifier_type::ShiftMask) {
|
|
|
|
input.push_str("S-");
|
|
|
|
}
|
|
|
|
if state.contains(gdk::enums::modifier_type::ControlMask) {
|
|
|
|
input.push_str("C-");
|
|
|
|
}
|
|
|
|
if state.contains(gdk::enums::modifier_type::Mod1Mask) {
|
|
|
|
input.push_str("A-");
|
|
|
|
}
|
|
|
|
input.push_str(val);
|
|
|
|
input.push_str(">");
|
|
|
|
input
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn convert_key(ev: &EventKey) -> Option<String> {
|
|
|
|
let keyval = ev.get_keyval();
|
|
|
|
let state = ev.get_state();
|
|
|
|
if let Some(ref keyval_name) = gdk::keyval_name(keyval) {
|
|
|
|
if let Some(cnvt) = KEYVAL_MAP.get(keyval_name as &str).cloned() {
|
|
|
|
return Some(keyval_to_input_string(cnvt, state));
|
|
|
|
}
|
|
|
|
}
|
2016-05-03 10:34:36 +00:00
|
|
|
|
2016-04-04 10:14:57 +00:00
|
|
|
if let Some(ch) = gdk::keyval_to_unicode(keyval) {
|
2016-05-03 10:34:36 +00:00
|
|
|
Some(if !state.is_empty() {
|
2016-04-04 10:14:57 +00:00
|
|
|
keyval_to_input_string(&ch.to_string(), state)
|
|
|
|
} else {
|
|
|
|
ch.to_string()
|
2016-05-03 10:34:36 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
2016-04-04 10:14:57 +00:00
|
|
|
}
|
|
|
|
}
|