fix keybindings

macos-click-through
keith 5 years ago
parent 840110ae73
commit 6758d4139b

@ -95,63 +95,59 @@ fn parse_keycode(keycode: VirtualKeyCode) -> Option<(&'static str, bool)> {
} }
fn append_modifiers(modifiers: ModifiersState, keycode_text: &str, special: bool) -> String { fn append_modifiers(modifiers: ModifiersState, keycode_text: &str, special: bool) -> String {
let mut result = String::with_capacity(10 + keycode_text.len()); // Add 10 due to modifiers terms. let mut result = keycode_text.to_string();
let mut special = special; let mut special = special;
if modifiers.logo() {
special = true;
result.push_str("D-");
}
if modifiers.alt() {
special = true;
result.push_str("M-");
}
if modifiers.ctrl() {
special = true;
result.push_str("C-");
}
if modifiers.shift() { if modifiers.shift() {
match keycode_text { result = match result.as_ref() {
"1" => result.push('!'), "1" => "!".to_string(),
"2" => result.push('@'), "2" => "@".to_string(),
"3" => result.push('#'), "3" => "#".to_string(),
"4" => result.push('$'), "4" => "$".to_string(),
"5" => result.push('%'), "5" => "%".to_string(),
"6" => result.push('^'), "6" => "^".to_string(),
"7" => result.push('&'), "7" => "&".to_string(),
"8" => result.push('*'), "8" => "*".to_string(),
"9" => result.push('('), "9" => "(".to_string(),
"0" => result.push(')'), "0" => ")".to_string(),
"'" => result.push('"'), "'" => "\"".to_string(),
"Bslash" => { "Bslash" => {
special = false; special = false;
result.push('|'); "|".to_string()
}, },
"," => { "," => {
special = true; special = true;
result.push_str("lt"); "lt".to_string()
}, },
"=" => result.push('+'), "=" => "+".to_string(),
"`" => result.push('~'), "`" => "~".to_string(),
"[" => result.push('{'), "[" => "{".to_string(),
"-" => result.push('_'), "-" => "_".to_string(),
"." => result.push('>'), "." => ">".to_string(),
"]" => result.push('}'), "]" => "}".to_string(),
";" => result.push(':'), ";" => ":".to_string(),
"/" => result.push('?'), "/" => "?".to_string(),
other => { other => {
special = true; special = true;
format!("S-{}", other)
result.push_str("S-");
result.push_str(other);
} }
}; };
} }
if modifiers.ctrl() {
special = true;
result = format!("C-{}", result);
}
if modifiers.alt() {
special = true;
result = format!("M-{}", result);
}
if modifiers.logo() {
special = true;
result = format!("D-{}", result);
}
if special { if special {
result.insert(0, '<'); result = format!("<{}>", result);
result.push('>');
} }
result result

@ -1,129 +0,0 @@
use std::sync::atomic::{AtomicBool, Ordering};
use skulpin::winit::event::{KeyboardInput, ElementState, ModifiersState, VirtualKeyCode};
use super::{BRIDGE, UiCommand};
lazy_static! {
pub static ref KEYBOARD_MANAGER: KeyboardManager = KeyboardManager::new();
}
pub struct KeyboardManager {
shift: AtomicBool,
ctrl: AtomicBool,
alt: AtomicBool,
logo: AtomicBool
}
impl KeyboardManager {
pub fn new() -> KeyboardManager {
KeyboardManager {
shift: AtomicBool::new(false),
ctrl: AtomicBool::new(false),
alt: AtomicBool::new(false),
logo: AtomicBool::new(false)
}
}
fn apply_modifiers(&self, text: String, escaped: bool) -> String {
let mut escaped = escaped;
let mut result = text;
if self.shift.load(Ordering::Relaxed) {
result = format!("S-{}", result);
escaped = true;
}
if self.ctrl.load(Ordering::Relaxed) {
result = format!("C-{}", result);
escaped = true;
}
if self.alt.load(Ordering::Relaxed) {
result = format!("M-{}", result);
escaped = true;
}
if self.logo.load(Ordering::Relaxed) {
result = format!("D-{}", result);
escaped = true;
}
if escaped {
format!("<{}>", result)
} else {
result
}
}
pub fn handle_keyboard_input(&self, input: KeyboardInput) {
let keycode = match input {
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: keycode,
..
} => keycode,
_ => None
};
keycode.and_then(|keycode| {
match keycode {
VirtualKeyCode::Escape => Some("ESC"),
VirtualKeyCode::F1 => Some("F1"),
VirtualKeyCode::F2 => Some("F2"),
VirtualKeyCode::F3 => Some("F3"),
VirtualKeyCode::F4 => Some("F4"),
VirtualKeyCode::F5 => Some("F5"),
VirtualKeyCode::F6 => Some("F6"),
VirtualKeyCode::F7 => Some("F7"),
VirtualKeyCode::F8 => Some("F8"),
VirtualKeyCode::F9 => Some("F9"),
VirtualKeyCode::F10 => Some("F10"),
VirtualKeyCode::F11 => Some("F11"),
VirtualKeyCode::F12 => Some("F12"),
VirtualKeyCode::F13 => Some("F13"),
VirtualKeyCode::F14 => Some("F14"),
VirtualKeyCode::F15 => Some("F15"),
VirtualKeyCode::F16 => Some("F16"),
VirtualKeyCode::F17 => Some("F17"),
VirtualKeyCode::F18 => Some("F18"),
VirtualKeyCode::F19 => Some("F19"),
VirtualKeyCode::F20 => Some("F20"),
VirtualKeyCode::F21 => Some("F21"),
VirtualKeyCode::F22 => Some("F22"),
VirtualKeyCode::F23 => Some("F23"),
VirtualKeyCode::F24 => Some("F24"),
VirtualKeyCode::Insert => Some("Insert"),
VirtualKeyCode::Home => Some("Home"),
VirtualKeyCode::Delete => Some("Delete"),
VirtualKeyCode::End => Some("End"),
VirtualKeyCode::PageDown => Some("PageDown"),
VirtualKeyCode::PageUp => Some("PageUp"),
VirtualKeyCode::Left => Some("Left"),
VirtualKeyCode::Up => Some("Up"),
VirtualKeyCode::Right => Some("Right"),
VirtualKeyCode::Down => Some("Down"),
VirtualKeyCode::Back => Some("BS"),
VirtualKeyCode::Return => Some("Enter"),
VirtualKeyCode::Backslash => Some("Bslash"),
VirtualKeyCode::Tab => Some("Tab"),
_ => None
}
}).map(|keyboard_input| {
// let keyboard_input = self.apply_modifiers(keyboard_input.to_string(), true);
// BRIDGE.queue_command(UiCommand::Keyboard(keyboard_input));
});
}
pub fn handle_received_character(&self, character: char) {
let keyboard_input = character.escape_unicode().to_string();
BRIDGE.queue_command(UiCommand::Keyboard(keyboard_input));
}
pub fn handle_modifiers(&self, modifiers: ModifiersState) {
self.shift.store(modifiers.shift(), Ordering::Relaxed);
self.ctrl.store(modifiers.ctrl(), Ordering::Relaxed);
self.alt.store(modifiers.alt(), Ordering::Relaxed);
self.logo.store(modifiers.logo(), Ordering::Relaxed);
}
}

@ -22,13 +22,13 @@ impl UiCommand {
.expect("Input failed"); .expect("Input failed");
}, },
UiCommand::MouseButton { action, position: (grid_x, grid_y) } => UiCommand::MouseButton { action, position: (grid_x, grid_y) } =>
nvim.input_mouse("left", dbg!(&action), "", 0, grid_x, grid_y).await nvim.input_mouse("left", &action, "", 0, grid_x, grid_y).await
.expect("Mouse Input Failed"), .expect("Mouse Input Failed"),
UiCommand::Scroll { direction, position: (grid_x, grid_y) } => UiCommand::Scroll { direction, position: (grid_x, grid_y) } =>
nvim.input_mouse("wheel", &direction, "", 0, grid_x, grid_y).await nvim.input_mouse("wheel", &direction, "", 0, grid_x, grid_y).await
.expect("Mouse Scroll Failed"), .expect("Mouse Scroll Failed"),
UiCommand::Drag(grid_x, grid_y) => UiCommand::Drag(grid_x, grid_y) =>
nvim.input_mouse("left", "drag", "", 0, dbg!(grid_x), dbg!(grid_y)).await nvim.input_mouse("left", "drag", "", 0, grid_x, grid_y).await
.expect("Mouse Drag Failed") .expect("Mouse Drag Failed")
} }
} }

Loading…
Cancel
Save