From 4a55182ce17fd4474f8be1e8819a41b7ccd11045 Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Sun, 31 Aug 2025 14:04:00 +0200 Subject: Wire aspect_ratio, phone_mode and pin_input through config/IPC/CLI The Lua and IPC/CLI surface for the three new core primitives (crates/core: aspect_ratio rule action, general.phone_mode, virtual- pointer window pinning): - srd.rule(..., { aspect_ratio = "9:16" }): parses a "W:H" string into a validated (u32, u32), rejecting a malformed value as a real Lua error at config-load time rather than silently ignoring it. - general.phone_mode config default, plus srd set phone_mode for the live equivalent (same shape as animations/shadows/rounded_corners). - pin_input IPC dispatch ({"cmd":"pin_input","pid":,"id":}, id omitted to unpin) and its CLI surface, srd dispatch pin input / unpin input . Keyed by the owning client's process id, not an opaque per-object id nothing outside the Wayland backend could ever learn - a controlling tool already knows its own pid for free. See docs/TODO.md for the full design reasoning behind each of these. --- crates/config/src/engine/tests.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/config/src/engine/tests.rs') diff --git a/crates/config/src/engine/tests.rs b/crates/config/src/engine/tests.rs index f170320..f4f011b 100644 --- a/crates/config/src/engine/tests.rs +++ b/crates/config/src/engine/tests.rs @@ -196,6 +196,32 @@ assert!(wm.borrow().is_floating(id)); } + #[test] + fn srd_rule_aspect_ratio_applies_a_parsed_w_h_pair_on_creation() { + let dir = tempfile::tempdir().unwrap(); + let wm = Rc::new(RefCell::new(WindowManager::new())); + let engine = Engine::new(wm.clone(), dir.path()).unwrap(); + engine.lua.load(r#"srd.rule({ class = "scrcpy" }, { aspect_ratio = "9:16" })"#).exec().unwrap(); + let id = { + let mut wm = wm.borrow_mut(); + let id = wm.alloc_window_id(); + let mut w = srdwm_core::Window::new(id, "phone"); + w.app_id = "scrcpy".into(); + wm.add_window(w); + id + }; + assert_eq!(wm.borrow().window(id).unwrap().aspect_ratio, Some((9, 16))); + } + + #[test] + fn srd_rule_rejects_a_malformed_aspect_ratio() { + let dir = tempfile::tempdir().unwrap(); + let wm = Rc::new(RefCell::new(WindowManager::new())); + let engine = Engine::new(wm.clone(), dir.path()).unwrap(); + let err = engine.lua.load(r#"srd.rule({ class = "x" }, { aspect_ratio = "sixteen by nine" })"#).exec(); + assert!(err.is_err()); + } + #[test] fn srd_monitor_split_stores_a_split_request_by_connector_name() { let dir = tempfile::tempdir().unwrap(); -- cgit v1.2.3