# sway config file (v4)
# TODO: add scratchpads (terminal, password manager, discord, task)

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

set $DISP_SEC DP-2
set $DISP_PRI HDMI-A-1

set $BOR_WIDTH 3
set $GAP_INNER 3

set $mod Mod4

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

set $e exec swaymsg mode default

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

set $TERM kitty

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

set $background #282A36
set $foreground #F8F8F2
set $focused #bd93f9
set $inactive #44475A
set $urgent #FF5555
set $workspace #50FA7B

# class                  border       bground       text     indicator  child_border
client.focused           $focused    $focused    $foreground $focused    $focused
client.focused_inactive  $inactive   $inactive   $foreground $inactive   $inactive
client.unfocused         $background $background $foreground $background $background
client.urgent            $inactive   $urgent     $foreground $urgent     $urgent
client.placeholder       $background $background $foreground $background $background

client.background       $foreground

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

font pango:JetBrains Mono Nerd Font 10
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"] {
  floating enable
  sticky toggle
  resize set width 22ppt
  resize set height 22ppt
  move position 77ppt 77ppt
}
# Float w3m image previews from newsboat
for_window [title="ImageMagick"] floating enable

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

for_window [class="steam"] move container to workspace $tag1
for_window [class="discord"] move container to workspace $tag8
for_window [class="obsidian"] move container to workspace $tag4
for_window [title="launcher"] {
  floating enable
  resize set width 40ppt
  resize set height 40ppt
  move position 30ppt 30ppt
}

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

# Power commands
bindsym $mod+p mode $mode_power
mode $mode_power {
    bindsym s exec shutdown now
    bindsym r exec reboot
    bindsym Escape mode default
}

# Utility commands
bindsym $mod+x mode utility
mode utility {
    bindsym q exit
    bindsym r reload
    bindsym g exec "~/.config/sway/scripts/gamemode.sh", $e
    bindsym v exec "~/bin/linux-toggle-vpn", $e
    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 ~/.config/sway/scripts/tabfocus.sh "h"
bindsym $mod+j exec ~/.config/sway/scripts/tabfocus.sh "j" 
bindsym $mod+k exec ~/.config/sway/scripts/tabfocus.sh "k"
bindsym $mod+l exec ~/.config/sway/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
bindsym $mod+z splith; layout tabbed; focus parent
bindsym $mod+Shift+z layout default 

# 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 @DEFAULT_SINK@ +2%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -2%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle

# Open applications
bindsym $mod+Shift+Return exec $TERM 
bindsym $mod+a mode launcher
mode launcher {
    bindsym r exec "$TERM --title launcher -e ~/bin/linux-app-launcher", $e
    bindsym Escape mode default
}
bindsym $mod+o mode open
mode open {
    bindsym b exec chromium, $e
    bindsym o exec obsidian, $e
    bindsym s exec steam || flatpak run com.valvesoftware.Steam, $e
    bindsym d exec discord || flatpak run com.discordapp.Discord, $e
    bindsym m exec mpv $(wl-paste), $e
    bindsym Escape mode default
}

for_window [con_mark="SCRATCHPAD_jop"] border pixel 1

# Scratchpads commands
bindsym $mod+Return exec sway-scratchpad \
                             --command "$TERM -e tmuxp load ~/.config/tmuxp/scratch.yml" \
                             --mark scratch \
                             --width 50 \
                             --height 71, $e
bindsym $mod+c mode scratch
mode scratch {
    bindsym b exec sway-scratchpad \
                       --command "blueman-manager" \
                       --mark blue \
                       --width 40 \
                       --height 71, $e
    bindsym Shift+c move scratchpad, $e
    bindsym c scratchpad show, $e
    bindsym Escape mode default
}

output $DISP_PRI {
    resolution 2560x1440@143.973Hz
    position 2560,0
}

output $DISP_SEC {
    resolution 2560x1440@143.912Hz
    position 0,0
}

bar {
    position top
    tray_output none
    pango_markup enabled
    status_command while ~/.config/sway/scripts/status.sh; do sleep 1; done
    colors {
        background #000000
        focused_workspace $workspace $workspace $background
    }
}

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

#exec_always --no-startup-id "configure-gtk"
exec_always --no-startup-id "dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK"
exec_always --no-startup-id "swaybg -i ~/media/pictures/wallpapers/solar_system_wallpapers/mars.png"
exec --no-startup-id "~/.config/sway/scripts/idle.sh"
exec --no-startup-id "udiskie"
