diff --git a/Cargo.lock b/Cargo.lock index 40b889ef..0b58690e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ dependencies = [ "errno 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "font 0.1.0", "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin 0.6.1 (git+https://github.com/jwilm/glutin?rev=ac3585f7bc8cd56b036de714cccfdc2532f343a7)", + "glutin 0.6.1 (git+https://github.com/jwilm/glutin?rev=78838c1e1497dc8a1b1c8f69da7a6f3cd7da15c1)", "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -311,7 +311,7 @@ dependencies = [ [[package]] name = "glutin" version = "0.6.1" -source = "git+https://github.com/jwilm/glutin?rev=ac3585f7bc8cd56b036de714cccfdc2532f343a7#ac3585f7bc8cd56b036de714cccfdc2532f343a7" +source = "git+https://github.com/jwilm/glutin?rev=78838c1e1497dc8a1b1c8f69da7a6f3cd7da15c1#78838c1e1497dc8a1b1c8f69da7a6f3cd7da15c1" dependencies = [ "android_glue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1079,7 +1079,7 @@ dependencies = [ "checksum gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65256ec4dc2592e6f05bfc1ca3b956a4e0698aa90b1dff1f5687d55a5a3fd59a" "checksum gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1d8edc81c5ae84605a62f5dac661a2313003b26d59839f81d47d46cf0f16a55" "checksum gleam 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b04d6c8a1df841e48dfe99ed67829c9d1d17b1bb3e44c5f3283992010e20359b" -"checksum glutin 0.6.1 (git+https://github.com/jwilm/glutin?rev=ac3585f7bc8cd56b036de714cccfdc2532f343a7)" = "" +"checksum glutin 0.6.1 (git+https://github.com/jwilm/glutin?rev=78838c1e1497dc8a1b1c8f69da7a6f3cd7da15c1)" = "" "checksum heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8c80e194758495a9109566134dc06e42ea0423987d6ceca016edaa90381b3549" "checksum inotify 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8458c07bdbdaf309c80e2c3304d14c3db64e7465d4f07cf589ccb83fd0ff31a" "checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" diff --git a/Cargo.toml b/Cargo.toml index d3132ddc..9da6e7ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ gl_generator = "0.5" [dependencies.glutin] git = "https://github.com/jwilm/glutin" -rev = "ac3585f7bc8cd56b036de714cccfdc2532f343a7" +rev = "78838c1e1497dc8a1b1c8f69da7a6f3cd7da15c1" [profile.release] debug = true 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 Processor { 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, mods: Mods, notifier: &mut N, - mode: TermMode + mode: TermMode, + string: Option, ) { 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; } }