#! /bin/sh

export XDG_CURRENT_DESKTOP='bspwm'

# Запуск демона горячих клавиш
pgrep -x sxhkd >/dev/null || sxhkd &

#Autostart

# Picom
/usr/bin/compfy --daemon &
#/usr/bin/picom --daemon &
#########pkill "picom"
#########picom  --daemon --animations --animation-window-mass 0.5 --animation-for-open-window slide-up --animation-stiffness-in-tag 650 --animation-for-transient-window slide-up

###picom --experimental-backends --daemon --animations --animation-window-mass 0.5 --animation-for-open-window zoom --animation-stiffness 350 --animation-for-transient-window zoom
######picom --experimental-backends --daemon --animations --animation-window-mass 0.5 --animation-for-open-window slide-up --animation-stiffness 550 --animation-for-transient-window slide-up

# Cursor
xsetroot -cursor_name left_ptr &

# Set display from arandr saved script
# 2-й монитор вертикальный
xrandr --dpi 102x102 --output HDMI-A-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate left --output DisplayPort-0 --primary --mode 3440x1440 --rate 100 --pos 0x560 --rotate normal
#xrandr --dpi 102x102 --output DP-1 --primary --mode 3440x1440 --rate 100 --pos 0x560 --rotate normal --output HDMI-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate left
#xrandr --dpi 102x102 --output DVI-D-0 --off --output DP-0 --primary --mode 3440x1440 --rate 100 --pos0x560 --rotate normal --output HDMI-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate left --output DP-1 --off
#xrandr --dpi 102x102 --output DVI-D-0 --off --output HDMI-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate left --output DP-0 --primary --mode 3440x1440 --rate 100 --pos 0x560 --rotate normal --output DP-1 --off
#xrandr --dpi 102x102 --output DVI-D-0 --off --output DP-0 --primary --mode 3440x1440 --rate 100 --pos 0x0 --rotate normal --output HDMI-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate right --output DP-1 --off
####xrandr --dpi 102x102 --output DVI-D-0 --off --output DP-0 --primary --mode 3440x1440 --rate 100 --pos 0x1120 --rotate normal --output HDMI-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate right --output DP-1 --off

# Пердыдущая настройка горизонтальная
#xrandr --dpi 102x102 --output DVI-D-0 --off --output DP-0 --primary --mode 3440x1440 --rate 100 --pos 0x0 --rotate normal --output HDMI-0 --mode 2560x1440 --rate 75 --pos 3440x0 --rotate normal --output DP-1 --off

##xrandr --dpi 102x102 --output DVI-D-0 --mode 1920x1080 --pos 2560x600 --rotate left --output HDMI-0 --mode 1920x1080 --pos 320x0 --rotate normal --output DP-0 --primary --mode 2560x1440 --rate 75 --pos 0x1080 --rotate normal
#xrandr --dpi 102x102 --output DVI-D-0 --off --output HDMI-0 --off --output DP-0 --primary --mode 2560x1440 --rate 75 --pos 0x0 --rotate normal --output DP-1 --off
###sh $HOME/.screenlayout/start.sh

# Запуск демона оповещений
####pkill "dunst"
/usr/bin/dunst &

# Polkit
/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &

/usr/libexec/xdg-desktop-portal-gtk &
xdg-user-dirs-gtk-update
snapshot-detect
xscreensaver -no-splash &
#/usr/local/bin/vivaldi-stop-screensaver.sh &
#/usr/local/bin/stop-screensaver.sh &
#xset s 0 0

# Wallpaper
nitrogen --restore &

# Шумодав для микрофона
#######pipewire -c filter-chain/source-rnnoise.conf &

# Отключение вертикальной синхронизации
#nvidia-settings -a 'SyncToVBlank=0'
#nvidia-settings -a "[gpu:0]/GpuPowerMizerMode=1"

# Start Polybar
##if [ -x /usr/bin/polybar ]; then
##  bash $HOME/.config/polybar/launch.sh
##fi

# Раскладка клавиатуры
#setxkbmap -model pc105 -layout "us,ru" -option grp:ctrl_shift_toggle &
setxkbmap -layout us,ru -option grp:ctrl_shift_toggle &
# Настройка скорости повторения клавиш
xset r 22 r rate 500 30 &
# Отключение акселирации у мыши
xset m 2 1 &
# Отключение спящего режима монитора
####xset -dpms s off
xset -dpms &

bspc monitor DisplayPort-0 -n monitor0 -d I II III IV V VI VII IX X
bspc monitor HDMI-A-0 -n monitor1 -d VIII
#bspc monitor DVI-D-0 -d IX

#bspc monitor DP-0 -n monitor0 -d I II III IV V VI VII IX X
#bspc monitor HDMI-0 -n monitor1 -d VIII
bspc monitor DisplayPort-0 -s HDMI-A-0

bspc config automatic_scheme alternate
bspc config initial_polarity second_child
bspc config removal_adjustment true

#bspc config external_rules_command ~/.config/bspwm/scripts/external_rules
bspc config border_width 2
#bspc config window_gap           6
bspc config window_gap 9
bspc config split_ratio 0.50
bspc config borderless_monocle true
bspc config single_monocle true
bspc config gapless_monocle true
bspc config pointer_follows_focus false
bspc config focus_follows_pointer true

