#!/usr/bin/env bash

BORDER_WIDTH=0 # change in bspwmrc
export WINDOW_GAP=25
DESKTOPS=(dev web misc env play out main srv daem util)

BSPWM_MONITORS=$(bspc query -M | tac)
MONITOR_COUNT=$(echo "${BSPWM_MONITORS}" | wc -w | awk '{ printf $1 }')
NUM_DESKTOPS=${#DESKTOPS[@]}
PER_MONITOR=$((NUM_DESKTOPS / MONITOR_COUNT))

source "$DOTFILES_PATH/scripts/get_color.sh"
source "$DOTFILES_PATH/scripts/get_x_fonts.sh"

# allow a per-device config to override options
if [ -f "$HOME/.env_bspwm" ]; then
	source "$HOME/.env_bspwm"
fi

# old colors
# bspc config normal_border_color   "#$(get_color 05)"
# bspc config focused_border_color  "#$(get_color 0D)"
# bspc config active_border_color   "#$(get_color 0D)"
# bspc config presel_feedback_color "#$(get_color 0D)"

bspc config normal_border_color   "#$(get_color 01)"
bspc config focused_border_color  "#$(get_color 0D)"
bspc config active_border_color   "#$(get_color 09)"
bspc config presel_feedback_color "#$(get_color 04)"
bspc config border_width          "$BORDER_WIDTH"
bspc config split_ratio           0.50
bspc config borderless_monocle    true
bspc config gapless_monocle       true

bspc config window_gap "$WINDOW_GAP"

i=1
for mon in ${BSPWM_MONITORS}; do
  max=$((i + PER_MONITOR - 1))
	screens=
	for j in $(seq $i $max); do
		ind=${DESKTOPS[$((j - 1))]}
		screens="$screens$ind "
	done
  bspc monitor "$mon" -d $screens
  i=$((max + 1))
done

# allow a per-device config to override options
if [ -f "$HOME/.env_bspwm_after" ]; then
	source "$HOME/.env_bspwm_after"
fi