Libei support - input emulation (#33)

Add support for input emulation through libei!
This commit is contained in:
Ferdinand Schober
2023-12-03 12:55:30 -08:00
committed by Ferdinand Schober
parent e6677c3061
commit 74eebc07d8
18 changed files with 570 additions and 265 deletions

View File

@@ -1,10 +1,6 @@
use std::error::Error;
use std::{error::Error, io};
#[cfg(unix)]
use std::{io, os::fd::RawFd, vec::Drain};
#[cfg(unix)]
use tokio::io::unix::AsyncFd;
use futures_core::Stream;
use crate::{client::{ClientHandle, ClientEvent}, event::Event};
use crate::backend::producer;
@@ -14,7 +10,8 @@ use std::env;
#[cfg(unix)]
enum Backend {
Wayland,
LayerShell,
Libei,
X11,
}
@@ -31,7 +28,22 @@ pub fn create() -> Result<Box<dyn EventProducer>, Box<dyn Error>> {
},
"wayland" => {
log::info!("XDG_SESSION_TYPE = wayland -> using wayland event producer");
Backend::Wayland
match env::var("XDG_CURRENT_DESKTOP") {
Ok(desktop) => match desktop.as_str() {
"GNOME" => {
log::info!("XDG_CURRENT_DESKTOP = GNOME -> using libei backend");
Backend::Libei
}
d => {
log::info!("XDG_CURRENT_DESKTOP = {d} -> using layer_shell backend");
Backend::LayerShell
}
}
Err(_) => {
log::warn!("XDG_CURRENT_DESKTOP not set! Assuming layer_shell support -> using layer_shell backend");
Backend::LayerShell
}
}
}
_ => panic!("unknown XDG_SESSION_TYPE"),
},
@@ -46,33 +58,25 @@ pub fn create() -> Result<Box<dyn EventProducer>, Box<dyn Error>> {
#[cfg(feature = "x11")]
Ok(Box::new(producer::x11::X11Producer::new()))
}
Backend::Wayland => {
Backend::LayerShell => {
#[cfg(not(feature = "wayland"))]
panic!("feature wayland not enabled");
#[cfg(feature = "wayland")]
Ok(Box::new(producer::wayland::WaylandEventProducer::new()?))
}
Backend::Libei => {
#[cfg(not(feature = "libei"))]
panic!("feature libei not enabled");
#[cfg(feature = "libei")]
Ok(Box::new(producer::libei::LibeiProducer::new()?))
},
}
}
pub trait EventProducer {
pub trait EventProducer: Stream<Item = io::Result<(ClientHandle, Event)>> + Unpin {
/// notify event producer of configuration changes
fn notify(&mut self, event: ClientEvent);
/// release mouse
fn release(&mut self);
/// unix only
#[cfg(unix)]
fn get_async_fd(&self) -> io::Result<AsyncFd<RawFd>>;
/// read an event
/// this function must be invoked to retrieve an Event after
/// the eventfd indicates a pending Event
#[cfg(unix)]
fn read_events(&mut self) -> Drain<(ClientHandle, Event)>;
#[cfg(not(unix))]
fn get_wait_channel(&mut self) -> Option<tokio::sync::mpsc::Receiver<(ClientHandle, Event)>>;
}