# Border
bspc config focused_border_color "#458588"
bspc config normal_border_color "#383737"
bspc config active_border_color "#383737"
bspc config presel_feedback_color "#504945"

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

# Desktop 1 
bspc rule -a kitterm desktop='^1' focus=on
bspc rule -a nmail desktop='^1' focus=on

# Desktop 2 
bspc rule -a qutebrowser desktop='^2' follow=on focus=on
bspc rule -a Vivaldi-stable desktop='^2' follow=on focus=on
#bspc rule -a firefox-esr desktop='^2'
#bspc rule -a firefox-esr:*:Picture-in-Picture state=floating
#bspc rule -a Places desktop='^2' state=floating

# Desktop 3 
##bspc rule -a firefox desktop='^2'
##bspc rule -a firefox:*:Picture-in-Picture state=floating
#bspc rule -a Cherrytree desktop='^2' focus=on

# Desktop 4  
#bspc rule -a Pcmanfm:Dialog state=floating center=true
bspc rule -a TelegramDesktop desktop='^4' focus=on
#bspc rule -a KotatogramDesktop desktop='^4' focus=on
bspc rule -a AyuGramDesktop desktop='^4' focus=on
#bspc rule -a Ripcord desktop='^4' focus=on
#bspc rule -a Cawbird desktop='^4' focus=on
#bspc rule -a Hexchat desktop='^4' focus=on
bspc rule -a matrix desktop='^4' focus=on

# Desktop 5 
bspc rule -a "VirtualBox Manager" desktop='^5' focus=on

# Desktop 6 說
bspc rule -a steam desktop='^5' focus=on
bspc rule -a Gimp-3.0 desktop='^6' follow=on focus=on
bspc rule -a Gimp-2.10 desktop='^6' follow=on focus=on
bspc rule -a Gimp desktop='^6' follow=on focus=on
bspc rule -a ocenaudio desktop='^6' follow=on focus=on
#bspc rule -a Audacious desktop='^6' focus=on
bspc rule -a Shotcut desktop='^6' focus=on

# Desktop 7 ﰭ
bspc rule -a Tixati desktop='^7' focus=on
#bspc rule -a Deluge-gtk desktop='^7' focus=on

# Desktop 8 藍
#bspc rule -a Xfce4-terminal desktop='^8' focus=on
#bspc rule -a Tilix desktop='^8' focus=on

# Desktop 9 
#bspc rule -a thunderbird desktop='^9' focus=on
bspc rule -a obsidian desktop='^8' focus=on

# Desktop 10 (2-й монитор DELL) 
bspc rule -a obs desktop='^10' focus=on
bspc rule -a FreeTube desktop='^10' focus=on
bspc rule -a Grayjay desktop='^10' focus=on
bspc rule -a WebApp-microblog desktop='^10' focus=on

# Без привязки
####bspc rule -a FluffyChat state=tiled
bspc rule -a Authpass state=tiled
#bspc rule -a hexchat state=tiled
bspc rule -a Yad state=floating
bspc rule -a pavucontrol state=floating center=true
bspc rule -a windot state=floating sticky=off center=false rectangle=988x520+1215+1000
bspc rule -a marktext state=floating center=true
bspc rule -a Xed state=floating center=true
bspc rule -a nvim_notes state=floating sticky=on center=false rectangle=800x1020+2500+700
#bspc rule -a Kupfer.py focus=on
#bspc rule -a Screenkey manage=off
####bspc rule -a mpv state=floating sticky=on rectangle=300x180+1060+475
bspc rule -a dragon-drop focus=off
#bspc rule -a KeePassXC hidden=on focus=on
#bspc rule -a MEGAsync state=floating border=off
#bspc rule -a Nextcloud state=floating border=off
bspc rule -a clipse state=floating rectangle=720x800+1060+475 center=true

#bspc config -d mpd window_gap 262
#bspc config -d mpd top_padding -34

# Move cursor center display
######xdotool mousemove 1200 1760

# Autostart Applications
redshift-gtk &
#ayugram-desktop &
AyuGram &
#telegram-desktop &
#kotatogram-desktop &
###ripcord &
openrgb --startminimized --profile "zloy" &
#clipton watcher &
#clipse --listen-shell &
greenclip daemon &
#obsidian &

# Move cursor center display
xdotool mousemove 1500 800

#kitty --class "nmail" --session ~/.config/kitty/session_mail.conf &
sleep 3
kitty --class "kitterm" --session ~/.config/kitty/session.conf &
#kitty --class "matrix" --session ~/.config/kitty/session_matrix.conf &
#kitty --class "clipse" --session ~/.config/kitty/session_clipse.conf &

#sleep 2
#megasync &
seafile-applet &
alertify &
#deluge-gtk &
keepassxc &
#parcellite &
#/usr/bin/clipton watcher &
easyeffects --gapplication-service
blueman-applet &
###systemctl --user start polybar.service
#sleep 5

#/usr/bin/telegram-desktop -workdir /home/zloy_linux/.local/share/TelegramDesktop/ -autostart &
#psensor &

# Переключение на 
sleep 3
bspc desktop -f ^2

####tixati &

# Low battery notifier
#~/.config/bspwm/scripts/low_bat_notifier.sh
