#i3 #ipc #json #serde #protocols #serde-json #window-event

i3_ipc

For communicating with i3 over it's IPC interface synchronously

11 breaking releases

0.16.0 Dec 31, 2022
0.15.0 Jul 5, 2022
0.14.0 Dec 10, 2021
0.13.0 Nov 4, 2021
0.5.0 Apr 21, 2019

#7 in #window-event

Download history 9/week @ 2024-08-29 25/week @ 2024-09-19 26/week @ 2024-09-26 19/week @ 2024-10-03 17/week @ 2024-10-10 9/week @ 2024-10-17 3/week @ 2024-10-24 5/week @ 2024-10-31 9/week @ 2024-11-07 2/week @ 2024-11-14 4/week @ 2024-11-21 3/week @ 2024-11-28 28/week @ 2024-12-05 65/week @ 2024-12-12

101 downloads per month
Used in 3 crates

MIT license

41KB
884 lines

i3-ipc (synchronous)

Crate API

A synchronous i3 IPC library. For async see tokio-i3ipc.

Subscribe

Subscribing to events is easy:

use i3_ipc::{
    event::{Event, Subscribe},
    I3Stream,
};
use std::io;

fn main() -> io::Result<()> {
    let mut i3 = I3Stream::conn_sub(&[Subscribe::Window, Subscribe::Workspace])?;
    for e in i3.listen() {
        match e? {
            Event::Workspace(ev) => println!("workspace change event {:?}", ev),
            Event::Window(ev) => println!("window event {:?}", ev),
            Event::Output(ev) => println!("output event {:?}", ev),
            Event::Mode(ev) => println!("mode event {:?}", ev),
            Event::BarConfig(ev) => println!("bar config update {:?}", ev),
            Event::Binding(ev) => println!("binding event {:?}", ev),
            Event::Shutdown(ev) => println!("shutdown event {:?}", ev),
            Event::Tick(ev) => println!("tick event {:?}", ev),
        }
    }
    Ok(())
}

Get

Getting information is equally easy, use any get_* method or run_command to send a message to i3:

use i3_ipc::{Connect, I3};
use std::io;

fn main() -> io::Result<()> {
    let mut i3 = I3::connect()?;
    let workspaces = i3.get_workspaces()?;
    println!("{:?}", workspaces);
    Ok(())
}

Dependencies

~0.7–1.6MB
~34K SLoC