diff --git a/src/profile.rs b/src/profile.rs index c518471..fc0190f 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use std::collections::{BTreeMap, HashSet}; use std::path::{Path, PathBuf}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct Profile { pub name: String, #[serde(default = "default_client")] @@ -63,10 +63,14 @@ fn default_mode() -> Mode { Mode::Maps } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Default, + Serialize, Deserialize, +)] #[serde(rename_all = "snake_case")] pub enum Mode { /// 1: only configured maps; everything else goes to the front window + #[default] Maps, /// 2: clone keys to the other game windows (front window still gets the real key) #[serde(alias = "repeater")] diff --git a/src/session.rs b/src/session.rs index db3fafb..545dab1 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1252,6 +1252,43 @@ mod tests { } } + #[test] + fn mouse_repeat_ms_clamps_env_var() { + // The default cadence is 50 ms when the env var is unset + // or malformed; explicit values in [1, 2000] pass through; + // out-of-range values fall back to 50. We assert the bounds + // by reading back Session.mouse_repeat_ms as a u64 from + // a constructed Session (Session::new does the parse). + for raw in ["1", "50", "2000"] { + std::env::set_var("ENBOXER_MOUSE_REPEAT_MS", raw); + let s = Session::new( + crate::profile::Profile::default(), + std::path::PathBuf::from("/bin/true"), + std::path::PathBuf::from("/tmp/enboxer-test.sock"), + ) + .expect("Session::new should succeed for a valid profile"); + let v: u64 = raw.parse().unwrap(); + assert_eq!( + s.mouse_repeat_ms, v, + "ENBOXER_MOUSE_REPEAT_MS={raw} should pass through" + ); + } + for raw in ["0", "2001", "not_a_number", ""] { + std::env::set_var("ENBOXER_MOUSE_REPEAT_MS", raw); + let s = Session::new( + crate::profile::Profile::default(), + std::path::PathBuf::from("/bin/true"), + std::path::PathBuf::from("/tmp/enboxer-test.sock"), + ) + .expect("Session::new should succeed for a valid profile"); + assert_eq!( + s.mouse_repeat_ms, 50, + "ENBOXER_MOUSE_REPEAT_MS={raw} should fall back to 50" + ); + } + std::env::remove_var("ENBOXER_MOUSE_REPEAT_MS"); + } + #[test] fn others_excludes_leader() { let slots = vec![