server/client: add XDG_SESSION_ID to the default socket path

This allows multiple foot servers to run in multiple sessions.
This commit is contained in:
Daniel Eklöf 2020-03-09 18:47:10 +01:00
parent 9e3a68d6e7
commit 8ab402b252
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 10 additions and 3 deletions

View file

@ -135,10 +135,13 @@ main(int argc, char *const *argv)
} else {
bool connected = false;
const char *xdg_session_id = getenv("XDG_SESSION_ID");
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
if (xdg_runtime != NULL) {
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot.sock", xdg_runtime);
if (xdg_session_id == NULL)
xdg_session_id = "<no-session>";
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot-%s.sock", xdg_runtime, xdg_session_id);
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0)
connected = true;
else