From 8fecd2b64a3844e79831c007374523ca0a7b719a Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 20 Aug 2023 05:10:03 -0500 Subject: [PATCH] connect default --- src/errors.rs | 3 +++ src/xlib/display.rs | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 {