# =============================================================================
# Sway Konfiguration - Überarbeitet für bessere Benutzerfreundlichkeit
# =============================================================================
#


#
# Mod-Taste (Logo-Taste). Mod1 ist die Alt-Taste.
set $mod Mod4

# =============================================================================
# Arbeitsbereiche (Workspaces) mit Namen und Icons
# =============================================================================
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"

# =============================================================================
# Programme & Variablen
# =============================================================================
# Dein bevorzugter Terminal-Emulator
set $term alacritty
# Dein bevorzugter Anwendungs-Launcher
set $menu 'wofi --show drun --allow-images --icon-theme breeze-dark'
# Dein Sperrbildschirm-Programm
set $lock swaylock -f -c 000000

# Schriftart für Fenstertitel
font pango:DejaVu Sans Mono 12
default_border pixel 2

# Home-Row-Richtungstasten (wie in Vim)
set $left h
set $down j
set $up k
set $right l

# =============================================================================
# Ausgabekonfiguration (Monitore & Hintergrund)
# =============================================================================
# Standard-Hintergrundbild (ersetzt durch swww)
output * bg ~/Bilder/wallpapersden.com_astronaut-with-jellyfish_2560x1440.jpg fill

# Gaps (Lücken zwischen Fenstern)
# Alte Konfiguration auskommentiert:
# gaps inner 10
# gaps outer 5
gaps outer 0
smart_gaps on

#
# Um die Namen deiner Monitore zu finden, führe aus: swaymsg -t get_outputs
# Beispiel: output HDMI-A-1 resolution 1920x1080 position 1920,0

# =============================================================================
# Eingabekonfiguration (Tastatur & Maus)
# =============================================================================
# Deutsches Tastaturlayout
input * xkb_layout de

# Maus-Modifier zum Verschieben und Ändern der Größe von Fenstern
# Halte $mod + linke Maustaste zum Verschieben
# Halte $mod + rechte Maustaste zum Ändern der Größe
floating_modifier $mod normal

# =============================================================================
# Tastenkombinationen (Key Bindings)
# =============================================================================

# ----------------------------------------------------------------------------- 
# Grundlegende Aktionen
# ----------------------------------------------------------------------------- 
# Terminal starten
bindsym $mod+Return exec $term

# Aktives Fenster schließen
bindsym $mod+Shift+q kill

# Anwendungs-Launcher starten
bindsym $mod+d exec $menu

# Konfiguration neu laden
bindsym $mod+Shift+c reload

# Sway beenden (beendet deine Wayland-Sitzung)
bindsym $mod+Shift+e exec swaynag -t warning -m 'Möchtest du Sway wirklich beenden?' -B 'Ja, beenden' 'swaymsg exit'

# Bildschirm sperren
bindsym $mod+l exec $lock

# ----------------------------------------------------------------------------- 
# Fenster-Fokus bewegen
# ----------------------------------------------------------------------------- 
# Fokus mit Pfeiltasten bewegen
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# Fokus innerhalb eines gestapelten/getabbten Containers wechseln
bindsym $mod+Tab focus child

# ----------------------------------------------------------------------------- 
# Aktives Fenster verschieben
# ----------------------------------------------------------------------------- 
# Fenster mit Pfeiltasten verschieben
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# ----------------------------------------------------------------------------- 
# Arbeitsbereiche (Workspaces)
# ----------------------------------------------------------------------------- 
# Zu einem Arbeitsbereich wechseln
bindsym $mod+1 workspace $ws1
bindsym $mod+2 workspace $ws2
bindsym $mod+3 workspace $ws3
bindsym $mod+4 workspace $ws4
bindsym $mod+5 workspace $ws5
bindsym $mod+6 workspace $ws6
bindsym $mod+7 workspace $ws7
bindsym $mod+8 workspace $ws8
bindsym $mod+9 workspace $ws9
bindsym $mod+0 workspace $ws10

# Aktives Fenster in einen Arbeitsbereich verschieben
bindsym $mod+Shift+1 move container to workspace $ws1
bindsym $mod+Shift+2 move container to workspace $ws2
bindsym $mod+Shift+3 move container to workspace $ws3
bindsym $mod+Shift+4 move container to workspace $ws4
bindsym $mod+Shift+5 move container to workspace $ws5
bindsym $mod+Shift+6 move container to workspace $ws6
bindsym $mod+Shift+7 move container to workspace $ws7
bindsym $mod+Shift+8 move container to workspace $ws8
bindsym $mod+Shift+9 move container to workspace $ws9
bindsym $mod+Shift+0 move container to workspace $ws10

# Alter Code auskommentiert:
# # Zu einem Arbeitsbereich wechseln
# 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
# 
# # Aktives Fenster in einen Arbeitsbereich verschieben
# 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

# ----------------------------------------------------------------------------- 
# Fenster-Layout
# ----------------------------------------------------------------------------- 
# Fenster horizontal teilen
bindsym $mod+b splith
# Fenster vertikal teilen
bindsym $mod+v splitv

# Layout-Stil wechseln (stacking, tabbed, split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# Vollbildmodus umschalten
bindsym $mod+f fullscreen

# Fenster zwischen "tiling" und "floating" umschalten
bindsym $mod+Shift+space floating toggle

