# ===========================================================================
#  i3 window manager — Catppuccin Macchiato
#  Font: Inconsolata Nerd Font
#  Docs: https://i3wm.org/docs/userguide.html
# ===========================================================================

set $mod Mod4
set $alt Mod1

# --- Catppuccin Macchiato palette -----------------------------------------
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     #181926

# --- fonts -----------------------------------------------------------------
font pango:Inconsolata Nerd Font 11

# --- applications ----------------------------------------------------------
set $term       kitty
set $filemanager thunar
set $menu       rofi -show drun
set $window_menu rofi -show window
set $runner     rofi -show run
set $powermenu  ~/.config/rofi/scripts/powermenu.sh
set $lock       betterlockscreen --lock dimblur

# ---------------------------------------------------------------------------
#  Appearance
# ---------------------------------------------------------------------------
# class                 border    backgr.   text      indicator child_border
client.focused          $mauve    $mauve    $crust    $lavender $mauve
client.focused_inactive $surface0 $surface0 $text     $surface0 $surface0
client.unfocused        $surface0 $base     $subtext0 $surface0 $surface0
client.urgent           $red      $red      $crust    $red      $red
client.placeholder      $base     $base     $text     $base     $base
client.background       $base

# Gaps + borders (i3 >= 4.22 has gaps built in)
default_border          pixel 2
default_floating_border pixel 2
hide_edge_borders       smart
gaps inner 8
gaps outer 4
smart_gaps on
smart_borders on

# Focus behaviour
focus_follows_mouse no
mouse_warping none
focus_on_window_activation smart
popup_during_fullscreen smart
workspace_auto_back_and_forth yes

# ---------------------------------------------------------------------------
#  Autostart
# ---------------------------------------------------------------------------
# exec_always => re-run on config reload; exec => only on i3 start.

# Wallpaper (feh restores whatever set-wallpaper.sh last applied)
exec_always --no-startup-id ~/.local/bin/set-wallpaper

# Compositor
exec_always --no-startup-id ~/.local/bin/restart-daemon picom

# Status bar
exec_always --no-startup-id ~/.config/polybar/launch.sh

# Notification daemon
exec_always --no-startup-id ~/.local/bin/restart-daemon dunst

# XDG autostart entries (nm-applet etc. that ship .desktop files)
exec --no-startup-id dex --autostart --environment i3

# PolicyKit authentication agent (GUI password prompts for gparted, etc.)
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

# Tray applets
exec --no-startup-id nm-applet
exec --no-startup-id blueman-applet
exec --no-startup-id udiskie --tray --no-automount --notify

# Auto-lock: lock on suspend and after 10 min of idle time
exec --no-startup-id xss-lock --transfer-sleep-lock -- $lock --nofork
exec --no-startup-id xset s 600 600
exec --no-startup-id numlockx on

# Cursor theme for the root window
exec_always --no-startup-id xsetroot -cursor_name left_ptr

# ---------------------------------------------------------------------------
#  Key bindings — launching
# ---------------------------------------------------------------------------
bindsym $mod+Return        exec --no-startup-id $term
bindsym $mod+Shift+Return  exec --no-startup-id $term --class kitty-float
bindsym $mod+e             exec --no-startup-id $filemanager
bindsym $mod+d             exec --no-startup-id $menu
bindsym $mod+Shift+d       exec --no-startup-id $runner
bindsym $mod+Tab           exec --no-startup-id $window_menu
bindsym $mod+Shift+e       exec --no-startup-id $powermenu
bindsym $mod+q             kill
bindsym $mod+Shift+q       exec --no-startup-id xkill

# Lock / session
bindsym $mod+Shift+x       exec --no-startup-id $lock
bindsym $mod+Shift+c       reload
bindsym $mod+Shift+r       restart

# ---------------------------------------------------------------------------
#  Key bindings — focus & movement
# ---------------------------------------------------------------------------
# vim keys …
bindsym $mod+h             focus left
bindsym $mod+j             focus down
bindsym $mod+k             focus up
bindsym $mod+l             focus right
# … and arrows
bindsym $mod+Left          focus left
bindsym $mod+Down          focus down
bindsym $mod+Up            focus up
bindsym $mod+Right         focus right

