#!/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.
# wbg -s scales to cover the output and crops the overflow (aspect kept,
# despite the flag name); without it a 16:9 image leaves black bands on
# a 16:10 screen.
if command -v wbg >/dev/null 2>&1; then
	wbg -s /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 &

# Dock: launchers and open windows (/etc/tisse/dock, ~/.config/tisse/dock).
# Shown on an empty desktop, hidden at the bottom edge while a window
# has the focus.
command -v tisse-dock >/dev/null 2>&1 && tisse-dock &

# 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: swayidle (idle/DPMS). tisse exports ext-idle-notify-v1, but
# this DPMS example also needs wlr-output-management for wlr-randr, which
# tisse does not implement yet.
# command -v swayidle >/dev/null 2>&1 && swayidle -w \
#     timeout 600 'wlr-randr --output "*" --off' resume 'wlr-randr --output "*" --on' &
