more principled keybindings

macos-click-through
keith 5 years ago
parent 04773807cb
commit dcd33bda1a

@ -1,285 +0,0 @@
use log::trace;
use skulpin::sdl2::keyboard::{Keycode, Mod};
pub fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> {
macro_rules! unsupported_key {
($name: ident) => {{
if cfg!(debug_assertions) {
trace!("Unsupported key: $name");
}
None
}};
}
// Documentation: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlkey.html
match keycode {
Keycode::Backspace => Some(("BS", true)),
Keycode::Tab => Some(("Tab", true)),
Keycode::Return => Some(("Enter", true)),
Keycode::Escape => Some(("Esc", true)),
Keycode::Space => Some((" ", false)),
Keycode::Exclaim => Some(("!", false)),
Keycode::Quotedbl => Some(("\"", false)),
Keycode::Hash => Some(("#", false)),
Keycode::Dollar => Some(("$", false)),
Keycode::Percent => Some(("%", false)),
Keycode::Ampersand => Some(("&", false)),
Keycode::Quote => Some(("'", false)),
Keycode::LeftParen => Some(("(", false)),
Keycode::RightParen => Some((")", false)),
Keycode::Asterisk => Some(("*", false)),
Keycode::Plus => Some(("+", false)),
Keycode::Comma => Some((",", false)),
Keycode::Minus => Some(("-", false)),
Keycode::Period => Some((".", false)),
Keycode::Slash => Some(("/", false)),
Keycode::Num0 => Some(("0", false)),
Keycode::Num1 => Some(("1", false)),
Keycode::Num2 => Some(("2", false)),
Keycode::Num3 => Some(("3", false)),
Keycode::Num4 => Some(("4", false)),
Keycode::Num5 => Some(("5", false)),
Keycode::Num6 => Some(("6", false)),
Keycode::Num7 => Some(("7", false)),
Keycode::Num8 => Some(("8", false)),
Keycode::Num9 => Some(("9", false)),
Keycode::Colon => Some((":", false)),
Keycode::Semicolon => Some((";", false)),
Keycode::Less => Some(("lt", false)),
Keycode::Equals => Some(("=", false)),
Keycode::Greater => Some(("gt", false)),
Keycode::Question => Some(("?", false)),
Keycode::At => Some(("@", false)),
Keycode::LeftBracket => Some(("[", false)),
Keycode::Backslash => Some(("\\", false)),
Keycode::RightBracket => Some(("]", false)),
Keycode::Caret => Some(("^", false)),
Keycode::Underscore => Some(("_", false)),
Keycode::Backquote => Some(("`", false)),
Keycode::A => Some(("a", false)),
Keycode::B => Some(("b", false)),
Keycode::C => Some(("c", false)),
Keycode::D => Some(("d", false)),
Keycode::E => Some(("e", false)),
Keycode::F => Some(("f", false)),
Keycode::G => Some(("g", false)),
Keycode::H => Some(("h", false)),
Keycode::I => Some(("i", false)),
Keycode::J => Some(("j", false)),
Keycode::K => Some(("k", false)),
Keycode::L => Some(("l", false)),
Keycode::M => Some(("m", false)),
Keycode::N => Some(("n", false)),
Keycode::O => Some(("o", false)),
Keycode::P => Some(("p", false)),
Keycode::Q => Some(("q", false)),
Keycode::R => Some(("r", false)),
Keycode::S => Some(("s", false)),
Keycode::T => Some(("t", false)),
Keycode::U => Some(("u", false)),
Keycode::V => Some(("v", false)),
Keycode::W => Some(("w", false)),
Keycode::X => Some(("x", false)),
Keycode::Y => Some(("y", false)),
Keycode::Z => Some(("z", false)),
Keycode::Delete => Some(("Delete", true)),
Keycode::CapsLock => unsupported_key!(CapsLock),
Keycode::F1 => Some(("F1", true)),
Keycode::F2 => Some(("F2", true)),
Keycode::F3 => Some(("F3", true)),
Keycode::F4 => Some(("F4", true)),
Keycode::F5 => Some(("F5", true)),
Keycode::F6 => Some(("F6", true)),
Keycode::F7 => Some(("F7", true)),
Keycode::F8 => Some(("F8", true)),
Keycode::F9 => Some(("F9", true)),
Keycode::F10 => Some(("F10", true)),
Keycode::F11 => Some(("F11", true)),
Keycode::F12 => Some(("F12", true)),
Keycode::PrintScreen => unsupported_key!(PrintScreen),
Keycode::ScrollLock => unsupported_key!(ScrollLock),
Keycode::Pause => unsupported_key!(Pause),
Keycode::Insert => Some(("Insert", true)),
Keycode::Home => Some(("Home", true)),
Keycode::PageUp => Some(("PageUp", true)),
Keycode::End => Some(("End", true)),
Keycode::PageDown => Some(("PageDown", true)),
Keycode::Right => Some(("Right", true)),
Keycode::Left => Some(("Left", true)),
Keycode::Down => Some(("Down", true)),
Keycode::Up => Some(("Up", true)),
Keycode::NumLockClear => unsupported_key!(NumLockClear),
Keycode::KpDivide => Some(("/", true)),
Keycode::KpMultiply => Some(("*", true)),
Keycode::KpMinus => Some(("-", true)),
Keycode::KpPlus => Some(("+", true)),
Keycode::KpEnter => Some(("Enter", true)),
Keycode::Kp0 => Some(("0", false)),
Keycode::Kp1 => Some(("1", false)),
Keycode::Kp2 => Some(("2", false)),
Keycode::Kp3 => Some(("3", false)),
Keycode::Kp4 => Some(("4", false)),
Keycode::Kp5 => Some(("5", false)),
Keycode::Kp6 => Some(("6", false)),
Keycode::Kp7 => Some(("7", false)),
Keycode::Kp8 => Some(("8", false)),
Keycode::Kp9 => Some(("9", false)),
Keycode::KpPeriod => Some((".", false)),
Keycode::Application => unsupported_key!(Application),
Keycode::Power => unsupported_key!(Power),
Keycode::KpEquals => Some(("=", false)),
Keycode::F13 => Some(("F13", true)),
Keycode::F14 => Some(("F14", true)),
Keycode::F15 => Some(("F15", true)),
Keycode::F16 => Some(("F16", true)),
Keycode::F17 => Some(("F17", true)),
Keycode::F18 => Some(("F18", true)),
Keycode::F19 => Some(("F19", true)),
Keycode::F20 => Some(("F20", true)),
Keycode::F21 => Some(("F21", true)),
Keycode::F22 => Some(("F22", true)),
Keycode::F23 => Some(("F23", true)),
Keycode::F24 => Some(("F24", true)),
Keycode::Execute => unsupported_key!(Execute),
Keycode::Help => unsupported_key!(Help),
Keycode::Menu => unsupported_key!(Menu),
Keycode::Select => unsupported_key!(Select),
Keycode::Stop => unsupported_key!(Stop),
Keycode::Again => unsupported_key!(Again),
Keycode::Undo => unsupported_key!(Undo),
Keycode::Cut => unsupported_key!(Cut),
Keycode::Copy => unsupported_key!(Copy),
Keycode::Paste => unsupported_key!(Paste),
Keycode::Find => unsupported_key!(Find),
Keycode::Mute => unsupported_key!(Mute),
Keycode::VolumeUp => unsupported_key!(VolumeUp),
Keycode::VolumeDown => unsupported_key!(VolumeDown),
Keycode::KpComma => unsupported_key!(KpComma),
Keycode::KpEqualsAS400 => unsupported_key!(KpEqualsAS400),
Keycode::AltErase => unsupported_key!(AltErase),
Keycode::Sysreq => unsupported_key!(Sysreq),
Keycode::Cancel => unsupported_key!(Cancel),
Keycode::Clear => unsupported_key!(Clear),
Keycode::Prior => unsupported_key!(Prior),
Keycode::Return2 => unsupported_key!(Return2),
Keycode::Separator => unsupported_key!(Separator),
Keycode::Out => unsupported_key!(Out),
Keycode::Oper => unsupported_key!(Oper),
Keycode::ClearAgain => unsupported_key!(ClearAgain),
Keycode::CrSel => unsupported_key!(CrSel),
Keycode::ExSel => unsupported_key!(ExSel),
Keycode::Kp00 => unsupported_key!(Kp00),
Keycode::Kp000 => unsupported_key!(Kp000),
Keycode::ThousandsSeparator => unsupported_key!(ThousandsSeparator),
Keycode::DecimalSeparator => unsupported_key!(DecimalSeparator),
Keycode::CurrencyUnit => unsupported_key!(CurrencyUnit),
Keycode::CurrencySubUnit => unsupported_key!(CurrencySubUnit),
Keycode::KpLeftParen => Some(("(", false)),
Keycode::KpRightParen => Some((")", false)),
Keycode::KpLeftBrace => Some(("[", false)),
Keycode::KpRightBrace => Some(("]", false)),
Keycode::KpTab => Some(("TAB", true)),
Keycode::KpBackspace => Some(("BS", true)),
Keycode::KpA => Some(("A", false)),
Keycode::KpB => Some(("B", false)),
Keycode::KpC => Some(("C", false)),
Keycode::KpD => Some(("D", false)),
Keycode::KpE => Some(("E", false)),
Keycode::KpF => Some(("F", false)),
Keycode::KpXor => unsupported_key!(KpXor),
Keycode::KpPower => Some(("^", false)),
Keycode::KpPercent => Some(("%", false)),
Keycode::KpLess => Some(("lt", true)),
Keycode::KpGreater => Some(("gt", true)),
Keycode::KpAmpersand => Some(("&", false)),
Keycode::KpDblAmpersand => unsupported_key!(KpDblAmpersand),
Keycode::KpVerticalBar => Some(("|", false)),
Keycode::KpDblVerticalBar => unsupported_key!(KpDblVerticalBar),
Keycode::KpColon => Some((":", false)),
Keycode::KpHash => Some(("#", false)),
Keycode::KpSpace => Some((" ", false)),
Keycode::KpAt => Some(("@", false)),
Keycode::KpExclam => Some(("!", false)),
Keycode::KpMemStore => unsupported_key!(KpMemStore),
Keycode::KpMemRecall => unsupported_key!(KpMemRecall),
Keycode::KpMemClear => unsupported_key!(KpMemClear),
Keycode::KpMemAdd => unsupported_key!(KpMemAdd),
Keycode::KpMemSubtract => unsupported_key!(KpMemSubtract),
Keycode::KpMemMultiply => unsupported_key!(KpMemMultiply),
Keycode::KpMemDivide => unsupported_key!(KpMemDivide),
Keycode::KpPlusMinus => unsupported_key!(KpPlusMinus),
Keycode::KpClear => unsupported_key!(KpClear),
Keycode::KpClearEntry => unsupported_key!(KpClearEntry),
Keycode::KpBinary => unsupported_key!(KpBinary),
Keycode::KpOctal => unsupported_key!(KpOctal),
Keycode::KpDecimal => unsupported_key!(KpDecimal),
Keycode::KpHexadecimal => unsupported_key!(KpHexadecimal),
Keycode::LCtrl => None,
Keycode::LShift => None,
Keycode::LAlt => None,
Keycode::LGui => None,
Keycode::RCtrl => None,
Keycode::RShift => None,
Keycode::RAlt => None,
Keycode::RGui => None,
Keycode::Mode => unsupported_key!(Mode),
Keycode::AudioNext => unsupported_key!(AudioNext),
Keycode::AudioPrev => unsupported_key!(AudioPrev),
Keycode::AudioStop => unsupported_key!(AudioStop),
Keycode::AudioPlay => unsupported_key!(AudioPlay),
Keycode::AudioMute => unsupported_key!(AudioMute),
Keycode::MediaSelect => unsupported_key!(MediaSelect),
Keycode::Www => unsupported_key!(Www),
Keycode::Mail => unsupported_key!(Mail),
Keycode::Calculator => unsupported_key!(Calculator),
Keycode::Computer => unsupported_key!(Computer),
Keycode::AcSearch => unsupported_key!(AcSearch),
Keycode::AcHome => unsupported_key!(AcHome),
Keycode::AcBack => unsupported_key!(AcBack),
Keycode::AcForward => unsupported_key!(AcForward),
Keycode::AcStop => unsupported_key!(AcStop),
Keycode::AcRefresh => unsupported_key!(AcRefresh),
Keycode::AcBookmarks => unsupported_key!(AcBookmarks),
Keycode::BrightnessDown => unsupported_key!(BrightnessDown),
Keycode::BrightnessUp => unsupported_key!(BrightnessUp),
Keycode::DisplaySwitch => unsupported_key!(DisplaySwitch),
Keycode::KbdIllumToggle =>unsupported_key!(KbdIllumToggle),
Keycode::KbdIllumDown => unsupported_key!(KbdIllumDown),
Keycode::KbdIllumUp => unsupported_key!(KbdIllumUp),
Keycode::Eject => unsupported_key!(Eject),
Keycode::Sleep => unsupported_key!(Sleep)
}
}
pub fn append_modifiers(modifiers: Mod, keycode_text: &str, special: bool) -> String {
let mut result = keycode_text.to_string();
let mut special = special;
if result == "<" {
result = "lt".to_string();
special = true;
}
if modifiers.contains(Mod::LSHIFTMOD) || modifiers.contains(Mod::RSHIFTMOD) {
special = true;
result = format!("S-{}", result);
}
if modifiers.contains(Mod::LCTRLMOD) || modifiers.contains(Mod::RCTRLMOD) {
special = true;
result = format!("C-{}", result);
}
if modifiers.contains(Mod::LALTMOD) || modifiers.contains(Mod::RALTMOD) {
special = true;
result = format!("M-{}", result);
}
if cfg!(not(target_os = "windows")) && (modifiers.contains(Mod::LGUIMOD) || modifiers.contains(Mod::RGUIMOD)) {
special = true;
result = format!("D-{}", result);
}
if special {
result = format!("<{}>", result);
}
result
}

