diff --git a/Cargo.lock b/Cargo.lock index 7ba513c..1261c8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,15 +16,16 @@ checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] @@ -36,27 +37,27 @@ checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys", @@ -293,9 +294,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "concurrent-queue" @@ -548,6 +549,12 @@ dependencies = [ "syn", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.12.1" @@ -1006,7 +1013,7 @@ dependencies = [ [[package]] name = "rwpspread" -version = "0.3.0-1" +version = "0.3.1" dependencies = [ "clap", "clap_complete", @@ -1269,9 +1276,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "v_frame" diff --git a/Cargo.toml b/Cargo.toml index 3bfc644..1d318e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rwpspread" -version = "0.3.0-1" +version = "0.3.1" edition = "2021" authors = ["0xk1f0"] description = "Multi-Monitor Wallpaper Utility" @@ -16,7 +16,7 @@ rand = { version = "0.8.5", default-features = false, features = ["std", "std_rn rayon = "1.10.0" serde = { version = "1.0.210", features = ["derive"] } serde_json = "1.0.128" -smithay-client-toolkit = { version = "0.19.2", default_features = false, features = [ "calloop" ] } +smithay-client-toolkit = { version = "0.19.2", default-features = false, features = [ "calloop" ] } toml = "0.8.19" [build-dependencies] @@ -25,12 +25,11 @@ clap_complete = "4.5.33" clap_mangen = "0.2.24" serde = { version = "1.0.210", features = ["derive"] } -# makes image lib faster for dev -[profile.dev-unopt] -inherits = "dev" +[profile.dev] opt-level = 3 -# Ref: https://github.com/johnthagen/min-sized-rust [profile.release] +codegen-units = 8 +opt-level = 3 strip = true lto = true diff --git a/build.rs b/build.rs index 6415873..9444bd0 100644 --- a/build.rs +++ b/build.rs @@ -23,6 +23,9 @@ fn manpage(outdir: &Path) -> Result<(), Error> { } fn main() -> Result<(), Box> { + println!("cargo:rustc-env=HYPRPAPER_VERSION={}", ">=0.7.0"); + println!("cargo:rustc-env=WPAPERD_VERSION={}", ">=1.0.1"); + println!("cargo:rustc-env=SWAYBG_VERSION={}", ">=1.2.1"); println!("cargo:rerun-if-changed=src/cli.rs"); let outdir = std::env::var("OUT_DIR").unwrap(); diff --git a/src/cli.rs b/src/cli.rs index 6818c46..9c656c4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -60,13 +60,24 @@ impl std::fmt::Display for Backend { } } +#[derive(clap::Args)] +#[group(required = true, multiple = false)] +pub struct InitGroup { + /// Image file or directory path + #[arg(short, long)] + image: Option, + + /// Show detectable information + #[arg(long)] + info: bool, +} + /// Multi-Monitor Wallpaper Utility #[derive(Parser)] #[command(version, about, long_about = None)] struct Args { - /// Image file or directory path - #[arg(short, long)] - image: String, + #[clap(flatten)] + init_group: InitGroup, /// Output directory path #[arg(short, long)] @@ -114,6 +125,7 @@ pub struct Config { pub daemon: bool, pub palette: bool, pub force_resplit: bool, + pub info: bool, pub align: Option, pub pre_path: Option, pub post_path: Option, @@ -121,12 +133,18 @@ pub struct Config { } impl Config { - pub fn new() -> Result { + pub fn new() -> Result, String> { // handle args let args = Args::parse(); + // check for early exit due to info passage + if args.init_group.image.is_none() && args.init_group.info { + return Ok(None); + } + // get valid input path - let input_path = Config::to_valid_path(&args.image, false, false).map_err(|err| err)?; + let input_path = Config::to_valid_path(&args.init_group.image.unwrap(), false, false) + .map_err(|err| err)?; // get valid output directory let outdir_path: Option; @@ -168,7 +186,7 @@ impl Config { let version: String = String::from(env!("CARGO_PKG_VERSION")); // construct - Ok(Self { + Ok(Some(Self { input_path, outdir_path, align: args.align, @@ -177,10 +195,11 @@ impl Config { daemon: args.daemon, palette: args.palette, force_resplit: args.force_resplit, + info: args.init_group.info, pre_path, post_path, version, - }) + })) } // check if target path is a symlink diff --git a/src/main.rs b/src/main.rs index 72d883b..e9d0979 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,34 +9,51 @@ use std::process; use wayland::MonitorConfig; use worker::Worker; -fn run() -> Result<(), String> { +fn run() -> Result { // create new config let worker_config = Config::new().map_err(|err| err)?; + // connect to wayland + let mut mon_conn = MonitorConfig::new().map_err(|err| err)?; + + // get monitor info + let mon_config = mon_conn.run().map_err(|err| err)?; + // check for backends if applicable - if worker_config.backend.is_some() - && !helpers::is_installed(&worker_config.backend.as_ref().unwrap().to_string()) + if worker_config.is_none() { + let mut result = String::from("Found the following displays:\n"); + for monitor in mon_config { + result.push_str(&format!("- {}\n", monitor)); + } + result.push_str("Supported versions:\n"); + result.push_str(&format!( + "- \x1B[32mhyprpaper\x1B[39m: {}\n- \x1B[32mwpaperd\x1B[39m: {}\n- \x1B[32mswaybg\x1B[39m: {}", + env!("HYPRPAPER_VERSION"), + env!("WPAPERD_VERSION"), + env!("SWAYBG_VERSION") + )); + return Ok(result); + } + let ready_config = worker_config.unwrap(); + + // check for backends if applicable + if ready_config.backend.is_some() + && !helpers::is_installed(&ready_config.backend.as_ref().unwrap().to_string()) { return Err(format!( "{} is not installed", - &worker_config.backend.as_ref().unwrap().to_string() + &ready_config.backend.as_ref().unwrap().to_string() )); } - // connect to wayland - let mut mon_conn = MonitorConfig::new().map_err(|err| err)?; - - // get monitor info - let mon_config = mon_conn.run().map_err(|err| err)?; - // create new splitter let mut worker = Worker::new(); // perform split - worker.run(&worker_config, mon_config).map_err(|err| err)?; + worker.run(&ready_config, mon_config).map_err(|err| err)?; // check for watchdog bool - if worker_config.daemon == true { + if ready_config.daemon == true { loop { // roundtrip eventhandler and check result let needs_recalc = mon_conn.refresh().map_err(|err| err)?; @@ -44,19 +61,25 @@ fn run() -> Result<(), String> { // redetect screens let mon_config = mon_conn.run().map_err(|err| err)?; // rerun splitter - worker.run(&worker_config, mon_config).map_err(|err| err)?; + worker.run(&ready_config, mon_config).map_err(|err| err)?; } } } // return - Ok(()) + Ok("".to_string()) } fn main() { // run with config - if let Err(err) = run() { - eprintln!("{}: \x1B[91m{}\x1B[39m", "rwpspread", err); - process::exit(1); + match run() { + Ok(ok) => { + println!("{}", ok); + process::exit(0); + } + Err(err) => { + eprintln!("{}: \x1B[91m{}\x1B[39m", "rwpspread", err); + process::exit(1); + } } } diff --git a/src/wayland.rs b/src/wayland.rs index 6b7e500..f806e88 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -7,6 +7,7 @@ use smithay_client_toolkit::{ registry::{ProvidesRegistryState, RegistryState}, registry_handlers, }; +use std::fmt; struct ListOutputs { registry_state: RegistryState, @@ -23,6 +24,16 @@ pub struct Monitor { pub y: i32, } +impl fmt::Display for Monitor { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!( + formatter, + "\x1B[32m{}\x1B[39m: {}x{} at {}:{}", + self.name, self.width, self.height, self.x, self.y + ) + } +} + pub struct MonitorConfig { lo: ListOutputs, eq: EventQueue,