From 9140f60c6989e278747456ec6cf62cf6e66c8ee6 Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Sat, 16 Dec 2023 12:11:43 +0100 Subject: [PATCH] X11: impl keyboard events (still disabled) Needs keycode translation --- src/backend/consumer/x11.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/backend/consumer/x11.rs b/src/backend/consumer/x11.rs index 2d46a40..2ab312e 100644 --- a/src/backend/consumer/x11.rs +++ b/src/backend/consumer/x11.rs @@ -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 {