@ -0,0 +1,97 @@
mod qwerty;
use log::{trace, error};
use skulpin::sdl2::keyboard::{Keycode, Mod};
use crate::settings::{SETTINGS, FromValue, Value};
use qwerty::*;
pub fn unsupported_key<R>(keycode: Keycode) -> Option<R> {
trace!("Unsupported key: {:?}", keycode);
None
}
#[derive(Clone)]
pub enum KeyboardLayout {
Qwerty
}
impl FromValue for KeyboardLayout {
fn from_value(&mut self, value: Value) {
match value.as_str() {
Some("qwerty") => *self = KeyboardLayout::Qwerty,
_ => error!("keyboard_layout setting expected a known keyboard layout name, but received: {}", value)
}
}
}
impl From<KeyboardLayout> for Value {
fn from(layout: KeyboardLayout) -> Self {
match layout {
KeyboardLayout::Qwerty => "qwerty".into()
}
}
}
#[derive(Clone)]
struct KeyboardSettings {
layout: KeyboardLayout
}
pub fn initialize_settings() {
SETTINGS.set(&KeyboardSettings {
layout: KeyboardLayout::Qwerty
});
register_nvim_setting!("keyboard_layout", KeyboardSettings::layout);
}
fn append_modifiers(keycode_text: &str, special: bool, shift: bool, ctrl: bool, alt: bool, gui: bool) -> String {
let mut result = keycode_text.to_string();
let mut special = special;
if result == "<" {
result = "lt".to_string();
special = true;
}
if shift {
special = true;
result = format!("S-{}", result);
}
if ctrl {
special = true;
result = format!("C-{}", result);
}
if alt {
special = true;
result = format!("M-{}", result);
}
if cfg!(not(target_os = "windows")) && gui {
special = true;
result = format!("D-{}", result);
}
if special {
result = format!("<{}>", result);
}
result
}
pub fn produce_neovim_keybinding_string(keycode: Option<Keycode>, keytext: Option<String>, modifiers: Mod) -> Option<String> {
let shift = modifiers.contains(Mod::LSHIFTMOD) || modifiers.contains(Mod::RSHIFTMOD);
let ctrl = modifiers.contains(Mod::LCTRLMOD) || modifiers.contains(Mod::RCTRLMOD);
let alt = modifiers.contains(Mod::LALTMOD) || modifiers.contains(Mod::RALTMOD);
let gui = modifiers.contains(Mod::LGUIMOD) || modifiers.contains(Mod::RGUIMOD);
if let Some(text) = keytext {
Some(append_modifiers(&text, false, shift, ctrl, alt, gui))
} else if let Some(keycode) = keycode {
(match SETTINGS.get::<KeyboardSettings>().layout {
KeyboardLayout::Qwerty => handle_qwerty_layout(keycode, shift, ctrl, alt),
}).map(|(transformed_text, special, shift, ctrl, alt)| append_modifiers(transformed_text, special, shift, ctrl, alt, gui))
} else {
None
}
}

@ -0,0 +1,264 @@
use super::unsupported_key;
use skulpin::sdl2::keyboard::Keycode;
pub fn handle_qwerty_layout(keycode: Keycode, shift: bool, ctrl: bool, alt: bool) -> Option<(&'static str, bool, bool, bool, bool)> {
match (keycode, shift, ctrl, alt) {
(Keycode::Backspace, shift, ctrl, alt) => Some(("BS", true, shift, ctrl, alt)),
(Keycode::Tab, shift, ctrl, alt) => Some(("Tab", true, shift, ctrl, alt)),
(Keycode::Return, shift, ctrl, alt) => Some(("Enter", true, shift, ctrl, alt)),
(Keycode::Escape, shift, ctrl, alt) => Some(("Esc", true, shift, ctrl, alt)),
(Keycode::Space, shift, ctrl, alt) => Some((" ", false, shift, ctrl, alt)),
(Keycode::Exclaim, shift, ctrl, alt) => Some(("!", false, shift, ctrl, alt)),
(Keycode::Quotedbl, shift, ctrl, alt) => Some(("\"", false, shift, ctrl, alt)),
(Keycode::Hash, shift, ctrl, alt) => Some(("#", false, shift, ctrl, alt)),
(Keycode::Dollar, shift, ctrl, alt) => Some(("$", false, shift, ctrl, alt)),
(Keycode::Percent, shift, ctrl, alt) => Some(("%", false, shift, ctrl, alt)),
(Keycode::Ampersand, shift, ctrl, alt) => Some(("&", false, shift, ctrl, alt)),
(Keycode::Quote, false, ctrl, alt) => Some(("'", false, false, ctrl, alt)),
(Keycode::Quote, true, ctrl, alt) => Some(("\"", false, false, ctrl, alt)),
(Keycode::LeftParen, shift, ctrl, alt) => Some(("(", false, shift, ctrl, alt)),
(Keycode::RightParen, shift, ctrl, alt) => Some((")", false, shift, ctrl, alt)),
(Keycode::Asterisk, shift, ctrl, alt) => Some(("*", false, shift, ctrl, alt)),
(Keycode::Plus, shift, ctrl, alt) => Some(("+", false, shift, ctrl, alt)),
(Keycode::Comma, false, ctrl, alt) => Some((",", false, shift, ctrl, alt)),
(Keycode::Comma, true, ctrl, alt) => Some(("<", false, shift, ctrl, alt)),
(Keycode::Minus, false, ctrl, alt) => Some(("-", false, false, ctrl, alt)),
(Keycode::Minus, true, ctrl, alt) => Some(("_", false, false, ctrl, alt)),
(Keycode::Period, false, ctrl, alt) => Some((".", false, false, ctrl, alt)),
(Keycode::Period, true, ctrl, alt) => Some((">", false, false, ctrl, alt)),
(Keycode::Slash, false, ctrl, alt) => Some(("/", false, false, ctrl, alt)),
(Keycode::Slash, true, ctrl, alt) => Some(("?", false, false, ctrl, alt)),
(Keycode::Num0, false, ctrl, alt) => Some(("0", false, shift, ctrl, alt)),
(Keycode::Num0, true, ctrl, alt) => Some((")", true, shift, ctrl, alt)),
(Keycode::Num1, false, ctrl, alt) => Some(("1", false, shift, ctrl, alt)),
(Keycode::Num1, true, ctrl, alt) => Some(("!", true, shift, ctrl, alt)),
(Keycode::Num2, false, ctrl, alt) => Some(("2", false, false, ctrl, alt)),
(Keycode::Num2, true, ctrl, alt) => Some(("@", false, false, ctrl, alt)),
(Keycode::Num3, false, ctrl, alt) => Some(("3", false, false, ctrl, alt)),
(Keycode::Num3, true, ctrl, alt) => Some(("#", false, false, ctrl, alt)),
(Keycode::Num4, false, ctrl, alt) => Some(("4", false, false, ctrl, alt)),
(Keycode::Num4, true, ctrl, alt) => Some(("$", false, false, ctrl, alt)),
(Keycode::Num5, false, ctrl, alt) => Some(("5", false, false, ctrl, alt)),
(Keycode::Num5, true, ctrl, alt) => Some(("%", false, false, ctrl, alt)),
(Keycode::Num6, false, ctrl, alt) => Some(("6", false, false, ctrl, alt)),
(Keycode::Num6, true, ctrl, alt) => Some(("^", false, false, ctrl, alt)),
(Keycode::Num7, false, ctrl, alt) => Some(("7", false, false, ctrl, alt)),
(Keycode::Num7, true, ctrl, alt) => Some(("&", false, false, ctrl, alt)),
(Keycode::Num8, false, ctrl, alt) => Some(("8", false, false, ctrl, alt)),
(Keycode::Num8, true, ctrl, alt) => Some(("*", false, false, ctrl, alt)),
(Keycode::Num9, false, ctrl, alt) => Some(("9", false, false, ctrl, alt)),
(Keycode::Num9, true, ctrl, alt) => Some(("(", true, false, ctrl, alt)),
(Keycode::Colon, shift, ctrl, alt) => Some((":", false, shift, ctrl, alt)),
(Keycode::Semicolon, false, ctrl, alt) => Some((";", false, false, ctrl, alt)),
(Keycode::Semicolon, true, ctrl, alt) => Some((":", false, false, ctrl, alt)),
(Keycode::Less, shift, ctrl, alt) => Some(("lt", false, shift, ctrl, alt)),
(Keycode::Equals, false, ctrl, alt) => Some(("=", false, false, ctrl, alt)),
(Keycode::Equals, true, ctrl, alt) => Some(("+", false, false, ctrl, alt)),
(Keycode::Greater, shift, ctrl, alt) => Some(("gt", false, shift, ctrl, alt)),
(Keycode::Question, shift, ctrl, alt) => Some(("?", false, shift, ctrl, alt)),
(Keycode::At, shift, ctrl, alt) => Some(("@", false, shift, ctrl, alt)),
(Keycode::LeftBracket, false, ctrl, alt) => Some(("[", false, false, ctrl, alt)),
(Keycode::LeftBracket, true, ctrl, alt) => Some(("{", false, false, ctrl, alt)),
(Keycode::Backslash, false, ctrl, alt) => Some(("\\", false, false, ctrl, alt)),
(Keycode::Backslash, true, ctrl, alt) => Some(("|", false, false, ctrl, alt)),
(Keycode::RightBracket, false, ctrl, alt) => Some(("]", false, false, ctrl, alt)),
(Keycode::RightBracket, true, ctrl, alt) => Some(("}", false, false, ctrl, alt)),
(Keycode::Caret, shift, ctrl, alt) => Some(("^", false, shift, ctrl, alt)),
(Keycode::Underscore, shift, ctrl, alt) => Some(("_", false, shift, ctrl, alt)),
(Keycode::Backquote, false, ctrl, alt) => Some(("`", false, false, ctrl, alt)),
(Keycode::Backquote, true, ctrl, alt) => Some(("~", false, false, ctrl, alt)),
(Keycode::A, shift, ctrl, alt) => Some(("a", false, shift, ctrl, alt)),
(Keycode::B, shift, ctrl, alt) => Some(("b", false, shift, ctrl, alt)),
(Keycode::C, shift, ctrl, alt) => Some(("c", false, shift, ctrl, alt)),
(Keycode::D, shift, ctrl, alt) => Some(("d", false, shift, ctrl, alt)),
(Keycode::E, shift, ctrl, alt) => Some(("e", false, shift, ctrl, alt)),
(Keycode::F, shift, ctrl, alt) => Some(("f", false, shift, ctrl, alt)),
(Keycode::G, shift, ctrl, alt) => Some(("g", false, shift, ctrl, alt)),
(Keycode::H, shift, ctrl, alt) => Some(("h", false, shift, ctrl, alt)),
(Keycode::I, shift, ctrl, alt) => Some(("i", false, shift, ctrl, alt)),
(Keycode::J, shift, ctrl, alt) => Some(("j", false, shift, ctrl, alt)),
(Keycode::K, shift, ctrl, alt) => Some(("k", false, shift, ctrl, alt)),
(Keycode::L, shift, ctrl, alt) => Some(("l", false, shift, ctrl, alt)),
(Keycode::M, shift, ctrl, alt) => Some(("m", false, shift, ctrl, alt)),
(Keycode::N, shift, ctrl, alt) => Some(("n", false, shift, ctrl, alt)),
(Keycode::O, shift, ctrl, alt) => Some(("o", false, shift, ctrl, alt)),
(Keycode::P, shift, ctrl, alt) => Some(("p", false, shift, ctrl, alt)),
(Keycode::Q, shift, ctrl, alt) => Some(("q", false, shift, ctrl, alt)),
(Keycode::R, shift, ctrl, alt) => Some(("r", false, shift, ctrl, alt)),
(Keycode::S, shift, ctrl, alt) => Some(("s", false, shift, ctrl, alt)),
(Keycode::T, shift, ctrl, alt) => Some(("t", false, shift, ctrl, alt)),
(Keycode::U, shift, ctrl, alt) => Some(("u", false, shift, ctrl, alt)),
(Keycode::V, shift, ctrl, alt) => Some(("v", false, shift, ctrl, alt)),
(Keycode::W, shift, ctrl, alt) => Some(("w", false, shift, ctrl, alt)),
(Keycode::X, shift, ctrl, alt) => Some(("x", false, shift, ctrl, alt)),
(Keycode::Y, shift, ctrl, alt) => Some(("y", false, shift, ctrl, alt)),
(Keycode::Z, shift, ctrl, alt) => Some(("z", false, shift, ctrl, alt)),
(Keycode::Delete, shift, ctrl, alt) => Some(("Delete", true, shift, ctrl, alt)),
(Keycode::CapsLock, _, _, _) => unsupported_key(Keycode::CapsLock),
(Keycode::F1, shift, ctrl, alt) => Some(("F1", true, shift, ctrl, alt)),
(Keycode::F2, shift, ctrl, alt) => Some(("F2", true, shift, ctrl, alt)),
(Keycode::F3, shift, ctrl, alt) => Some(("F3", true, shift, ctrl, alt)),
(Keycode::F4, shift, ctrl, alt) => Some(("F4", true, shift, ctrl, alt)),
(Keycode::F5, shift, ctrl, alt) => Some(("F5", true, shift, ctrl, alt)),
(Keycode::F6, shift, ctrl, alt) => Some(("F6", true, shift, ctrl, alt)),
(Keycode::F7, shift, ctrl, alt) => Some(("F7", true, shift, ctrl, alt)),
(Keycode::F8, shift, ctrl, alt) => Some(("F8", true, shift, ctrl, alt)),
(Keycode::F9, shift, ctrl, alt) => Some(("F9", true, shift, ctrl, alt)),
(Keycode::F10, shift, ctrl, alt) => Some(("F10", true, shift, ctrl, alt)),
(Keycode::F11, shift, ctrl, alt) => Some(("F11", true, shift, ctrl, alt)),
(Keycode::F12, shift, ctrl, alt) => Some(("F12", true, shift, ctrl, alt)),
(Keycode::PrintScreen, _, _, _) => unsupported_key(Keycode::PrintScreen),
(Keycode::ScrollLock, _, _, _) => unsupported_key(Keycode::ScrollLock),
(Keycode::Pause, _, _, _) => unsupported_key(Keycode::Pause),
(Keycode::Insert, shift, ctrl, alt) => Some(("Insert", true, shift, ctrl, alt)),
(Keycode::Home, shift, ctrl, alt) => Some(("Home", true, shift, ctrl, alt)),
(Keycode::PageUp, shift, ctrl, alt) => Some(("PageUp", true, shift, ctrl, alt)),
(Keycode::End, shift, ctrl, alt) => Some(("End", true, shift, ctrl, alt)),
(Keycode::PageDown, shift, ctrl, alt) => Some(("PageDown", true, shift, ctrl, alt)),
(Keycode::Right, shift, ctrl, alt) => Some(("Right", true, shift, ctrl, alt)),
(Keycode::Left, shift, ctrl, alt) => Some(("Left", true, shift, ctrl, alt)),
(Keycode::Down, shift, ctrl, alt) => Some(("Down", true, shift, ctrl, alt)),
(Keycode::Up, shift, ctrl, alt) => Some(("Up", true, shift, ctrl, alt)),
(Keycode::NumLockClear, _, _, _) => unsupported_key(Keycode::NumLockClear),
(Keycode::KpDivide, shift, ctrl, alt) => Some(("/", true, shift, ctrl, alt)),
(Keycode::KpMultiply, shift, ctrl, alt) => Some(("*", true, shift, ctrl, alt)),
(Keycode::KpMinus, shift, ctrl, alt) => Some(("-", true, shift, ctrl, alt)),
(Keycode::KpPlus, shift, ctrl, alt) => Some(("+", true, shift, ctrl, alt)),
(Keycode::KpEnter, shift, ctrl, alt) => Some(("Enter", true, shift, ctrl, alt)),
(Keycode::Kp0, shift, ctrl, alt) => Some(("0", false, shift, ctrl, alt)),
(Keycode::Kp1, shift, ctrl, alt) => Some(("1", false, shift, ctrl, alt)),
(Keycode::Kp2, shift, ctrl, alt) => Some(("2", false, shift, ctrl, alt)),
(Keycode::Kp3, shift, ctrl, alt) => Some(("3", false, shift, ctrl, alt)),
(Keycode::Kp4, shift, ctrl, alt) => Some(("4", false, shift, ctrl, alt)),
(Keycode::Kp5, shift, ctrl, alt) => Some(("5", false, shift, ctrl, alt)),
(Keycode::Kp6, shift, ctrl, alt) => Some(("6", false, shift, ctrl, alt)),
(Keycode::Kp7, shift, ctrl, alt) => Some(("7", false, shift, ctrl, alt)),
(Keycode::Kp8, shift, ctrl, alt) => Some(("8", false, shift, ctrl, alt)),
(Keycode::Kp9, shift, ctrl, alt) => Some(("9", false, shift, ctrl, alt)),
(Keycode::KpPeriod, shift, ctrl, alt) => Some((".", false, shift, ctrl, alt)),
(Keycode::Application, _, _, _) => unsupported_key(Keycode::Application),
(Keycode::Power, _, _, _) => unsupported_key(Keycode::Power),
(Keycode::KpEquals, shift, ctrl, alt) => Some(("=", false, shift, ctrl, alt)),
(Keycode::F13, shift, ctrl, alt) => Some(("F13", true, shift, ctrl, alt)),
(Keycode::F14, shift, ctrl, alt) => Some(("F14", true, shift, ctrl, alt)),
(Keycode::F15, shift, ctrl, alt) => Some(("F15", true, shift, ctrl, alt)),
(Keycode::F16, shift, ctrl, alt) => Some(("F16", true, shift, ctrl, alt)),
(Keycode::F17, shift, ctrl, alt) => Some(("F17", true, shift, ctrl, alt)),
(Keycode::F18, shift, ctrl, alt) => Some(("F18", true, shift, ctrl, alt)),
(Keycode::F19, shift, ctrl, alt) => Some(("F19", true, shift, ctrl, alt)),
(Keycode::F20, shift, ctrl, alt) => Some(("F20", true, shift, ctrl, alt)),
(Keycode::F21, shift, ctrl, alt) => Some(("F21", true, shift, ctrl, alt)),
(Keycode::F22, shift, ctrl, alt) => Some(("F22", true, shift, ctrl, alt)),
(Keycode::F23, shift, ctrl, alt) => Some(("F23", true, shift, ctrl, alt)),
(Keycode::F24, shift, ctrl, alt) => Some(("F24", true, shift, ctrl, alt)),
(Keycode::Execute, _, _, _) => unsupported_key(Keycode::Execute),
(Keycode::Help, _, _, _) => unsupported_key(Keycode::Help),
(Keycode::Menu, _, _, _) => unsupported_key(Keycode::Menu),
(Keycode::Select, _, _, _) => unsupported_key(Keycode::Select),
(Keycode::Stop, _, _, _) => unsupported_key(Keycode::Stop),
(Keycode::Again, _, _, _) => unsupported_key(Keycode::Again),
(Keycode::Undo, _, _, _) => unsupported_key(Keycode::Undo),
(Keycode::Cut, _, _, _) => unsupported_key(Keycode::Cut),
(Keycode::Copy, _, _, _) => unsupported_key(Keycode::Copy),
(Keycode::Paste, _, _, _) => unsupported_key(Keycode::Paste),
(Keycode::Find, _, _, _) => unsupported_key(Keycode::Find),
(Keycode::Mute, _, _, _) => unsupported_key(Keycode::Mute),
(Keycode::VolumeUp, _, _, _) => unsupported_key(Keycode::VolumeUp),
(Keycode::VolumeDown, _, _, _) => unsupported_key(Keycode::VolumeDown),
(Keycode::KpComma, _, _, _) => unsupported_key(Keycode::KpComma),
(Keycode::KpEqualsAS400, _, _, _) => unsupported_key(Keycode::KpEqualsAS400),
(Keycode::AltErase, _, _, _) => unsupported_key(Keycode::AltErase),
(Keycode::Sysreq, _, _, _) => unsupported_key(Keycode::Sysreq),
(Keycode::Cancel, _, _, _) => unsupported_key(Keycode::Cancel),
(Keycode::Clear, _, _, _) => unsupported_key(Keycode::Clear),
(Keycode::Prior, _, _, _) => unsupported_key(Keycode::Prior),
(Keycode::Return2, _, _, _) => unsupported_key(Keycode::Return2),
(Keycode::Separator, _, _, _) => unsupported_key(Keycode::Separator),
(Keycode::Out, _, _, _) => unsupported_key(Keycode::Out),
(Keycode::Oper, _, _, _) => unsupported_key(Keycode::Oper),
(Keycode::ClearAgain, _, _, _) => unsupported_key(Keycode::ClearAgain),
(Keycode::CrSel, _, _, _) => unsupported_key(Keycode::CrSel),
(Keycode::ExSel, _, _, _) => unsupported_key(Keycode::ExSel),
(Keycode::Kp00, _, _, _) => unsupported_key(Keycode::Kp00),
(Keycode::Kp000, _, _, _) => unsupported_key(Keycode::Kp000),
(Keycode::ThousandsSeparator, _, _, _) => unsupported_key(Keycode::ThousandsSeparator),
(Keycode::DecimalSeparator, _, _, _) => unsupported_key(Keycode::DecimalSeparator),
(Keycode::CurrencyUnit, _, _, _) => unsupported_key(Keycode::CurrencyUnit),
(Keycode::CurrencySubUnit, _, _, _) => unsupported_key(Keycode::CurrencySubUnit),
(Keycode::KpLeftParen, shift, ctrl, alt) => Some(("(", false, shift, ctrl, alt)),
(Keycode::KpRightParen, shift, ctrl, alt) => Some(("(", false, shift, ctrl, alt)),
(Keycode::KpLeftBrace, shift, ctrl, alt) => Some(("[", false, shift, ctrl, alt)),
(Keycode::KpRightBrace, shift, ctrl, alt) => Some(("]", false, shift, ctrl, alt)),
(Keycode::KpTab, shift, ctrl, alt) => Some(("TAB", true, shift, ctrl, alt)),
(Keycode::KpBackspace, shift, ctrl, alt) => Some(("BS", true, shift, ctrl, alt)),
(Keycode::KpA, shift, ctrl, alt) => Some(("A", false, shift, ctrl, alt)),
(Keycode::KpB, shift, ctrl, alt) => Some(("B", false, shift, ctrl, alt)),
(Keycode::KpC, shift, ctrl, alt) => Some(("C", false, shift, ctrl, alt)),
(Keycode::KpD, shift, ctrl, alt) => Some(("D", false, shift, ctrl, alt)),
(Keycode::KpE, shift, ctrl, alt) => Some(("E", false, shift, ctrl, alt)),
(Keycode::KpF, shift, ctrl, alt) => Some(("F", false, shift, ctrl, alt)),
(Keycode::KpXor, _, _, _) => unsupported_key(Keycode::KpXor),
(Keycode::KpPower, shift, ctrl, alt) => Some(("^", false, shift, ctrl, alt)),
(Keycode::KpPercent, shift, ctrl, alt) => Some(("%", false, shift, ctrl, alt)),
(Keycode::KpLess, shift, ctrl, alt) => Some(("lt", true, shift, ctrl, alt)),
(Keycode::KpGreater, shift, ctrl, alt) => Some(("gt", true, shift, ctrl, alt)),
(Keycode::KpAmpersand, shift, ctrl, alt) => Some(("&", false, shift, ctrl, alt)),
(Keycode::KpDblAmpersand, _, _, _) => unsupported_key(Keycode::KpDblAmpersand),
(Keycode::KpVerticalBar, shift, ctrl, alt) => Some(("|", false, shift, ctrl, alt)),
(Keycode::KpDblVerticalBar, _, _, _) => unsupported_key(Keycode::KpDblVerticalBar),
(Keycode::KpColon, shift, ctrl, alt) => Some((":", false, shift, ctrl, alt)),
(Keycode::KpHash, shift, ctrl, alt) => Some(("#", false, shift, ctrl, alt)),
(Keycode::KpSpace, shift, ctrl, alt) => Some((" ", false, shift, ctrl, alt)),
(Keycode::KpAt, shift, ctrl, alt) => Some(("@", false, shift, ctrl, alt)),
(Keycode::KpExclam, shift, ctrl, alt) => Some(("!", false, shift, ctrl, alt)),
(Keycode::KpMemStore, _, _, _) => unsupported_key(Keycode::KpMemStore),
(Keycode::KpMemRecall, _, _, _) => unsupported_key(Keycode::KpMemRecall),
(Keycode::KpMemClear, _, _, _) => unsupported_key(Keycode::KpMemClear),
(Keycode::KpMemAdd, _, _, _) => unsupported_key(Keycode::KpMemAdd),
(Keycode::KpMemSubtract, _, _, _) => unsupported_key(Keycode::KpMemSubtract),
(Keycode::KpMemMultiply, _, _, _) => unsupported_key(Keycode::KpMemMultiply),
(Keycode::KpMemDivide, _, _, _) => unsupported_key(Keycode::KpMemDivide),
(Keycode::KpPlusMinus, _, _, _) => unsupported_key(Keycode::KpPlusMinus),
(Keycode::KpClear, _, _, _) => unsupported_key(Keycode::KpClear),
(Keycode::KpClearEntry, _, _, _) => unsupported_key(Keycode::KpClearEntry),
(Keycode::KpBinary, _, _, _) => unsupported_key(Keycode::KpBinary),
(Keycode::KpOctal, _, _, _) => unsupported_key(Keycode::KpOctal),
(Keycode::KpDecimal, _, _, _) => unsupported_key(Keycode::KpDecimal),
(Keycode::KpHexadecimal, _, _, _) => unsupported_key(Keycode::KpHexadecimal),
(Keycode::LCtrl, _, _, _) => None,
(Keycode::LShift, _, _, _) => None,
(Keycode::LAlt, _, _, _) => None,
(Keycode::LGui, _, _, _) => None,
(Keycode::RCtrl, _, _, _) => None,
(Keycode::RShift, _, _, _) => None,
(Keycode::RAlt, _, _, _) => None,
(Keycode::RGui, _, _, _) => None,
(Keycode::Mode, _, _, _) => unsupported_key(Keycode::Mode),
(Keycode::AudioNext, _, _, _) => unsupported_key(Keycode::AudioNext),
(Keycode::AudioPrev, _, _, _) => unsupported_key(Keycode::AudioPrev),
(Keycode::AudioStop, _, _, _) => unsupported_key(Keycode::AudioStop),
(Keycode::AudioPlay, _, _, _) => unsupported_key(Keycode::AudioPlay),
(Keycode::AudioMute, _, _, _) => unsupported_key(Keycode::AudioMute),
(Keycode::MediaSelect, _, _, _) => unsupported_key(Keycode::MediaSelect),
(Keycode::Www, _, _, _) => unsupported_key(Keycode::Www),
(Keycode::Mail, _, _, _) => unsupported_key(Keycode::Mail),
(Keycode::Calculator, _, _, _) => unsupported_key(Keycode::Calculator),
(Keycode::Computer, _, _, _) => unsupported_key(Keycode::Computer),
(Keycode::AcSearch, _, _, _) => unsupported_key(Keycode::AcSearch),
(Keycode::AcHome, _, _, _) => unsupported_key(Keycode::AcHome),
(Keycode::AcBack, _, _, _) => unsupported_key(Keycode::AcBack),
(Keycode::AcForward, _, _, _) => unsupported_key(Keycode::AcForward),
(Keycode::AcStop, _, _, _) => unsupported_key(Keycode::AcStop),
(Keycode::AcRefresh, _, _, _) => unsupported_key(Keycode::AcRefresh),
(Keycode::AcBookmarks, _, _, _) => unsupported_key(Keycode::AcBookmarks),
(Keycode::BrightnessDown, _, _, _) => unsupported_key(Keycode::BrightnessDown),
(Keycode::BrightnessUp, _, _, _) => unsupported_key(Keycode::BrightnessUp),
(Keycode::DisplaySwitch, _, _, _) => unsupported_key(Keycode::DisplaySwitch),
(Keycode::KbdIllumToggle, _, _, _) =>unsupported_key(Keycode::KbdIllumToggle),
(Keycode::KbdIllumDown, _, _, _) => unsupported_key(Keycode::KbdIllumDown),
(Keycode::KbdIllumUp, _, _, _) => unsupported_key(Keycode::KbdIllumUp),
(Keycode::Eject, _, _, _) => unsupported_key(Keycode::Eject),
(Keycode::Sleep, _, _, _) => unsupported_key(Keycode::Sleep)
}
}

