Files
anode/scripts/anode-session
T

135 lines
3.2 KiB
Bash
Raw Normal View History

#!/bin/sh
# ANODE X11 desktop session entrypoint (strict POSIX sh)
set -u
: "${XDG_CONFIG_HOME:=$HOME/.config}"
: "${ANODE_PREFIX:=/usr/local}"
: "${XDG_CURRENT_DESKTOP:=ANODE}"
: "${XDG_SESSION_DESKTOP:=anode}"
: "${DESKTOP_SESSION:=anode}"
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
while [ $# -gt 0 ]; do
case "$1" in
--profile)
if [ $# -ge 2 ]; then
ANODE_SESSION_PROFILE="$2"
shift 2
else
shift
fi
;;
--profile=*)
ANODE_SESSION_PROFILE="${1#--profile=}"
shift
;;
*)
shift
;;
esac
done
export XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP DESKTOP_SESSION
if [ -n "${ANODE_SESSION_PROFILE:-}" ]; then
export ANODE_SESSION_PROFILE
fi
# Ensure ANODE prefix binaries are on PATH
case ":$PATH:" in
*":$SCRIPT_DIR:"*) ;;
*) PATH="$SCRIPT_DIR:$PATH" ;;
esac
case ":$PATH:" in
*":$ANODE_PREFIX/bin:"*) ;;
*) PATH="$ANODE_PREFIX/bin:$PATH" ;;
esac
export PATH
for _envfile in "$ANODE_PREFIX/share/anode/env.sh" "$SCRIPT_DIR/../data/env.sh"; do
if [ -r "$_envfile" ]; then
. "$_envfile"
break
fi
done
unset _envfile
if [ ! -f "$XDG_CONFIG_HOME/anode/scale.conf" ] && command -v anode-apply-scale >/dev/null 2>&1; then
anode-apply-scale auto --no-apply >/dev/null 2>&1 || true
fi
if [ -f "$XDG_CONFIG_HOME/anode/scale.env" ]; then
. "$XDG_CONFIG_HOME/anode/scale.env"
fi
if [ ! -f "$HOME/.Xresources" ] && command -v anode-apply-theme >/dev/null 2>&1; then
anode-apply-theme AnodeDefault >/dev/null 2>&1 || true
elif [ -f "$HOME/.Xresources" ] && command -v xrdb >/dev/null 2>&1; then
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
fi
if command -v xsetroot >/dev/null 2>&1; then
xsetroot -cursor_name left_ptr >/dev/null 2>&1 || true
fi
BG_PIDS=""
spawn_bg() {
if command -v "$1" >/dev/null 2>&1; then
"$@" >/dev/null 2>&1 &
BG_PIDS="$BG_PIDS $!"
fi
}
cleanup_bg() {
for _pid in $BG_PIDS; do
kill "$_pid" 2>/dev/null || true
done
}
trap cleanup_bg EXIT INT TERM
spawn_bg xsettingsd
spawn_bg dunst
spawn_bg anode-statusd
spawn_bg anode-powerd
spawn_bg anode-touchd
if [ "${ANODE_TOUCH:-0}" = "1" ]; then
spawn_bg anode-vkbd
fi
# Seed default user autostart files on first session launch
mkdir -p "$XDG_CONFIG_HOME/anode/autostart.d"
if [ ! -e "$XDG_CONFIG_HOME/anode/autostart" ]; then
for _tpl in "$ANODE_PREFIX/share/anode/autostart" "$SCRIPT_DIR/../share/anode/autostart" "$SCRIPT_DIR/../data/autostart"; do
if [ -r "$_tpl" ]; then
cp "$_tpl" "$XDG_CONFIG_HOME/anode/autostart" 2>/dev/null || true
break
fi
done
unset _tpl
fi
# Launch i3-style and XDG session autostart entries once DWM is ready
if command -v anode-autostart >/dev/null 2>&1; then
(
_i=0
if command -v xprop >/dev/null 2>&1; then
while [ "$_i" -lt 20 ]; do
if xprop -root _NET_SUPPORTING_WM_CHECK 2>/dev/null | grep -q "window id"; then
break
fi
_i=$(( _i + 1 ))
sleep 0.1
done
else
sleep 1
fi
anode-autostart start
) >/dev/null 2>&1 &
BG_PIDS="$BG_PIDS $!"
fi
if command -v dwm >/dev/null 2>&1; then
dwm
else
printf 'anode-session: dwm executable not found\n' >&2
exit 1
fi