use DISPLAY environment variable

This commit is contained in:
Michael Zhang 2020-07-13 12:48:23 -05:00
parent 5b7e0c98a7
commit ee9f00284d
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
3 changed files with 6 additions and 2 deletions

2
Cargo.lock generated
View file

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "adler32"
version = "1.0.3"

View file

@ -4,7 +4,7 @@ description = "Screenshot capture for Linux."
version = "0.3.3"
repository = "https://github.com/iptq/leanshot"
license-file = "LICENSE"
authors = ["Michael Zhang <failed.down@gmail.com>"]
authors = ["Michael Zhang <iptq@protonmail.com>"]
[workspace]
members = [".", "imlib2", "imlib2/imlib2-sys", "xlib"]

View file

@ -1,3 +1,5 @@
use std::env;
use imlib2::{self, Image as Image2};
use xlib::{Display, Visual, Window};
@ -12,7 +14,7 @@ pub struct GUI {
impl GUI {
pub fn new() -> Result<Self, ScreenshotError> {
let display = Display::connect(":0")?;
let display = Display::connect(env::var("DISPLAY").unwrap_or_else(|_| ":0".to_owned()))?;
Ok(GUI { display })
}