#!/usr/bin/env bash
exec 2>&1 > >(tee -i /tmp/hlwm-autostart.log)

PIDS_FILE=/tmp/hlwm-autostart-pids

hc() {
    herbstclient "$@"
}

store_pid() {
    echo $! >> $PIDS_FILE
}

cd $(dirname $0)

source ./gruvbox_colors.sh

OLD_PIDS=$(cat $PIDS_FILE)
kill $(echo $OLD_PIDS)
rm $PIDS_FILE

hc emit_hook reload

hc set default_frame_layout 1 # horizontal
hc set_layout horizontal      # need to manually change the current one as well
hc set tree_style '╾│ ├└╼─┐'

./wallpaper.sh
./bindings.sh
./rules.sh
./styling.sh

hc unlock
hc detect_monitors

panel_height=20
statusbar_height=20

for monitor in $(hc list_monitors | cut -d: -f1) ; do
    # start it on each monitor
    hc pad $monitor $panel_height 0 $statusbar_height 0
    ./panel.py $monitor & store_pid
    ./statusbar.sh $monitor & store_pid
done

./tray.sh & store_pid
udiskie --tray & store_pid

systemctl --user restart sxhkd
systemctl --user restart xautolock
systemctl --user restart battery-warning.timer

wmname LG3D
