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

@@ -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 {