feat(proto): SurfaceState + SetState command + State event + SurfaceView.state

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-09 22:10:54 +07:00
parent c2f8ef4214
commit 4bd4aa4a36
4 changed files with 67 additions and 0 deletions
+22
View File
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::ids::{GroupId, SurfaceId, WorkspaceId};
use crate::layout::LayoutNode;
use crate::status::SurfaceState;
use crate::workspace::{Group, WorkspaceView};
/// Wire envelope. `kind` is the serde tag.
@@ -114,6 +115,7 @@ pub enum Cmd {
order: Option<u32>,
},
DeleteGroup { group_id: GroupId },
SetState { surface_id: SurfaceId, state: SurfaceState },
Status,
Shutdown,
}
@@ -131,6 +133,7 @@ pub enum Evt {
WorkspaceClosed { workspace_id: WorkspaceId },
GroupsChanged { groups: Vec<Group> },
SurfaceRestarted { surface_id: SurfaceId },
State { surface_id: SurfaceId, state: SurfaceState },
}
#[cfg(test)]
@@ -240,4 +243,23 @@ mod tests {
let back: Envelope = serde_json::from_str(&serde_json::to_string(&evt).unwrap()).unwrap();
assert_eq!(back, evt);
}
#[test]
fn set_state_round_trips() {
let env = Envelope::Req {
id: 1,
cmd: Cmd::SetState { surface_id: SurfaceId("s_1".into()), state: crate::status::SurfaceState::Done },
};
let back: Envelope = serde_json::from_str(&serde_json::to_string(&env).unwrap()).unwrap();
assert_eq!(back, env);
}
#[test]
fn state_event_round_trips() {
let evt = Envelope::Evt(Evt::State { surface_id: SurfaceId("s_1".into()), state: crate::status::SurfaceState::Wait });
let j = serde_json::to_string(&evt).unwrap();
assert!(j.contains(r#""evt":"state""#));
let back: Envelope = serde_json::from_str(&j).unwrap();
assert_eq!(back, evt);
}
}