mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-22 05:33:45 -04:00
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:
parent
9e3a68d6e7
commit
8ab402b252
2 changed files with 10 additions and 3 deletions
5
client.c
5
client.c
|
|
@ -135,10 +135,13 @@ main(int argc, char *const *argv)
|
||||||
} else {
|
} else {
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
|
||||||
|
const char *xdg_session_id = getenv("XDG_SESSION_ID");
|
||||||
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
|
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
|
||||||
if (xdg_runtime != NULL) {
|
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)
|
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0)
|
||||||
connected = true;
|
connected = true;
|
||||||
else
|
else
|
||||||
|
|
|
||||||
8
config.c
8
config.c
|
|
@ -561,12 +561,16 @@ err:
|
||||||
static char *
|
static char *
|
||||||
get_server_socket_path(void)
|
get_server_socket_path(void)
|
||||||
{
|
{
|
||||||
|
const char *xdg_session_id = getenv("XDG_SESSION_ID");
|
||||||
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
|
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
|
||||||
if (xdg_runtime == NULL)
|
if (xdg_runtime == NULL)
|
||||||
return strdup("/tmp/foot.sock");
|
return strdup("/tmp/foot.sock");
|
||||||
|
|
||||||
char *path = malloc(strlen(xdg_runtime) + 1 + strlen("foot.sock") + 1);
|
if (xdg_session_id == NULL)
|
||||||
sprintf(path, "%s/foot.sock", xdg_runtime);
|
xdg_session_id = "<no-session>";
|
||||||
|
|
||||||
|
char *path = malloc(strlen(xdg_runtime) + 1 + strlen("foot-.sock") + strlen(xdg_session_id) + 1);
|
||||||
|
sprintf(path, "%s/foot-%s.sock", xdg_runtime, xdg_session_id);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue