i3 --get-socketpath's use case is getting the socket path even if running a command where I3SOCK is not set (but DISPLAY is set). This happens regularly in scripts ran outside of the graphical session (systemd, cron...).
The way i3 does it is by setting a property on the root window. We could do the same with a tiny private Wayland protocol.
I'm pretty meh on this
Out of interest, what is the use case for --get-socketpath if all it does is return $SWAYSOCK?
I am asking because I sometimes run commands remotely and had been manually setting SWAYSOCK by building the path to the socket dynamically (/run/user/(id -u)/sway-ipc.(id -u).(pidof sway).sock). However I recently switched to using --get-socketpath only to find it didn't work as I thought it would.
@ohk2kt3t4 FYI: I didn't understand it either.
Therefore I looked at the code to fix it and found this:
// We want to use socket name set by user, not existing socket from another sway instance.
if (getenv("SWAYSOCK") != NULL && access(getenv("SWAYSOCK"), F_OK) == -1) {
strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path) - 1);
ipc_sockaddr->sun_path[sizeof(ipc_sockaddr->sun_path) - 1] = 0;
}
You can define the SWAYSOCK path yourself :+1: (probably documented somewhere).
This solution works for me.
--get-socketpath exists for compat with i3.