From 80ed98c50655692ffc767dac1532cbb42a2b3d9d Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 6 Nov 2021 09:25:45 +0100 Subject: [PATCH] fix(clipboard): read wayland display from env-variable instead of hard-coding it. Fix #846 --- espanso-clipboard/src/wayland/fallback/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/espanso-clipboard/src/wayland/fallback/mod.rs b/espanso-clipboard/src/wayland/fallback/mod.rs index 157bdd5..c916dac 100644 --- a/espanso-clipboard/src/wayland/fallback/mod.rs +++ b/espanso-clipboard/src/wayland/fallback/mod.rs @@ -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());