######################
## Raine's i3 config ##
## Sept 2, 2023      ##
#######################

## Mostly similar to i3's config yet differs

# Useful variables:
# This section probably gets changed a lot
# ---
set $terminal alacritty
set $screen_lock i3lock -c "#111111" --nofork
set $appmenu i3-dmenu-desktop

set $screenshot maim | xclip -selection clipboard -t image/png
set $alt_screenshot maim ~/Pictures/Screenshots/$(date +%s).png

set $mod Mod4
set $alt Mod1
set $font pango:monospace 8

# Startup Applications:
# Things that will startup when starting i3.
# ---
exec --no-startup-id dex --autostart --environment i3
exec --no-startup-id nm-applet
exec --no-startup-id xss-lock --transfer-sleep-lock -- $screen_lock 
exec --no-startup-id gnome-keyring-daemon --start --components=ssh,secrets,pkcs11

# Extra variables:
# Only need changing for very specific installations.
# ---
set $audio_volume_up XF86AudioRaiseVolume
set $audio_volume_down XF86AudioLowerVolume
set $audio_mute XF86AudioMute
set $audio_mute_mic XF86AudioMicMute

set $brightness_up XF86MonBrightnessUp
set $brightness_down XF86MonBrightnessDown

set $nav_up l
set $nav_down k
set $nav_left j
set $nav_right semicolon

set $ws_1 "1:main"
set $ws_2 "2:term"
set $ws_3 "3:browser"
set $ws_4 "4:mail"
set $ws_5 "5"
set $ws_6 "6"
set $ws_7 "7"
set $ws_8 "8"
set $ws_9 "9:background"
set $ws_10 "10:multimedia"

set $mode_resize_combo Mod4+r
set $mode_session_combo Mod4+Delete

set $op_floating_modifier Mod1

set $meta_refresh_statusbar killall -SIGUSR1 i3status
bar {
    strip_workspace_numbers yes
    status_command i3status
}

# END OF CONFIG

# Customization
#! Customization
# class                 border  backgr. text    indicator child_border
client.focused          #D991BA #D27099 #ffffff #D96FBA   #D951B0
client.focused_inactive #333333 #5f676a #ffffff #484e50   #5f676a
client.unfocused        #333333 #222222 #888888 #292d2e   #222222
client.urgent           #EF2929 #900000 #ffffff #900000   #900000
client.placeholder      #000000 #0c0c0c #ffffff #000000   #0c0c0c
client.background       #888A85

# Generic
floating_modifier $op_floating_modifier
tiling_drag modifier titlebar
font $font

# Open a terminal
bindsym $mod+Return exec $terminal

# Kill current window
bindsym $alt+Shift+q kill

# Open app menu
bindsym $mod+Shift+d exec --no-startup-id $appmenu 

# Lock screen
bindsym $mod+l exec --no-startup-id $screen_lock

# Screenshots
bindsym Print exec $screenshot
bindsym Mod1+Print exec $alt_screenshot

# Audio
bindsym $audio_volume_up exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $meta_refresh_statusbar
bindsym $audio_volume_down exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -10% && $meta_refresh_statusbar
bindsym $audio_mute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle && $meta_refresh_statusbar
bindsym $audio_mute_mic exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $meta_refresh_statusbar

# Brightness
bindsym $brightness_up exec --no-startup-id brightnessctl set +5% && $meta_refresh_statusbar
bindsym $brightness_down exec --no-startup-id brightnessctl set 5%- && $meta_refresh_statusbar

# Change focused window
bindsym $alt+$nav_up focus up
bindsym $alt+$nav_down focus down
bindsym $alt+$nav_left focus left
bindsym $alt+$nav_right focus right
bindsym $alt+Up focus up
bindsym $alt+Down focus down
bindsym $alt+Left focus left
bindsym $alt+Right focus right

# Move focused window
bindsym $alt+Shift+Up move up
bindsym $alt+Shift+Down move down
bindsym $alt+Shift+Left move left
bindsym $alt+Shift+Right move right
bindsym $alt+Shift+$nav_up move up
bindsym $alt+Shift+$nav_down move down
bindsym $alt+Shift+$nav_left move left
bindsym $alt+Shift+$nav_right move right

# Splits
bindsym $alt+h split h
bindsym $alt+v split v

# Make current window fullscreen
bindsym $alt+f fullscreen toggle

# Change container layout
bindsym $mod+Mod1+s layout stacking
bindsym $mod+Mod1+t layout tabbed
bindsym $mod+Mod1+e layout toggle split

# Floating stuff
bindsym $mod+space focus mode_toggle
bindsym $alt+space floating toggle

# Scratchpad
bindsym $alt+minus move scratchpad
bindsym $mod+minus scratchpad show

# Switch to workspace
bindsym $mod+1 workspace $ws_1
bindsym $mod+2 workspace $ws_2
bindsym $mod+3 workspace $ws_3
bindsym $mod+4 workspace $ws_4
bindsym $mod+5 workspace $ws_5
bindsym $mod+6 workspace $ws_6
bindsym $mod+7 workspace $ws_7
bindsym $mod+8 workspace $ws_8
bindsym $mod+9 workspace $ws_9
bindsym $mod+0 workspace $ws_10

# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace $ws_1
bindsym $mod+Shift+2 move container to workspace $ws_2
bindsym $mod+Shift+3 move container to workspace $ws_3
bindsym $mod+Shift+4 move container to workspace $ws_4
bindsym $mod+Shift+5 move container to workspace $ws_5
bindsym $mod+Shift+6 move container to workspace $ws_6
bindsym $mod+Shift+7 move container to workspace $ws_7
bindsym $mod+Shift+8 move container to workspace $ws_8
bindsym $mod+Shift+9 move container to workspace $ws_9
bindsym $mod+Shift+0 move container to workspace $ws_10

# Move to workspace next to current
bindsym $mod+$nav_left workspace prev
bindsym $mod+$nav_right workspace next
bindsym $mod+Left workspace prev
bindsym $mod+Right workspace next

# WM stuff
# reload i3 config
bindsym $mod+Control+c reload
# restart i3
bindsym $mod+Control+r restart
# exit i3 (recognized combo; for people who need to exit your session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'Exit i3?' -B 'Yes, exit i3' 'i3-msg exit'"

# Modes
bindsym $mode_resize_combo mode resize
mode "resize" {
    bindsym $nav_left   resize shrink width 10 px or 10 ppt
    bindsym $nav_down   resize grow height 10 px or 10 ppt
    bindsym $nav_up     resize shrink height 10 px or 10 ppt
    bindsym $nav_right  resize grow width 10 px or 10 ppt
    bindsym Left        resize shrink width 10 px or 10 ppt
    bindsym Down        resize grow height 10 px or 10 ppt
    bindsym Up          resize shrink height 10 px or 10 ppt
    bindsym Right       resize grow width 10 px or 10 ppt

    bindsym Return mode "default"
    bindsym Escape mode "default"
    bindsym $mode_resize_combo mode "default"
}

bindsym $mode_session_combo mode "session"
mode "session" {
    bindsym l exec --no-startup-id $lock, mode "default"
    bindsym e exec --no-startup-id i3-msg exit, mode "default"
    bindsym Shift+r exec --no-startup-id systemctl reboot, mode "default"
    bindsym Shift+s exec --no-startup-id systemctl poweroff -i, mode "default"

    bindsym Return mode "default"
    bindsym Escape mode "default"
    bindsym $mode_session_combo mode "default"
}