i3_ipc

Crates.ioi3_ipc
lib.rsi3_ipc
version0.16.0
sourcesrc
created_at2019-04-13 02:28:02.013666
updated_at2022-12-31 00:41:34.01328
descriptionFor communicating with i3 over it's IPC interface synchronously
homepage
repositoryhttps://github.com/leshow/tokio-i3ipc/tree/master/i3-ipc
max_upload_size
id127566
size15,429
Evan Cameron (leshow)

documentation

README

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(())
}
Commit count: 249

cargo fmt