# i3 config file (v4)
# TODO: add scratchpads (terminal, password manager, discord, task)
# Test a edit!

#-------------------------------------------------------------------------------
#----- VARIABLES
#-------------------------------------------------------------------------------

set $HOME /home/tstarr

set $DISP_PRI HDMI-0
set $DISP_SEC DP-3

set $BOR_WIDTH 4
set $GAP_INNER 4

set $mod Mod4

set $tag1 "1:game" 
set $tag2 "2:dev"  
set $tag3 "3:web"  
set $tag4 "4:dev"  
set $tag5 "5:web"  
set $tag6 "6:web"  
set $tag7 "7:web" 
set $tag8 "8:comm"

set $e exec i3-msg mode default

set $mode_power "[r]eboot | [s]hutdown"

#-------------------------------------------------------------------------------
#----- COLORS 
#-------------------------------------------------------------------------------

# class                 border  bground text    indicator child_border
client.focused          #bd93f9 #bd93f9 #F8F8F2 #bd93f9   #bd93f9
client.focused_inactive #44475A #44475A #F8F8F2 #44475A   #44475A
client.unfocused        #282A36 #282A36 #BFBFBF #282A36   #282A36
client.urgent           #44475A #FF5555 #F8F8F2 #FF5555   #FF5555
client.placeholder      #282A36 #282A36 #F8F8F2 #282A36   #282A36

client.background       #F8F8F2

#-------------------------------------------------------------------------------
#----- MISC. CONFIGURATION
#-------------------------------------------------------------------------------

font                    pango:Google Noto 8.5
default_border pixel 3
default_floating_border pixel 3

#-------------------------------------------------------------------------------
#----- BINDING WORKSPACE TO DISPLAY
#-------------------------------------------------------------------------------

workspace $tag1 output $DISP_PRI
workspace $tag2 output $DISP_PRI
workspace $tag3 output $DISP_PRI
workspace $tag4 output $DISP_PRI
workspace $tag5 output $DISP_SEC
workspace $tag6 output $DISP_SEC
workspace $tag7 output $DISP_SEC
workspace $tag8 output $DISP_SEC

#-------------------------------------------------------------------------------
#----- CONTAINER GAPS
#-------------------------------------------------------------------------------

# CREATING GAPS BETWEEN THE WINDOWS AND EDGES
gaps inner              $GAP_INNER
gaps outer              0
gaps horizontal         0
gaps vertical           0
gaps top                0 
gaps bottom             0
gaps right              0
gaps left               0

#-------------------------------------------------------------------------------
#----- FORCE FLOATING
#-------------------------------------------------------------------------------

for_window [title="Steam - News"]   floating enable
for_window [title="Friends List"]   floating enable

for_window [title="Picture-in-Picture"] sticky toggle

for_window [con_mark="scratch-term"] floating enable, \
    resize set 800 px 600 px, \
    move position 880 px 420 px

for_window [con_mark="scratch-warrior"] floating enable, \
    resize set 1500 px 800 px, \
    move position 530 px 320 px

for_window [class="Blueman-manager"] floating enable, \
    resize set 1000 px 800 px, \
    move position 780 px 320 px

for_window [class="scratch-nb"] floating enable, \
    resize set 1000 px 800 px, \
    move position 780 px 320 px

#-------------------------------------------------------------------------------
#----- BINDING APPLICATIONS TO WORKSPACE
#-------------------------------------------------------------------------------

assign [class="Steam"]              "1:game"
for_window [class="Steam"]          move container to workspace "1:game"
for_window [class="discord"]        move container to workspace $tag8

#-------------------------------------------------------------------------------
#----- KEY BINDINGS
#-------------------------------------------------------------------------------

# [p]ower commands
bindsym $mod+p mode $mode_power
mode $mode_power {
    bindsym s exec loginctl poweroff
    bindsym r exec loginctl reboot
    bindsym Escape mode default
}

# [x]utility commands
bindsym $mod+x mode utility
mode utility {
    bindsym q exit
    bindsym r restart
    bindsym p exec "rofi-rbw", $e
    # TODO: gamemode (mod+Ctrl+g). Needs script to toggle
    bindsym Escape mode default
}

