#! /bin/sh

# Set a background color
if command -v xsetroot > /dev/null ; then
  xsetroot -solid "#303030"
fi

# Define autostart files
AUTOSTART="${XDG_CONFIG_HOME:-"$HOME/.config"}/olde/autostart"
GLOBALAUTOSTART="/etc/xdg/olde/autostart"

# Run the user openbox autostart script if it exists, else run the global
# openbox autostart script
if test -r $AUTOSTART; then
    sh $AUTOSTART
elif test -r $GLOBALAUTOSTART; then
    sh $GLOBALAUTOSTART
fi

# Run XDG autostart
# This is a Python script which should reside in /usr/libexec, but that's not
# the case ATM, so we need to locate it first. This is not very clean but it'll
# do for now
OB_XDG_AS="$(find /usr/lib -name "openbox-xdg-autostart")"
if [ -n "$OB_XDG_AS" ] ; then
  exec "$OB_XDG_AS" OLDE
else
  printf "Cannot find Openbox XDG autostart script.\n" >&2
fi
