#  _ ___
# |_|_  |___ ___ ___ ___ ___
# | |_  |___| . | .'| . |_ -|
# |_|___|   |_  |__,|  _|___|
#           |___|   |_|

# 1...............Variables
# 2.........Gaps n' norders
# 3..................Colors
# 4................Bindings
# 5..............Workspaces
# 6.....................Bar
# 7.................Runtime



# -----[ Variables ]----- #

# Modifier Keys (alt & win)
set $mod Mod1
set $win Mod4

set $gaps 10

# Terminal
#set $terminal "alacritty --command /usr/bin/zsh"
set $terminal "kitty /usr/bin/zsh"

# File Browser
set $file_browser "alacritty --class vifm --command /usr/bin/zsh -ic vifm"

# Font (window title, bar)
#font pango:scientifica 12
font pango:Hack 12

# -----[ Gaps and Borders ]----- #

# Inner Gapsize (in px)
gaps inner 5
# Outer Gapsize (in px)
gaps outer 5

# Border width (in px)
new_window pixel 2

# -----[ Colors ]----- #

# load color configuration from Xresource file (pywal)

set_from_resource $foreground foreground #292d3e
set_from_resource $background background #292d3e

set_from_resource $base00 color0  #292d3e
set_from_resource $base01 color10 #444267
set_from_resource $base02 color11 #32374d
set_from_resource $base03 color8  #676e95
set_from_resource $base04 color12 #8796b0
set_from_resource $base05 color7  #959dcb
set_from_resource $base06 color13 #959dcb
set_from_resource $base07 color15 #ffffff
set_from_resource $base08 color1  #f07178
set_from_resource $base09 color9  #f78c6c
set_from_resource $base0A color3  #ffcb6b
set_from_resource $base0B color2  #c3e88d
set_from_resource $base0C color6  #89ddff
set_from_resource $base0D color4  #82aaff
set_from_resource $base0E color5  #c792ea
set_from_resource $base0F color14 #ff5370


# -----[ Bindings ]----- #

# Brightness Keys
bindsym XF86MonBrightnessUp exec light -A 15
bindsym XF86MonBrightnessDown exec light -U 15

# Audio Keys - Volume and Mute
bindsym $mod+plus		exec --no-startup-id amixer -D pulse sset Master 5%+
bindsym $mod+Shift+plus		exec --no-startup-id amixer -D pulse sset Master 15%+
bindsym $mod+minus 		exec --no-startup-id amixer -D pulse sset Master 5%-
bindsym $mod+Shift+minus	exec --no-startup-id amixer -D pulse sset Master 15%-

bindsym XF86AudioRaiseVolume    exec --no-startup-id amixer -D pulse sset Master 5%+
bindsym XF86AudioLowerVolume    exec --no-startup-id amixer -D pulse sset Master 5%-
bindsym XF86AudioMute           exec --no-startup-id amixer -D pulse sset Master toggle

# Spotify Control Scripts
bindsym XF86AudioPrev exec --no-startup-id $HOME/.scripts/tools/spotify-ctrl Previous
bindsym XF86AudioPlay exec --no-startup-id $HOME/.scripts/tools/spotify-ctrl Play
bindsym XF86AudioNext exec --no-startup-id $HOME/.scripts/tools/spotify-ctrl Next

# Screenshot script
bindsym Print --release exec --no-startup-id flameshot gui

# this spawns in scratchpad mode!
set $dropdownterm "alacritty --class ddpython -e /bin/bash -ic python"
bindsym $mod+p exec $dropdownterm

# set $dropdownnotes "st -n ddnotes -e /bin/bash -ic 'vim $HOME/projects/internal/notes/todo.md'"
set $dropdownnotes "alacritty --class ddnotes -e /bin/bash -ic 'vim $HOME/projects/internal/notes/todo.md'"
bindsym $mod+n exec $dropdownnotes

# script that shows mounted devices for fast unmount
bindsym $mod+u exec $HOME/.scripts/tools/umount.sh

