# i3 config file (v4)

# Catppuccin Macchiato : https://github.com/catppuccin/i3/blob/main/themes/catppuccin-macchiato
set $rosewater #f4dbd6
set $flamingo  #f0c6c6
set $pink      #f5bde6
set $mauve     #c6a0f6
set $red       #ed8796
set $maroon    #ee99a0
set $peach     #f5a97f
set $yellow    #eed49f
set $green     #a6da95
set $teal      #8bd5ca
set $sky       #91d7e3
set $sapphire  #7dc4e4
set $blue      #8aadf4
set $lavender  #b7bdf8
set $text      #cad3f5
set $subtext1  #b8c0e0
set $subtext0  #a5adcb
set $overlay2  #939ab7
set $overlay1  #8087a2
set $overlay0  #6e738d
set $surface2  #5b6078
set $surface1  #494d64
set $surface0  #363a4f
set $base      #24273a
set $mantle    #1e2030
set $crust     #181926i

# target                 title     bg    text   indicator  border
client.focused           $lavender $base $text  $rosewater $lavender
client.focused_inactive  $overlay0 $base $text  $rosewater $overlay0
client.unfocused         $overlay0 $base $text  $rosewater $overlay0
client.urgent            $peach    $base $peach $overlay0  $peach
client.placeholder       $overlay0 $base $text  $overlay0  $overlay0
client.background        $base

##################################
# STARTING CONFIGURATION
##################################
# Mod1 = alt
set $mod Mod1

set $resize_mode Resize  —  [←]  [→]  [↑]  [↓]
set $film_mode Film Mode  —  [u]p  [d]own

# font for window titles.
font pango:Roboto, Bold 10

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

# no border nor title
new_window none
default_border pixel 0
default_floating_border pixel 5 

# hide borders when touching edges
hide_edge_borders both

# do not sync mouse position and focus
focus_follows_mouse no

# if a popup is coming when an app is fullscreen, leave the fullscreen
popup_during_fullscreen leave_fullscreen

# let urgency hint when switching to workspace
force_display_urgency_hint 500 ms

# script to lock the screen
set $Locker ~/.config/i3/lock/lock.sh

# settings for i3 gaps
gaps inner 10
gaps outer 0
smart_gaps on

##################################
# PROGRAMS STARTED AUTOMATICALLY
##################################

# Load Xresources
exec --no-startup-id xrdb -merge ~/.Xresources

# Start compositor
exec --no-startup-id picom --config ~/.config/picom.conf

# Start NetworkManager applet
exec --no-startup-id nm-applet

# Start polybar
exec_always --no-startup-id $HOME/.config/polybar/scripts/launch_polybar.sh

# set numlock on
exec --no-startup-id numlockx on

# turn to black screen after 9 minutes of doing nothing
exec --no-startup-id xset dpms 600

# autolock after 9 minutes of doing nothing
exec --no-startup-id xautolock -time 9 -locker $Locker -corners ----

# notifications
exec dunst

# set ALSA initial volume
exec --no-startup-id amixer -D hw:PCH -M sset Master 50%

# standard apps
exec --no-startup-id i3-msg 'workspace 1; exec i3-sensible-terminal'
exec firefox
exec thunderbird
exec signal-desktop
exec telegram-desktop
exec obsidian
exec --no-startup-id redshift-gtk
exec qbittorrent
exec pavucontrol
exec helvum
exec blueman-manager
# fetch keys from HSM
exec --no-startup-id gpg --card-status

# ensure keyboard layout
exec --no-startup-id setxkbmap fr
##################################
# BINDINGS FOR STARTING PROGRAMS
##################################
# start a terminal
bindsym $mod+Return exec --no-startup-id i3-sensible-terminal

# start rofi (a program launcher)
bindsym $mod+d exec rofi -show run
bindsym $mod+Shift+d exec rofimoji

# just lock the screen
bindsym $mod+l exec --no-startup-id $Locker && sleep 1

# lock and suspend to SWAP
bindsym $mod+Shift+l exec --no-startup-id $Locker && systemctl suspend

# open Explorer
bindsym $mod+e exec --no-startup-id nemo

# screenshot and save to file
bindsym Shift+Print exec ~/.config/i3/scripts/screenshot.py -s
# screenshot and upload to Lychee
bindsym Print exec ~/.config/i3/scripts/screenshot.py -u
# screenshot with flameshot
bindsym $mod+Shift+i exec flameshot gui

mode "$film_mode" {
  bindsym u exec ~/.config/i3/scripts/film_mode.sh on
  bindsym d exec ~/.config/i3/scripts/film_mode.sh off
  bindsym Escape mode "default"
}
# toggle film mode
bindsym $mod+Shift+f mode "$film_mode"

# pass
bindsym $mod+p exec passmenu

# playback control
bindsym Mod4+p exec playerctl play-pause
bindsym Mod4+Right exec playerctl next
bindsym Mod4+Left exec playerctl previous

##################################
# BINDINGS FOR STANDARD OPERATIONS
##################################
# kill focused window
bindsym $mod+q kill

