#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

# Merging .Xresources
# https://wiki.archlinux.org/index.php/X_resources
xrdb -merge ~/.Xresources

# Gnome Keyring
# https://wiki.archlinux.org/index.php/GNOME_Keyring
#eval $(/usr/bin/gnome-keyring-daemon --start --components=gpg,pkcs11,secrets,ssh)
# You probably need to do this too:
#export GNOME_KEYRING_CONTROL GNOME_KEYRING_PID GPG_AGENT_INFO SSH_AUTH_SOCK

# urxvt daemon
#while true; do
#  urxvtd &
#  sleep 60
#done

# http://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies/697064#697064
#until urxvtd; do
#    echo "urxvtd crashed with exit code $?.  Respawning.." >&2
#    sleep 1
#done &

#urxvtd &

# Thunar daemon
#thunar --daemon &

# Redshift colour profile manager with settings for Utrecht (Netherlands)
# https://wiki.archlinux.org/index.php/Redshift 
redshift -l 52.091790:5.114570 &

echo "Determining if on AC or battery"
if cat /sys/class/power_supply/AC/online | grep 0 > /dev/null 2>&1
then
    echo "Laptop is on battery"
else
    echo "Laptop is on AC"
    dropboxd &
    insync start &
fi

#case "$1"
#in
#  openbox)
#    conky &
#    exec openbox-session
#  ;;
#  *) exec cinnamon-session;;
#esac

#xsetroot -solid "#ffffff"
conky &

exec openbox-session