Find sway's socket when the environment is stale

Running wl-pick from certain terminals failed outright:

  wl-pick: cannot reach sway (No such file or directory (os error 2))

swayipc takes the path from I3SOCK or SWAYSOCK and falls back to asking sway
directly only when neither is set. A variable that is set but stale is used
as it stands, and fails -- which is what happens to every shell descended
from a process that outlived the sway that started it. One long-running
daemon in the ancestry is enough, and nothing about the failure points at
the environment.

The running compositor is the one we want in any case, so look for its
socket in XDG_RUNTIME_DIR when the environment's path does not connect.
Sockets are named sway-ipc.<uid>.<pid>.sock, so the pid says which are worth
trying, checked against /proc for a process that really is a sway, since pids
are reused. Several live compositors is a real situation -- a nested sway --
so that asks for SWAYSOCK rather than guessing.

The environment still wins when it points at something that exists. Its
lookup is no longer delegated to swayipc at all, because that spawns
`sway --get-socketpath` when the variables are unset and lets the child
print "sway socket not detected." over anything we would rather say.
This commit is contained in:
Milad Alizadeh
2026-09-07 17:37:48 +01:00
parent c607fc9a1c
commit 8e317682a1
3 changed files with 114 additions and 3 deletions
+6
View File
@@ -227,6 +227,12 @@ only sway is tested. sway is also the source of truth for the window list, over
its IPC socket, which is the one thing that would need replacing to run
elsewhere (`ext-foreign-toplevel-list-v1` already reports app id and title).
The socket is found from `SWAYSOCK`/`I3SOCK` when those point at something that
exists, and otherwise by looking for the running sway's socket in
`$XDG_RUNTIME_DIR`. Inheriting a stale path is easy — any process that outlives
the sway that started it hands one to every shell it spawns — and a picker on a
keybinding should not be the thing that notices.
Known upstream issue: holding per-toplevel capture sessions open makes windows
blurry on **fractionally scaled** outputs
([sway#9113](https://github.com/swaywm/sway/issues/9113)). Integer scales are