wayland: move input logic to the event loop
This commit is contained in:
parent
7336cacf07
commit
17fde48ed7
4 changed files with 450 additions and 467 deletions
|
|
@ -4,17 +4,18 @@ use {VirtualKeyCode, ElementState, WindowEvent as Event};
|
|||
|
||||
use events::ModifiersState;
|
||||
|
||||
use super::{wayland_kbd, make_wid, EventsLoopSink};
|
||||
use super::{wayland_kbd, EventsLoopSink, WindowId};
|
||||
use wayland_client::EventQueueHandle;
|
||||
use wayland_client::protocol::{wl_keyboard, wl_surface};
|
||||
use wayland_client::protocol::wl_keyboard;
|
||||
|
||||
pub struct KbdHandler {
|
||||
pub target: Option<(Arc<wl_surface::WlSurface>,Arc<Mutex<EventsLoopSink>>)>
|
||||
sink: Arc<Mutex<EventsLoopSink>>,
|
||||
pub target: Option<WindowId>
|
||||
}
|
||||
|
||||
impl KbdHandler {
|
||||
pub fn new() -> KbdHandler {
|
||||
KbdHandler { target: None }
|
||||
pub fn new(sink: Arc<Mutex<EventsLoopSink>>) -> KbdHandler {
|
||||
KbdHandler { sink: sink, target: None }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,14 +31,14 @@ impl wayland_kbd::Handler for KbdHandler {
|
|||
state: wl_keyboard::KeyState,
|
||||
utf8: Option<String>)
|
||||
{
|
||||
if let Some((ref window, ref sink)) = self.target {
|
||||
if let Some(wid) = self.target {
|
||||
let state = match state {
|
||||
wl_keyboard::KeyState::Pressed => ElementState::Pressed,
|
||||
wl_keyboard::KeyState::Released => ElementState::Released,
|
||||
};
|
||||
let vkcode = key_to_vkey(rawkey, keysym);
|
||||
let mut guard = sink.lock().unwrap();
|
||||
guard.push_event(
|
||||
let mut guard = self.sink.lock().unwrap();
|
||||
guard.send_event(
|
||||
Event::KeyboardInput(
|
||||
state,
|
||||
rawkey as u8,
|
||||
|
|
@ -49,13 +50,13 @@ impl wayland_kbd::Handler for KbdHandler {
|
|||
logo: mods.logo
|
||||
}
|
||||
),
|
||||
make_wid(window)
|
||||
wid
|
||||
);
|
||||
// send char event only on key press, not release
|
||||
if let ElementState::Released = state { return }
|
||||
if let Some(txt) = utf8 {
|
||||
for chr in txt.chars() {
|
||||
guard.push_event(Event::ReceivedCharacter(chr), make_wid(window));
|
||||
guard.send_event(Event::ReceivedCharacter(chr), wid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue