# General variables {{{
set $mod Mod4
set $lock screensaver
set $terminal x-terminal-emulator
#set $launcher dmenu_run -fn '-*-fixed-*-r-normal-*-*-120-*-*-*-*-iso8859-*' -nb '#000000' -nf '#FFFFFF' -sb '#1793d1'
set $rofi /usr/bin/rofi -font "Roboto Sans 20" -l 6 -eh 1 -display-run ""
set $autorandr /usr/bin/autorandr
# firefox
set $w01 "1 󰈹"
# code
set $w02 "2 󰗀"
set $w03 "3"
set $w04 "4"
set $w05 "5"
set $w06 "6"
set $w07 "7"
set $w08 "8"
# shield
set $w09 "9 󰕥"
# steam
set $w10 "10 󰓓"
# lock
set $w11 "11 󰍁"
# spotify
set $w12 "12 󰓇"

# }}}
# German keyboard mappings {{{
# ┏━━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━┓
# ┃   9 ┃ 67 ┃ 68 ┃ 69 ┃ 70 ┃ 71 ┃ 72 ┃ 73 ┃ 74 ┃ 75 ┃ 76 ┃ 95 ┃ 96 ┃  77 ┃   127 ┃   118 ┃ 119 ┃
# ┃ Esc ┃ F1 ┃ F2 ┃ F3 ┃ F4 ┃ F5 ┃ F6 ┃ F7 ┃ F8 ┃ F9 ┃ F10┃ F11┃ F12┃ Num ┃ Break ┃ Einfg ┃ Del ┃
# ┡━━━━━╇━━━━┻┯━━━┻━┯━━┻━━┯━┻━━━┯┻━━━━╇━━━━┻┯━━━┻━┯━━┻━━┯━┻━━━┯┻━━━━╇━━━━━╇━━━━━┳━┻━━━━━━━┻┳━━━━┫
# │  49 │  10 │  11 │  12 │  13 │  14 │  15 │  16 │  17 │  18 │  19 │  20 │  21 ┃       22 ┃ 110┃
# │ ^   │ 1   │ 2   │ 3   │ 4   │ 5   │ 6   │ 7   │ 8   │ 9   │ 0   │ ß   │ `   ┃ ⌫        ┃ Hom┃
# ┢━━━━━┷━━┱──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┺━━┳━━━━━━━╋━━━━┫
# ┃     23 ┃  24 │  25 │  26 │  27 │  28 │  29 │  30 │  31 │  32 │  33 │  34 │  35 ┃    36 ┃ 112┃
# ┃ ↹      ┃ q   │ w   │ e   │ r   │ t   │ z   │ u   │ i   │ o   │ p   │ ü   │ +   ┃ ⏎     ┃ Pg↑┃
# ┣━━━━━━━━┻┱────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┺┓      ┣━━━━┫
# ┃      66 ┃  38 │  39 │  40 │  41 │  42 │  43 │  44 │  45 │  46 │  47 │  48 │  51 ┃      ┃ 117┃
# ┃ ⇬       ┃ a   │ s   │ d   │ f   │ g   │ h   │ j   │ k   │ l   │ ö   │ ä   │ #   ┃      ┃ Pg↓┃
# ┣━━━━━━┳━━┹──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┲━━┷━━━━━┻━┳━━━━╋━━━━┫
# ┃   50 ┃  94 │  52 │  53 │  54 │  55 │  56 │  57 │  58 │  59 │  60 │  61 ┃       62 ┃ 111┃ 115┃
# ┃ ⇧    ┃ <   │ y   │ x   │ c   │ v   │ b   │ n   │ m   │ ,   │ .   │ -   ┃ ⇧        ┃ ↑  ┃ End┃
# ┣━━━━━┳┻━━━━┳┷━━━━┳┷━━━━┱┴─────┴─────┴─────┴─────┴─────┴──┲━━┷━━━┳━┷━━━━┳┻━━━━━┳━━━━╋━━━━╋━━━━┫
# ┃  37 ┃     ┃ Mod4┃ Mod1┃                              65 ┃  108 ┃  135 ┃  105 ┃ 113┃ 116┃ 114┃
# ┃ Ctrl┃ FN  ┃super┃ Alt ┃ Space                           ┃ AltGr┃ menu ┃ Ctrl ┃ ←  ┃ ↓  ┃ →  ┃
# ┗━━━━━┻━━━━━┻━━━━━┻━━━━━┹─────────────────────────────────┺━━━━━━┻━━━━━━┻━━━━━━┻━━━━┻━━━━┻━━━━┛
# }}}

# Defaults appearence, floating windows and general X-settings (X11) {{{
set $c_bg1  "#282A2E"
set $c_bg2  "#373B41"
set $c_fg   "#C5C8C6"
set $c_pri  "#F0C674"
set $c_sec  "#8ABEB7"
set $c_warn "#A54242"
set $c_dis  "#707880"
set $font "pango:monospace 11"
font $font
                      # border  back     text    indicator  child_border
