pub struct AsyncClient<S>(/* private fields */);async only.Expand description
A connection to the Sawfish window manager using asynchronous I/O.
Implementations§
Source§impl AsyncClient<Compat<UnixStream>>
impl AsyncClient<Compat<UnixStream>>
Sourcepub async fn open(display: Option<&str>) -> Result<Self, ConnError>
Available on crate feature tokio only.
pub async fn open(display: Option<&str>) -> Result<Self, ConnError>
tokio only.Opens a connection to the Sawfish server using the Tokio runtime.
The display argument specifies an optional display string, (such as
":0"). If not provided, the DISPLAY environment variable is used.
Source§impl<S: AsyncRead + AsyncWrite + Unpin> AsyncClient<S>
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncClient<S>
Sourcepub fn new(socket: S) -> Self
pub fn new(socket: S) -> Self
Constructs a connection to the Sawfish server over an asynchronous Unix socket.
Because the creation of an asynchronous Unix socket depends on the async
runtime, responsibility to open the connection falls on the caller. Use
server_path to determine path to the Unix Socket the Sawfish server
is (supposed to be) listening on.
§Example
use tokio_util::compat::TokioAsyncReadCompatExt;
type TokioClient = sawfish_client::AsyncClient<
tokio_util::compat::Compat<tokio::net::UnixStream>>;
async fn open() -> TokioClient {
let path = sawfish_client::server_path(None).unwrap();
let sock = tokio::net::UnixStream::connect(path).await.unwrap();
sawfish_client::AsyncClient::new(sock.compat())
}Sourcepub async fn eval(
&mut self,
form: impl AsRef<[u8]>,
) -> Result<EvalResponse, EvalError>
pub async fn eval( &mut self, form: impl AsRef<[u8]>, ) -> Result<EvalResponse, EvalError>
Sends a Lisp form to the Sawfish server for evaluation and waits for
a reply.
- If there’s an error sending the
formto the server (e.g. an I/O error), returns anErr(error)value. - Otherwise, if the
formhas been successfully sent to the server but evaluation failed (e.g. due to syntax error), returnsOk(Err(data))value. - Otherwise, if the
formhas been successfully executed by the server, returnsOk(Ok(data))value.
§Example
use futures_util::{AsyncRead, AsyncWrite};
async fn system_name<S: AsyncRead + AsyncWrite + Unpin>(
client: &mut sawfish_client::AsyncClient<S>,
) -> Option<String> {
match client.eval("(system-name)").await {
Ok(Ok(data)) => {
Some(String::from_utf8_lossy(&data).into_owned())
}
Ok(Err(data)) => {
println!("Error evaluating form: {}",
String::from_utf8_lossy(&data));
None
}
Err(err) => {
println!("Communication error: {err}");
None
}
}
}Sourcepub async fn send(&mut self, form: impl AsRef<[u8]>) -> Result<(), EvalError>
pub async fn send(&mut self, form: impl AsRef<[u8]>) -> Result<(), EvalError>
Sends a Lisp form to the Sawfish server for evaluation but does not
wait for a reply.
If there’s an error sending the form to the server (e.g. an I/O
error), returns an Err(error) value. Otherwise, so long as the form
was successfully sent, returns Ok(()) even if evaluation on the server
side has changed (e.g. due to syntax error). Use Self::eval instead
to check whether evaluation succeeded.
§Example
use futures_util::{AsyncRead, AsyncWrite};
async fn set_screen_viewport<S: AsyncRead + AsyncWrite + Unpin>(
client: &mut sawfish_client::AsyncClient<S>,
x: u32,
y: u32,
) {
let form = format!("(set-screen-viewport {x} {y})");
if let Err(err) = client.send(&form).await {
println!("Communication error: {err}");
}
}