# =====GENERAL=====
# Main modifier; Mod1 is alt
set $mod Mod4

# Modifier for floating-related operations
floating_modifier $mod

# Layout for new workspaces; default means tiling
workspace_layout default

#do not show titlebar on windows: 
default_border pixel

# thin borders
hide_edge_borders both

# Font for window titles & bar, unless specified otherwise
font pango:Noto Sans Regular 8


# =====WINDOW MANAGEMENT=====
# change focus
bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l focus right

# move focused window
bindsym $mod+Shift+h move left
bindsym $mod+Shift+j move down
bindsym $mod+Shift+k move up
bindsym $mod+Shift+l move right

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

# kill focused window
bindsym $mod+x kill

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

# Resize focused window
mode "resize" {
    bindsym h resize shrink width 10 px or 10 ppt
    bindsym j resize shrink height 10 px or 10 ppt
    bindsym k resize grow height 10 px or 10 ppt
    bindsym l resize grow width 10 px or 10 ppt

    bindsym Escape mode "default"
}

bindsym $mod+r mode "resize"

#resize floating windows with mouse scroll:
bindsym --whole-window --border $mod+button4 resize shrink height 5 px or 5 ppt
bindsym --whole-window --border $mod+button5 resize grow height 5 px or 5 ppt
bindsym --whole-window --border $mod+shift+button4 resize shrink width 5 px or 5 ppt
bindsym --whole-window --border $mod+shift+button5 resize grow width 5 px or 5 ppt


# =====WORKSPACES=====
set $ws01 ""
set $ws02 ""
set $ws03 ""
set $ws04 ""
set $ws05 ""
set $ws11 "α"
set $ws12 "β"
set $ws13 "γ"
set $ws14 "δ"
set $ws15 "ε"
set $ws21 "2:1"
set $ws22 "2:2"
set $ws23 "2:3"
set $ws24 "2:4"
set $ws25 "2:5"

workspace $ws01 output primary
workspace $ws02 output primary
workspace $ws03 output primary
workspace $ws04 output primary
workspace $ws05 output primary
workspace $ws11 output eDP-1-1
workspace $ws12 output eDP-1-1
workspace $ws13 output eDP-1-1
workspace $ws14 output eDP-1-1
workspace $ws15 output eDP-1-1
workspace $ws21 output HDMI-0
workspace $ws22 output HDMI-0
workspace $ws23 output HDMI-0
workspace $ws24 output HDMI-0
workspace $ws25 output HDMI-0

# switch to main workspaces
bindsym $mod+y workspace $ws01
bindsym $mod+u workspace $ws02
bindsym $mod+i workspace $ws03
bindsym $mod+o workspace $ws04
bindsym $mod+p workspace $ws05

# move focused container to main workspace
bindsym $mod+Shift+y move container to workspace $ws01
bindsym $mod+Shift+u move container to workspace $ws02
bindsym $mod+Shift+i move container to workspace $ws03
bindsym $mod+Shift+o move container to workspace $ws04
bindsym $mod+Shift+p move container to workspace $ws05

# Manage other workspaces
mode "eDP-1-1" {
    # switch to workspace
    bindsym y workspace $ws11
    bindsym u workspace $ws12
    bindsym i workspace $ws13
    bindsym o workspace $ws14
    bindsym p workspace $ws15

    # move focused container to workspace
    bindsym Shift+y move container to workspace $ws11
    bindsym Shift+u move container to workspace $ws12
    bindsym Shift+i move container to workspace $ws13
    bindsym Shift+o move container to workspace $ws14
    bindsym Shift+p move container to workspace $ws15

    # Go to HDMI-0 mode
    bindsym e mode "HDMI-0"

    # Go back to normal mode
    bindsym Escape mode "default"
}

mode "HDMI-0" {
    # switch to workspace
    bindsym y workspace $ws21
    bindsym u workspace $ws22
    bindsym i workspace $ws23
    bindsym o workspace $ws24
    bindsym p workspace $ws25

    # move focused container to workspace
    bindsym Shift+y move container to workspace $ws21
    bindsym Shift+u move container to workspace $ws22
    bindsym Shift+i move container to workspace $ws23
    bindsym Shift+o move container to workspace $ws24
    bindsym Shift+p move container to workspace $ws25

    # Go to eDP-1-1 mode
    bindsym e mode "eDP-1-1"

    # Go back to normal mode
    bindsym Escape mode "default"
}

bindsym $mod+e mode "eDP-1-1"

# Configuration mode
mode "config" {
    # Switch split mode
    bindsym j split vertical; mode "default"
    bindsym h split horizontal; mode "default"
    bindsym k split vertical; mode "default"
    bindsym l split horizontal; mode "default"

    # Switch layout
    bindsym y layout stacking; mode "default"
    bindsym u layout tabbed; mode "default"
    bindsym i layout toggle split; mode "default"

    # Go back to normal mode
    bindsym Escape mode "default"
}

bindsym $mod+s mode "config"

# Assign certain programs to workspaces
# for_window [class=Xfce4-terminal] focus
# assign [class="(?i)firefox"] $ws02
# for_window [class=(?i)firefox] focus
# assign [class="Thunar"] $ws03
# for_window [class=Thunar] focus
# assign [class="Thunderbird"] $ws04
# for_window [class=Thunderbird] focus
# assign [class="TelegramDesktop"] $ws05
# for_window [class=TelegramDesktop] focus


# =====OTHER KEYBINDINGS=====
# reload the configuration file
bindsym $mod+Shift+c reload

# Restart i3 in-place
bindsym $mod+Shift+r restart

# exit i3 (logs you out of your X session)
bindsym $mod+Shift+q exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"

# Volume
bindsym XF86AudioRaiseVolume exec amixer -D pulse sset Master 5%+ && pkill -RTMIN+1 i3blocks
bindsym XF86AudioLowerVolume exec amixer -D pulse sset Master 5%- && pkill -RTMIN+1 i3blocks
bindsym $mod+XF86AudioRaiseVolume exec amixer -D pulse sset Master 1%+ && pkill -RTMIN+1 i3blocks
bindsym $mod+XF86AudioLowerVolume exec amixer -D pulse sset Master 1%- && pkill -RTMIN+1 i3blocks
bindsym XF86AudioMute exec amixer -D pulse set Master toggle

# Foobar2000 controls
bindsym F8 exec --no-startup-id wine ~/.wine/drive_c/users/jjr/Desktop/foobar2000/foobar2000.exe /playpause

# Backlight
bindsym XF86MonBrightnessUp exec brightnessctl --device='intel_backlight' set +10%
bindsym XF86MonBrightnessDown exec brightnessctl --device='intel_backlight' set 10%-

# Keyboard brightness
bindsym XF86KbdBrightnessUp exec brightnessctl --device='smc::kbd_backlight' set +10%
bindsym XF86KbdBrightnessDown exec brightnessctl --device='smc::kbd_backlight' set 10%-

# Screenshot
bindsym Print exec "scrot ~/%Y-%m-%d-%T-screenshot.png"

# Show shutdown menu
bindsym $mod+Escape exec ~/.config/i3/scripts/shutdown_menu -p rofi -c


# =====APPLICATIONS=====
# Launch applications
# start a terminal
bindsym $mod+Return exec --no-startup-id st
# Launch output device configuration
bindsym $mod+m exec --no-startup-id pavucontrol -t 3
# Open dmenu
bindsym $mod+d exec --no-startup-id i3-dmenu-desktop
# Open Galculator
bindsym XF86Calculator exec --no-startup-id galculator


# =====AUTOSTART APPLICATIONS=====
#get auth work with polkit-gnome
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
# Run setup script
exec --no-startup-id ~/.config/i3/startup.sh
# Bluetooth applet
exec --no-startup-id blueman-tray
# Nextcloud sync
exec --no-startup-id nextcloud
# Compositor
exec --no-startup-id picom --config ~/.config/picom.conf --experimental-backends
# Network Manager applet
exec --no-startup-id nm-applet
#set powersavings for display
exec --no-startup-id xset s 480 dpms 600 600 600
# Desktop notifications
exec --no-startup-id /usr/bin/dunst
# Mail notifications
# exec --no-startup-id thunderbird
# Joplin sync
exec --no-startup-id joplin-desktop


# =====FLOAT RULES=====
for_window [class="Yad" instance="yad"] floating enable
for_window [class="Galculator" instance="galculator"] floating enable
for_window [class="Xsane" instance="xsane"] floating enable
for_window [class="Pavucontrol" instance="pavucontrol"] floating enable
for_window [class="qt5ct" instance="qt5ct"] floating enable
for_window [class="Blueberry.py" instance="blueberry.py"] floating enable
for_window [class="Bluetooth-sendto" instance="bluetooth-sendto"] floating enable
for_window [class="Gufw.py" instance="gufw.py"] floating enable


# =====COLORS=====
set $bg-color            #2f343f
set $inactive-bg-color   #2f343f
set $text-color          #f3f4f5
set $inactive-text-color #676e7d
set $urgent-bg-color     #e53935
set $indicator-color     #a0a0a0

# set window colors
#                       border             background         text                 indicator
client.focused          $bg-color          $bg-color          $text-color          $indicator-color
client.unfocused        $inactive-bg-color $inactive-bg-color $inactive-text-color $indicator-color
client.focused_inactive $inactive-bg-color $inactive-bg-color $inactive-text-color $indicator-color
client.urgent           $urgent-bg-color   $urgent-bg-color   $text-color          $indicator-color


# =====STATUS BAR=====
bar {
    status_command i3blocks -c ~/.config/i3/i3blocks.conf 
    position bottom
    tray_output primary
    colors {
      separator          #666666
        background         #222222
        statusline         #dddddd
        focused_workspace  #0088CC #0088CC #ffffff
        active_workspace   #333333 #333333 #ffffff
        inactive_workspace #333333 #333333 #888888
        urgent_workspace   #2f343a #900000 #ffffff
    }
}