async-i3ipc

Crates.ioasync-i3ipc
lib.rsasync-i3ipc
version0.7.0
sourcesrc
created_at2020-08-21 02:15:35.872581
updated_at2022-12-31 00:42:03.547181
descriptionBindings for i3 and async-std allowing async applications to communicate with i3 over it's IPC interface. Contains futures implementations and convenience functions for working with i3.
homepage
repositoryhttps://github.com/leshow/tokio-i3ipc/tree/master/async-i3ipc
max_upload_size
id278983
size39,895
Evan Cameron (leshow)

documentation

README

async-i3ipc

Crate API

This crate provides types and functions for working with i3's IPC protocol within async-std. It re-exports the subcrate i3ipc-types because it is also used for a synchronous version of the code.

I expect the most common use case will be to subscribe to some events and listen:

use async_i3ipc::{
    event::{Event, Subscribe},
    I3,
};
use std::io;

// prefer creating the runtime yourself and using only a single core.
// this will hardly need to have a runtime with 1 thread for each core
// on your machine
#[async_std::main]
async fn main() -> io::Result<()> {
    let mut i3 = I3::connect().await?;
    let resp = i3.subscribe([Subscribe::Window]).await?;

    println!("{:#?}", resp);
    let mut listener = i3.listen();
    while let Ok(event) = listener.next().await {
        match event {
            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(())
}
Commit count: 249

cargo fmt