2026-04-23 07:00:06 -03:00
|
|
|
// Input-device discovery, routing, and local/remote handoff control.
|
2025-06-08 22:24:14 -05:00
|
|
|
|
2026-04-13 02:52:32 -03:00
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
use anyhow::bail;
|
2026-04-14 04:02:39 -03:00
|
|
|
use anyhow::{Context, Result};
|
2026-04-08 20:00:14 -03:00
|
|
|
use evdev::{AbsoluteAxisCode, Device, EventType, KeyCode, RelativeAxisCode};
|
2026-04-21 12:48:57 -03:00
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
use std::os::unix::fs::MetadataExt;
|
2026-04-14 20:05:26 -03:00
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
use std::path::{Path, PathBuf};
|
2026-04-17 04:35:41 -03:00
|
|
|
use std::sync::{
|
|
|
|
|
Arc,
|
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
|
};
|
2026-04-14 23:03:18 -03:00
|
|
|
use std::time::Instant;
|
2025-12-01 11:38:51 -03:00
|
|
|
use tokio::{
|
|
|
|
|
sync::broadcast::Sender,
|
|
|
|
|
time::{Duration, interval},
|
|
|
|
|
};
|
2025-11-30 23:41:29 -03:00
|
|
|
use tracing::{debug, info, warn};
|
2025-06-08 22:24:14 -05:00
|
|
|
|
2025-06-23 07:18:26 -05:00
|
|
|
use lesavka_common::lesavka::{KeyboardReport, MouseReport};
|
2025-06-11 22:01:16 -05:00
|
|
|
|
2026-04-16 15:07:25 -03:00
|
|
|
use super::{
|
|
|
|
|
keyboard::{KeyboardAggregator, build_keyboard_report, emit_live_keyboard_report},
|
|
|
|
|
mouse::MouseAggregator,
|
|
|
|
|
};
|
2025-06-29 04:54:39 -05:00
|
|
|
use crate::layout::{Layout, apply as apply_layout};
|
2026-04-08 20:00:14 -03:00
|
|
|
use tokio::sync::mpsc::UnboundedSender;
|
2025-06-08 22:24:14 -05:00
|
|
|
|
|
|
|
|
pub struct InputAggregator {
|
2025-06-17 20:54:31 -05:00
|
|
|
kbd_tx: Sender<KeyboardReport>,
|
|
|
|
|
mou_tx: Sender<MouseReport>,
|
|
|
|
|
dev_mode: bool,
|
2025-06-28 15:45:35 -05:00
|
|
|
released: bool,
|
2025-06-28 17:55:15 -05:00
|
|
|
magic_active: bool,
|
2026-04-08 20:00:14 -03:00
|
|
|
pending_release: bool,
|
|
|
|
|
pending_kill: bool,
|
|
|
|
|
pending_keys: HashSet<KeyCode>,
|
2026-04-16 15:07:25 -03:00
|
|
|
last_keyboard_report: [u8; 8],
|
2026-04-08 20:00:14 -03:00
|
|
|
paste_tx: Option<UnboundedSender<String>>,
|
2025-06-17 20:54:31 -05:00
|
|
|
keyboards: Vec<KeyboardAggregator>,
|
|
|
|
|
mice: Vec<MouseAggregator>,
|
2026-04-16 12:58:05 -03:00
|
|
|
selected_keyboard_path: Option<String>,
|
|
|
|
|
selected_mouse_path: Option<String>,
|
2026-04-21 12:46:47 -03:00
|
|
|
#[cfg(not(coverage))]
|
2026-04-21 12:48:57 -03:00
|
|
|
known_input_paths: HashMap<PathBuf, u64>,
|
2026-04-13 23:11:35 -03:00
|
|
|
capture_remote_boot: bool,
|
2026-04-14 04:02:39 -03:00
|
|
|
quick_toggle_key: Option<KeyCode>,
|
|
|
|
|
quick_toggle_down: bool,
|
|
|
|
|
quick_toggle_debounce: Duration,
|
|
|
|
|
last_quick_toggle_at: Option<Instant>,
|
2026-04-20 18:41:48 -03:00
|
|
|
pending_release_started_at: Option<Instant>,
|
|
|
|
|
pending_release_timeout: Duration,
|
2026-04-20 21:11:33 -03:00
|
|
|
remote_failsafe_started_at: Option<Instant>,
|
|
|
|
|
remote_failsafe_timeout: Duration,
|
2026-04-14 20:05:26 -03:00
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
routing_control_path: Option<PathBuf>,
|
|
|
|
|
#[cfg(not(coverage))]
|
2026-04-20 18:41:48 -03:00
|
|
|
last_routing_request_raw: Option<String>,
|
|
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
quick_toggle_control_path: Option<PathBuf>,
|
|
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
last_quick_toggle_request_raw: Option<String>,
|
2026-04-14 20:05:26 -03:00
|
|
|
#[cfg(not(coverage))]
|
2026-04-16 12:58:05 -03:00
|
|
|
clipboard_control_path: Option<PathBuf>,
|
|
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
clipboard_control_marker: u128,
|
|
|
|
|
#[cfg(not(coverage))]
|
2026-04-14 20:05:26 -03:00
|
|
|
routing_state_path: Option<PathBuf>,
|
|
|
|
|
#[cfg(not(coverage))]
|
|
|
|
|
published_remote_capture: Option<bool>,
|
2026-04-17 04:35:41 -03:00
|
|
|
remote_capture_enabled: Arc<AtomicBool>,
|
2025-06-08 22:24:14 -05:00
|
|
|
}
|
|
|
|
|
|
2026-04-23 07:00:06 -03:00
|
|
|
include!("inputs/construction_and_scan.rs");
|
|
|
|
|
include!("inputs/run_loop.rs");
|
|
|
|
|
include!("inputs/routing_state.rs");
|
2026-04-13 23:11:35 -03:00
|
|
|
|
2026-04-23 07:00:06 -03:00
|
|
|
include!("inputs/device_classification.rs");
|
|
|
|
|
include!("inputs/toggle_keys.rs");
|
|
|
|
|
include!("inputs/runtime_controls.rs");
|
2026-04-15 04:44:06 -03:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2026-04-23 07:00:06 -03:00
|
|
|
#[path = "tests/inputs.rs"]
|
|
|
|
|
mod tests;
|