#!/usr/bin/env bash
test -z "$PROFILE_LOADED" && source ~/.profile

export XDG_CACHE_HOME="/tmp/"
export _JAVA_AWT_WM_NONREPARENTING="1"

window_manager="dwm"

async_startup_commands=(
    "gpick"
    "pidgin"
    "st"
    "volti"
    "wmname LG3D"
    "xcompmgr -n"
    "xfce4-session"
    "xmodmap ~/.xmodmaprc"
    "xset s off -dpms"
    "xsetroot -solid #000000"
)

if command -v slock; then
    export DISPLAY_LOCKER="slock"
else
    export DISPLAY_LOCKER="xscreensaver-command -l"
    async_startup_commands+=("xscreensaver -no-splash")
fi

# On my personal machines, I use Firefox and Chromium while I use exclusively
# use Google Chrome at work.
if [[ "$(hostname -f)" = *.codevat.com ]]; then
    async_startup_commands+=(
        "chromium"
        "firefox"
    )
else
    async_startup_commands+=(
        "google-chrome"
    )
fi

for command in "${async_startup_commands[@]}"; do
    eval " $command" &
done

# Automatically relaunch the window manger if its exits with a non-zero exit
# code with a short delay between each launch.
while ! $window_manager; do
    sleep 1
done

