Skip to content

Commit

Permalink
Merge pull request #218 from hyprland-community/new-socket-location
Browse files Browse the repository at this point in the history
Support new hyprland socket location
  • Loading branch information
yavko committed May 1, 2024
2 parents 8a3d0f1 + 4262013 commit 4a78ffd
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,41 @@ fn init_socket_path(socket_type: SocketType) -> crate::Result<PathBuf> {
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<PathBuf> {
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<PathBuf> {
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)
}
Expand Down

0 comments on commit 4a78ffd

Please sign in to comment.