#! /bin/sh

function kill_program {
  if ps -A | grep $1; then
    killall -q $1
  fi
}


bspc monitor -d      

bspc config border_width         $(echo 3 \* $SCALE | bc)
bspc config window_gap           $(echo 12 \* $SCALE | bc)

bspc config split_ratio           0.52
bspc config borderless_monocle    true
bspc config gapless_monocle       true
bspc config single_monocle        true
bspc config focus_follows_pointer true
bspc config focused_border_color  '#8E83B8'
bspc config normal_border_color   '#51425C'
bspc config pointer_modifier      mod1

bspc rule -a Nextcloud            desktop='^1' state=floating     follow=on
bspc rule -a "*:transgui"                      state=floating     follow=on
bspc rule -a Google-chrome        desktop='^3'                    follow=on
bspc rule -a Code                 desktop='^4'                    follow=on
bspc rule -a Org.gnome.Nautilus   desktop='^5'                    follow=on
bspc rule -a TelegramDesktop                   state=floating     sticky=on
bspc rule -a baka-mplayer                      state=floating     sticky=on
bspc rule -a smplayer                          state=floating     sticky=on
bspc config external_rules_command $HOME/.config/bspwm/external-rules.sh

# restart subscribers
kill_program bspc
kill_program udevadm
$HOME/.config/bspwm/layout_monitor.sh &
$HOME/.config/bspwm/udev_monitor.sh &

# set wallpaper
systemctl --user start wallpaper.timer
feh --bg-fill --randomize ${HOME}/.config/wallpaper/mizore_shirayuki.png

# restart programs
kill_program conky
kill_program glava
kill_program gnome-keyring-daemon
kill_program picom
kill_program pasystray
kill_program polybar
kill_program dunst
kill_program polkit-gnome-authentication-agent-1
kill_program gsd-xsettings
kill_program nautilus
kill_program blueman-applet
kill_program network-manager-applet

gnome-keyring-daemon --start --components=pkcs11 &
/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
/usr/lib/gsd-xsettings &
xsetroot -cursor_name left_ptr
picom --experimental-backends &
polybar mybar &
fcitx5 &
dunst &
sxhkd &
nautilus &
transgui &
blueman-applet &
network-manager-applet &
dex -a
conky
glava &
libinput-gestures-setup restart
[[ -f ~/.Xmodmap ]] && xmodmap ~/.Xmodmap
