#!/bin/sh
#
# fluxbox startup-script:
#
# Lines starting with a '#' are ignored.

# Change your keymap:
xmodmap "/root/.Xmodmap"

# merge xresource settings
xrdb -merge ~/.Xresources

# set background color and big wait mouse cursor
xsetroot -solid '#222222'
xsetroot -xcf /usr/share/icons/breeze_cursors/cursors/watch 37

# preload compton and fluxbox to cache
(compton --help; fluxbox --help) >/dev/null 2>/dev/null

# preload wallpaper
cat /usr/share/wallpapers/slax_wallpaper.jpg > /dev/null 2>/dev/null

# Keep black screen for first two seconds while the sound plays.
# This slows startup by 2 seconds, but it is nice effect.
SND=/usr/share/sounds/startup.wav
if [ -r $SND ]; then
   cat $SND > /dev/null # preload
   aplay $SND &
   sleep 1 &
   SOUNDPID=$!
fi

# Applications you want to run with fluxbox.
# MAKE SURE THAT APPS THAT KEEP RUNNING HAVE AN ''&'' AT THE END.
#
# unclutter -idle 2 &
# wmnd &
# wmsmixer -w &
# idesk &
#
# Debian-local change:
#   - fbautostart has been added with a quick hack to check to see if it
#     exists. If it does, we'll start it up by default.
which fbautostart > /dev/null
if [ $? -eq 0 ]; then
    fbautostart
fi

# Slax-local change:
# We need to postpone compton after fluxbox starts, else it won't set
# the transparency of toolbar properly... So we check the fehbg file,
# which is created by fluxbox at the phase when it sets background.
# Once the file exist, fluxbox-toolbar is already started

SIGNALFILE=~/.fehbg
rm -f $SIGNALFILE
(
   while [ ! -e $SIGNALFILE ]; do
      sleep 0.05
   done
   compton --sw-opti -e 0.9 --fade-exclude 'role*="fluxbox-toolbar"' --opacity-rule '70:role*="fluxbox-toolbar"' --no-fading-destroyed-argb -D 5 -c -f -l -2 -t -2 -r 0 -o 1 -z --shadow-exclude 'bounding_shaped'
) &

# volume icon in system tray
volumeicon &

# wait for the sound
wait $SOUNDPID

# And last but not least we start fluxbox.
# Because it is the last app you have to run it with ''exec'' before it.

exec fluxbox
