X11: impl keyboard events (still disabled)

Needs keycode translation
This commit is contained in:
Ferdinand Schober
2023-12-16 12:11:43 +01:00
parent 0fbf9f4dc2
commit 9140f60c69

View File

@@ -1,8 +1,8 @@
use async_trait::async_trait;
use std::ptr;
use x11::{xlib, xtest};
use x11::{xlib::{self, XKeysymToKeycode, XCloseDisplay}, xtest};
use crate::{client::ClientHandle, consumer::EventConsumer, event::{Event, PointerEvent, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, BTN_FORWARD, BTN_BACK}};
use crate::{client::ClientHandle, consumer::EventConsumer, event::{Event, PointerEvent, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, BTN_FORWARD, BTN_BACK, KeyboardEvent}};
pub struct X11Consumer {
display: *mut xlib::Display,
@@ -57,6 +57,12 @@ impl X11Consumer {
xtest::XTestFakeButtonEvent(self.display, direction, 0, 0);
}
}
fn emulate_key(&self, key: u32, state: u8) {
unsafe {
xtest::XTestFakeKeyEvent(self.display, key, state as i32, 0);
}
}
}
impl Default for X11Consumer {
@@ -65,6 +71,14 @@ impl Default for X11Consumer {
}
}
impl Drop for X11Consumer {
fn drop(&mut self) {
unsafe {
XCloseDisplay(self.display);
}
}
}
#[async_trait]
impl EventConsumer for X11Consumer {
async fn consume(&mut self, event: Event, _: ClientHandle) {
@@ -85,7 +99,9 @@ impl EventConsumer for X11Consumer {
}
PointerEvent::Frame {} => {}
},
Event::Keyboard(_) => {}
Event::Keyboard(KeyboardEvent::Key { time: _, key, state }) => {
// self.emulate_key(key, state);
}
_ => {}
}
unsafe {