working keybindings

macos-click-through
Keith Simmons 5 years ago committed by keith
parent f25381530f
commit b758f01b62

@ -2,7 +2,7 @@ use log::trace;
// use skulpin::winit::event::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode}; // use skulpin::winit::event::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode};
use skulpin::sdl2::keyboard::{Keycode, Mod}; use skulpin::sdl2::keyboard::{Keycode, Mod};
fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> { pub fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> {
macro_rules! unsupported_key { macro_rules! unsupported_key {
($name: ident) => {{ ($name: ident) => {{
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
@ -15,10 +15,10 @@ fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> {
// Documentation: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlkey.html // Documentation: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlkey.html
match keycode { match keycode {
Keycode::Backspace => Some(("BS", true)), Keycode::Backspace => Some(("BS", true)),
Keycode::Tab => Some((" ", false)), Keycode::Tab => Some(("Tab", true)),
Keycode::Return => Some(("\n", false)), Keycode::Return => Some(("Enter", true)),
Keycode::Escape => Some(("ESC", true)), Keycode::Escape => Some(("Esc", true)),
Keycode::Space => Some((" ", true)), Keycode::Space => Some((" ", false)),
Keycode::Exclaim => Some(("!", false)), Keycode::Exclaim => Some(("!", false)),
Keycode::Quotedbl => Some(("\"", false)), Keycode::Quotedbl => Some(("\"", false)),
Keycode::Hash => Some(("#", false)), Keycode::Hash => Some(("#", false)),
@ -114,7 +114,7 @@ fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> {
Keycode::KpMultiply => Some(("*", true)), Keycode::KpMultiply => Some(("*", true)),
Keycode::KpMinus => Some(("-", true)), Keycode::KpMinus => Some(("-", true)),
Keycode::KpPlus => Some(("+", true)), Keycode::KpPlus => Some(("+", true)),
Keycode::KpEnter => Some(("\n", true)), Keycode::KpEnter => Some(("Enter", true)),
Keycode::Kp0 => Some(("0", false)), Keycode::Kp0 => Some(("0", false)),
Keycode::Kp1 => Some(("1", false)), Keycode::Kp1 => Some(("1", false)),
Keycode::Kp2 => Some(("2", false)), Keycode::Kp2 => Some(("2", false)),
@ -179,7 +179,7 @@ fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> {
Keycode::KpRightParen => Some((")", false)), Keycode::KpRightParen => Some((")", false)),
Keycode::KpLeftBrace => Some(("[", false)), Keycode::KpLeftBrace => Some(("[", false)),
Keycode::KpRightBrace => Some(("]", false)), Keycode::KpRightBrace => Some(("]", false)),
Keycode::KpTab => Some((" ", false)), Keycode::KpTab => Some(("TAB", true)),
Keycode::KpBackspace => Some(("BS", true)), Keycode::KpBackspace => Some(("BS", true)),
Keycode::KpA => Some(("A", false)), Keycode::KpA => Some(("A", false)),
Keycode::KpB => Some(("B", false)), Keycode::KpB => Some(("B", false)),
@ -248,7 +248,7 @@ fn parse_keycode(keycode: Keycode) -> Option<(&'static str, bool)> {
Keycode::KbdIllumDown => unsupported_key!(KbdIllumDown), Keycode::KbdIllumDown => unsupported_key!(KbdIllumDown),
Keycode::KbdIllumUp => unsupported_key!(KbdIllumUp), Keycode::KbdIllumUp => unsupported_key!(KbdIllumUp),
Keycode::Eject => unsupported_key!(Eject), Keycode::Eject => unsupported_key!(Eject),
Keycode::Sleep => unsupported_key!(Sleep), Keycode::Sleep => unsupported_key!(Sleep)
} }
} }

@ -6,9 +6,10 @@ use skulpin::LogicalSize;
use skulpin::sdl2; use skulpin::sdl2;
use skulpin::sdl2::EventPump; use skulpin::sdl2::EventPump;
use skulpin::sdl2::event::Event; use skulpin::sdl2::event::Event;
use skulpin::sdl2::keyboard::Mod;
use skulpin::{RendererBuilder, PresentMode, CoordinateSystem}; use skulpin::{RendererBuilder, PresentMode, CoordinateSystem};
use crate::bridge::{construct_keybinding_string, BRIDGE, UiCommand}; use crate::bridge::{parse_keycode, append_modifiers, 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;
@ -54,6 +55,7 @@ pub fn ui_loop() {
let mut window = video_subsystem.window("Neovide", logical_size.width, logical_size.height) let mut window = video_subsystem.window("Neovide", logical_size.width, logical_size.height)
.position_centered() .position_centered()
.allow_highdpi()
.vulkan() .vulkan()
.build() .build()
.expect("Failed to create window"); .expect("Failed to create window");
@ -63,7 +65,7 @@ pub fn ui_loop() {
.prefer_integrated_gpu() .prefer_integrated_gpu()
.use_vulkan_debug_layer(true) .use_vulkan_debug_layer(true)
.present_mode_priority(vec![PresentMode::Mailbox, PresentMode::Immediate]) .present_mode_priority(vec![PresentMode::Mailbox, PresentMode::Immediate])
.coordinate_system(CoordinateSystem::Logical) .coordinate_system(CoordinateSystem::Physical)
.build(&window) .build(&window)
.expect("Failed to create renderer"); .expect("Failed to create renderer");
info!("renderer created"); info!("renderer created");
@ -90,12 +92,37 @@ pub fn ui_loop() {
for event in event_pump.poll_iter() { for event in event_pump.poll_iter() {
match event { match event {
Event::Quit {..} => break 'running, Event::Quit {..} => break 'running,
Event::KeyDown {
keycode: Some(keycode),
keymod: modifiers,
..
} => {
dbg!(keycode);
if let Some((key_text, special)) = parse_keycode(keycode) {
let will_text_input =
!modifiers.contains(Mod::LCTRLMOD) &&
!modifiers.contains(Mod::RCTRLMOD) &&
!modifiers.contains(Mod::LALTMOD) &&
!modifiers.contains(Mod::RALTMOD) &&
!modifiers.contains(Mod::LGUIMOD) &&
!modifiers.contains(Mod::RGUIMOD);
if will_text_input && !special {
break;
}
BRIDGE.queue_command(UiCommand::Keyboard(append_modifiers(modifiers, key_text, special)));
}
},
Event::TextInput {
text,
..
} => BRIDGE.queue_command(UiCommand::Keyboard(text)),
_ => {} _ => {}
} }
} }
if REDRAW_SCHEDULER.should_draw() || SETTINGS.get("no_idle").read_bool() {
debug!("Render Triggered"); debug!("Render Triggered");
if REDRAW_SCHEDULER.should_draw() || SETTINGS.get("no_idle").read_bool() {
if skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| { if skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| {
if renderer.draw(canvas, coordinate_system_helper) { if renderer.draw(canvas, coordinate_system_helper) {
handle_new_grid_size(window.vulkan_drawable_size().into(), &renderer) handle_new_grid_size(window.vulkan_drawable_size().into(), &renderer)
@ -107,7 +134,7 @@ pub fn ui_loop() {
} }
let elapsed = frame_start.elapsed(); let elapsed = frame_start.elapsed();
let frame_length = Duration::from_secs_f32(1.0 / 60.0); let frame_length = Duration::from_secs_f32(1.0 / 30.0);
if elapsed < frame_length { if elapsed < frame_length {
sleep(frame_length - elapsed); sleep(frame_length - elapsed);
} }

Loading…
Cancel
Save