# unicode emoji finder
bindsym $mod+i exec rofimoji

# yt-mpv
bindsym $mod+y exec $HOME/.scripts/tools/yt-viewer.sh

# Locking the screen
bindsym $win+l exec blurlock


# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# Execute terminal
bindsym $mod+Return exec $terminal

# kill focused window ( without shift)
bindsym $mod+q kill

# Scratchpad bindings
# make a terminal a scratchpad window
bindsym $mod+t move scratchpad

# show scratchpad
bindsym $mod+s scratchpad show

# Program launcher and Window switcher
bindsym $mod+d exec "rofi -show combi -show-icons -combi-modi \\"run,drun\\""
bindsym $mod+Tab exec rofi -show window

# Use win+e as filemanager shortcut (using ranger)
bindsym $mod+o exec $file_browser

# change focus (vim bindings)
bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right 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

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# split in vertical and horizontal orientation
bindsym $mod+v split v
bindsym $mod+c split h

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

# change container layout (stacked, toggle split)
bindsym $mod+w layout stacking
bindsym $mod+e layout toggle split

bindsym $mod+g gaps inner current set 0;
bindsym $mod+Shift+g gaps inner current set $gaps;

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

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

# reload the configuration file
bindsym $mod+Shift+c reload

# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart

# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e 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'"


bindsym $mod+Shift+p exec flameshot gui

# Mucho grande resizerino
# Use zuio bindings for resizing on the fly
bindsym $mod+Shift+y resize shrink width 10 px or 10 ppt
bindsym $mod+Shift+u resize grow height 10 px or 10 ppt
bindsym $mod+Shift+i resize shrink height 10 px or 10 ppt
bindsym $mod+Shift+o resize grow width 10 px or 10 ppt

# oldschool resize mode!
bindsym $mod+r mode "resize"

# show screen on laptop screen only (needs autorandr profile 'default')
bindsym $mod+Shift+d exec "autorandr -l default"

# These bindings trigger as soon as you enter the resize mode
mode "resize" {

        # resizing using vim bindings
        bindsym h resize shrink width 10 px or 10 ppt
        bindsym j resize grow height 10 px or 10 ppt
        bindsym k resize shrink height 10 px or 10 ppt
        bindsym l resize grow width 10 px or 10 ppt

        # same bindings, but for the arrow keys
        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

        # back to normal: Enter or Escape
        bindsym Return mode "default"
        bindsym Escape mode "default"
}


# -----[ Workspaces ]----- #

# Workspace Strings (only numbers, no unicoderino)
set $ws1  "1"
set $ws2  "2"
set $ws3  "3"
set $ws4  "4"
set $ws5  "5"
set $ws6  "6"
set $ws7  "7"
set $ws8  "8"
set $ws9  "9"
set $ws10 "10"

# switch to workspace
bindsym $mod+1 workspace $ws1;move workspace to output primary;
bindsym $mod+2 workspace $ws2
bindsym $mod+3 workspace $ws3
bindsym $mod+4 workspace $ws4
bindsym $mod+5 workspace $ws5;move workspace to output DP2-3;
bindsym $mod+6 workspace $ws6
bindsym $mod+7 workspace $ws7
bindsym $mod+8 workspace $ws8
bindsym $mod+9 workspace $ws9
bindsym $mod+0 workspace $ws10

# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace 1
bindsym $mod+Shift+2 move container to workspace 2
bindsym $mod+Shift+3 move container to workspace 3
bindsym $mod+Shift+4 move container to workspace 4
bindsym $mod+Shift+5 move container to workspace 5
bindsym $mod+Shift+6 move container to workspace 6
bindsym $mod+Shift+7 move container to workspace 7
bindsym $mod+Shift+8 move container to workspace 8
bindsym $mod+Shift+9 move container to workspace 9
bindsym $mod+Shift+0 move container to workspace 10



# -----[ Bar ]----- #