@ -1,6 +1,8 @@
#[macro_use]
pub mod layouts;
mod events; mod events;
mod handler; mod handler;
mod keybindings;
mod ui_commands; mod ui_commands;
use std::sync::Arc; use std::sync::Arc;
@ -14,7 +16,7 @@ use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use log::{info, error, trace}; use log::{info, error, trace};
pub use events::*; pub use events::*;
pub use keybindings::*; pub use layouts::*;
use crate::settings::*; use crate::settings::*;
pub use ui_commands::UiCommand; pub use ui_commands::UiCommand;
use handler::NeovimHandler; use handler::NeovimHandler;
@ -93,7 +95,7 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
nvim.ui_attach(width as i64, height as i64, &options).await nvim.ui_attach(width as i64, height as i64, &options).await
.unwrap_or_explained_panic("Could not attach ui to neovim process"); .unwrap_or_explained_panic("Could not attach ui to neovim process");
if let Err(command_error) = nvim.command("runtime! ginit.vim").await { if let Err(command_error) = nvim.command("runtime! ginit.vim").await {
nvim.command("echomsg \"error encountered in ginit.vim\"").await.ok(); nvim.command(&format!("echomsg \"error encountered in ginit.vim {:?}\"", command_error)).await.ok();
} }
info!("Neovim process attached"); info!("Neovim process attached");