bindsym $mod+Shift+h       move left
bindsym $mod+Shift+j       move down
bindsym $mod+Shift+k       move up
bindsym $mod+Shift+l       move right
bindsym $mod+Shift+Left    move left
bindsym $mod+Shift+Down    move down
bindsym $mod+Shift+Up      move up
bindsym $mod+Shift+Right   move right

# ---------------------------------------------------------------------------
#  Key bindings — layout
# ---------------------------------------------------------------------------
bindsym $mod+b             split h
bindsym $mod+v             split v
bindsym $mod+f             fullscreen toggle
bindsym $mod+s             layout stacking
bindsym $mod+w             layout tabbed
bindsym $mod+g             layout toggle split
bindsym $mod+Shift+space   floating toggle
bindsym $mod+space         focus mode_toggle
bindsym $mod+a             focus parent
bindsym $mod+Shift+a       focus child
bindsym $mod+minus         scratchpad show
bindsym $mod+Shift+minus   move scratchpad

# Gap tweaks on the fly
bindsym $mod+plus          gaps inner current plus 4
bindsym $mod+Shift+plus    gaps inner current minus 4
bindsym $mod+Shift+g       gaps inner current set 8; gaps outer current set 4

# Drag floating windows with the modifier held
floating_modifier $mod
tiling_drag modifier titlebar

# ---------------------------------------------------------------------------
#  Workspaces
# ---------------------------------------------------------------------------
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: "

bindsym $mod+1 workspace number $ws1
bindsym $mod+2 workspace number $ws2
bindsym $mod+3 workspace number $ws3
bindsym $mod+4 workspace number $ws4
bindsym $mod+5 workspace number $ws5
bindsym $mod+6 workspace number $ws6
bindsym $mod+7 workspace number $ws7
bindsym $mod+8 workspace number $ws8
bindsym $mod+9 workspace number $ws9
bindsym $mod+0 workspace number $ws10

bindsym $mod+Shift+1 move container to workspace number $ws1
bindsym $mod+Shift+2 move container to workspace number $ws2
bindsym $mod+Shift+3 move container to workspace number $ws3
bindsym $mod+Shift+4 move container to workspace number $ws4
bindsym $mod+Shift+5 move container to workspace number $ws5
bindsym $mod+Shift+6 move container to workspace number $ws6
bindsym $mod+Shift+7 move container to workspace number $ws7
bindsym $mod+Shift+8 move container to workspace number $ws8
bindsym $mod+Shift+9 move container to workspace number $ws9
bindsym $mod+Shift+0 move container to workspace number $ws10

# Cycle workspaces
bindsym $mod+Ctrl+Right    workspace next
bindsym $mod+Ctrl+Left     workspace prev
bindsym $alt+Tab           workspace back_and_forth

# Move workspace between monitors
bindsym $mod+Ctrl+Shift+Right move workspace to output right
bindsym $mod+Ctrl+Shift+Left  move workspace to output left

# ---------------------------------------------------------------------------
#  Media / hardware keys
# ---------------------------------------------------------------------------
bindsym XF86AudioRaiseVolume exec --no-startup-id ~/.local/bin/volume up
bindsym XF86AudioLowerVolume exec --no-startup-id ~/.local/bin/volume down
bindsym XF86AudioMute        exec --no-startup-id ~/.local/bin/volume mute
bindsym XF86AudioMicMute     exec --no-startup-id ~/.local/bin/volume micmute
bindsym XF86AudioPlay        exec --no-startup-id playerctl play-pause
bindsym XF86AudioNext        exec --no-startup-id playerctl next
bindsym XF86AudioPrev        exec --no-startup-id playerctl previous
bindsym XF86MonBrightnessUp   exec --no-startup-id ~/.local/bin/brightness up
bindsym XF86MonBrightnessDown exec --no-startup-id ~/.local/bin/brightness down