client.focused          $c_bg2  $c_pri   $c_bg1  $c_warn    $c_bg2
client.focused_inactive $c_sec  $c_bg2   $c_fg   $c_warn    $c_bg1
client.unfocused        $c_bg2  $c_bg1   $c_fg   $c_sec     $c_bg1
client.urgent           $c_pri  $c_warn  $c_bg1  $c_pri     $c_pri
client.placeholder      $c_bg1  $c_bg1   $c_fg   $c_fg      $c_bg1
client.background       $c_bg1

default_border none
default_floating_border normal

for_window [window_role="^About"]                  floating enable
for_window [instance="^Update"]                    floating enable
for_window [instance="^gcalctool"]                 floating enable
for_window [instance="^gnome-keyring"]             floating enable
for_window [instance="^file_progress"]             floating enable
for_window [instance="^arandr"]                    floating enable resize set width 900
for_window [class="jetbrains-idea" title="splash"] floating enable
for_window [class="^Microsoft Teams - Preview$"]   floating enable

# If I have opened the nm-openconnect-auth-dialog I set focus by myself,
# otherwise it appeared automatically and I don't want the focus!
no_focus [instance="^nm-openconnect-auth-dialog"]

# Status-Bar
bar {
    # I'll use polybar instead of i3status
    i3bar_command $HOME/.config/polybar/launch.sh
}
# ensure a neat network-tray icon
exec nm-applet || true

# warn when battery dies, I do nothing else but this will give me time to save everthing :)
exec --no-startup-id ~/Development/nemoinho/github.com/rjekker/i3-battery-popup -Nn -f "$font" -s ~/Development/nemoinho/github.com/rjekker/i3-battery-popup.wav

# set some nice looking background
exec_always --no-startup-id feh --bg-fill ~/.config/i3/green-wheat.jpg

# gaps and transparency 
gaps inner 10
gaps outer 5
# compton allows some transparent windows if I like :)
exec_always --no-startup-id compton --config ~/.config/compton.conf -b

# TODO: move the following to Xresources or similar, it feels clunky here
# switch to screensaver after 1 hour w/o interaction 
exec_always xset s 3600 3600
# switch off screen after 1 hour w/o interaction
exec_always xset dpms 3600 3630 3660
# set a blazing fast keyboard repeat rate, and make it happen more quickly (defaults: 660/25) 
exec_always xset r rate 250 100

# }}}

# $mod                                (super) {{{
floating_modifier $mod

# }}}
# Layout                              ($mod+[asdf]) {{{
bind $mod+38 layout stacking
bind $mod+39 layout tabbed
bind $mod+40 layout default
bind $mod+41 fullscreen

# }}}
# Split container horizontal/vertical ($mod[+shift]+o) {{{
bind $mod+32 split v
bind $mod+Shift+32 split h

# }}}
# Focus outer container               ($mod+ö|$mod+control+shift+o) {{{
bind $mod+Shift+Control+32 focus parent
bind $mod+47 focus parent
#bind $mod+Control+32 focus parent

# }}}
# Fullscreen                          ($mod+shift+f) {{{
bind $mod+Shift+41 fg

# }}}
# Toggle floating                     ($mod+shift+space) {{{
bind $mod+Shift+65 floating toggle

# }}}
# Toggle floating focus               ($mod+control+space) {{{
bind $mod+Control+65 focus mode_toggle

# }}}
# Change focus                        ($mod+[hjkl|arrows]) {{{
bind $mod+43 focus left
bind $mod+44 focus down
bind $mod+45 focus up
bind $mod+46 focus right
bind $mod+113 focus left
bind $mod+116 focus down
bind $mod+111 focus up
bind $mod+114 focus right

# }}}
# Change workspace [1…12]             ($mod+[1234567890ß´]) {{{
bind $mod+10 workspace $w01
bind $mod+11 workspace $w02
bind $mod+12 workspace $w03
bind $mod+13 workspace $w04
bind $mod+14 workspace $w05
bind $mod+15 workspace $w06
bind $mod+16 workspace $w07
bind $mod+17 workspace $w08
bind $mod+18 workspace $w09
bind $mod+19 workspace $w10
bind $mod+20 workspace $w11
bind $mod+21 workspace $w12

# }}}
# Move window within workspace        ($mod+shift+[hjkl|arrows]) {{{
bind $mod+Shift+43 move left
bind $mod+Shift+44 move down
bind $mod+Shift+45 move up
bind $mod+Shift+46 move right
bind $mod+Shift+113 move left
bind $mod+Shift+116 move down
bind $mod+Shift+111 move up
bind $mod+Shift+114 move right

