#! /bin/sh

###
# AUTOSTART
###
xsetroot -cursor_name left_ptr	#fix background cursor being different
sxhkd &
~/.config/polybar/launch.sh &
nitrogen --restore
picom --experimental-backends &
dunst &
copyq &
nm-applet &
#blueman-applet &
xfce4-power-manager &
numlockx on &
/usr/bin/lxqt-policykit-agent &

###
# MONITORS
###
if [ "`hostname`" = "setsuna" ]; then
	bspc monitor "HDMI-A-1" -d 1 2 3 4 5 6 7
	bspc monitor "DVI-D-0" -d 8 9
elif [ "`hostname`" = "beef-book" ]; then
	if [ -n "`polybar -m | grep "DP-1"`" ]; then
		# for docked desktop use: assign 2 workspaces to the second VGA monitor accordingly if it is connected
		if [ -n "`polybar -m | grep "VGA-0"`" ]; then
			bspc monitor "DP-1" -d 1 2 3 4 5 6 7
			bspc monitor "VGA-0" -d 8 9
		else
			bspc monitor "DP-1" -d 1 2 3 4 5 6 7 8 9
		fi
	#elif [ -n "`polybar -m | grep "VGA-0"`" ]; then
	#	if [ -n "`polybar -m | grep "LVDS-1-1"`" ]; then
	#		bspc monitor "LVDS-1-1" -d 1 2 3 4 5 6 7
	#		bspc monitor "VGA-0" -d 8 9
	#	else
	#		bspc monitor "VGA-0" -d 1 2 3 4 5 6 7 8 9
	#	fi
	else
		bspc monitor -d 1 2 3 4 5 6 7 8 9
		#bspc monitor "DP-1" -d 1 2 3 4 5 6 7 8 9
		#bspc monitor "LVDS1" -d 1 2 3 4 5 6 7 8 9
		#bspc monitor "LVDS-1-1" -d 1 2 3 4 5 6 7 8 9
	fi
elif [ "`hostname`" = "salad-book" ]; then
	bspc monitor "eDP-1" -d 1 2 3 4 5 6 7 8 9
	bspc monitor "HDMI-0" -d 1 2 3 4 5 6 7 8 9
	bspc monitor "VGA-0" -d 1 2 3 4 5 6 7 8 9
fi

###
# GLOBAL SETTINGS
###
bspc config focus_follows_pointer true
bspc config remove_disabled_monitors true
bspc config remove_unplugged_monitors true
bspc config merge_overlapping_monitors true
bspc config pointer_follows_monitor true
bspc config center_pseudo_tiled false

#bspc config bottom_padding	25
#bspc config top_monocle_padding	0
bspc config border_width	2
bspc config window_gap		10 

bspc config split_ratio          0.50
bspc config borderless_monocle   true
bspc config gapless_monocle      true


###
# COLORS
###

# Read colors from Xresources and use them upfront
# I am sorry for how cursed this is

clist=`xrdb -query`
echo "$clist" | while read line
do
	name=$(echo $line | cut -d: -f1)
	color=$(echo $line | cut -d: -f2)
	case "$name" in
		"*.color6")	bspc config active_border_color $color \
				&& bspc config presel_feedback_color $color ;;
		"*.background")	bspc config normal_border_color $color ;;
		"*.foreground")	bspc config focused_border_color $color ;;
	esac
done


###
# RULES
###

bspc rule -a Gimp		desktop='^6' state=floating follow=on
bspc rule -a Pavucontrol	state=floating
bspc rule -a copyq		state=floating
bspc rule -a Blueman-manager	state=floating
bspc rule -a Arandr		state=floating
bspc rule -a Galculator		state=floating
bspc rule -a Nitrogen		state=floating
bspc rule -a Emacs		state=tiled
bspc rule -a Screenkey		manage=off
bspc rule -a Navigator		desktop='^1'
bspc rule -a discord		desktop='^4'
bspc rule -a lightcord		desktop='^4'
bspc rule -a Element		desktop='^4'
bspc rule -a dosbox		state=floating
bspc rule -a AlarmWindow	state=floating
bspc rule -a pop-up		state=floating
bspc rule -a setup		state=floating