Hack to interpret more keyboard events on Linux

macos-click-through
Jon Valdés 5 years ago
parent 4f7f8654a6
commit c6d2a9a0f5

@ -94,7 +94,7 @@ fn parse_keycode(keycode: VirtualKeyCode) -> Option<(&'static str, bool)> {
} }
} }
fn append_modifiers(modifiers: ModifiersState, keycode_text: &str, special: bool) -> String { pub fn append_modifiers(modifiers: ModifiersState, keycode_text: &str, special: bool) -> String {
let mut result = keycode_text.to_string(); let mut result = keycode_text.to_string();
let mut special = special; let mut special = special;

@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
use image::{load_from_memory, GenericImageView, Pixel}; use image::{load_from_memory, GenericImageView, Pixel};
use skulpin::{CoordinateSystem, RendererBuilder, PresentMode}; use skulpin::{CoordinateSystem, RendererBuilder, PresentMode};
use skulpin::winit::dpi::LogicalSize; use skulpin::winit::dpi::LogicalSize;
use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent}; use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent, ModifiersState};
use skulpin::winit::event_loop::{ControlFlow, EventLoop}; use skulpin::winit::event_loop::{ControlFlow, EventLoop};
use skulpin::winit::window::{Icon, WindowBuilder}; use skulpin::winit::window::{Icon, WindowBuilder};
use log::{info, debug, trace, error}; use log::{info, debug, trace, error};
@ -73,6 +73,9 @@ pub fn ui_loop() {
let mut mouse_down = false; let mut mouse_down = false;
let mut mouse_pos = (0, 0); let mut mouse_pos = (0, 0);
let mut allow_next_char = false;
let mut next_char_modifiers = ModifiersState::empty();
info!("Starting window event loop"); info!("Starting window event loop");
event_loop.run(move |event, _window_target, control_flow| { event_loop.run(move |event, _window_target, control_flow| {
trace!("Window Event: {:?}", event); trace!("Window Event: {:?}", event);
@ -101,11 +104,28 @@ pub fn ui_loop() {
}, },
.. ..
} => { } => {
if input.virtual_keycode == None {
allow_next_char = true;
}else {
allow_next_char = false;
}
next_char_modifiers = input.modifiers;
construct_keybinding_string(input) construct_keybinding_string(input)
.map(UiCommand::Keyboard) .map(UiCommand::Keyboard)
.map(|keybinding_string| BRIDGE.queue_command(keybinding_string)); .map(|keybinding_string| BRIDGE.queue_command(keybinding_string));
}, },
Event::WindowEvent {
event: WindowEvent::ReceivedCharacter(c),
..
} => {
if allow_next_char {
let keybinding = super::bridge::append_modifiers(next_char_modifiers, &c.to_string(), false);
BRIDGE.queue_command(UiCommand::Keyboard(keybinding));
}
},
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CursorMoved { event: WindowEvent::CursorMoved {
position, position,

Loading…
Cancel
Save