# i3 config file (v4)
#    _ _____    ____             __ _                       _   _             
#   (_)___ /   / ___|___  _ __  / _(_) __ _ _   _ _ __ __ _| |_(_) ___  _ __  
#   | | |_ \  | |   / _ \| '_ \| |_| |/ _` | | | | '__/ _` | __| |/ _ \| '_ \ 
#  _| |___) | | |__| (_) | | | |  _| | (_| | |_| | | | (_| | |_| | (_) | | | |
# (_)_|____/   \____\___/|_| |_|_| |_|\__, |\__,_|_|  \__,_|\__|_|\___/|_| |_|
#                                     |___/                                   

set $mod Mod4
set $TERMINAL alacritty
#set $TERMINAL urxvt

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
font pango:Jetbrains Mono 10
# font pango:Terminus 10
# font Terminus
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# start a terminal
bindsym $mod+Return exec "$TERMINAL &"
bindsym $mod+Shift+Return exec "$TERMINAL --role=floating &"

# kill focused window
bindsym $mod+Shift+q kill

# start dmenu (a program launcher)
#bindsym $mod+d exec --no-startup-id rofi -show drun   -theme themes/app-launcher
bindsym $mod+d exec --no-startup-id rofi-appsmenu
bindsym $mod+i exec --no-startup-id rofi -show window -theme /usr/share/rofi-menus-git/themes/appsmenu.rasi
bindsym $mod+a exec --no-startup-id ~/.config/rofi/scripts/traefik.sh
bindsym $mod+Shift+o exec --no-startup-id rofi-vpn
bindsym $mod+o exec --no-startup-id ~/.config/rofi/scripts/sound.sh
bindsym $mod+c exec --no-startup-id rofi -show ssh -theme /usr/share/rofi-menus-git/themes/appsmenu.rasi 
 
set $workspacer ~/.config/i3/i3-workspacer.py

# go to new workspace blocks
#bindsym $mod+Tab exec --no-startup-id $workspacer go -d up
#bindsym $mod+m exec --no-startup-id $workspacer go -d down

# move to new workspace blocks
#bindsym $mod+Shift+Tab exec --no-startup-id $workspacer move -d up
#bindsym $mod+Shift+m exec --no-startup-id $workspacer move -d down

# switch to workspace
bindsym $mod+grave exec --no-startup-id ~/.config/i3/i3-goto-workspace
bindsym $mod+1 exec --no-startup-id $workspacer go -n 1
bindsym $mod+2 exec --no-startup-id $workspacer go -n 2
bindsym $mod+3 exec --no-startup-id $workspacer go -n 3
bindsym $mod+4 exec --no-startup-id $workspacer go -n 4
bindsym $mod+5 exec --no-startup-id $workspacer go -n 5
bindsym $mod+6 exec --no-startup-id $workspacer go -n 6
bindsym $mod+7 exec --no-startup-id $workspacer go -n 7
bindsym $mod+8 exec --no-startup-id $workspacer go -n 8
bindsym $mod+9 exec --no-startup-id $workspacer go -n 9
bindsym $mod+0 exec --no-startup-id $workspacer go -n 10

# move focused container to workspace
bindsym $mod+Shift+grave exec --no-startup-id ~/.config/i3/i3-moveto-workspace
bindsym $mod+Shift+1 exec --no-startup-id $workspacer move -n 1
bindsym $mod+Shift+2 exec --no-startup-id $workspacer move -n 2
bindsym $mod+Shift+3 exec --no-startup-id $workspacer move -n 3
bindsym $mod+Shift+4 exec --no-startup-id $workspacer move -n 4
bindsym $mod+Shift+5 exec --no-startup-id $workspacer move -n 5
bindsym $mod+Shift+6 exec --no-startup-id $workspacer move -n 6
bindsym $mod+Shift+7 exec --no-startup-id $workspacer move -n 7
bindsym $mod+Shift+8 exec --no-startup-id $workspacer move -n 8
bindsym $mod+Shift+9 exec --no-startup-id $workspacer move -n 9
bindsym $mod+Shift+0 exec --no-startup-id $workspacer move -n 10

# renaming workspace
bindsym $mod+n exec --no-startup-id ~/.config/i3/i3-rename-workspace
bindsym $mod+Shift+n exec --no-startup-id ~/.config/i3/i3-renumber-workspace
# move focused window
bindsym $mod+j move left
bindsym $mod+k move down
bindsym $mod+l move up
bindsym $mod+semicolon move right

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

# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

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

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

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

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

# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
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"

# 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 'Exit i3 and end your X session?' -b 'Yes' 'i3-msg exit'"

# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode

        bindsym j resize shrink width 10 px or 10 ppt
        bindsym k resize grow height 10 px or 10 ppt
        bindsym l resize shrink height 10 px or 10 ppt
        bindsym semicolon 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 Shift+j resize shrink width 1 px or 1 ppt
        bindsym Shift+k resize grow height 1 px or 1 ppt
        bindsym Shift+l resize shrink height 1 px or 1 ppt
        bindsym Shift+semicolon resize grow width 1 px or 1 ppt

        bindsym Shift+Left resize shrink width 1 px or 1 ppt
        bindsym Shift+Down resize grow height 1 px or 1 ppt
        bindsym Shift+Up resize shrink height 1 px or 1 ppt
        bindsym Shift+Right resize grow width 1 px or 1 ppt

        # back to normal: Enter or Escape or $mod+r 
        bindsym Return mode "default"
        bindsym Escape mode "default"
        bindsym $mod+r mode "default"
}

