#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod global;
pub mod interface;
pub mod object;
pub mod protocol;
pub mod proxy;
pub mod wire;
mod connection;
mod socket;
pub use connection::Connection;
pub use wayrs_scanner as scanner;
use proxy::Proxy;
use std::ffi::CStr;
use std::fmt;
use std::io;
#[derive(Debug, thiserror::Error)]
pub enum ConnectError {
#[error("both $XDG_RUNTIME_DIR and $WAYLAND_DISPLAY must be set")]
NotEnoughEnvVars,
#[error(transparent)]
Io(#[from] io::Error),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IoMode {
Blocking,
NonBlocking,
}
#[macro_export]
macro_rules! cstr {
($str:literal) => {{
const X: &'static ::std::ffi::CStr = $crate::cstr(concat!($str, "\0"));
X
}};
}
#[doc(hidden)]
pub const fn cstr(string: &str) -> &CStr {
let bytes = string.as_bytes();
assert!(!bytes.is_empty());
let mut i = 0;
while i < bytes.len() {
let byte = bytes[i];
assert!((byte != 0 && i + 1 != bytes.len()) || (byte == 0 && i + 1 == bytes.len()));
i += 1;
}
unsafe { CStr::from_bytes_with_nul_unchecked(bytes) }
}
#[non_exhaustive]
pub struct EventCtx<'a, D, P: Proxy> {
pub conn: &'a mut Connection<D>,
pub state: &'a mut D,
pub proxy: P,
pub event: P::Event,
}
impl<'a, D, P: Proxy> fmt::Debug for EventCtx<'a, D, P>
where
P: fmt::Debug,
P::Event: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EventCtx")
.field("proxy", &self.proxy)
.field("event", &self.event)
.finish_non_exhaustive()
}
}