#! /bin/sh

# Manage multi-monitor workspaces and dead nodes
external_output="$(xrandr | grep -E "HDMI-A-0 connected|DisplayPort-0 connected|DisplayPort-1 connected" | awk 'NR==1{print $1}')"
lid_state="$(cat /proc/acpi/button/lid/LID0/state | awk '{print $2}')"

if [[ ${#external_output} -ne 0 && $lid_state == "open" ]]; then
    bspc monitor eDP -d 1 2 3 4 5
    bspc monitor $external_output -d 6 7 8 9 10
else
    bspc monitor -d 1 2 3 4 5 6 7 8 9 10
fi

bspc config remove_disabled_monitors      true
bspc config merge_overlapping_monitors    false

bspc config border_width         2
bspc config window_gap          28

bspc config split_ratio          0.52
bspc config borderless_monocle   true
bspc config gapless_monocle      true

bspc config focus_follows_pointer true

# bspc rule -a Gimp desktop='^8' state=floating follow=on
# Examples
# get title: $ xtitle $(bspc query -N -d .focused)
# bspc rule -a Chromium desktop='^2'
# bspc rule -a Kupfer.py focus=on
# bspc rule -a Screenkey manage=off
bspc rule -a '*' class=^Terminal$ state=pseudo_tiled
bspc rule -a dialog state=floating

## [MANUAL] Polybar z-index
xdo lower -N "Polybar"
xdo above -N "Polybar" -t $(xdo id -N Bspwm -n root)

######################
# Init required apps #
######################

### Keyboard
setxkbmap -layout us -variant intl -option caps:escape

### Wallpaper
feh --bg-fill ~/.config/wp

# Status bar
bash ~/.config/polybar/launch.sh &
