Skip to content

Commit

Permalink
add option to config
Browse files Browse the repository at this point in the history
  • Loading branch information
feschber committed Jun 28, 2024
1 parent 1db43c4 commit c2fde88
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# example configuration

# capture_backend = "LayerShell"

# release bind
release_bind = [ "KeyA", "KeyS", "KeyD", "KeyF" ]

Expand Down
4 changes: 3 additions & 1 deletion src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
Expand Down
6 changes: 3 additions & 3 deletions src/capture/error.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/capture/macos.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::capture::error::MacOSInputCaptureCreationError;
use crate::capture::InputCapture;
use crate::client::{ClientEvent, ClientHandle};
use crate::event::Event;
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;

Expand Down
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand All @@ -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>>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit c2fde88

Please sign in to comment.