//! Touch diagnostics. Replaces v1's tools/diag.sh and tools/find-device.sh. //! //! The question it exists to answer is "the panel works, so why does nothing //! happen?" -- which in v1 meant reading lisgd's `Cfg(f=1) <=> Evt(f=2)` output //! and knowing that meant the contact count. Here the answer is printed in //! English instead. use anyhow::{bail, Result}; use crate::config::Config; use crate::input::{list_touchscreens, Event, Touchpanel}; pub fn list() -> Result<()> { let found = list_touchscreens(); if found.is_empty() { bail!( "no multitouch devices found under /dev/input/by-id/.\n\ If the panel is plugged in, you may not have permission to read the \ devices: install the udev rule or join the 'input' group and log back in." ); } println!("Multitouch devices:\n"); for (path, name) in found { println!(" {name}\n {path}\n"); } println!("Put the path in touch.device. Always the by-id path -- eventN numbers"); println!("get reshuffled on reboot or USB re-enumeration."); Ok(()) } pub fn run(cfg: &Config) -> Result<()> { println!("Watching {}", cfg.touch.device); println!( " panel {}x{}, threshold {}px, leniency {}\u{b0}, contacts accepted: {:?}", cfg.touch.width, cfg.touch.height, cfg.touch.threshold, cfg.touch.leniency, cfg.touch.fingers ); println!( " grab: {}\n", if cfg.touch.grab { "yes -- X will not see these touches" } else { "no -- X also receives these touches" } ); println!("Swipe left, right, up and down. Ctrl-C when done.\n"); let mut panel = Touchpanel::open(&cfg.touch)?; let g = &cfg.gestures; panel.run(|ev| { match ev { Event::Swipe(s) => { let action = match s.direction { d if d == g.forward => "forward", d if d == g.back => "back", d if d == g.up => "up", d if d == g.down => "down", _ => "not bound to anything", }; println!( " {:?} swipe, {} contact(s) -> {action}", s.direction, s.fingers ); } Event::Discarded(dir, why) => { println!(" {dir:?} swipe ignored: {why}"); } } true }) }