# }}}
# Move window to workspace            ($mod+shift+[1234567890ß´]) {{{
bind $mod+Shift+10 move container to workspace $w01
bind $mod+Shift+11 move container to workspace $w02
bind $mod+Shift+12 move container to workspace $w03
bind $mod+Shift+13 move container to workspace $w04
bind $mod+Shift+14 move container to workspace $w05
bind $mod+Shift+15 move container to workspace $w06
bind $mod+Shift+16 move container to workspace $w07
bind $mod+Shift+17 move container to workspace $w08
bind $mod+Shift+18 move container to workspace $w09
bind $mod+Shift+19 move container to workspace $w10
bind $mod+Shift+20 move container to workspace $w11
bind $mod+Shift+21 move container to workspace $w12

# }}}
# Move workspace to screen            ($mod+[shift|control]+[ui]) {{{
bind $mod+Shift+30   move workspace to output left
bind $mod+Shift+31   move workspace to output right
bind $mod+Control+30 move workspace to output up
bind $mod+Control+31 move workspace to output down

# }}}
# Reload i3 configuration             ($mod+shift+r) {{{
bind $mod+Shift+27 reload

# }}}
# Restart i3                          ($mod+shift+backspace) {{{
bind $mod+Shift+22 restart

# }}}
# Exit i3                             ($mod+control+backspace) {{{
bind $mod+Control+22 exit

# }}}
# Change border                       ($mod+b) {{{
bind $mod+56 border toggle

# }}}
# Start terminal                      ($mod+enter) {{{
bind $mod+36 exec $terminal
bind $mod+48 split h; exec $terminal
bind $mod+51 split v; exec $terminal

# }}}
# Start application                   ($mod+p) {{{
bind $mod+33 exec $rofi -show run

# }}}
# Lock screen                         ($mod+Control+Shift+l) {{{
bindsym $mod+Shift+Control+l exec $lock
bindsym $mod+Shift+Control+p exec $lock --configure

# }}}
# Kill window                         ($mod+shift+q) {{{
bind $mod+Shift+24 kill

# }}}
# Suspend / Shutdown                  ($mod+F12) {{{
bindsym $mod+F12 exec "bash -c '$lock & sleep 3; systemctl suspend; $autorandr --change'"
bindsym $mod+Control+F12 exec bash -c "shutdown -h now &"

# }}}
# Manage sound                        ($mod+[F1,F3,F5,F6]|Audio-Keys) {{{
bindsym XF86AudioRaiseVolume exec ~/.config/i3/audio set-sink-volume +3%
bindsym XF86AudioLowerVolume exec ~/.config/i3/audio set-sink-volume -3%
bindsym XF86AudioMute exec ~/.config/i3/audio set-sink-mute toggle
bindsym $mod+F6 exec ~/.config/i3/audio set-sink-volume +3%
bindsym $mod+F5 exec ~/.config/i3/audio set-sink-volume -3%
bindsym $mod+F3 exec ~/.config/i3/audio set-sink-mute toggle
bindsym $mod+F1 exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
# }}}
# Manage monitors                     ($mod+[control]+[F2,F8,F9]) {{{
bindsym XF86MonBrightnessUp exec sudo ~/.local/bin/backlight inc
bindsym XF86MonBrightnessDown exec sudo ~/.local/bin/backlight dec
bindsym $mod+F9 exec sudo ~/.local/bin/backlight inc
bindsym $mod+F8 exec sudo ~/.local/bin/backlight dec
bindsym $mod+F2 exec bash -c '$autorandr --change && sleep 1 && i3-msg restart'
bindsym $mod+Control+F2 exec bash -c '$autorandr | $rofi -dmenu | xargs -r $autorandr --load && sleep 1 && i3-msg restart'
bindsym $mod+Control+Shift+F2 exec bash -c '$autorandr --load laptop && sleep 1 && i3-msg restart'

# }}}
# Switching keyboard layout           ($mod+[F10]) {{{

# my laptop has a broken keyboard and this is a workaround
exec switch-keyboard-variant nemoinho
bindsym $mod+F10 exec switch-keyboard-variant

# }}}
# Shortcuts to different applications ($mod+Control+[cdefmv]|$mod+Control+Shift+f){{{

bind $mod+61 move scratchpad
bind $mod+35 exec ~/.local/bin/wiki
bindsym $mod+Control+f exec $(screenshot)
bindsym $mod+Shift+Control+f exec $(screenshot --focused)
bindsym $mod+Control+v exec $($terminal -e vim)
bindsym $mod+Control+c exec $($terminal --title "i3-config" -e vim ~/.config/i3/config)
bindsym $mod+Control+m exec $($terminal --title btop -e btop)
bindsym $mod+Control+d exec $($terminal --title ctop -e ctop)
bindsym $mod+Control+e exec $($terminal -e mutt)

# }}}

# Start podman {{{
# TODO: there is probaply also another "better" place for this
exec --no-startup-id systemctl --user start podman.socket
#}}}
