feat(vdisplay): Stage 5 layout foundation — arrangement engine + /display/layout + group placement
§6A layout, riding the Stages 1-3 registry with no protocol change: - vdisplay/layout.rs: pure arrangement engine — auto-row (left-to-right in acquire order, top-aligned) + manual (per-identity-slot offsets, auto-row fallback for unpinned members). Unit-tested. - Registry group model (Linux): group = backend (one desktop per compositor session). /display/state groups entries, orders by acquire (gen), and computes each member's position via the engine (pure `assemble_displays`, unit-tested). DisplayInfo carries group/display_index/position/identity_slot/topology. The backend reports its resolved slot via the new VirtualDisplay::last_identity_slot (KWin only), so the arrangement + state key on per-client identity. - Registry-driven position apply: new VirtualDisplay::apply_position(x,y) (default no-op; KWin drives kscreen-doctor). Right after create the registry computes the new display's position over its whole group (pure `position_for_new`, unit-tested) and applies it — one seam for BOTH deterministic auto-row AND manual placement. Guarded: the origin (0,0) is skipped, so a single-display / first-of-group session (and every non-KWin backend) issues no positioning — the historical single-display path is unchanged. On-glass-validation-pending. - PUT /api/v1/display/layout: persists the console's manual arrangement via the pure EffectivePolicy::with_manual_layout transform (locks current effective behavior into explicit Custom fields + sets a manual layout, so arranging is orthogonal to the other axes). OpenAPI regenerated. - /display/settings `enforced` now lists all five axes (keep_alive, topology, mode_conflict [Stage 4], identity [Stage 3], layout [Stage 5]) — was stale at keep_alive+topology; the console reads it to know which controls are live. Still Stage-5 TODO (design/display-management.md §11): Mutter/wlroots group-aware analogues, per-group topology restore, the web arrangement table, gamescope decline. cargo build/test/clippy/fmt green; OpenAPI in sync. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -273,6 +273,29 @@ impl DisplayPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
impl EffectivePolicy {
|
||||
/// Build a persistable `Custom` [`DisplayPolicy`] that keeps THIS effective behavior but replaces
|
||||
/// the arrangement with a **manual** layout at `positions` — the `/display/layout` endpoint's
|
||||
/// transform, factored out pure so arranging displays stays orthogonal to the other axes and is
|
||||
/// unit-tested without touching the global store. (`Custom` so the explicit fields — incl. the new
|
||||
/// layout — rule; a named preset would ignore them.)
|
||||
pub fn with_manual_layout(&self, positions: BTreeMap<String, Position>) -> DisplayPolicy {
|
||||
DisplayPolicy {
|
||||
version: 1,
|
||||
preset: Preset::Custom,
|
||||
keep_alive: self.keep_alive,
|
||||
topology: self.topology,
|
||||
mode_conflict: self.mode_conflict,
|
||||
identity: self.identity,
|
||||
layout: Layout {
|
||||
mode: LayoutMode::Manual,
|
||||
positions,
|
||||
},
|
||||
max_displays: self.max_displays,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The field bundle a named preset expands to; `None` for [`Preset::Custom`]. The single expansion
|
||||
/// table — the docs' preset table mirrors this and the `presets_match_doc` test guards the shape.
|
||||
pub fn preset_fields(preset: Preset) -> Option<EffectivePolicy> {
|
||||
@@ -526,6 +549,33 @@ mod tests {
|
||||
assert_eq!(p.max_displays, 16);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_manual_layout_preserves_behavior_and_sets_positions() {
|
||||
// Start from a preset's effective behavior (workstation: 5-min linger, exclusive, per-client).
|
||||
let eff = DisplayPolicy {
|
||||
preset: Preset::Workstation,
|
||||
..DisplayPolicy::default()
|
||||
}
|
||||
.effective();
|
||||
let mut positions = BTreeMap::new();
|
||||
positions.insert("1".to_string(), Position { x: 0, y: 0 });
|
||||
positions.insert("7".to_string(), Position { x: 2560, y: 0 });
|
||||
let p = eff.with_manual_layout(positions);
|
||||
// Preset drops to Custom so the explicit fields (incl. the layout) rule…
|
||||
assert_eq!(p.preset, Preset::Custom);
|
||||
// …every other behavior axis is preserved verbatim…
|
||||
assert_eq!(p.keep_alive, eff.keep_alive);
|
||||
assert_eq!(p.topology, eff.topology);
|
||||
assert_eq!(p.mode_conflict, eff.mode_conflict);
|
||||
assert_eq!(p.identity, eff.identity);
|
||||
assert_eq!(p.max_displays, eff.max_displays);
|
||||
// …and the arrangement is the manual layout we asked for, surviving the effective round-trip.
|
||||
let e2 = p.effective();
|
||||
assert_eq!(e2.layout.mode, LayoutMode::Manual);
|
||||
let want = Position { x: 2560, y: 0 };
|
||||
assert_eq!(e2.layout.positions.get("7"), Some(&want));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_json_fills_defaults() {
|
||||
// A hand-written file with only a couple of fields loads, the rest defaulting.
|
||||
|
||||
Reference in New Issue
Block a user