# === ~/.config/sway/config ===
# MINIMAL — single file, no includes. Tier-1+2+3 in one go.
# We can split into includes later once this is proven to boot.

# === variables ===
set $mod Mod4
set $term foot
set $menu wofi --show drun --insensitive -p "launch"
set $browser zen
set $fileManager thunar

# === output / input ===
# Gruvbox wallpaper — sway's native bg command manages swaybg lifecycle internally
output * bg $HOME/.local/share/wallpapers/teach-invaders-gruvbox.png fill

# Touchpad: tap-to-click, natural scroll, drag
input type:touchpad {
    tap enabled
    tap_button_map lrm
    natural_scroll enabled
    dwt enabled
    accel_profile adaptive
}

# === window borders (gruvbox-hard) ===
default_border pixel 2
default_floating_border pixel 2
gaps inner 8
gaps outer 4
smart_borders on
smart_gaps on

# gruvbox-orange focus border (replaces the default "generic blue")
client.focused          #d79921 #1d2021 #ebdbb2 #d79921 #d79921
client.unfocused        #3c3836 #1d2021 #a89984 #3c3836 #3c3836
client.focused_inactive #504945 #1d2021 #a89984 #504945 #504945
client.urgent           #fb4934 #1d2021 #ebdbb2 #fb4934 #fb4934

# === swaybar (replaced by waybar — keeping as fallback) ===
# If waybar isn't installed yet, this provides a basic bar.
bar {
    swaybar_command waybar
}

# === autostart (kept tiny, all stderr silenced) ===
# Make user-local themes/icons visible to GTK and Qt
exec sh -c 'export XDG_DATA_DIRS="$HOME/.local/share:$HOME/.local/share/flatpak/exports/share:/usr/local/share:/usr/share"; export XDG_DATA_HOME="$HOME/.local/share"; export XDG_CONFIG_HOME="$HOME/.config"; systemctl --user import-environment XDG_DATA_DIRS XDG_DATA_HOME XDG_CONFIG_HOME 2>/dev/null; dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway'
exec /usr/libexec/polkit-gnome-authentication-agent-1
exec clipmenud
exec sh -c 'systemctl --user start xdg-desktop-portal xdg-desktop-portal-wlr 2>/dev/null || true'
exec sh -c 'gsettings set org.gnome.desktop.interface gtk-theme Gruvbox-Material-Dark-Hard 2>/dev/null; gsettings set org.gnome.desktop.interface icon-theme Gruvbox-Material-Dark 2>/dev/null; gsettings set org.gnome.desktop.interface color-scheme prefer-dark 2>/dev/null; true'
exec gnome-keyring-daemon --start --components=secrets
exec mako
exec wlsunset -l 39.96 -L -82.99
exec sworkstyle

# === idle / lock ===
# Single source of truth: start-swayidle.sh is also called by caffeine.sh
# to restart swayidle after toggling off the inhibit. Don't inline the
# swayidle command here — keep the two in sync via the wrapper.
exec $HOME/.config/sway/start-swayidle.sh

# === keybinds ===
bindsym $mod+Return exec $term
bindsym $mod+d exec $menu
bindsym $mod+e exec $fileManager
bindsym $mod+b exec $browser
bindsym $mod+q kill
bindsym $mod+Shift+c reload
bindsym Ctrl+Alt+l exec $HOME/.config/sway/lock-fancy.sh
bindsym $mod+slash exec $HOME/.config/sway/cheatsheet.sh
bindsym $mod+question exec $HOME/.config/sway/cheatsheet.sh
bindsym $mod+Shift+e exec swaynag -t warning -m 'Exit Sway?' -B 'Yes, exit Sway' 'swaymsg exit'

bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus 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

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

bindsym $mod+f fullscreen
bindsym $mod+v split toggle splitv
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+space exec $menu
bindsym $mod+Shift+space floating toggle

bindsym Print exec grim -g "$(slurp)" ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png
bindsym $mod+Print exec grim ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png
bindsym $mod+Shift+s exec grim -g "$(slurp)" - | wl-copy

mode "resize" {
    bindsym Left resize shrink width 30px
    bindsym Down resize grow height 30px
    bindsym Up resize shrink height 30px
    bindsym Right resize grow width 30px
    bindsym Escape mode "default"
    bindsym Return mode "default"
}
bindsym $mod+r mode "resize"

# === F12 dropdown terminal ===
# F12 opens a floating foot. Uses -a dropdown so for_window only floats
# the dropdown, not regular foot windows from Super+Enter.
# Close it with Super+Q or Ctrl+D.
bindsym F12 exec foot -a dropdown
bindsym $mod+grave exec foot -a dropdown
for_window [app_id="dropdown"] floating enable, sticky enable, resize set width 1100 height 600, move position center

# === media keys ===
bindsym --locked XF86AudioRaiseVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
bindsym --locked XF86AudioLowerVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindsym --locked XF86AudioMute exec wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindsym --locked XF86AudioMicMute exec wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
bindsym --locked XF86AudioPlay exec playerctl play-pause 2>/dev/null || true
bindsym --locked XF86AudioNext exec playerctl next 2>/dev/null || true
bindsym --locked XF86AudioPrev exec playerctl previous 2>/dev/null || true
bindsym --locked XF86MonBrightnessUp exec sh -c 'echo $(( $(cat /sys/class/backlight/acpi_video0/brightness) + 1 > $(cat /sys/class/backlight/acpi_video0/max_brightness) ? $(cat /sys/class/backlight/acpi_video0/max_brightness) : $(cat /sys/class/backlight/acpi_video0/brightness) + 1 )) | sudo tee /sys/class/backlight/acpi_video0/brightness'
bindsym --locked XF86MonBrightnessDown exec sh -c 'echo $(( $(cat /sys/class/backlight/acpi_video0/brightness) - 1 < 0 ? 0 : $(cat /sys/class/backlight/acpi_video0/brightness) - 1 )) | sudo tee /sys/class/backlight/acpi_video0/brightness'

# pointer / mouse — the gruvbox-material-gtk repo doesn't ship an xcursor theme,
# so leave the default alone. (Cursor shows fine on the default theme.)
