sway --get-socketpath doesn't work if SWAYSOCK is unset

Created on 16 Sep 2018  路  4Comments  路  Source: swaywm/sway

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.

enhancement

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephenBrown2 picture StephenBrown2  路  4Comments

RyanDwyer picture RyanDwyer  路  3Comments

DpoBoceka picture DpoBoceka  路  4Comments

aidanharris picture aidanharris  路  3Comments

ahilsend picture ahilsend  路  4Comments