bindsym $mod+r mode "resize"

#   _ _____    ____          _                    ____  _     _ _   
#  (_)___ /   / ___|   _ ___| |_ ___  _ __ ___   / ___|| |__ (_) |_ 
#  | | |_ \  | |  | | | / __| __/ _ \| '_ ` _ \  \___ \| '_ \| | __|
# _| |___) | | |__| |_| \__ \ || (_) | | | | | |  ___) | | | | | |_ 
#(_)_|____/   \____\__,_|___/\__\___/|_| |_| |_| |____/|_| |_|_|\__|
#                                                                   
# gaps
gaps inner 10

workspace 1 output eDP1
workspace 2 output eDP1
workspace 3 output DP1-1

# workspace settings
workspace_auto_back_and_forth yes
show_marks yes

# settings
hide_edge_borders both
for_window [class="^.*"] title_format "%title [%class]"
for_window [class="^.*"] border pixel 0
for_window [class="Telegram"] move scratchpad, border pixel 1
for_window [class="Mattermost"] move scratchpad, border pixel 1
for_window [class="discord"] move scratchpad, border pixel 1
for_window [window_role="floating"] floating enable
for_window [class="QSyncthingTray"] floating enable
for_window [class="Thunderbird" window_type="normal"] move scratchpad, floating enable, resize set 1600 1050, border pixel 2
for_window [class="Nautilus"] floating enable
for_window [class="Gnome-calculator"] floating enable
for_window [class="zoom"] move scratchpad, floating enable
for_window [class="Signal"] move scratchpad
#for_window [instance="joplin"] resize set 1300 900, move scratchpad, move position center

# keybinds
bindsym Mod1+Tab workspace back_and_forth
bindsym $mod+Tab focus right
bindsym $mod+Ctrl+Tab focus left
bindsym Print exec "~/bin/screenshot.sh"
#bindsym $mod+Print exec "owo -sq --fullscreen --no-cursor"

bindsym $mod+minus [class="Telegram"] scratchpad show
bindsym $mod+p [class="Mattermost"] scratchpad show
bindsym $mod+Shift+d [class="discord"] scratchpad show
bindsym $mod+Shift+s [class="Joplin"] scratchpad show
bindsym $mod+Shift+z [class="zoom"] scratchpad show
bindsym $mod+Shift+x [class="Signal"] scratchpad show
bindsym $mod+Shift+m [class="Thunderbird"] scratchpad show

bindsym $mod+Delete exec rofi -modi system:$HOME/.config/rofi/scripts/powermenu.sh -show system -theme themes/system-menu
bindsym $mod+shift+Delete exec betterlockscreen -l

# audio binds
#bindsym XF86AudioMicMute exec --no-startup-id pulseaudio-ctl mute-input 
#bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume alsa_output.pci-0000_00_1f.3.analog-stereo +10% && pactl set-sink-mute 1 0
#bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume alsa_output.pci-0000_00_1f.3.analog-stereo -10% && pactl set-sink-mute 1 0
#bindsym XF86AudioMute        exec --no-startup-id pactl set-sink-mute alsa_output.pci-0000_00_1f.3.analog-stereo toggle

# backlight binds
#bindsym XF86MonBrightnessDown exec --no-startup-id ~/bin/brightness.sh down
#bindsym XF86MonBrightnessUp exec --no-startup-id ~/bin/brightness.sh up

# Use pactl to adjust volume in PulseAudio.
set $refresh_i3status killall -SIGUSR1 i3status
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -10% && $refresh_i3status
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle && $refresh_i3status
bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $refresh_i3status
bindsym XF86MonBrightnessUp exec xrandr --output eDP1 --brightness 1.9 # increase screen brightness
bindsym XF86MonBrightnessDown exec xrandr --output eDP1 --brightness 1.4 # decrease screen brightness

# startup

exec_always --no-startup-id $HOME/.config/polybar/launch.sh
exec --no-startup-id ~/bin/autoconfgure_display.sh
exec --no-startup-id i3-msg 'workspace 1; exec $TERMINAL; workspace 2; exec chromium;'
#exec --no-startup-id feh --bg-scale ~/Wallpapers/seneca.jpg
exec --no-startup-id picom --config ~/.config/i3/picom.conf -b
#exec --no-startup-id xset dpms 500
exec --no-startup-id nm-applet --sm-disable
exec --no-startup-id pasystray
exec --no-startup-id joplin-desktop
exec --no-startup-id clipit
#exec --no-startup-id xautolock -time 10 -locker "betterlockscreen -l dim"
exec --no-startup-id ~/bin/dunstwal
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

exec telegram-desktop
#exec mattermost-desktop

exec --no-startup-id sleep 4; i3-msg '[class="Telegram"] move scratchpad'
exec --no-startup-id sleep 6; i3-msg '[class="Joplin"] move scratchpad'
exec --no-startup-id sleep 12; i3-msg '[class="Mattermost"] move scratchpad'
exec --no-startup-id sleep 4; i3-msg '[instance="joplin"] resize set 1300 900'

exec_always --no-startup-id wal -R -n


exec --no-startup-id sleep 4
exec --no-startup-id sleep 4
exec --no-startup-id ~/bin/theme
