Configurable capture backend (#150)

capture backend can now be configured via the `capture_backend` cli argument / config entry
This commit is contained in:
Ferdinand Schober
2024-06-29 00:10:36 +02:00
committed by GitHub
parent 232c048c19
commit 3528ef4fae
15 changed files with 278 additions and 93 deletions

View File

@@ -5,8 +5,9 @@ use std::{collections::HashSet, net::SocketAddr};
use tokio::{process::Command, sync::mpsc::Sender, task::JoinHandle};
use crate::{
capture::{self, InputCapture},
capture::{self, error::CaptureCreationError, InputCapture},
client::{ClientEvent, ClientHandle},
config::CaptureBackend,
event::{Event, KeyboardEvent},
scancode,
server::State,
@@ -25,14 +26,15 @@ pub enum CaptureEvent {
}
pub fn new(
backend: Option<CaptureBackend>,
server: Server,
sender_tx: Sender<(Event, SocketAddr)>,
timer_tx: Sender<()>,
release_bind: Vec<scancode::Linux>,
) -> (JoinHandle<Result<()>>, Sender<CaptureEvent>) {
) -> Result<(JoinHandle<Result<()>>, Sender<CaptureEvent>), CaptureCreationError> {
let (tx, mut rx) = tokio::sync::mpsc::channel(32);
let task = tokio::task::spawn_local(async move {
let mut capture = capture::create().await;
let mut capture = capture::create(backend).await?;
let mut pressed_keys = HashSet::new();
loop {
tokio::select! {
@@ -62,7 +64,7 @@ pub fn new(
}
anyhow::Ok(())
});
(task, tx)
Ok((task, tx))
}
fn update_pressed_keys(pressed_keys: &mut HashSet<scancode::Linux>, key: u32, state: u8) {