pub struct Client(/* private fields */);Expand description
A connection to the Sawfish window manager.
Implementations§
Source§impl Client
impl Client
Sourcepub fn open(display: Option<&str>) -> Result<Self, ConnError>
pub fn open(display: Option<&str>) -> Result<Self, ConnError>
Opens a connection to the Sawfish server.
The display argument specifies an optional display string, (such as
":0"). If not provided, the DISPLAY environment variable is used.
Tries to connect to the Unix socket of the Sawfish server. If that
fails and the experimental-xcb Cargo feature is enabled, tries using
X11 protocol to communicate with Sawfish.
Sourcepub fn eval(
&mut self,
form: impl AsRef<[u8]>,
) -> Result<EvalResponse, EvalError>
pub 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, returnsOk(Err(data))value. - Otherwise, if the
formhas been successfully executed by the server, returnsOk(Ok(data))value.
§Example
let mut client = sawfish_client::Client::open(None).unwrap();
match client.eval("(system-name)") {
Ok(Ok(data)) => {
println!("Form evaluated to: {}",
String::from_utf8_lossy(&data))
}
Ok(Err(data)) => {
println!("Error evaluating form: {}",
String::from_utf8_lossy(&data))
}
Err(err) => println!("Communication error: {err}")
}Sourcepub fn send(&mut self, form: impl AsRef<[u8]>) -> Result<(), EvalError>
pub 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
let mut client = sawfish_client::Client::open(None).unwrap();
match client.send("(set-screen-viewport 0 0)") {
Ok(()) => println!("Form successfully sent"),
Err(err) => println!("Communication error: {err}")
}