Skip to content

Commit

Permalink
rename producer, consumer to emulation and capture (#98)
Browse files Browse the repository at this point in the history
input emulation / input capture is clearer than event consumer and producer
  • Loading branch information
feschber authored Mar 21, 2024
1 parent 78c9de4 commit 742b158
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 237 deletions.
38 changes: 19 additions & 19 deletions src/producer.rs → src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,55 @@ pub mod windows;
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
pub mod x11;

/// fallback event producer
/// fallback input capture (does not produce events)
pub mod dummy;

pub async fn create() -> Box<dyn EventProducer> {
pub async fn create() -> Box<dyn InputCapture> {
#[cfg(target_os = "macos")]
match macos::MacOSProducer::new() {
match macos::MacOSInputCapture::new() {
Ok(p) => return Box::new(p),
Err(e) => log::info!("macos event producer not available: {e}"),
Err(e) => log::info!("macos input capture not available: {e}"),
}

#[cfg(windows)]
match windows::WindowsProducer::new() {
match windows::WindowsInputCapture::new() {
Ok(p) => return Box::new(p),
Err(e) => log::info!("windows event producer not available: {e}"),
Err(e) => log::info!("windows input capture not available: {e}"),
}

#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
match libei::LibeiProducer::new().await {
match libei::LibeiInputCapture::new().await {
Ok(p) => {
log::info!("using libei event producer");
log::info!("using libei input capture");
return Box::new(p);
}
Err(e) => log::info!("libei event producer not available: {e}"),
Err(e) => log::info!("libei input capture not available: {e}"),
}

#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
match wayland::WaylandEventProducer::new() {
match wayland::WaylandInputCapture::new() {
Ok(p) => {
log::info!("using layer-shell event producer");
log::info!("using layer-shell input capture");
return Box::new(p);
}
Err(e) => log::info!("layer_shell event producer not available: {e}"),
Err(e) => log::info!("layer_shell input capture not available: {e}"),
}

#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
match x11::X11Producer::new() {
match x11::X11InputCapture::new() {
Ok(p) => {
log::info!("using x11 event producer");
log::info!("using x11 input capture");
return Box::new(p);
}
Err(e) => log::info!("x11 event producer not available: {e}"),
Err(e) => log::info!("x11 input capture not available: {e}"),
}

log::error!("falling back to dummy event producer");
Box::new(dummy::DummyProducer::new())
log::error!("falling back to dummy input capture");
Box::new(dummy::DummyInputCapture::new())
}

pub trait EventProducer: Stream<Item = io::Result<(ClientHandle, Event)>> + Unpin {
/// notify event producer of configuration changes
pub trait InputCapture: Stream<Item = io::Result<(ClientHandle, Event)>> + Unpin {
/// notify input capture of configuration changes
fn notify(&mut self, event: ClientEvent) -> io::Result<()>;

/// release mouse
Expand Down
12 changes: 6 additions & 6 deletions src/producer/dummy.rs → src/capture/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ use std::task::{Context, Poll};

use futures_core::Stream;

use crate::capture::InputCapture;
use crate::event::Event;
use crate::producer::EventProducer;

use crate::client::{ClientEvent, ClientHandle};

pub struct DummyProducer {}
pub struct DummyInputCapture {}

impl DummyProducer {
impl DummyInputCapture {
pub fn new() -> Self {
Self {}
}
}

impl Default for DummyProducer {
impl Default for DummyInputCapture {
fn default() -> Self {
Self::new()
}
}

impl EventProducer for DummyProducer {
impl InputCapture for DummyInputCapture {
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
Expand All @@ -33,7 +33,7 @@ impl EventProducer for DummyProducer {
}
}

impl Stream for DummyProducer {
impl Stream for DummyInputCapture {
type Item = io::Result<(ClientHandle, Event)>;

fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down
12 changes: 6 additions & 6 deletions src/producer/libei.rs → src/capture/libei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use futures_core::Stream;
use once_cell::sync::Lazy;

use crate::{
capture::InputCapture as LanMouseInputCapture,
client::{ClientEvent, ClientHandle, Position},
event::{Event, KeyboardEvent, PointerEvent},
producer::EventProducer,
};

#[derive(Debug)]
Expand All @@ -43,7 +43,7 @@ enum ProducerEvent {
}

#[allow(dead_code)]
pub struct LibeiProducer<'a> {
pub struct LibeiInputCapture<'a> {
input_capture: Pin<Box<InputCapture<'a>>>,
libei_task: JoinHandle<Result<()>>,
event_rx: tokio::sync::mpsc::Receiver<(u32, Event)>,
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn update_barriers(
Ok(id_map)
}

impl<'a> Drop for LibeiProducer<'a> {
impl<'a> Drop for LibeiInputCapture<'a> {
fn drop(&mut self) {
self.libei_task.abort();
}
Expand Down Expand Up @@ -212,7 +212,7 @@ async fn wait_for_active_client(
Ok(())
}

impl<'a> LibeiProducer<'a> {
impl<'a> LibeiInputCapture<'a> {
pub async fn new() -> Result<Self> {
let input_capture = Box::pin(InputCapture::new().await?);
let input_capture_ptr = input_capture.as_ref().get_ref() as *const InputCapture<'static>;
Expand Down Expand Up @@ -522,7 +522,7 @@ async fn handle_ei_event(
}
}

impl<'a> EventProducer for LibeiProducer<'a> {
impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> {
fn notify(&mut self, event: ClientEvent) -> io::Result<()> {
let notify_tx = self.notify_tx.clone();
tokio::task::spawn_local(async move {
Expand All @@ -543,7 +543,7 @@ impl<'a> EventProducer for LibeiProducer<'a> {
}
}

impl<'a> Stream for LibeiProducer<'a> {
impl<'a> Stream for LibeiInputCapture<'a> {
type Item = io::Result<(ClientHandle, Event)>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down
10 changes: 5 additions & 5 deletions src/producer/macos.rs → src/capture/macos.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use crate::capture::InputCapture;
use crate::client::{ClientEvent, ClientHandle};
use crate::event::Event;
use crate::producer::EventProducer;
use anyhow::{anyhow, Result};
use futures_core::Stream;
use std::task::{Context, Poll};
use std::{io, pin::Pin};

pub struct MacOSProducer;
pub struct MacOSInputCapture;

impl MacOSProducer {
impl MacOSInputCapture {
pub fn new() -> Result<Self> {
Err(anyhow!("not yet implemented"))
}
}

impl Stream for MacOSProducer {
impl Stream for MacOSInputCapture {
type Item = io::Result<(ClientHandle, Event)>;

fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending
}
}

impl EventProducer for MacOSProducer {
impl InputCapture for MacOSInputCapture {
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions src/producer/wayland.rs → src/capture/wayland.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
capture::InputCapture,
client::{ClientEvent, ClientHandle, Position},
producer::EventProducer,
};

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -124,7 +124,7 @@ impl AsRawFd for Inner {
}
}

pub struct WaylandEventProducer(AsyncFd<Inner>);
pub struct WaylandInputCapture(AsyncFd<Inner>);

struct Window {
buffer: wl_buffer::WlBuffer,
Expand Down Expand Up @@ -256,7 +256,7 @@ fn draw(f: &mut File, (width, height): (u32, u32)) {
}
}

impl WaylandEventProducer {
impl WaylandInputCapture {
pub fn new() -> Result<Self> {
let conn = match Connection::connect_to_env() {
Ok(c) => c,
Expand Down Expand Up @@ -390,7 +390,7 @@ impl WaylandEventProducer {

let inner = AsyncFd::new(Inner { queue, state })?;

Ok(WaylandEventProducer(inner))
Ok(WaylandInputCapture(inner))
}

fn add_client(&mut self, handle: ClientHandle, pos: Position) {
Expand Down Expand Up @@ -587,7 +587,7 @@ impl Inner {
}
}

impl EventProducer for WaylandEventProducer {
impl InputCapture for WaylandInputCapture {
fn notify(&mut self, client_event: ClientEvent) -> io::Result<()> {
match client_event {
ClientEvent::Create(handle, pos) => {
Expand All @@ -609,7 +609,7 @@ impl EventProducer for WaylandEventProducer {
}
}

impl Stream for WaylandEventProducer {
impl Stream for WaylandInputCapture {
type Item = io::Result<(ClientHandle, Event)>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down
10 changes: 5 additions & 5 deletions src/producer/windows.rs → src/capture/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use futures::Stream;
use std::{io, pin::Pin};

use crate::{
capture::InputCapture,
client::{ClientEvent, ClientHandle},
event::Event,
producer::EventProducer,
};

pub struct WindowsProducer {}
pub struct WindowsInputCapture {}

impl EventProducer for WindowsProducer {
impl InputCapture for WindowsInputCapture {
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
Expand All @@ -21,13 +21,13 @@ impl EventProducer for WindowsProducer {
}
}

impl WindowsProducer {
impl WindowsInputCapture {
pub(crate) fn new() -> Result<Self> {
Err(anyhow!("not implemented"))
}
}

impl Stream for WindowsProducer {
impl Stream for WindowsInputCapture {
type Item = io::Result<(ClientHandle, Event)>;
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending
Expand Down
10 changes: 5 additions & 5 deletions src/producer/x11.rs → src/capture/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use std::task::Poll;

use futures_core::Stream;

use crate::capture::InputCapture;
use crate::event::Event;
use crate::producer::EventProducer;

use crate::client::{ClientEvent, ClientHandle};

pub struct X11Producer {}
pub struct X11InputCapture {}

impl X11Producer {
impl X11InputCapture {
pub fn new() -> Result<Self> {
Err(anyhow!("not implemented"))
}
}

impl EventProducer for X11Producer {
impl InputCapture for X11InputCapture {
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
Expand All @@ -27,7 +27,7 @@ impl EventProducer for X11Producer {
}
}

impl Stream for X11Producer {
impl Stream for X11InputCapture {
type Item = io::Result<(ClientHandle, Event)>;

fn poll_next(
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Client {
/// fix ips, determined by the user
pub fix_ips: Vec<IpAddr>,
/// unique handle to refer to the client.
/// This way any event consumer / producer backend does not
/// This way any emulation / capture backend does not
/// need to know anything about a client other than its handle.
pub handle: ClientHandle,
/// all ip addresses associated with a particular client
Expand Down
Loading

0 comments on commit 742b158

Please sign in to comment.