#!/bin/sh
# Tisse desktop autostart — SliTaz default.
#
# Installed at /etc/tisse/autostart and run by tisse-session once
# WAYLAND_DISPLAY is live (precedence: ~/.config/tisse/autostart >
# /etc/tisse/autostart > tisse-session inline fallback). Copy to
# ~/.config/tisse/autostart to customise.
#
# The terminal (Mod+Return) and launcher (Mod+D / Ctrl+Space) are spawned
# by the compositor, not here — see ~/.config/tisse/config / config.example.

# Wallpaper on the background layer: wbg (image), else swaybg as fallback.
if command -v wbg >/dev/null 2>&1; then
	wbg /usr/share/backgrounds/tisse.png &
elif command -v swaybg >/dev/null 2>&1; then
	swaybg -i /usr/share/backgrounds/tisse.png -m fill &
fi

# Panel: yambar with the SliTaz/Tisse bar config.
command -v yambar >/dev/null 2>&1 && yambar -c /etc/tisse/yambar-config.yml &

# Notifications: fnott (fcft+pixman, no GTK). Needs a D-Bus session bus —
# see tisse-session (dbus-run-session) if notifications don't appear.
command -v fnott >/dev/null 2>&1 && fnott &

# Volume/brightness overlay bar: wob, fed by /etc/tisse/media.sh through a
# FIFO (the XF86Audio*/Brightness* keys write the new 0-100 value to it).
if command -v wob >/dev/null 2>&1; then
	_wf="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/tisse/wob.fifo"
	mkdir -p "$(dirname "$_wf")"
	[ -p "$_wf" ] || { rm -f "$_wf"; mkfifo "$_wf"; }
	if [ -f /etc/tisse/wob.ini ]; then
		tail -f "$_wf" | wob -c /etc/tisse/wob.ini &
	else
		tail -f "$_wf" | wob &
	fi
fi

# Optional (uncomment when wired up):
# swayidle — idle/DPMS; needs tisse to implement the idle protocol (ext-
#   idle-notify-v1) first, otherwise it does nothing.
# command -v swayidle >/dev/null 2>&1 && swayidle -w \
#     timeout 600 'wlr-randr --output "*" --off' resume 'wlr-randr --output "*" --on' &
# wob — overlay bar for volume/brightness; reads a FIFO that volume/
#   brightness key handlers write to (not wired yet).