# layout commands
bindsym $mod+Ctrl+t splitv; layout tabbed
bindsym $mod+Ctrl+v layout splitv
bindsym $mod+Ctrl+s layout splith
bindsym $mod+Ctrl+h resize shrink width 50
bindsym $mod+Ctrl+j resize shrink height 50
bindsym $mod+Ctrl+k resize grow height 50
bindsym $mod+Ctrl+l resize grow width 50
bindsym $mod+Ctrl+c move position center

# program management
bindsym $mod+d kill
bindsym $mod+f fullscreen toggle
bindsym $mod+t floating toggle
bindsym $mod+s sticky toggle
bindsym $mod+Tab focus mode_toggle 
floating_modifier $mod

# spatial container management
bindsym $mod+h exec $HOME/.config/i3/scripts/tabfocus.sh "h"
bindsym $mod+j exec $HOME/.config/i3/scripts/tabfocus.sh "j"
bindsym $mod+k exec $HOME/.config/i3/scripts/tabfocus.sh "k"
bindsym $mod+l exec $HOME/.config/i3/scripts/tabfocus.sh "l"
bindsym $mod+Shift+h move left
bindsym $mod+Shift+j move down
bindsym $mod+Shift+k move up
bindsym $mod+Shift+l move right
bindsym $mod+minus split v
bindsym $mod+backslash split h

# workspace management
bindsym $mod+1 workspace $tag1
bindsym $mod+2 workspace $tag2
bindsym $mod+3 workspace $tag3
bindsym $mod+4 workspace $tag4
bindsym $mod+q workspace $tag5
bindsym $mod+w workspace $tag6
bindsym $mod+e workspace $tag7
bindsym $mod+r workspace $tag8
bindsym $mod+Shift+1 move container to workspace $tag1
bindsym $mod+Shift+2 move container to workspace $tag2
bindsym $mod+Shift+3 move container to workspace $tag3
bindsym $mod+Shift+4 move container to workspace $tag4
bindsym $mod+Shift+q move container to workspace $tag5
bindsym $mod+Shift+w move container to workspace $tag6
bindsym $mod+Shift+e move container to workspace $tag7
bindsym $mod+Shift+r move container to workspace $tag8

# audio
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume 0 +2%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume 0 -2%
bindsym XF86AudioMute exec pactl set-sink-mute 0 toggle

# [o]pen applications
bindsym $mod+Return exec alacritty
bindsym $mod+a exec rofi -show drun -show-icons
bindsym $mod+Shift+a exec rofi -show window -show-icons
bindsym $mod+o mode open
mode open {
    bindsym b exec flatpak run org.mozilla.firefox, $e
    bindsym s exec steam, $e
    bindsym d exec flatpak run com.discordapp.Discord, $e
    bindsym Escape mode default
}

# s[c]ratchpads commands
bindsym $mod+c mode scratch
mode scratch {
    bindsym Return exec $HOME/.config/i3/scripts/scratch.sh \
        'scratch-term' 'alacritty', $e
    bindsym n exec $HOME/.config/i3/scripts/scratch.sh \
        'scratch-nb' 'alacritty -e tmuxinator start nb', $e
    bindsym t exec $HOME/.config/i3/scripts/scratch.sh \
        'scratch-warrior' 'alacritty -e tmuxinator start task', $e
    bindsym Escape mode default
}

#-------------------------------------------------------------------------------
#----- AUTOSTART WITH I3
#-------------------------------------------------------------------------------

exec --no-startup-id "autorandr --change && i3-msg restart"
exec --no-startup-id "pipewire & pipewire-pulse &"
exec --no-startup-id "udiskie &"
exec_always --no-startup-id "$HOME/.config/i3/scripts/autolayout.sh"
exec_always --no-startup-id "$HOME/.config/i3/scripts/polybar.sh"
exec_always --no-startup-id "blueman-applet"
exec_always --no-startup-id "nm-applet"
exec_always --no-startup-id "flameshot"
exec_always --no-startup-id "xsetroot -solid '#282A36'"