# Screenshots (maim)
bindsym Print              exec --no-startup-id ~/.local/bin/screenshot full
bindsym Shift+Print        exec --no-startup-id ~/.local/bin/screenshot area
bindsym $mod+Print         exec --no-startup-id ~/.local/bin/screenshot window

# Notification control
bindsym $mod+n             exec --no-startup-id dunstctl history-pop
bindsym $mod+Shift+n       exec --no-startup-id dunstctl close-all
bindsym $mod+Ctrl+n        exec --no-startup-id dunstctl set-paused toggle

# Wallpaper shuffle
bindsym $mod+Shift+w       exec --no-startup-id ~/.local/bin/set-wallpaper --random

# ---------------------------------------------------------------------------
#  Modes
# ---------------------------------------------------------------------------
mode "resize" {
    bindsym h resize shrink width  4 px or 4 ppt
    bindsym j resize grow   height 4 px or 4 ppt
    bindsym k resize shrink height 4 px or 4 ppt
    bindsym l resize grow   width  4 px or 4 ppt

    bindsym Left  resize shrink width  4 px or 4 ppt
    bindsym Down  resize grow   height 4 px or 4 ppt
    bindsym Up    resize shrink height 4 px or 4 ppt
    bindsym Right resize grow   width  4 px or 4 ppt

    bindsym Return mode "default"
    bindsym Escape mode "default"
    bindsym $mod+r mode "default"
}
bindsym $mod+r mode "resize"

set $mode_display Display:  [a]uto  [d]uplicate  [e]xtend-right  [l]aptop-only
mode "$mode_display" {
    bindsym a exec --no-startup-id "~/.local/bin/display auto", mode "default"
    bindsym d exec --no-startup-id "~/.local/bin/display duplicate", mode "default"
    bindsym e exec --no-startup-id "~/.local/bin/display extend", mode "default"
    bindsym l exec --no-startup-id "~/.local/bin/display internal", mode "default"
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+p mode "$mode_display"

# ---------------------------------------------------------------------------
#  Window rules
# ---------------------------------------------------------------------------
for_window [class="^.*"] title_format "<span foreground='#cad3f5'>%title</span>"

# Float dialogs and small utilities
for_window [window_role="pop-up"]        floating enable
for_window [window_role="bubble"]        floating enable
for_window [window_role="dialog"]        floating enable
for_window [window_type="dialog"]        floating enable
for_window [window_type="menu"]          floating enable
for_window [window_type="utility"]       floating enable
for_window [window_type="toolbar"]       floating enable
for_window [window_type="splash"]        floating enable

for_window [class="Pavucontrol"]         floating enable, resize set 900 600, move position center
for_window [class="Blueman-manager"]     floating enable, resize set 800 560, move position center
for_window [class="Nm-connection-editor"] floating enable, resize set 800 560, move position center
for_window [class="Lxappearance"]        floating enable, move position center
for_window [class="Thunar" instance="^dialog$"] floating enable
for_window [class="File-roller"]         floating enable, move position center
for_window [class="Xarchiver"]           floating enable, move position center
for_window [class="kitty-float"]         floating enable, resize set 1000 620, move position center
for_window [title="^Picture-in-Picture$"] floating enable, sticky enable, resize set 640 360, move position 1250 700

# Assign apps to workspaces
assign [class="(?i)firefox|chromium|Brave-browser"] $ws2
assign [class="Thunar"] $ws4

# No focus stealing from these
no_focus [class="Steam"]

# ---------------------------------------------------------------------------
#  i3bar — disabled; polybar handles the status bar.
#  Kept as a commented fallback in case polybar ever fails to start.
# ---------------------------------------------------------------------------
# bar {
#     status_command i3status
#     colors {
#         background $base
#         statusline $text
#         focused_workspace  $mauve $mauve $crust
#         active_workspace   $surface0 $surface0 $text
#         inactive_workspace $base $base $subtext0
#         urgent_workspace   $red $red $crust
#     }
# }

# ---------------------------------------------------------------------------
#  Local overrides — anything in this directory wins, and it is never
#  overwritten by the bootstrap script.
# ---------------------------------------------------------------------------
include ~/.config/i3/config.d/*.conf
