Merge pull request #109 from jonvaldes/linux-input-hack

Linux input hack
macos-click-through
Keith Simmons 5 years ago committed by GitHub
commit 5cca9ba3f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 special = special;

@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
use image::{load_from_memory, GenericImageView, Pixel};
use skulpin::{CoordinateSystem, RendererBuilder, PresentMode};
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::window::{Icon, WindowBuilder};
use log::{info, debug, trace, error};
@ -73,6 +73,9 @@ pub fn ui_loop() {
let mut mouse_down = false;
let mut mouse_pos = (0, 0);
let mut allow_next_char = false;
let mut next_char_modifiers = ModifiersState::empty();
info!("Starting window event loop");
event_loop.run(move |event, _window_target, control_flow| {
trace!("Window Event: {:?}", event);
@ -101,11 +104,32 @@ pub fn ui_loop() {
},
..
} => {
// Only interpret 'char' events when we get a previous event without a virtual
// keycode (which we ignore for KeyboardInput events).
// This is a hack so we don't lose a bunch of input events on Linux
if input.virtual_keycode == None {
allow_next_char = true;
}else {
allow_next_char = false;
}
next_char_modifiers = input.modifiers;
construct_keybinding_string(input)
.map(UiCommand::Keyboard)
.map(|keybinding_string| BRIDGE.queue_command(keybinding_string));
},
Event::WindowEvent {
event: WindowEvent::ReceivedCharacter(c),
..
} => {
if allow_next_char {
next_char_modifiers.remove(ModifiersState::SHIFT);
let keybinding = super::bridge::append_modifiers(next_char_modifiers, &c.to_string(), false);
BRIDGE.queue_command(UiCommand::Keyboard(keybinding));
}
},
Event::WindowEvent {
event: WindowEvent::CursorMoved {
position,

Loading…
Cancel
Save