diff --git a/Configs/.local/lib/hyde/shell/activate b/Configs/.local/lib/hyde/shell/activate index 08b6f3c54..0013cb443 100644 --- a/Configs/.local/lib/hyde/shell/activate +++ b/Configs/.local/lib/hyde/shell/activate @@ -7,6 +7,24 @@ HYDE_ACTIVATED=1 HYDE_MODE="" HYPRLAND_CONFIG="" +# A per-user runtime directory. Falling back to a shared directory would put +# sockets from every session into one namespace, so the fallback is private and +# only readable by its owner. +hyde_runtime_dir() { + _uid=$(id -u 2>/dev/null) || _uid='' + + if [ -n "$_uid" ] && [ -d "/run/user/$_uid" ] && [ -w "/run/user/$_uid" ]; then + printf '%s\n' "/run/user/$_uid" + unset _uid + return 0 + fi + + _dir="${TMPDIR:-/tmp}/hyde-${_uid:-$$}" + mkdir -p "$_dir" 2>/dev/null && chmod 700 "$_dir" 2>/dev/null + printf '%s\n' "$_dir" + unset _uid _dir +} + setup_xdg() { : "${XDG_CONFIG_HOME:=$HOME/.config}" : "${XDG_CACHE_HOME:=$HOME/.cache}" @@ -14,7 +32,7 @@ setup_xdg() { : "${XDG_STATE_HOME:=$HOME/.local/state}" # fallback only - : "${XDG_RUNTIME_DIR:=/tmp}" + [ -n "${XDG_RUNTIME_DIR:-}" ] || XDG_RUNTIME_DIR=$(hyde_runtime_dir) export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_STATE_HOME XDG_RUNTIME_DIR } @@ -69,18 +87,49 @@ hyprland_has_lua() { return 1 } +# Mirrors the resolution order in pyutils/lua_env.py, so a runtime that is good +# enough to provision the environment is not rejected here. +hyde_find_bin() { + for _candidate in "$@"; do + [ -n "$_candidate" ] || continue + if command -v "$_candidate" >/dev/null 2>&1; then + printf '%s\n' "$_candidate" + unset _candidate + return 0 + fi + done + + unset _candidate + return 1 +} + +hyde_find_lua() { + hyde_find_bin "${LUA:-}" lua lua5.5 lua5.4 lua5.3 +} + +hyde_find_luarocks() { + hyde_find_bin "${LUAROCKS:-}" luarocks luarocks-5.5 luarocks-5.4 luarocks-5.3 +} + check_lua_runtime() { - hyde_has lua || return 1 - hyde_has luarocks || return 1 + _missing='' + hyde_find_lua >/dev/null || _missing='lua' + hyde_find_luarocks >/dev/null || _missing="${_missing:+$_missing }luarocks" + + [ -z "$_missing" ] || { + printf 'Lua runtime incomplete, missing: %s\n' "$_missing" >&2 + unset _missing + return 1 + } + + unset _missing + return 0 } setup_lua_mode() { HYPRLAND_CONFIG=$(find_hyde_lua) - check_lua_runtime || { - printf 'Lua runtime incomplete\n' >&2 - return 1 - } + check_lua_runtime || return 1 hyprland_has_lua || { printf 'Hyprland lacks Lua support\n' >&2 diff --git a/Configs/.local/lib/hyde/shell/activate.fish b/Configs/.local/lib/hyde/shell/activate.fish index 52821d146..e6d39de5e 100644 --- a/Configs/.local/lib/hyde/shell/activate.fish +++ b/Configs/.local/lib/hyde/shell/activate.fish @@ -9,12 +9,30 @@ set -x HYDE_ACTIVATED 1 set -x HYDE_MODE "" set -x HYPRLAND_CONFIG "" +# A per-user runtime directory. Falling back to a shared directory would put +# sockets from every session into one namespace, so the fallback is private and +# only readable by its owner. +function hyde_runtime_dir + set -l uid (id -u 2>/dev/null) + if test -n "$uid" -a -d "/run/user/$uid" -a -w "/run/user/$uid" + echo "/run/user/$uid" + return 0 + end + set -l tmp $TMPDIR + test -n "$tmp"; or set tmp /tmp + set -l dir "$tmp/hyde-$uid" + mkdir -p $dir 2>/dev/null; and chmod 700 $dir 2>/dev/null + echo $dir +end + +# Assignment is unconditional so a value that already exists in a non-exported +# scope still reaches child processes. function setup_xdg - set -q XDG_CONFIG_HOME; or set -x XDG_CONFIG_HOME "$HOME/.config" - set -q XDG_CACHE_HOME; or set -x XDG_CACHE_HOME "$HOME/.cache" - set -q XDG_DATA_HOME; or set -x XDG_DATA_HOME "$HOME/.local/share" - set -q XDG_STATE_HOME; or set -x XDG_STATE_HOME "$HOME/.local/state" - set -q XDG_RUNTIME_DIR; or set -x XDG_RUNTIME_DIR "/tmp" + set -gx XDG_CONFIG_HOME (test -n "$XDG_CONFIG_HOME"; and echo $XDG_CONFIG_HOME; or echo "$HOME/.config") + set -gx XDG_CACHE_HOME (test -n "$XDG_CACHE_HOME"; and echo $XDG_CACHE_HOME; or echo "$HOME/.cache") + set -gx XDG_DATA_HOME (test -n "$XDG_DATA_HOME"; and echo $XDG_DATA_HOME; or echo "$HOME/.local/share") + set -gx XDG_STATE_HOME (test -n "$XDG_STATE_HOME"; and echo $XDG_STATE_HOME; or echo "$HOME/.local/state") + set -gx XDG_RUNTIME_DIR (test -n "$XDG_RUNTIME_DIR"; and echo $XDG_RUNTIME_DIR; or hyde_runtime_dir) end function hyde_die @@ -61,18 +79,41 @@ function hyprland_has_lua return 1 end +# Mirrors the resolution order in pyutils/lua_env.py, so a runtime that is good +# enough to provision the environment is not rejected here. +function hyde_find_bin + for candidate in $argv + test -n "$candidate"; or continue + if hyde_has $candidate + echo $candidate + return 0 + end + end + return 1 +end + +function hyde_find_lua + hyde_find_bin $LUA lua lua5.5 lua5.4 lua5.3 +end + +function hyde_find_luarocks + hyde_find_bin $LUAROCKS luarocks luarocks-5.5 luarocks-5.4 luarocks-5.3 +end + function check_lua_runtime - hyde_has lua; or return 1 - hyde_has luarocks; or return 1 + set -l missing + hyde_find_lua >/dev/null; or set -a missing lua + hyde_find_luarocks >/dev/null; or set -a missing luarocks + if test (count $missing) -gt 0 + echo "Lua runtime incomplete, missing: $missing" >&2 + return 1 + end end function setup_lua_mode set -l cfg (find_hyde_lua) and set -gx HYPRLAND_CONFIG $cfg - check_lua_runtime; or begin - echo "Lua runtime incomplete" >&2 - return 1 - end + check_lua_runtime; or return 1 hyprland_has_lua; or begin echo "Hyprland lacks Lua support" >&2 return 1 @@ -82,9 +123,9 @@ function setup_lua_mode end function setup_session - set -q XDG_CURRENT_DESKTOP; or set -x XDG_CURRENT_DESKTOP "HyDE" - set -q XDG_SESSION_DESKTOP; or set -x XDG_SESSION_DESKTOP "HyDE" - set -q XDG_SESSION_TYPE; or set -x XDG_SESSION_TYPE "wayland" + set -gx XDG_CURRENT_DESKTOP (test -n "$XDG_CURRENT_DESKTOP"; and echo $XDG_CURRENT_DESKTOP; or echo "HyDE") + set -gx XDG_SESSION_DESKTOP (test -n "$XDG_SESSION_DESKTOP"; and echo $XDG_SESSION_DESKTOP; or echo "HyDE") + set -gx XDG_SESSION_TYPE (test -n "$XDG_SESSION_TYPE"; and echo $XDG_SESSION_TYPE; or echo "wayland") end function hyde_activate diff --git a/Scripts/pkg_core.lst b/Scripts/pkg_core.lst index 5fb311dfc..81f6866cb 100644 --- a/Scripts/pkg_core.lst +++ b/Scripts/pkg_core.lst @@ -41,6 +41,7 @@ wl-clip-persist # Keep Wayland clipboard hyprsunset # blue light filter # --------------------------------------------------- // Dependencies +lua # lua interpreter, required by the hyprland configuration hyprpolkitagent # authentication agent xdg-desktop-portal-hyprland # xdg desktop portal for hyprland xdg-desktop-portal-gtk # file picker and dbus integration