diff options
author | Joe Wilm <joe@jwilm.com> | 2016-11-11 19:59:18 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-11-17 17:15:56 -0800 |
commit | 8360ab44ece57194ab40ddd280dcb5ce35ae91b7 (patch) | |
tree | 4a2f0a06081723f48ff86e3870b29aaca42e37f7 /src | |
parent | 6925daa823a86aa8d3fafe21591bb883cb053ef3 (diff) | |
download | alacritty-8360ab44ece57194ab40ddd280dcb5ce35ae91b7.tar.gz alacritty-8360ab44ece57194ab40ddd280dcb5ce35ae91b7.zip |
Fallback to received chars when no bindings
Committed this on a plane with no internet; need to get a real glutin
ref pushed somewhere and update this commit before merging into master.
Diffstat (limited to 'src')
-rw-r--r-- | src/event.rs | 48 | ||||
-rw-r--r-- | src/input.rs | 90 |
2 files changed, 65 insertions, 73 deletions
diff --git a/src/event.rs b/src/event.rs index 6e28f289..a2a4075d 100644 --- a/src/event.rs +++ b/src/event.rs @@ -37,41 +37,41 @@ impl<N: input::Notify> Processor<N> { fn handle_event(&mut self, event: glutin::Event) { match event { glutin::Event::Closed => panic!("window closed"), // TODO ... - glutin::Event::ReceivedCharacter(c) => { - match c { - // Ignore BACKSPACE and DEL. These are handled specially. - '\u{8}' | '\u{7f}' => (), - // Extra thing on macOS delete? - '\u{f728}' => (), - // OSX arrow keys send invalid characters; ignore. - '\u{f700}' | '\u{f701}' | '\u{f702}' | '\u{f703}' => (), - // Same with home/end. Am I missing something? Would be - // nice if glutin provided the received char in - // KeyboardInput event so a choice could be made there - // instead of having to special case everything. - '\u{f72b}' | '\u{f729}' | '\u{f72c}' | '\u{f72d}' => (), - // These letters are handled in the bindings system - 'v' => (), - _ => { - println!("printing char {:?}", c); - let buf = encode_char(c); - self.notifier.notify(buf); - } - } - }, + // glutin::Event::ReceivedCharacter(c) => { + // match c { + // // Ignore BACKSPACE and DEL. These are handled specially. + // '\u{8}' | '\u{7f}' => (), + // // Extra thing on macOS delete? + // '\u{f728}' => (), + // // OSX arrow keys send invalid characters; ignore. + // '\u{f700}' | '\u{f701}' | '\u{f702}' | '\u{f703}' => (), + // // Same with home/end. Am I missing something? Would be + // // nice if glutin provided the received char in + // // KeyboardInput event so a choice could be made there + // // instead of having to special case everything. + // '\u{f72b}' | '\u{f729}' | '\u{f72c}' | '\u{f72d}' => (), + // // These letters are handled in the bindings system + // 'v' => (), + // _ => { + // println!("printing char {:?}", c); + // let buf = encode_char(c); + // self.notifier.notify(buf); + // } + // } + // }, glutin::Event::Resized(w, h) => { self.resize_tx.send((w, h)).expect("send new size"); // Acquire term lock let mut terminal = self.terminal.lock(); terminal.dirty = true; }, - glutin::Event::KeyboardInput(state, _code, key, mods) => { + glutin::Event::KeyboardInput(state, _code, key, mods, string) => { // Acquire term lock let terminal = self.terminal.lock(); let processor = &mut self.input_processor; let notifier = &mut self.notifier; - processor.process_key(state, key, mods, notifier, *terminal.mode()); + processor.process_key(state, key, mods, notifier, *terminal.mode(), string); }, glutin::Event::MouseInput(state, button) => { let terminal = self.terminal.lock(); diff --git a/src/input.rs b/src/input.rs index 1f9a82b2..667029f2 100644 --- a/src/input.rs +++ b/src/input.rs @@ -292,7 +292,8 @@ impl Processor { key: Option<VirtualKeyCode>, mods: Mods, notifier: &mut N, - mode: TermMode + mode: TermMode, + string: Option<String>, ) { if let Some(key) = key { // Ignore release events @@ -302,57 +303,46 @@ impl Processor { let bindings = match key { // Arrows - VirtualKeyCode::Left => LEFT_BINDINGS, - VirtualKeyCode::Up => UP_BINDINGS, - VirtualKeyCode::Down => DOWN_BINDINGS, - VirtualKeyCode::Right => RIGHT_BINDINGS, + VirtualKeyCode::Left => Some(LEFT_BINDINGS), + VirtualKeyCode::Up => Some(UP_BINDINGS), + VirtualKeyCode::Down => Some(DOWN_BINDINGS), + VirtualKeyCode::Right => Some(RIGHT_BINDINGS), // Function keys - VirtualKeyCode::F1 => F1_BINDINGS, - VirtualKeyCode::F2 => F2_BINDINGS, - VirtualKeyCode::F3 => F3_BINDINGS, - VirtualKeyCode::F4 => F4_BINDINGS, - VirtualKeyCode::F5 => F5_BINDINGS, - VirtualKeyCode::F6 => F6_BINDINGS, - VirtualKeyCode::F7 => F7_BINDINGS, - VirtualKeyCode::F8 => F8_BINDINGS, - VirtualKeyCode::F9 => F9_BINDINGS, - VirtualKeyCode::F10 => F10_BINDINGS, - VirtualKeyCode::F11 => F11_BINDINGS, - VirtualKeyCode::F12 => F12_BINDINGS, - VirtualKeyCode::PageUp => PAGEUP_BINDINGS, - VirtualKeyCode::PageDown => PAGEDOWN_BINDINGS, - VirtualKeyCode::Home => HOME_BINDINGS, - VirtualKeyCode::End => END_BINDINGS, - VirtualKeyCode::Back => BACKSPACE_BINDINGS, - VirtualKeyCode::Delete => DELETE_BINDINGS, - VirtualKeyCode::H => H_BINDINGS, - VirtualKeyCode::V => V_BINDINGS, - // Mode keys ignored now - VirtualKeyCode::LAlt | VirtualKeyCode::RAlt | VirtualKeyCode::LShift | - VirtualKeyCode::RShift | VirtualKeyCode::LControl | VirtualKeyCode::RControl | - VirtualKeyCode::LWin | VirtualKeyCode::RWin => return, - // All of the alphanumeric keys get passed through here as well, but there's no work - // to be done for them. - VirtualKeyCode::A | VirtualKeyCode::B | VirtualKeyCode::C | VirtualKeyCode::D | - VirtualKeyCode::E | VirtualKeyCode::F | VirtualKeyCode::G | - VirtualKeyCode::I | VirtualKeyCode::J | VirtualKeyCode::K | VirtualKeyCode::L | - VirtualKeyCode::M | VirtualKeyCode::N | VirtualKeyCode::O | VirtualKeyCode::P | - VirtualKeyCode::Q | VirtualKeyCode::R | VirtualKeyCode::S | VirtualKeyCode::T | - VirtualKeyCode::U | VirtualKeyCode::W | VirtualKeyCode::X | - VirtualKeyCode::Y | VirtualKeyCode::Z => return, - VirtualKeyCode::Key1 | VirtualKeyCode::Key2 | VirtualKeyCode::Key3 | - VirtualKeyCode::Key4 | VirtualKeyCode::Key5 | VirtualKeyCode::Key6 | - VirtualKeyCode::Key7 | VirtualKeyCode::Key8 | VirtualKeyCode::Key9 | - VirtualKeyCode::Key0 => return, - // Log something by default + VirtualKeyCode::F1 => Some(F1_BINDINGS), + VirtualKeyCode::F2 => Some(F2_BINDINGS), + VirtualKeyCode::F3 => Some(F3_BINDINGS), + VirtualKeyCode::F4 => Some(F4_BINDINGS), + VirtualKeyCode::F5 => Some(F5_BINDINGS), + VirtualKeyCode::F6 => Some(F6_BINDINGS), + VirtualKeyCode::F7 => Some(F7_BINDINGS), + VirtualKeyCode::F8 => Some(F8_BINDINGS), + VirtualKeyCode::F9 => Some(F9_BINDINGS), + VirtualKeyCode::F10 => Some(F10_BINDINGS), + VirtualKeyCode::F11 => Some(F11_BINDINGS), + VirtualKeyCode::F12 => Some(F12_BINDINGS), + VirtualKeyCode::PageUp => Some(PAGEUP_BINDINGS), + VirtualKeyCode::PageDown => Some(PAGEDOWN_BINDINGS), + VirtualKeyCode::Home => Some(HOME_BINDINGS), + VirtualKeyCode::End => Some(END_BINDINGS), + VirtualKeyCode::Back => Some(BACKSPACE_BINDINGS), + VirtualKeyCode::Delete => Some(DELETE_BINDINGS), + VirtualKeyCode::H => Some(H_BINDINGS), + VirtualKeyCode::V => Some(V_BINDINGS), _ => { - println!("Unhandled key: {:?}; state: {:?}; mods: {:?}", - key, state, mods); - return; + None }, }; - self.process_bindings(bindings, mode, notifier, mods); + if let Some(bindings) = bindings { + if self.process_bindings(bindings, mode, notifier, mods) { + return; + } + } + + // Didn't process a binding; print the provided character + if let Some(string) = string { + notifier.notify(string.into_bytes()); + } } } @@ -360,7 +350,7 @@ impl Processor { bindings: &[Binding], mode: TermMode, notifier: &mut N, - mods: Mods) + mods: Mods) -> bool where N: Notify { // Check each binding @@ -394,11 +384,13 @@ impl Processor { } } - break; + return true; } } } } + + return false; } } |