connect default

This commit is contained in:
Michael Zhang 2023-08-20 05:10:03 -05:00
parent 5387a0f543
commit 8fecd2b64a
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
2 changed files with 9 additions and 1 deletions

View file

@ -31,6 +31,9 @@ pub enum Error {
#[error("nul error: {0}")] #[error("nul error: {0}")]
Nul(#[from] std::ffi::NulError), Nul(#[from] std::ffi::NulError),
#[error("env var error: {0}")]
Var(#[from] std::env::VarError),
#[error("error")] #[error("error")]
Error, Error,
} }

View file

@ -1,7 +1,7 @@
use std::ffi::CString; use std::ffi::CString;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::ptr; use std::{ptr, env};
use x11::xlib; use x11::xlib;
@ -43,6 +43,11 @@ impl Display {
Ok(Display { inner }) Ok(Display { inner })
} }
pub fn connect_default() -> Result<Display> {
let env = env::var("DISPLAY")?;
Self::connect(env)
}
/// Create a Display for an existing connection /// Create a Display for an existing connection
pub fn from_handle(handle: u64) -> Self { pub fn from_handle(handle: u64) -> Self {
Display { Display {