# Start i3bar to display a workspace bar (plus the system information from i3status)
bar {
        # default status string
        #i3bar_command i3bar
        status_command i3blocks -c ~/.config/i3blocks/i3blocks.conf
        font pango:JetBrainsMono Nerd Font Mono 10
        modifier None
	position top
        tray_output primary
        strip_workspace_numbers yes

        # Base16 colors
	colors {
		background $base00
		separator  $base01
                statusline $base04

                # State             Border  BG      Text
               focused_workspace   $base05 $base0D $base00
               active_workspace    $base05 $base03 $base00
               inactive_workspace  $base03 $base01 $base05
               urgent_workspace    $base08 $base08 $base00
               binding_mode        $base00 $base0A $base00
            }
    }

    # Colors of the Windows - using base16
    # Property Name         Border  BG      Text    Indicator   Child Border
    client.focused          $base05 $base0D $base00 $base0D     $base0D
    client.focused_inactive $base01 $base01 $base05 $base03     $base01
    client.unfocused        $base01 $base00 $base05 $base01     $base01
    client.urgent           $base08 $base08 $base00 $base08     $base08
    client.placeholder      $base00 $base00 $base05 $base00     $base00
    client.background       $base07



# -----[ Windows ]----- #

# Settings for the drop-drown python instance

for_window [instance="ddpython"]        resize set 1000 400
for_window [instance="ddpython"]        move scratchpad
for_window [instance="ddpython"]        border pixel 3
for_window [instance="ddpython"]        sticky enable
for_window [instance="ddpython"]        scratchpad show
for_window [instance="ddpython"]        floating enable

# MPV floating and fitted

for_window [class="mpv"]        resize set 650 370
for_window [class="mpv"]        border pixel 3
for_window [class="mpv"]        floating enable


for_window [instance="vifm"]        resize set 1000 400
for_window [instance="vifm"]        border pixel 3
for_window [instance="vifm"]        floating enable

# Same procedure for dropdown notes
for_window [instance="ddnotes"]        resize set 1100 700
for_window [instance="ddnotes"]        move scratchpad
for_window [instance="ddnotes"]        border pixel 3
for_window [instance="ddnotes"]        sticky enable
for_window [instance="ddnotes"]        scratchpad show
for_window [instance="ddnotes"]        floating enable


# rdesktop for Windows VM
for_window [instance="^rdesktop.*"]        resize set 1100 700
for_window [instance="^rdesktop.*"]        move scratchpad
for_window [instance="^rdesktop.*"]        border pixel 2
for_window [instance="^rdesktop.*"]        sticky enable
for_window [instance="^rdesktop.*"]        scratchpad show
for_window [instance="^rdesktop.*"]        floating enable

# Minitube (small floating)
for_window [class="Minitube"]        resize set 650 370
for_window [class="Minitube"]        border pixel 3
for_window [class="Minitube"]        floating enable

# ms teams notifications
no_focus [title="Microsoft Teams Notification"]
for_window [title="Microsoft Teams Notification"] floating enable
for_window [title="Microsoft Teams Notification"] resize set 400 150
for_window [title="Microsoft Teams Notification"] move position 1600px 20px
no_focus [title="Microsoft Teams Notification"]

# move them to seperate workspaces
assign [instance="telegram"]            9
assign [instance="spotify"]             8


# YAD
for_window [class="Yad"] floating enable



# -----[ Runtime ]----- #

exec         --no-startup-id udiskie -a -n -t                                                           # automounting USB sticks
exec         --no-startup-id nm-applet                                                                  # network manager applet
exec         --no-startup-id volumeicon                                                                 # applet for audio
exec         --no-startup-id redshift-gtk                                                               # bluelight filter
exec         --no-startup-id xfce4-power-manager                                                        # display power settings
exec_always  --no-startup-id wal -R                                                                     # use wal colorschemes
exec_always  --no-startup-id setxkbmap -rules evdev -model evdev -layout us -variant altgr-intl         # us-international kb layout
exec_always  --no-startup-id autorandr -c --force
exec_always  --no-startup-id flameshot
exec_always  --no-startup-id xset r rate 400 50                                                         # Speed up keyboard input speed