# Fokus zwischen "tiling" und "floating" Bereich wechseln
bindsym $mod+space focus mode_toggle

# ----------------------------------------------------------------------------- 
# Scratchpad (Ein "Versteck" für Fenster)
# ----------------------------------------------------------------------------- 
# Aktives Fenster ins Scratchpad verschieben
bindsym $mod+Shift+minus move scratchpad

# Fenster aus dem Scratchpad holen/verstecken
bindsym $mod+minus scratchpad show

# ----------------------------------------------------------------------------- 
# Modus: Fenstergröße ändern
# ----------------------------------------------------------------------------- 
mode "resize" {
    # Fenstergröße mit Pfeiltasten ändern
    bindsym Left resize shrink width 10px
    bindsym Right resize grow width 10px
    bindsym Up resize shrink height 10px
    bindsym Down resize grow height 10px

    # Fenstergröße mit Vim-Tasten (h,j,k,l) ändern
    bindsym $left resize shrink width 10px
    bindsym $right resize grow width 10px
    bindsym $up resize shrink height 10px
    bindsym $down resize grow height 10px

    # Modus verlassen
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
# Modus "resize" starten
bindsym $mod+r mode "resize"

# =============================================================================
# Hilfsprogramme & Systemtasten
# =============================================================================
# Lautstärke (benötigt pactl)
bindsym --locked XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym --locked XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle

# Bildschirmhelligkeit (benötigt brightnessctl)
bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+

# Screenshots (benötigt grim und slurp)
# Ganzen Bildschirm aufnehmen
bindsym Print exec grim ~/Bilder/screenshot-$(date +%Y%m%d-%H%M%S).png
# Einen Bereich auswählen und aufnehmen
bindsym Shift+Print exec grim -g "$(slurp)" ~/Bilder/screenshot-$(date +%Y%m%d-%H%M%S).png

# =============================================================================
# Statusleiste (z.B. waybar)
# =============================================================================
# Die Standard-Sway-Bar wird hier deaktiviert, da du waybar verwendest.
# Wenn du die Standard-Leiste nutzen willst, entferne die '#' vor dem bar-Block.
#
# bar {
#     position top
#     status_command while date +'%Y-%m-%d %X'; do sleep 1; done
#     colors {
#         statusline #ffffff
#         background #323232
#         inactive_workspace #32323200 #32323200 #5c5c5c
#     }
# }

# =============================================================================
# Autostart-Anwendungen
# =============================================================================
# Startet den Wallpaper-Manager
# exec mpvpaper -o "loop" DP-3 /home/jonnybravo/Bilder/270983_large.mp4

# exec waybar # Original command commented out
exec sleep 1 && waybar # Start Waybar with a 1-second delay
exec mako --config ~/.config/mako/config
# Startet den Display-Manager für automatische Profile
exec kanshi
# Startet einen Clipboard-Manager (clipman muss installiert sein)
exec wl-paste --watch clipman store
# Startet udiskie für Automounting
exec udiskie &
# Startet das Skript für die automatische Bluetooth-Verbindung
exec /home/jonnybravo/.config/sway/scripts/auto-bluetooth.sh &

# Alter Code auskommentiert:
# # Optional: Startet einen Clipboard-Manager (Zwischenablage-Verlauf)
# # exec wl-paste -t text --watch clipman store

# =============================================================================
# Idle-Management (Automatisches Sperren & Abschalten)
# =============================================================================
# Sperrt den Bildschirm nach 5 Minuten, schaltet ihn nach 10 Minuten aus
exec swayidle -w \
         timeout 300 '$lock' \
         timeout 600 'swaymsg "output * dpms off"' \
         resume 'swaymsg "output * dpms on"'


# Lade zusätzliche Konfigurations-Snippets
# include /etc/sway/config.d/*

# =============================================================================
# Fenster-Regeln (for_window)
# =============================================================================
#
# Um die 'app_id' oder 'class' eines Fensters herauszufinden, fokussiere es
# und führe im Terminal aus: swaymsg -t get_tree
#
# ----------------------------------------------------------------------------- 
# Spezifische Programme auf Workspaces zuweisen
# ----------------------------------------------------------------------------- 
# Brave Browser startet auf Workspace 2 (nicht schwebend)
for_window [app_id="brave-browser"] move to workspace $ws2 
# floating enable

# Firefox als schwebendes Fenster
for_window [app_id="firefox"] floating enable

# ----------------------------------------------------------------------------- 
# Bestimmte Fenster automatisch schweben lassen
# ----------------------------------------------------------------------------- 
# Dialogfenster und Benachrichtigungen
for_window [window_type="dialog"] floating enable
for_window [window_type="notification"] floating enable

# Taschenrechner
for_window [app_id="gnome-calculator"] floating enable

# KDE Systemeinstellungen
for_window [app_id="systemsettings"] floating enable

# Qalculate! (GTK Taschenrechner)
for_window [app_id="qalculate-gtk"] floating enable, resize set 400px 600px

# pulseaudio Einstellungen!
for_window [app_id="org.pulseaudio.pavucontrol"] floating enable, resize set 800px 600px

# VLC als schwebendes Fenster
for_window [class="vlc"] floating enable, resize set 800px 450px, position center

# Thunar als schwebendes Fenster
for_window [app_id="thunar"] floating enable, resize set 1000px 700px, position center
