From f65d3d04dcfd85959d89fc63cd93de9ac6bf1800 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 23 Mar 2024 17:09:57 +0000 Subject: [PATCH] sway: do the WAYLAND_DISPLAY moving inside sway config itself --- hosts/common/programs/sway/default.nix | 13 ++----------- hosts/common/programs/sway/sway-config | 11 +++++++++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/hosts/common/programs/sway/default.nix b/hosts/common/programs/sway/default.nix index f118fa082..cbd743b8f 100644 --- a/hosts/common/programs/sway/default.nix +++ b/hosts/common/programs/sway/default.nix @@ -8,7 +8,7 @@ let swayLauncher = pkgs.writeShellScriptBin "sway" '' # delete DISPLAY-related vars from env before launch, else sway will try to connect to a remote display. # (consider: nested sway sessions, where sway actually has a reason to read these) - exec env -u DISPLAY -u WAYLAND_DISPLAY ${configuredSway}/bin/sway 2>&1 + exec env -u DISPLAY -u WAYLAND_DISPLAY "REAL_WAYLAND_DISPLAY=$WAYLAND_DISPLAY" ${configuredSway}/bin/sway 2>&1 ''; in pkgs.symlinkJoin { @@ -232,16 +232,7 @@ in ''; # readiness.waitExists = "$SWAYSOCK"; readiness.waitCommand = pkgs.writeShellScript "sway-readycheck" '' - # wait for sway to create its socket AND its wayland display. - # it doesn't know to create the wayland display in the right directory, so have to manually move it socket... bleh. - # TODO: socket moving could be more reliable inside of the sway config - set -e - test -e "$SWAYSOCK" - expected_display="$XDG_RUNTIME_DIR/$(basename "$WAYLAND_DISPLAY")" - test -e "$expected_display" && test -e "$expected_display.lock" - set +e # make only a best-effort to move these; if it fails (because e.g. perms, or destination exists somehow), don't hold up init - mv "$expected_display" "$WAYLAND_DISPLAY" - mv "$expected_display.lock" "$WAYLAND_DISPLAY.lock" + test -e "$SWAYSOCK" && test -e "$WAYLAND_DISPLAY" ''; }; # link the graphical-session into the default target, so sway gets auto-started diff --git a/hosts/common/programs/sway/sway-config b/hosts/common/programs/sway/sway-config index c20f7b677..dd81d34f4 100644 --- a/hosts/common/programs/sway/sway-config +++ b/hosts/common/programs/sway/sway-config @@ -236,6 +236,13 @@ output $out_moby { # scale 1.6 } +# move the wayland socket that sway implicitly created to the place which other apps expect to find it +exec --no-startup-id mv $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY $REAL_WAYLAND_DISPLAY +exec --no-startup-id mv $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY.lock $REAL_WAYLAND_DISPLAY.lock +# i'm sure there's a simpler way. not certain that this actually updates the sway environment variables anyway +# the double-$ means to set the variable at *runtime*, not at "compile-time" (so that it doesn't impact the line immediately above us +set $$WAYLAND_DISPLAY "$(echo $REAL_WAYLAND_DISPLAY)" + # manually export PATH here, since all my user services need that, and sane-sandboxed implementation depends on it. # also, manually export XDG_DATA_DIRS. glib fails in weird ways (e.g. thinks everything is application/x-octet-stream mime type) without it. @@ -243,8 +250,8 @@ output $out_moby { # # XXX: dbus-update-activation-environment --systemd is ASYNCHRONOUS. it returns before the systemd environment is actually updated. # hence, call `systemctl import-environment` ourselves. i could probably remove the dbus stuff and be safe, but at least for now it's an OK backup. -exec --no-startup-id systemctl --user import-environment PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP -exec --no-startup-id dbus-update-activation-environment --systemd PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP +# exec --no-startup-id systemctl --user import-environment PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP +# exec --no-startup-id dbus-update-activation-environment --systemd PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP # previously: `include /etc/sway/config.d/*` was needed for xdg-desktop-portal-* to work. # stock nixos `programs.sway` would setup /etc/sway/config.d with additional variables to import to the dbus env.