diff --git a/Cargo.lock b/Cargo.lock index 9c77064..746c6fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.80" @@ -658,6 +706,46 @@ dependencies = [ "libloading 0.8.1", ] +[[package]] +name = "clap" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.51", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + [[package]] name = "cmake" version = "0.1.50" @@ -677,6 +765,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "combine" version = "4.6.6" @@ -2784,6 +2878,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "strum" version = "0.25.0" @@ -3070,6 +3170,12 @@ dependencies = [ "serde", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vec_map" version = "0.8.2" @@ -3616,12 +3722,13 @@ dependencies = [ [[package]] name = "wlx-overlay-s" -version = "0.2.1" +version = "0.2.2" dependencies = [ "anyhow", "ash", "chrono", "chrono-tz", + "clap", "cstr", "ctrlc", "dbus", diff --git a/Cargo.toml b/Cargo.toml index ebf566e..9a41b42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ anyhow = "1.0.79" ash = "^0.37.2" chrono = "0.4.29" chrono-tz = "0.8.5" +clap = { version = "4.5.1", features = ["derive"] } cstr = "0.2.11" ctrlc = { version = "3.4.2", features = ["termination"] } dbus = { version = "0.9.7" } diff --git a/src/main.rs b/src/main.rs index a319669..e1f8c67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,23 +9,47 @@ mod overlays; mod shaders; mod state; -use std::{ - io::{stdout, IsTerminal}, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }, +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, }; +use clap::Parser; use flexi_logger::FileSpec; +/// The lightweight desktop overlay for OpenVR and OpenXR +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + #[cfg(feature = "openvr")] + /// Start overlay with OpenVR backend + #[arg(long)] + openvr: bool, + + #[cfg(feature = "openxr")] + /// Start overlay with OpenXR backend + #[arg(long)] + openxr: bool, + + /// Uninstall OpenVR manifest and exit + #[arg(long)] + uninstall: bool, + + /// Folder path to write logs to + #[arg(short, long)] + log_to: Option, +} + fn main() -> Result<(), Box> { - if stdout().is_terminal() { - flexi_logger::Logger::try_with_env_or_str("info")?.start()?; - } else { + let args = Args::parse(); + if let Some(log_to) = args.log_to { flexi_logger::Logger::try_with_env_or_str("info")? - .log_to_file(FileSpec::default().directory("/tmp")) + .log_to_file(FileSpec::default().directory(&log_to)) + .log_to_stdout() .start()?; + println!("Logging to: {}", &log_to); + } else { + flexi_logger::Logger::try_with_env_or_str("info")?.start()?; } log::info!( @@ -35,7 +59,7 @@ fn main() -> Result<(), Box> { ); #[cfg(feature = "openvr")] - if std::env::args().any(|arg| arg == "--uninstall") { + if args.uninstall { crate::backend::openvr::openvr_uninstall(); return Ok(()); } @@ -48,16 +72,16 @@ fn main() -> Result<(), Box> { } }); - auto_run(running); + auto_run(running, args.openvr, args.openxr); Ok(()) } -fn auto_run(running: Arc) { +fn auto_run(running: Arc, openvr: bool, openxr: bool) { use backend::common::BackendError; #[cfg(feature = "openxr")] - { + if !openvr { use crate::backend::openxr::openxr_run; match openxr_run(running.clone()) { Ok(()) => return, @@ -70,7 +94,7 @@ fn auto_run(running: Arc) { } #[cfg(feature = "openvr")] - { + if !openxr { use crate::backend::openvr::openvr_run; match openvr_run(running.clone()) { Ok(()) => return, @@ -82,5 +106,5 @@ fn auto_run(running: Arc) { }; } - log::error!("No supported backends found"); + log::error!("No more backends to try"); } diff --git a/src/overlays/screen.rs b/src/overlays/screen.rs index 9506e30..43a26ad 100644 --- a/src/overlays/screen.rs +++ b/src/overlays/screen.rs @@ -44,7 +44,7 @@ use crate::{ overlay::{OverlayData, OverlayRenderer, OverlayState, SplitOverlayBackend}, }, config::def_pw_tokens, - graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy, BLEND_ALPHA}, + graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy}, hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}, state::{AppSession, AppState}, };