Rust core: YAML grid config, navigation state machine, evdev input

Replaces the three shell scripts' logic with one binary. tmux stays the
pane engine; src/session/ is the only module that knows that.

The grid model: coordinates are sparse ordinals, so only their sort order
matters and a socktop group is one cell however many hosts it holds.
Horizontal movement walks a cell's sub-sequence (tiled overview, then each
host zoomed) and leaves only after the last one; entry direction decides
whether you land on the first or last sub-screen. Vertical movement returns
to where you were in that row, and snaps to the nearest column only on the
first visit.

Notable details found while building:

* Unquoted "at: 0x0" is hexadecimal 0 to YAML, and "1x0" is not valid hex,
  so only the row-0 entries would break. Deserialization catches the integer
  case and names the fix.
* Panes are addressed by tmux id, never index, and each command is wrapped
  so the pane outlives it. v1's remain-on-exit cannot do this: it is a
  per-window option that new windows do not inherit, so a monitor that exits
  during construction destroys its window and the next split fails with
  "no current target". Now a dead monitor stays on screen with its status.
* Contact-count averaging, not summing: a panel reporting one finger as
  three contacts must not look like three times the travel.
* Movement subcommands wait for the move to happen and report where they
  landed, so they are scriptable rather than fire-and-forget.

36 tests: the grid model, the gesture classifier and an end-to-end pass
against a real tmux server.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
jasonwitty
2026-09-09 13:01:08 -07:00
co-authored by Claude Opus 5
parent 9f4bcec250
commit 9f082b52b7
16 changed files with 3337 additions and 0 deletions
+169
View File
@@ -0,0 +1,169 @@
//! Turning a config screen into the panes tmux should run.
//!
//! Only `socktop` produces more than one pane today. The representation is a
//! plain `Vec<Pane>` per cell, so a future type wanting the same treatment is a
//! data change rather than a redesign.
use anyhow::{bail, Context, Result};
use crate::config::{expand_tilde, Binaries, Config, Coord, Layout, MonitorType, Screen};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Pane {
/// Shown in the pane border.
pub title: String,
/// argv, already split. Never passed through a shell.
pub command: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct Cell {
pub coord: Coord,
pub kind: MonitorType,
/// Human label for the position indicator.
pub label: String,
pub panes: Vec<Pane>,
pub layout: Layout,
/// Which sub-screen of this cell is current. Persists while you are
/// elsewhere, so a vertical return lands where you left.
pub cursor: usize,
}
impl Cell {
/// A multi-pane cell shows a tiled overview first, then each pane zoomed.
/// A single-pane cell has nothing to zoom into, so it is one sub-screen.
pub fn has_overview(&self) -> bool {
self.panes.len() > 1
}
pub fn screens(&self) -> usize {
if self.has_overview() {
self.panes.len() + 1
} else {
1
}
}
pub fn last_screen(&self) -> usize {
self.screens() - 1
}
/// `None` for the overview, otherwise the pane index to zoom.
pub fn zoomed_pane(&self) -> Option<usize> {
match (self.has_overview(), self.cursor) {
(true, 0) => None,
(true, i) => Some(i - 1),
(false, _) => Some(0),
}
}
/// What the indicator shows for the current sub-screen.
pub fn screen_label(&self) -> String {
match self.zoomed_pane() {
None => format!("{} (all)", self.label),
Some(i) if self.has_overview() => self.panes[i].title.clone(),
Some(_) => self.label.clone(),
}
}
}
pub fn build_cell(screen: &Screen, bins: &Binaries) -> Result<Cell> {
let at = screen.at;
let extra = screen.args.clone().unwrap_or_default();
// An explicit `command:` replaces the generated one for every type.
if let Some(cmd) = &screen.command {
let mut argv = shell_words::split(cmd)
.with_context(|| format!("screen {at}: cannot parse command: {cmd}"))?;
if argv.is_empty() {
bail!("screen {at}: command is empty");
}
argv[0] = expand_tilde(&argv[0]);
argv.extend(extra);
let title = screen
.title
.clone()
.unwrap_or_else(|| screen.kind.to_string());
return Ok(Cell {
coord: at,
kind: screen.kind,
label: title.clone(),
panes: vec![Pane { title, command: argv }],
layout: screen.layout.unwrap_or_default(),
cursor: 0,
});
}
let bin = bins.get(screen.kind);
let (label, panes) = match screen.kind {
MonitorType::Socktop => {
let hosts = screen
.socktop_group
.as_ref()
.expect("validated: socktop needs socktop_group");
let panes = hosts
.0
.iter()
.map(|h| Pane {
title: h.clone(),
command: {
let mut c = vec![bin.clone(), "-P".into(), h.clone()];
c.extend(extra.clone());
c
},
})
.collect();
let label = if hosts.0.len() == 1 {
hosts.0[0].clone()
} else {
format!("{} hosts", hosts.0.len())
};
(label, panes)
}
MonitorType::UptimeKumaStatus => {
let url = screen.url.as_ref().expect("validated: kuma needs url");
let mut c = vec![bin, url.clone()];
c.extend(extra);
(
"uptime kuma".to_string(),
vec![Pane { title: "uptime kuma".into(), command: c }],
)
}
MonitorType::Unifly => {
let mut c = vec![bin, "tui".into()];
// Carved out for when the fork grows the flags; see notes/PLAN-v2.md.
if let Some(site) = &screen.site {
c.push("--site".into());
c.push(site.clone());
}
if let Some(controller) = &screen.controller {
c.push("--controller".into());
c.push(controller.clone());
}
c.extend(extra);
(
"unifly".to_string(),
vec![Pane { title: "unifly".into(), command: c }],
)
}
MonitorType::Generic => unreachable!("validated: generic always has a command"),
};
let label = screen.title.clone().unwrap_or(label);
Ok(Cell {
coord: at,
kind: screen.kind,
label,
panes,
layout: screen.layout.unwrap_or_default(),
cursor: 0,
})
}
pub fn build_cells(cfg: &Config) -> Result<Vec<Cell>> {
cfg.screens.iter().map(|s| build_cell(s, &cfg.binaries)).collect()
}