# change focus
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move containers
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 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

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

# focus the parent container
bindsym $mod+a focus parent

# switch to workspace
bindsym $mod+ampersand workspace number 1
bindsym $mod+eacute workspace number 2
bindsym $mod+quotedbl workspace number 3
bindsym $mod+apostrophe workspace number 4
bindsym $mod+parenleft workspace number 5
bindsym $mod+minus workspace number 6
bindsym $mod+egrave workspace number 7
bindsym $mod+underscore workspace number 8
bindsym $mod+ccedilla workspace number 9
bindsym $mod+agrave workspace number 10

# move focused container to workspace
bindsym $mod+Shift+ampersand move container to workspace 1
bindsym $mod+Shift+eacute move container to workspace 2
bindsym $mod+Shift+quotedbl move container to workspace 3
bindsym $mod+Shift+apostrophe move container to workspace 4
bindsym $mod+Shift+5 move container to workspace 5
bindsym $mod+Shift+minus move container to workspace 6
bindsym $mod+Shift+egrave move container to workspace 7
bindsym $mod+Shift+underscore move container to workspace 8
bindsym $mod+Shift+ccedilla move container to workspace 9
bindsym $mod+Shift+agrave move container to workspace 10

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

# resize window (you can also use the mouse for that)
mode "$resize_mode" {
        bindsym Left resize shrink width 40 px or 20 ppt; move position center
        bindsym Down resize grow height 40 px or 20 ppt; move position center
        bindsym Up resize shrink height 40 px or 20 ppt; move position center
        bindsym Right resize grow width 40 px or 20 ppt; move position center
        bindsym Escape mode "default"
}

bindsym $mod+r mode "$resize_mode"


# ALSA keybinding (won't work with some keyboards... scroll in polybar in that case)
bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -D pulse -M sset Master 5%+
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -D pulse -M sset Master 5%-
bindsym XF86AudioMute exec --no-startup-id amixer -D pulse -M sset 'Master' toggle

##################################
# BINDINGS FOR NOTIFICATIONS
##################################

bindsym Ctrl+Shift+space exec dunstctl close-all
bindsym Ctrl+$mod+space exec dunstctl history-pop
bindsym Shift+BackSpace exec dunstctl close

##################################
# OPERATIONS FOR SPECIFIC WINDOWS
##################################

# some windows will float automatically
for_window [class="(?i)Thunderbird"] floating enable
for_window [window_role="About"] floating enable
for_window [window_role="Organizer"] floating enable
for_window [title="^Terminator *"] floating enable
for_window [window_role="pop-up"] floating enable
for_window [window_role="task_dialog"] floating enable
for_window [title="Preferences$"] floating enable
for_window [class="Telegram"] floating enable

for_window [class="(?i)Thunderbird"] move position center
for_window [window_role="GtkFileChooserDialog"] move position center

# === Scratchpad ===
# Make the currently focused window a scratchpad
bindsym $mod+Shift+BackSpace move scratchpad
for_window [class="Signal" window_type="normal"] move scratchpad
for_window [class="Telegram"] move scratchpad
# we don't use class="Thunderbird" to not move windows like "MsgCompose" to scratchpad : only the main window will be in scratchpad
for_window [instance="Mail"] move scratchpad
for_window [class="blueman-manager"] move scratchpad
for_window [instance="helvum"] floating enable, move scratchpad
for_window [instance="pavucontrol"] floating enable, move scratchpad
# only target main window
for_window [title="qBittorrent v*"] move scratchpad
bindsym $mod+Shift+m [instance="Mail"] scratchpad show, move position center
bindsym $mod+Shift+s [class="Signal"] scratchpad show, move position center
bindsym $mod+Shift+e [title="qBittorrent v*"] scratchpad show, move position center
bindsym $mod+Shift+t [class="Telegram"] scratchpad show, move position center
bindsym Mod4+ampersand [title="(?i)perso.*obsidian"] scratchpad show, move container to workspace 4, workspace 4, floating disable
bindsym Mod4+eacute [title="(?i)tech.*obsidian"] scratchpad show, move container to workspace 4, workspace 4, floating disable
bindsym Mod4+quotedbl [title="(?i)notes.*obsidian"] scratchpad show, move container to workspace 4, workspace 4, floating disable

# Thanks to this epic discussion, with an unexpected ending, I am happily
# able to resize floating windows by percentage of the screen width/height,
# making it compatible with the shared configuration
# https://github.com/i3/i3/issues/2816
for_window [instance="Mail" window_type="normal"] resize set 90 ppt 85 ppt
for_window [class="Signal"] resize set 90 ppt 85 ppt
for_window [class="Telegram"] resize set 90 ppt 85 ppt

# automatic workspace
assign [class="(?i)Obsidian"] → number 4
assign [class="(?i)Tor Browser"] → number 5
assign [class="(?i)Firefox" window_role="browser"] → number 3
assign [class="(?i)VSCodium"] → number 2

bindsym $mod+j [instance="pavucontrol"] scratchpad show, move position center
bindsym $mod+Shift+j [instance="helvum"] scratchpad show, move position center