diff --git a/src/shared.rs b/src/shared.rs index 82d0a16..f7aa918 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -330,8 +330,41 @@ fn init_socket_path(socket_type: SocketType) -> crate::Result { hypr_err!("Corrupted Hyprland socket variable: Invalid unicode!") } }; - let mut p = PathBuf::from("/tmp/hypr"); - p.push(instance); + + let mut p: PathBuf; + fn var_path(instance: String) -> Option { + if let Ok(runtime_path) = var("XDG_RUNTIME_DIR") { + let mut buf = PathBuf::from(runtime_path); + buf.push("hypr"); + buf.push(instance); + if buf.exists() { + return Some(buf); + } + } + None + } + fn uid_path(instance: String) -> Option { + if let Ok(uid) = var("UID") { + let mut buf = PathBuf::from("/run/user/".to_owned() + &uid); + buf.push("hypr"); + buf.push(instance); + if buf.exists() { + return Some(buf); + } + } + None + } + let old_buf = PathBuf::from("/tmp/hypr/".to_owned() + &instance); + if let Some(path) = var_path(instance.clone()) { + p = path; + } else if let Some(path) = uid_path(instance) { + p = path; + } else if old_buf.exists() { + p = old_buf; + } else { + hypr_err!("No xdg runtime path found!") + } + p.push(socket_type.socket_name()); Ok(p) }