@ -10,7 +10,6 @@ mod renderer;
mod error_handling; mod error_handling;
mod redraw_scheduler; mod redraw_scheduler;
#[macro_use] extern crate derive_new; #[macro_use] extern crate derive_new;
#[macro_use] extern crate rust_embed; #[macro_use] extern crate rust_embed;
#[macro_use] extern crate lazy_static; #[macro_use] extern crate lazy_static;
@ -26,6 +25,7 @@ fn main() {
window::initialize_settings(); window::initialize_settings();
redraw_scheduler::initialize_settings(); redraw_scheduler::initialize_settings();
renderer::cursor_renderer::initialize_settings(); renderer::cursor_renderer::initialize_settings();
bridge::layouts::initialize_settings();
initialize(&BRIDGE); initialize(&BRIDGE);
ui_loop(); ui_loop();

@ -11,7 +11,7 @@ use skulpin::sdl2::keyboard::Keycode;
use skulpin::{RendererBuilder, Renderer as SkulpinRenderer, PresentMode, CoordinateSystem, dpis}; use skulpin::{RendererBuilder, Renderer as SkulpinRenderer, PresentMode, CoordinateSystem, dpis};
use crate::settings::*; use crate::settings::*;
use crate::bridge::{parse_keycode, append_modifiers, BRIDGE, UiCommand}; use crate::bridge::{produce_neovim_keybinding_string, BRIDGE, UiCommand};
use crate::renderer::Renderer; use crate::renderer::Renderer;
use crate::redraw_scheduler::REDRAW_SCHEDULER; use crate::redraw_scheduler::REDRAW_SCHEDULER;
use crate::editor::EDITOR; use crate::editor::EDITOR;
@ -49,7 +49,6 @@ struct WindowWrapper {
title: String, title: String,
previous_size: LogicalSize, previous_size: LogicalSize,
previous_dpis: (f32, f32), previous_dpis: (f32, f32),
ignore_text_input: bool,
transparency: f32, transparency: f32,
fullscreen: bool fullscreen: bool
} }
@ -115,7 +114,6 @@ impl WindowWrapper {
title: String::from("Neovide"), title: String::from("Neovide"),
previous_size, previous_size,
previous_dpis, previous_dpis,
ignore_text_input: false,
transparency: 1.0, transparency: 1.0,
fullscreen: false fullscreen: false
} }
@ -149,12 +147,14 @@ impl WindowWrapper {
pub fn handle_keyboard_input(&mut self, keycode: Option<Keycode>, text: Option<String>) { pub fn handle_keyboard_input(&mut self, keycode: Option<Keycode>, text: Option<String>) {
let modifiers = self.context.keyboard().mod_state(); let modifiers = self.context.keyboard().mod_state();
trace!("Keyboard Input Received: keycode-{:?} modifiers-{:?} text-{:?}", keycode, modifiers, text);
text.as_deref() if keycode.is_some() || text.is_some() {
.map(|text| (text, false)) trace!("Keyboard Input Received: keycode-{:?} modifiers-{:?} text-{:?}", keycode, modifiers, text);
.or_else(|| keycode.map(parse_keycode).flatten()) }
.map(|(text, special)| BRIDGE.queue_command(UiCommand::Keyboard(append_modifiers(modifiers, text, special))));
if let Some(keybinding_string) = produce_neovim_keybinding_string(keycode, text, modifiers) {
BRIDGE.queue_command(UiCommand::Keyboard(keybinding_string));
}
} }
pub fn handle_pointer_motion(&mut self, x: i32, y: i32) { pub fn handle_pointer_motion(&mut self, x: i32, y: i32) {

Loading…
Cancel
Save