#!/bin/bash

## Environtment
export PATH="${PATH}:~/.config/bspwm/bin"

## Get colors from .Xresources -------------------------------#
xrdb ~/.Xresources
getcolors () {
	FOREGROUND=$(xrdb -query | grep 'foreground:'| awk '{print $NF}')
	BACKGROUND=$(xrdb -query | grep 'background:'| awk '{print $NF}')
	BLACK=$(xrdb -query | grep 'color0:'| awk '{print $NF}')
	RED=$(xrdb -query | grep 'color1:'| awk '{print $NF}')
	GREEN=$(xrdb -query | grep 'color2:'| awk '{print $NF}')
	YELLOW=$(xrdb -query | grep 'color3:'| awk '{print $NF}')
	BLUE=$(xrdb -query | grep 'color4:'| awk '{print $NF}')
	MAGENTA=$(xrdb -query | grep 'color5:'| awk '{print $NF}')
	CYAN=$(xrdb -query | grep 'color6:'| awk '{print $NF}')
	WHITE=$(xrdb -query | grep 'color7:'| awk '{print $NF}')
}
getcolors

## Configurations -------------------------------#
`/opt/bin/monitor/multiple_monitor.sh -i`
is_connected=`/opt/bin/monitor/multiple_monitor.sh -c`
echo $is_connected
if [ $is_connected = true ]; then
    bspc monitor DP-5 -d 6 7 8 9 0
    bspc monitor DP-4 -d 1 2 3 4 5
else
    bspc monitor -d 'I' 'II' 'III' 'IV' 'V' 'VI' 'VII' 'VIII' 'IX' 'X'
fi

bspc config border_width 1
bspc config window_gap 6
bspc config split_ratio .5

bspc config focused_border_color "$BLUE" 
bspc config normal_border_color "$BACKGROUND"
bspc config active_border_color "$MAGENTA"
bspc config presel_feedback_color "$GREEN"

bspc config borderless_monocle true
bspc config gapless_monocle true
bspc config paddingless_monocle true
bspc config single_monocle false
bspc config focus_follows_pointer true


# remove all rules first
bspc rule -r *:*


## Autostart -------------------------------#

# Kill if already running
killall -9 sxhkd dunst #xfce4-power-manager xsettingsd 

# Lauch notification daemon
dunst  \
-geom "280x50-10+38" -frame_width "1" -font "Iosevka Custom 9" \
-lb "$BACKGROUND" -lf "$FOREGROUND" -lfr "$BLUE" \
-nb "$BACKGROUND" -nf "$FOREGROUND" -nfr "$BLUE" \
-cb "$BACKGROUND" -cf "$RED" -cfr "$RED" &

# Lauch xsettingsd daemon
#xsettingsd &

# polkit agent
if [[ ! `pidof xfce-polkit` ]]; then
	/usr/lib/xfce-polkit/xfce-polkit &
fi

# Lauch keybindings daemon
sxhkd &

# Enable Super Keys For Menu
# ksuperkey -e 'Super_L=Alt_L|F1' &
# ksuperkey -e 'Super_R=Alt_L|F1' &

# Enable power management
#xfce4-power-manager &

# Fix cursor
xsetroot -cursor_name left_ptr

# Restore wallpaper
bash $HOME/.fehbg

# Start mpd
#exec mpd &



# Start bspwm scripts
/home/lildurden/.config/bspwm/bin/bspcolors
#/home/lildurden/.config/bspwm/bin/bspcomp
/home/lildurden/.config/bspwm/bin/bspbar 
/home/lildurden/.config/bspwm/bin/bspfloat &
#/usr/bin/nm-applet &
/usr/bin/blueman-applet &

systemctl --user start low_battery.service

## Adjust backlight (AMD)
#blight -d amdgpu_bl0 set 15%
