bazzite/system_files/deck/silverblue/usr/bin/gnome-session-oneshot
RJ Trujillo e77996f02f
feat(deck): Add (hidden) toggleable desktop Wayland session session support (#118)
* feat(deck): Implement optional support for switching to GNOME on Wayland

This adds a variable, DESKTOP_WAYLAND, to /etc/default/desktop-wayland that gets sourced
by steamos-session-select and determines whether or not to use Wayland or X11. By default,
this ships as false

* feat(deck): Implement optional support for switching to Plasma on Wayland

* feat(deck): Add hidden just script to toggle Wayland desktop session

Omitted from 'just list'
2023-08-08 02:27:41 +00:00

51 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/bash
set -e
die() { echo >&2 "!! $*"; exit 1; }
SENTINEL_FILE="steamos-session-select"
# If we proceed, execute this
CHAINED_SESSION="/usr/bin/gnome-session"
# If we decide the sentinel is consumed, execute this command instead and fail
RESTORE_SESSION=(/usr/bin/steamos-session-select) # No arguments restores the session
# Find or check config sentinel
function check_sentinel()
{
if [[ -z ${HOME+x} ]]; then
echo >&2 "$0: No \$HOME variable!"
# Rather than break we'll just launch plasma and hope for the best?
return 0
fi
local config_dir="${XDG_CONF_DIR:-"$HOME/.config"}"
(
cd "$HOME"
cd "$config_dir"
sentinel_value="$(cat "$SENTINEL_FILE")"
if [[ "$sentinel_value" == "x11" || "$sentinel_value" == "wayland" ]]; then
echo "/usr/bin/gnome-session"
else
return 1
fi
rm "$SENTINEL_FILE"
) || return 1 # If we couldn't read the value or it wasn't what we wanted
# Found value and removed it, we're good to continue
return 0
}
if CONFIGURED_CHAINED_SESSION=$(check_sentinel); then
# We found and consumed the oneshot sentinel, proceed to launch plasma
echo >&2 "$0: Found and removed sentinel file for one-shot desktop, proceeding to launch"
exec "$CONFIGURED_CHAINED_SESSION"
else
echo >&2 "$0: Sentinel value not found, executing session-select to restore session"
"${RESTORE_SESSION[@]}" || echo >&2 "$0: !! Failed to restore previous session, executing chained session"
# Session restore should've stopped us, if it is broken at least let plasma continue to open
exec "$CHAINED_SESSION"
fi