add option to config

This commit is contained in:
Ferdinand Schober
2024-06-28 23:44:55 +02:00
parent 1db43c4751
commit c2fde88900
5 changed files with 17 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
# example configuration
# capture_backend = "LayerShell"
# release bind
release_bind = [ "KeyA", "KeyS", "KeyD", "KeyF" ]

View File

@@ -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")))]

View File

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

View File

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

View File

@@ -15,6 +15,7 @@ pub const DEFAULT_PORT: u16 = 4242;
#[derive(Serialize, Deserialize, Debug)]
pub struct ConfigToml {
pub capture_backend: Option<CaptureBackend>,
pub port: Option<u16>,
pub frontend: Option<String>,
pub release_bind: Option<Vec<scancode::Linux>>,
@@ -26,6 +27,7 @@ pub struct ConfigToml {
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct TomlClient {
pub capture_backend: Option<CaptureBackend>,
pub hostname: Option<String>,
pub host_name: Option<String>,
pub ips: Option<Vec<IpAddr>>,
@@ -78,7 +80,7 @@ struct CliArgs {
emulation_backend: Option<EmulationBackend>,
}
#[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,