Skip to content

Instantly share code, notes, and snippets.

@camspiers
Last active November 29, 2025 22:45
Show Gist options
  • Select an option

  • Save camspiers/53d67a975a21f8eb25ae74ab291bd211 to your computer and use it in GitHub Desktop.

Select an option

Save camspiers/53d67a975a21f8eb25ae74ab291bd211 to your computer and use it in GitHub Desktop.
Resize 1 or 2 windowed workspace to fill
use niri_ipc::socket::Socket;
use niri_ipc::state::{EventStreamState, EventStreamStatePart};
use niri_ipc::{Action, Request, Response};
fn main() -> std::io::Result<()> {
let mut read_socket = Socket::connect()?;
let mut write_socket = Socket::connect()?;
let mut state = EventStreamState::default();
if matches!(
read_socket.send(Request::EventStream)?,
Ok(Response::Handled)
) {
let mut read_event = read_socket.read_events();
while let Ok(event) = read_event() {
state.apply(event);
for (&workspace_id, _) in &state.workspaces.workspaces {
let window_ids: Vec<_> = state
.windows
.windows
.iter()
.filter_map(|(&id, window)| {
(window.workspace_id == Some(workspace_id) && !window.is_floating).then_some(id)
})
.collect();
let window_count = window_ids.len();
if matches!(window_count, 1 | 2) {
for window_id in window_ids {
let _ = write_socket.send(Request::Action(Action::SetWindowWidth {
id: Some(window_id),
change: niri_ipc::SizeChange::SetProportion(100.0 / window_count as f64),
}))?;
}
}
}
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment