#! /bin/sh

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


bspc monitor -d      

bspc config border_width         $(echo 1 \* $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  '#eb564d'
bspc config normal_border_color   '#ccc'

bspc rule -a Nextcloud            desktop='^1' state=floating     follow=on
bspc rule -a "*:transgui"         desktop='^1' state=floating     follow=on
bspc rule -a TelegramDesktop      desktop='^1' 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 baka-mplayer                      state=floating     sticky=on
bspc rule -a smplayer                          state=floating     sticky=on

# restart subscribers
kill_program bspc
bash $HOME/.config/bspwm/set_subscribers.sh &

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

# restart programs
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
libinput-gestures-setup restart
[[ -f ~/.Xmodmap ]] && xmodmap ~/.Xmodmap

# Elan input setting
xinput set-prop 'Elan Touchpad' 'libinput Tapping Enabled' 1
xinput set-prop 'Elan Touchpad' 'libinput Natural Scrolling Enabled' 1
xinput set-prop 'Elan TrackPoint' 'libinput Accel Speed' -0.3
# Magic Trackpad 2
xinput set-prop 'Apple Inc. Magic Trackpad 2' 'libinput Natural Scrolling Enabled' 1
xinput set-prop 'Apple Inc. Magic Trackpad 2' 'libinput Accel Speed' 0.5
# Macbook Pro Trackpad
xinput set-prop "bcm5974" "libinput Natural Scrolling Enabled" 1
xinput set-prop "bcm5974" "libinput Accel Speed" 0.5
# Logitech G402
xinput set-prop 'Logitech Gaming Mouse G402' 'libinput Accel Speed' -0.8
# Logitech G102
xinput set-prop 'Logitech G102 LIGHTSYNC Gaming Mouse' 'libinput Natural Scrolling Enabled' 1
xinput set-prop 'Logitech G102 LIGHTSYNC Gaming Mouse' 'libinput Accel Speed' -0.5

