#[cfg(feature = "experimental-xcb")]
use xcb::x;
#[derive(Debug, derive_more::From)]
#[non_exhaustive]
pub enum ConnError {
NoDisplay,
NoLogname,
Io(std::path::PathBuf, std::io::Error),
#[cfg(feature = "experimental-xcb")]
BadScreen(i32),
#[cfg(feature = "experimental-xcb")]
ServerNotFound,
#[cfg(feature = "experimental-xcb")]
#[from(xcb::Error, xcb::ConnError, xcb::ProtocolError)]
X11(xcb::Error),
}
impl core::fmt::Display for ConnError {
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::NoDisplay => {
"No display specified and DISPLAY variable not set".fmt(fmtr)
}
Self::NoLogname => "LOGNAME environment variable not set".fmt(fmtr),
#[cfg(feature = "experimental-xcb")]
Self::BadScreen(screen) => {
write!(fmtr, "Invalid screen number {screen}")
}
#[cfg(feature = "experimental-xcb")]
Self::ServerNotFound => {
"No Sawfish server found on X11 screen".fmt(fmtr)
}
#[cfg(feature = "experimental-xcb")]
Self::X11(err) => err.fmt(fmtr),
Self::Io(path, err) => write!(fmtr, "{}: {}", path.display(), err),
}
}
}
#[derive(Debug, derive_more::From)]
#[non_exhaustive]
pub enum EvalError {
NoResponse,
ResponseTooLarge(std::ffi::c_ulong),
#[from(std::io::Error, std::io::ErrorKind)]
Io(std::io::Error),
#[cfg(feature = "experimental-xcb")]
BadResponse {
window: x::Window,
atom: x::Atom,
typ: x::Atom,
format: u8,
},
#[cfg(feature = "experimental-xcb")]
#[from(xcb::Error, xcb::ConnError, xcb::ProtocolError)]
X11(xcb::Error),
}
impl core::fmt::Display for EvalError {
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::NoResponse => "No response to non-async request".fmt(fmtr),
Self::ResponseTooLarge(len) => {
write!(fmtr, "Response of {len} bytes too large")
}
Self::Io(err) => err.fmt(fmtr),
#[cfg(feature = "experimental-xcb")]
Self::BadResponse { window, atom, typ, format } => {
use xcb::Xid;
write!(
fmtr,
"Invalid format of response property (window:{}, atom:{}, \
typ:{}, format:{})",
window.resource_id(),
atom.resource_id(),
typ.resource_id(),
format
)
}
#[cfg(feature = "experimental-xcb")]
Self::X11(err) => err.fmt(fmtr),
}
}
}
impl std::error::Error for ConnError {}
impl std::error::Error for EvalError {}