Add a dummy backend

This commit is contained in:
Ferdinand Schober
2023-12-17 19:06:27 +01:00
committed by Ferdinand Schober
parent eca367cdb4
commit f5a0ff4f3a
11 changed files with 163 additions and 183 deletions

View File

@@ -15,3 +15,6 @@ pub mod libei;
#[cfg(target_os = "macos")]
pub mod macos;
/// fallback consumer
pub mod dummy;

View File

@@ -0,0 +1,21 @@
use async_trait::async_trait;
use crate::{consumer::EventConsumer, event::Event, client::{ClientHandle, ClientEvent}};
pub struct DummyConsumer;
impl DummyConsumer {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl EventConsumer for DummyConsumer {
async fn consume(&mut self, event: Event, client_handle: ClientHandle) {
log::info!("received event: ({client_handle}) {event}");
}
async fn notify(&mut self, client_event: ClientEvent) {
log::info!("{client_event:?}");
}
async fn destroy(&mut self) {}
}

View File

@@ -1,3 +1,4 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use std::ptr;
use x11::{xlib::{self, XCloseDisplay}, xtest};
@@ -11,15 +12,16 @@ pub struct X11Consumer {
unsafe impl Send for X11Consumer {}
impl X11Consumer {
pub fn new() -> Self {
pub fn new() -> Result<Self> {
let display = unsafe {
match xlib::XOpenDisplay(ptr::null()) {
d if d == ptr::null::<xlib::Display>() as *mut xlib::Display => None,
display => Some(display),
d if d == ptr::null::<xlib::Display>() as *mut xlib::Display => {
Err(anyhow!("could not open display"))
}
display => Ok(display),
}
};
let display = display.expect("could not open display");
Self { display }
}?;
Ok(Self { display })
}
fn relative_motion(&self, dx: i32, dy: i32) {
@@ -68,12 +70,6 @@ impl X11Consumer {
}
}
impl Default for X11Consumer {
fn default() -> Self {
Self::new()
}
}
impl Drop for X11Consumer {
fn drop(&mut self) {
unsafe {

View File

@@ -1,10 +1,17 @@
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
pub mod libei;
#[cfg(target_os = "macos")]
pub mod macos;
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
pub mod wayland;
#[cfg(windows)]
pub mod windows;
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
pub mod x11;
/// fallback event producer
pub mod dummy;

View File

@@ -0,0 +1,41 @@
use std::io;
use std::pin::Pin;
use std::task::{Poll, Context};
use futures_core::Stream;
use crate::event::Event;
use crate::producer::EventProducer;
use crate::client::{ClientEvent, ClientHandle};
pub struct DummyProducer {}
impl DummyProducer {
pub fn new() -> Self {
Self {}
}
}
impl Default for DummyProducer {
fn default() -> Self {
Self::new()
}
}
impl EventProducer for DummyProducer {
fn notify(&mut self, _: ClientEvent) {}
fn release(&mut self) {}
}
impl Stream for DummyProducer {
type Item = io::Result<(ClientHandle, Event)>;
fn poll_next(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
Poll::Pending
}
}

View File

@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{anyhow, Result};
use std::{io, task::Poll};
use futures_core::Stream;
@@ -9,7 +9,7 @@ pub struct LibeiProducer {}
impl LibeiProducer {
pub fn new() -> Result<Self> {
Ok(Self {})
Err(anyhow!("not implemented"))
}
}

View File

@@ -1,3 +1,4 @@
use anyhow::{anyhow, Result};
use std::io;
use std::task::Poll;
@@ -11,14 +12,8 @@ use crate::client::{ClientEvent, ClientHandle};
pub struct X11Producer {}
impl X11Producer {
pub fn new() -> Self {
Self {}
}
}
impl Default for X11Producer {
fn default() -> Self {
Self::new()
pub fn new() -> Result<Self> {
return Err(anyhow!("not implemented"));
}
}