fix(clipboard): read wayland display from env-variable instead of hard-coding it. Fix #846

This commit is contained in:
Federico Terzi 2021-11-06 09:25:45 +01:00
parent 0983fa82d5
commit 80ed98c506

View File

@ -26,7 +26,7 @@ use std::{
use crate::{Clipboard, ClipboardOptions};
use anyhow::Result;
use log::error;
use log::{error, warn};
use std::process::Command;
use thiserror::Error;
use wait_timeout::ChildExt;
@ -49,7 +49,15 @@ impl WaylandFallbackClipboard {
// Try to connect to the wayland display
let wayland_socket = if let Ok(runtime_dir) = std::env::var("XDG_RUNTIME_DIR") {
PathBuf::from(runtime_dir).join("wayland-0")
let wayland_display = if let Ok(display) = std::env::var("WAYLAND_DISPLAY") {
display
} else {
warn!("Could not determine wayland display from WAYLAND_DISPLAY env variable, falling back to 'wayland-0'");
warn!("Note that this might not work on some systems.");
"wayland-0".to_string()
};
PathBuf::from(runtime_dir).join(wayland_display)
} else {
error!("environment variable XDG_RUNTIME_DIR is missing, can't initialize the clipboard");
return Err(WaylandFallbackClipboardError::MissingEnvVariable().into());