#i3 #ipc #protocol #json #serde

i3_ipc

For communicating with i3 over it’s IPC interface synchronously

8 breaking releases

0.12.0 Jan 11, 2021
0.11.0 Nov 2, 2020
0.10.0 Aug 21, 2020
0.9.0 Jul 1, 2020
0.5.0 Apr 21, 2019

#168 in Network programming

Download history 2/week @ 2020-12-30 23/week @ 2021-01-06 23/week @ 2021-01-13 6/week @ 2021-01-20 4/week @ 2021-01-27 4/week @ 2021-02-03 62/week @ 2021-02-10 33/week @ 2021-02-17 2/week @ 2021-02-24 10/week @ 2021-03-03 2/week @ 2021-03-10 3/week @ 2021-03-17 31/week @ 2021-03-24 32/week @ 2021-03-31 17/week @ 2021-04-07 19/week @ 2021-04-14

63 downloads per month

MIT license

37KB
835 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.8–1.5MB
~35K SLoC