From c2fde8890030a95b40aa233de59593d8bd052b9d Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Fri, 28 Jun 2024 23:44:55 +0200 Subject: [PATCH] add option to config --- config.toml | 2 ++ src/capture.rs | 4 +++- src/capture/error.rs | 6 +++--- src/capture/macos.rs | 2 +- src/config.rs | 10 ++++++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/config.toml b/config.toml index ef66ae3..b05d249 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,7 @@ # example configuration +# capture_backend = "LayerShell" + # release bind release_bind = [ "KeyA", "KeyS", "KeyD", "KeyF" ] diff --git a/src/capture.rs b/src/capture.rs index 731d8ee..e4b86f7 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -37,7 +37,9 @@ pub async fn create( if let Some(backend) = backend { return match backend { #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] - CaptureBackend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)), + CaptureBackend::InputCapturePortal => { + Ok(Box::new(libei::LibeiInputCapture::new().await?)) + } #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] CaptureBackend::LayerShell => Ok(Box::new(wayland::WaylandInputCapture::new()?)), #[cfg(all(unix, feature = "x11", not(target_os = "macos")))] diff --git a/src/capture/error.rs b/src/capture/error.rs index 4d9d3e0..15231c8 100644 --- a/src/capture/error.rs +++ b/src/capture/error.rs @@ -1,14 +1,14 @@ -use thiserror::Error; use std::fmt::Display; +use thiserror::Error; +#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] +use std::io; #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] use wayland_client::{ backend::WaylandError, globals::{BindError, GlobalError}, ConnectError, DispatchError, }; -#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] -use std::io; #[derive(Debug, Error)] pub enum CaptureCreationError { diff --git a/src/capture/macos.rs b/src/capture/macos.rs index 2ed044a..58f940c 100644 --- a/src/capture/macos.rs +++ b/src/capture/macos.rs @@ -1,3 +1,4 @@ +use crate::capture::error::MacOSInputCaptureCreationError; use crate::capture::InputCapture; use crate::client::{ClientEvent, ClientHandle}; use crate::event::Event; @@ -5,7 +6,6 @@ use anyhow::Result; use futures_core::Stream; use std::task::{Context, Poll}; use std::{io, pin::Pin}; -use crate::capture::error::MacOSInputCaptureCreationError; pub struct MacOSInputCapture; diff --git a/src/config.rs b/src/config.rs index 9b9df8f..c88af93 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,6 +15,7 @@ pub const DEFAULT_PORT: u16 = 4242; #[derive(Serialize, Deserialize, Debug)] pub struct ConfigToml { + pub capture_backend: Option, pub port: Option, pub frontend: Option, pub release_bind: Option>, @@ -26,6 +27,7 @@ pub struct ConfigToml { #[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] pub struct TomlClient { + pub capture_backend: Option, pub hostname: Option, pub host_name: Option, pub ips: Option>, @@ -78,7 +80,7 @@ struct CliArgs { emulation_backend: Option, } -#[derive(Debug, Clone, Copy, ValueEnum)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)] pub enum CaptureBackend { #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] InputCapturePortal, @@ -190,6 +192,11 @@ impl Config { .and_then(|c| c.release_bind.clone()) .unwrap_or(Vec::from_iter(DEFAULT_RELEASE_KEYS.iter().cloned())); + let capture_backend = match args.capture_backend { + Some(b) => Some(b), + None => config_toml.as_ref().and_then(|c| c.capture_backend), + }; + let mut clients: Vec<(TomlClient, Position)> = vec![]; if let Some(config_toml) = config_toml { @@ -210,7 +217,6 @@ impl Config { let daemon = args.daemon; let test_capture = args.test_capture; let test_emulation = args.test_emulation; - let capture_backend = args.capture_backend; Ok(Config { capture_backend,