diff --git a/src/errors.rs b/src/errors.rs index b6d8770..1f93fe2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -31,6 +31,9 @@ pub enum Error { #[error("nul error: {0}")] Nul(#[from] std::ffi::NulError), + #[error("env var error: {0}")] + Var(#[from] std::env::VarError), + #[error("error")] Error, } diff --git a/src/xlib/display.rs b/src/xlib/display.rs index b0f10cc..6fc4cc1 100644 --- a/src/xlib/display.rs +++ b/src/xlib/display.rs @@ -1,7 +1,7 @@ use std::ffi::CString; use std::mem::MaybeUninit; use std::os::raw::c_char; -use std::ptr; +use std::{ptr, env}; use x11::xlib; @@ -43,6 +43,11 @@ impl Display { Ok(Display { inner }) } + pub fn connect_default() -> Result { + let env = env::var("DISPLAY")?; + Self::connect(env) + } + /// Create a Display for an existing connection pub fn from_handle(handle: u64) -> Self { Display {