feat: add strict workspacing

This commit is contained in:
atagen 2025-06-21 21:50:07 +10:00
parent 05e12ea2f2
commit 49473b92a3

View File

@ -16,6 +16,7 @@ use std::collections::HashMap;
pub struct NiriTag {
tags: HashMap<u8, bool>,
windows: HashMap<u64, u8>,
active_ws: Vec<u64>,
state: EventStreamState,
socket: BufReader<UnixStream>,
ev_tx: channel::Sender<TagEvent>,
@ -33,6 +34,7 @@ impl NiriTag {
windows: HashMap::new(),
state: EventStreamState::default(),
socket: create_niri_socket().await?,
active_ws: Vec::new(),
ev_tx,
})
}
@ -308,8 +310,45 @@ impl NiriTag {
self.windows.remove(&id);
Ok(())
}
// WorkspaceActivated { .. } => (),
// WorkspacesChanged { .. } => (),
WorkspaceActivated { id, .. } => {
if !self.active_ws.contains(&id) {
let q = query(&mut self.socket, Request::Workspaces).await?;
let wsid = if let Reply::Ok(Response::Workspaces(workspaces)) = q {
let new_ws = workspaces
.iter()
.find(|ws| ws.id == id)
.expect("Activated workspace not found in workspace query");
workspaces
.iter()
.find(|ws| {
ws.output == new_ws.output
&& ws.id != new_ws.id
&& self.active_ws.contains(&ws.id)
})
.expect("Could not find a valid niri-tag workspace to return to")
.id
} else {
return Err(anyhow!("Invalid response to workspace query"));
};
tell(
&mut self.socket,
Request::Action(Action::FocusWorkspace {
reference: WorkspaceReferenceArg::Id(wsid),
}),
)
.await
} else {
Ok(())
}
}
WorkspacesChanged { workspaces } => {
self.active_ws = workspaces
.into_iter()
.filter(|ws| ws.is_active)
.map(|ws| ws.id)
.collect();
Ok(())
}
// WorkspaceUrgencyChanged { .. } => (),
// WindowsChanged { .. } => (),
// WindowUrgencyChanged { .. } => (),