wayland: add optional reis emulated input support

Add support for the Emulated Input protocol using the Rust library.
This commit is contained in:
Richard Acayan 2024-10-17 21:26:25 -04:00
parent 89c96c511a
commit 030ca29ddd
No known key found for this signature in database
GPG key ID: 0346F4894879DB73

View file

@ -24,6 +24,13 @@ use crate::wayland::viewporter::wp_viewporter;
use crate::wayland::viewporter::wp_viewport; 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_manager_v1;
use crate::wayland::virtual_keyboard_unstable_v1::zwp_virtual_keyboard_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::io::Error;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
@ -49,6 +56,8 @@ pub struct Dispatcher {
seat: Seat<Surface<Self>, VirtualKeyboard, Self>, seat: Seat<Surface<Self>, VirtualKeyboard, Self>,
gfx: Arc<Mutex<Graphics<Surface<Self>>>>, gfx: Arc<Mutex<Graphics<Surface<Self>>>>,
osk: Option<VisibilityManager>, osk: Option<VisibilityManager>,
libei_caps: u64,
} }
impl Dispatcher { impl Dispatcher {
@ -106,6 +115,8 @@ impl Dispatcher {
seat, seat,
gfx, gfx,
osk: None, 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<wl_buffer::WlBuffer, u32> for Dispatcher { impl Dispatch<wl_buffer::WlBuffer, u32> for Dispatcher {
fn event(ctx: &mut Dispatcher, fn event(ctx: &mut Dispatcher,
_buf: &wl_buffer::WlBuffer, _buf: &wl_buffer::WlBuffer,