#i3 #ipc #async #tokio #protocols #window-event #api-bindings

async-i3ipc

为 i3 和 async-std 提供绑定,允许异步应用程序通过其 IPC 接口与 i3 进行通信。包含 futures 实现,以及与 i3 一起工作的便利函数。

5 个版本 (重大变更)

0.7.0 2022年12月31日
0.5.0 2021年12月10日
0.4.0 2021年11月4日
0.3.0 2021年1月11日
0.1.0 2020年8月21日

#1530异步

每月 46 次下载
用于 desktopd

MIT 许可证

46KB
922

async-i3ipc

Crate API

此 crate 提供在 async-std 中使用 i3 的 IPC 协议的类型和函数。因为它也用于代码的同步版本,所以重新导出子 crate i3ipc-types

我预计最常见的用例将是订阅某些事件并进行监听

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(())
}

依赖关系

~5–18MB
~214K SLoC