31个版本 (7个稳定版)
| 3.1.0 | 2022年7月1日 | 
|---|---|
| 2.0.0 | 2021年9月14日 | 
| 1.2.1 | 2021年7月21日 | 
| 0.3.0 | 2021年6月11日 | 
| 0.1.0 | 2020年11月30日 | 
#1858 in 异步
每月下载量68次
用于  8 crates
2MB
 57K  SLoC
breadx 是一个功能全面且强大的 X11 客户端协议实现,同时易于使用。
breadx 旨在成为一个最小化的 X11 协议实现,可以在需要客户端的任何情况下使用。 breadx 内置以下功能
- 全面: breadx对所有 X11 协议扩展提供一等支持。这些扩展可以作为功能启用和禁用。
- 无锁: 默认连接实现不使用任何锁和等待,除了标准 I/O 原语之外。目标是确保用户的目标与实际向服务器发送数据之间尽可能少地有层。
- 安全: breadx有#[forbid(unsafe_code)],这意味着breadx中永远不会存在任何不安全代码。这意味着breadx永远不会成为任何未定义行为的起因。
- 灵活: 对于需要共享连接的情况,breadx提供了线程不安全和线程安全的变体。
- no_std: 通过禁用- std功能,- breadx可以在不依赖标准库的情况下使用。
- 异步操作:启用 async功能后,breadx的基本功能可以在异步环境中使用。默认情况下,breadx是运行时无关的,但可以启用对tokio和async-std的支持。
- 简单易用:通过以上功能,客户可以在 breadx中用非常少的代码行创建并使用客户端。
breadx 不提供的功能
- 数据处理:用于简化图像处理/ICCCM等操作的API位于其他crate中。
- 与Xlib/XCB接口:breadx不提供直接与Xlib/XCB交互的方式。
使用方法
breadx 中的所有函数都存在于 Display 的上下文中。创建 Display 有许多方法,但在大多数情况下,DisplayConnection::connect() 将无缝连接到当前运行的X11服务器。
从那里开始,breadx 中实际使用的多数函数存在于 DisplayFunctionsExt 扩展特性中。
use breadx::{prelude::*, display::DisplayConnection, protocol::xproto};
// establish a connection to the X11 server
let mut connection = DisplayConnection::connect(None)?;
// create a window
// note the "_checked" suffix, this indicates that the result of the
// function will be checked by the server after it is run
// also note that we need to create an XID for the window ahead of time
let wid = connection.generate_xid()?;
connection.create_window_checked(
    0, // depth
    wid,
    connection.default_screen().root, // parent
    0, // x
    0, // y
    600, // width
    400, // height
    0, // border width
    xproto::WindowClass::COPY_FROM_PARENT,
    0, // visual
    xproto::CreateWindowAux::new()
        .background_pixel(connection.default_screen().white_pixel)
)?;
// map the window to the screen
// note the lack of _checked here
connection.map_window(wid)?;
// primary event loop
loop {
    let event = connection.wait_for_event()?;
    match event {
        // match on the Event struct in here
        # _ => {},
    }
}
有关 breadx 使用方法的更多信息,请参阅 教程。
依赖项
~7–21MB
~281K SLoC