Respect XDG_RUNTIME_DIR for /path/to/swayr-%s.sock

/run may not exist outside of systemd distributions. Instead of guessing
rely on XDG_RUNTIME_DIR and fall back to /tmp. XDG_RUNTIME_DIR is always
defined under Wayland, so the fallback would only be triggered if swayr
is used from X11 or VT/serial console.
timeout_old
Jan Beich 3 years ago committed by Tassilo Horn
parent 955b904df5
commit 71a9c390e7
  1. 20
      Cargo.lock
  2. 1
      Cargo.toml
  3. 11
      src/util.rs

20
Cargo.lock generated

@ -146,15 +146,6 @@ version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "os_str_bytes"
version = "2.4.0"
@ -297,7 +288,6 @@ dependencies = [
"serde_json",
"swayipc",
"toml",
"users",
]
[[package]]
@ -376,16 +366,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "users"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
dependencies = [
"libc",
"log",
]
[[package]]
name = "vec_map"
version = "0.8.2"

@ -12,7 +12,6 @@ edition = "2018"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
clap = "3.0.0-beta.2"
users = "0.11.0"
swayipc = "3.0.0-alpha.3"
toml = "0.5.8"
directories = "3.0"

@ -23,9 +23,16 @@ use std::process as proc;
pub fn get_swayr_socket_path() -> String {
let wayland_display = std::env::var("WAYLAND_DISPLAY");
let xdg_runtime_dir = std::env::var("XDG_RUNTIME_DIR");
format!(
"/run/user/{}/swayr-{}.sock",
users::get_current_uid(),
"{}/swayr-{}.sock",
match xdg_runtime_dir {
Ok(val) => val,
Err(_e) => {
eprintln!("Couldn't get XDG_RUNTIME_DIR!");
String::from("/tmp")
}
},
match wayland_display {
Ok(val) => val,
Err(_e) => {

Loading…
Cancel
Save