From 030ca29dddcf00472e3efcb31991167dc7a6e5d1 Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Thu, 17 Oct 2024 21:26:25 -0400 Subject: [PATCH] wayland: add optional reis emulated input support Add support for the Emulated Input protocol using the Rust library. --- src/wayland/dispatcher.rs | 93 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/wayland/dispatcher.rs b/src/wayland/dispatcher.rs index 8772866..ea9de23 100644 --- a/src/wayland/dispatcher.rs +++ b/src/wayland/dispatcher.rs @@ -24,6 +24,13 @@ use crate::wayland::viewporter::wp_viewporter; use crate::wayland::viewporter::wp_viewport; use crate::wayland::virtual_keyboard_unstable_v1::zwp_virtual_keyboard_manager_v1; use crate::wayland::virtual_keyboard_unstable_v1::zwp_virtual_keyboard_v1; +use reis::PendingRequestResult; +use reis::ei::Context; +use reis::ei::Event; +use reis::ei::connection; +use reis::ei::device; +use reis::ei::keyboard; +use reis::ei::seat; use std::io::Error; use std::sync::Arc; use std::sync::Mutex; @@ -49,6 +56,8 @@ pub struct Dispatcher { seat: Seat, VirtualKeyboard, Self>, gfx: Arc>>>, osk: Option, + + libei_caps: u64, } impl Dispatcher { @@ -106,6 +115,8 @@ impl Dispatcher { seat, gfx, osk: None, + + libei_caps: 0, }) } @@ -156,6 +167,88 @@ impl Dispatcher { } } +#[allow(dead_code)] +impl Dispatcher { + fn dispatch_ei_connection(&mut self, + _conn: connection::Connection, + evt: connection::Event) + { + match evt { + connection::Event::Ping { ping } => { + ping.done(0); + }, + connection::Event::Seat { .. } => (), + _ => eprintln!("warn: unknown ei_connection event emitted"), + }; + } + + fn dispatch_ei_device(&mut self, + dev: device::Device, + evt: device::Event) + { + match evt { + device::Event::DeviceType { .. } => (), + device::Event::Done => (), + device::Event::Frame { serial, .. } => { + self.seat.keyboard_mut().set_ei_serial(serial); + }, + device::Event::Interface { object } => { + if let Some(kbd) = object.downcast() { + self.seat.keyboard_mut().set_ei_keyboard(dev, kbd); + } + }, + device::Event::Name { .. } => (), + device::Event::Resumed { serial } => { + self.seat.keyboard_mut().set_ei_serial(serial); + dev.start_emulating(serial, 0); + }, + _ => eprintln!("warn: unknown ei_device event emitted"), + }; + } + + fn dispatch_ei_keyboard(&mut self, _kbd: keyboard::Keyboard, evt: keyboard::Event) + { + match evt { + _ => eprintln!("warn: unknown ei_keyboard event emitted"), + }; + } + + fn dispatch_ei_seat(&mut self, seat: seat::Seat, evt: seat::Event) + { + match evt { + seat::Event::Capability { mask, interface } => { + if interface == "ei_keyboard" { + self.libei_caps |= mask; + } + }, + seat::Event::Done => { + seat.bind(self.libei_caps); + }, + seat::Event::Device { .. } => (), + seat::Event::Name { .. } => (), + _ => eprintln!("warn: unknown ei_seat event emitted"), + }; + } + + pub fn dispatch_ei(&mut self, ctx: &Context) + { + while let Some(evt) = ctx.pending_event() { + let evt = match evt { + PendingRequestResult::Request(e) => e, + _ => panic!(), + }; + + match evt { + Event::Connection(c, e) => self.dispatch_ei_connection(c, e), + Event::Device(d, e) => self.dispatch_ei_device(d, e), + Event::Keyboard(k, e) => self.dispatch_ei_keyboard(k, e), + Event::Seat(s, e) => self.dispatch_ei_seat(s, e), + _ => eprintln!("warn: unknown libei event emitted"), + }; + } + } +} + impl Dispatch for Dispatcher { fn event(ctx: &mut Dispatcher, _buf: &wl_buffer::WlBuffer,