Crate sawfish_client

Crate sawfish_client 

Source
Expand description

§sawfish-client

A library for handling communication with the Sawfish window manager to allow remote form evaluation. In other words, Rust implementation of the sawfish-client program shipped with Sawfish.

§Example usage

fn sawfish_eval(form: &str) -> Result<Vec<u8>, ()> {
    // Establish connection.  open will read
    // $DISPLAY to get the display name.
    let mut conn = sawfish_client::open(None)
        .map_err(|err| { eprintln!("{err}"); })?;

    // Evaluate the form.
    println!(">>> {form}");
    match conn.eval(form) {
        Err(err) => {
            eprintln!("{err}");
            Err(())
        }
        Ok(Err(data)) => {
            let msg = String::from_utf8_lossy(&data);
            println!("!!! {msg}");
            Err(())
        }
        Ok(Ok(data)) => {
            let msg = String::from_utf8_lossy(&data);
            println!("<<< {msg}");
            Ok(data)
        }
    }
}

Furthermore, the crate comes with an example binary which can be examined to see how the library functions.

§Features

The crate defines the following Cargo feature:

  • async — adds AsyncClient type which uses future_io traits to support asynchronous I/O. It can be used with any async runtime so long as a compatible async I/O object is provided. Because opening the Unix socket depends on the runtime, with AsyncClient that now must be done by the caller.

  • tokio — adds TokioClient type alias and open_tokio function which simplify using the library with the Tokio async runtime. This feature does not introduce any new capabilities to sawfish-client but is provided for convenience of Tokio users. This feature implies async.

  • expemirental-xcb — adds experimental support for X11-based communication with Sawfish. Normally, the library connects to Sawfish via a Unix socket. With this feature, if connecting to the socket fails, it tries to use X11-based communication instead. Note that this feature is only supported with synchronous client.

Structs§

AsyncClientasync
A connection to the Sawfish window manager using asynchronous I/O.
Client
A connection to the Sawfish window manager.

Enums§

ConnError
Error during establishing connection to the Sawfish server.
EvalError
Error during sending form for evaluation.

Functions§

open
Opens a connection to the Sawfish server.
open_tokiotokio
Opens a connection to the Sawfish server using the Tokio runtime.
server_pathasync
Returns path of the Unix socket the Sawfish server is (or should be) listening on.

Type Aliases§

EvalResponse
Result of a form evaluation.
TokioClienttokio
An alias for the AsyncClient which uses Tokio runtime Unix stream.