#window-manager #xcb #x11 #window #ewmh #icccm

xcb-wm

Rust implementation of xcb-wm - icccm and ewmh extensions for xcb

10 unstable releases (3 breaking)

0.4.0 Aug 25, 2022
0.3.6 Jun 6, 2022
0.2.1 May 29, 2022
0.1.0 May 21, 2022

#860 in GUI

MIT license

120KB
2.5K SLoC

xcb-wm

The long lost Rust implementation of the icccm and ewmh extensions for the X Window System protocol.

xcb-wm provides type safe and Rust-native abstractions. It simplifies the usage of window manager extensions to X11.

xcb-wm sits on top of rust-xcb similar to how libxcb-wm sits on top of libxcb. If you are already using rust-xcb you are also familiar with xcb-wm. The public APIs and general usage are intentionally close.

xcb-wm works with rust-xcb 1.x and later.

Usage

Add this to your Cargo.toml:

[dependencies]
xcb-wm = "0.4.0"

Each request is either a Get*, a Set* or a Send* struct. Get* structs can be used to get ewmh or iccm properties. Set* structs can be used to set properties. Send* structs can be used to send client messages. You can read up on the protocol definitions for more details but in general every property has a corresponding Get* request. Set* requests are mostly useful before a window is mapped. Send* requests for everything else.

Each request can be sent either checked or unchecked. This is typesafe by special cookies for each of them. You get the request cookie by calling send_request/send_request_unchecked.

You can retrieve a reply and wrap it into a high level and meaningful Rust struct by calling wait_for_reply/wait_for_reply_unchecked on the cookie. For requests that don't have a reply (i.e. Set* and Send* requests) you can use check_request to check for errors.

Examples

Get the names of available desktops:

use xcb;
use xcb_wm::ewmh;

// Create a `rust-xcb` connection
let xcb_con = xcb::Connection::connect(Option::None).unwrap().0;

// Wrap the connection in an `xcb-wm::ewmh` connection for ewmh extensions.
// 
// Note that this does not take ownership of the `rust-xcb` connection
// so you can continue to use other xcb functionality with the same
// connection.
let ewmh_con = ewmh::Connection::connect(&xcb_con);

// Create a request for the _NET_DESKTOP_NAMES property
let request = ewmh::proto::GetDesktopNames;
let cookie = ewmh_con.send_request(&request);

// Get a `GetDesktopNamesReply` reply
//
// Replies are automatically de-serialized into meaningful Rust structs. You
// take full ownership of the reply struct.
let reply = ewmh_con.wait_for_reply(cookie).unwrap();

// All replies implement `Debug` so you can also print them
println!("{:?}", reply);

Dependencies

~0.6–0.8MB
~18K SLoC