// niri config — ported from the Hyprland/eww setup.
// Docs: https://niri-wm.github.io/niri/  ·  validate with `niri validate`.

input {
    keyboard {
        xkb {
            layout "ch"
        }
        numlock
    }
    touchpad {
        tap
    }
    mouse {}
}

// Outputs — scale 1.25 like the Hyprland setup. Mode omitted on purpose so niri
// picks the highest refresh rate automatically (144 Hz on DP-3). Positions are
// left to niri's auto-placement.
output "DP-3" {
    scale 1.25
}
output "HDMI-A-1" {
    scale 1.25
}

layout {
    gaps 10
    center-focused-column "never"

    preset-column-widths {
        proportion 0.33333
        proportion 0.5
        proportion 0.66667
    }
    default-column-width { proportion 0.5; }

    // Fuji violet accent on the focus ring.
    focus-ring {
        width 3
        active-color "#a39ec4"
        inactive-color "#505050"
    }
    border {
        off
    }

    // Subtle window shadow for depth.
    shadow {
        on
        softness 20
        spread 3
        offset x=0 y=4
        color "#00000070"
    }
}

// ---- autostart ------------------------------------------------------------
// Bring up the systemd user session so portals (dark mode via
// org.freedesktop.portal.Settings) and TANINUX user services start.
spawn-at-startup "dbus-update-activation-environment" "--systemd" "--all"
spawn-at-startup "systemctl" "--user" "start" "tanin-session.target"
spawn-at-startup "/bin/sh" "-c" "$HOME/.config/eww/launch.sh"
spawn-at-startup "waypaper" "--restore"
spawn-at-startup "wlsunset" "-l" "47" "-L" "8.3" "-d" "600" "-t" "4000" "-T" "6500"
spawn-at-startup "nm-applet"
spawn-at-startup "/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1"
spawn-at-startup "nextcloud" "--background"

hotkey-overlay {
    skip-at-startup
}

screenshot-path "~/Pictures/Screenshots/Screenshot from %Y-%m-%d %H-%M-%S.png"

animations {
    // On by default. Uncomment to disable everything:
    // off
}

// Ask apps to drop their client-side decorations (title/header bars); niri then
// draws only its own border/focus-ring. Apps that honour the protocol lose the
// top bar. (Some GTK apps ignore it and keep their headerbar — that's the app.)
prefer-no-csd

// Rounded corners for all windows.
window-rule {
    geometry-corner-radius 14
    clip-to-geometry true
}

// ---- eww frosted-glass / effects (enable after first boot) ----------------
// niri's layer-shell effects are version-sensitive; once niri runs we verify the
// real namespace with `niri msg --json layers` and enable blur/rounding/shadow.
// /-layer-rule {
//     match namespace="^gtk-layer-shell$"
//     geometry-corner-radius 14
//     shadow { on; softness 8; spread 0; offset x=0 y=2; color "#00000088"; }
// }

binds {
    Mod+Shift+Slash { show-hotkey-overlay; }

    // --- launchers / apps (Hyprland muscle memory) ---
    Mod+Backspace hotkey-overlay-title="Terminal: kitty"   { spawn "kitty"; }
    Mod+T         hotkey-overlay-title="Terminal: kitty"   { spawn "kitty"; }
    Mod+E         hotkey-overlay-title="Files: nautilus"   { spawn "nautilus"; }
    Mod+Space     hotkey-overlay-title="Apps: Spotlight"   { spawn-sh "$HOME/.config/eww/scripts/spotlight.sh open"; }
    Mod+C         hotkey-overlay-title="Calc: rofi"        { spawn-sh "rofi -show calc"; }

    // --- eww panels ---
    Mod+A hotkey-overlay-title="Control Center" { spawn-sh "$HOME/.config/eww/scripts/panel.sh toggle control-center"; }
    Mod+N hotkey-overlay-title="Calendar"       { spawn-sh "$HOME/.config/eww/scripts/panel.sh toggle calendar"; }
    Mod+Shift+R hotkey-overlay-title="Restart bar" { spawn-sh "$HOME/.config/eww/launch.sh"; }
    // Panic-close: dismiss any open/stuck eww overlay (niri has no global Escape
    // bind; a stuck :focusable spotlight would otherwise hold the keyboard).
    Mod+Escape hotkey-overlay-title="Close overlays" { spawn-sh "$HOME/.config/eww/scripts/dismiss.sh"; }

    // --- window management ---
    Mod+W { close-window; }
    Mod+F { toggle-window-floating; }
    Mod+Shift+F { fullscreen-window; }
    Mod+M { maximize-column; }
    Mod+V { switch-focus-between-floating-and-tiling; }
    Mod+R { switch-preset-column-width; }
    Mod+Minus { set-column-width "-10%"; }
    Mod+Equal { set-column-width "+10%"; }

    // --- focus (arrows + hjkl) ---
    Mod+Left  { focus-column-left; }
    Mod+Right { focus-column-right; }
    Mod+Up    { focus-window-up; }
    Mod+Down  { focus-window-down; }
    Mod+H { focus-column-left; }
    Mod+L { focus-column-right; }
    Mod+K { focus-window-up; }
    Mod+J { focus-window-down; }

    // --- move columns/windows ---
    Mod+Ctrl+Left  { move-column-left; }
    Mod+Ctrl+Right { move-column-right; }
    Mod+Ctrl+Up    { move-window-up; }
    Mod+Ctrl+Down  { move-window-down; }

    // --- workspaces (focus + move, Hyprland-style Shift to move) ---
    Mod+1 { focus-workspace 1; }
    Mod+2 { focus-workspace 2; }
    Mod+3 { focus-workspace 3; }
    Mod+4 { focus-workspace 4; }
    Mod+5 { focus-workspace 5; }
    Mod+6 { focus-workspace 6; }
    Mod+7 { focus-workspace 7; }
    Mod+8 { focus-workspace 8; }
    Mod+9 { focus-workspace 9; }
    Mod+Shift+1 { move-column-to-workspace 1; }
    Mod+Shift+2 { move-column-to-workspace 2; }
    Mod+Shift+3 { move-column-to-workspace 3; }
    Mod+Shift+4 { move-column-to-workspace 4; }
    Mod+Shift+5 { move-column-to-workspace 5; }
    Mod+Shift+6 { move-column-to-workspace 6; }
    Mod+Shift+7 { move-column-to-workspace 7; }
    Mod+Shift+8 { move-column-to-workspace 8; }
    Mod+Shift+9 { move-column-to-workspace 9; }

    Mod+Page_Down { focus-workspace-down; }
    Mod+Page_Up   { focus-workspace-up; }
    Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
    Mod+WheelScrollUp   cooldown-ms=150 { focus-workspace-up; }

    // --- multi-monitor ---
    Mod+Shift+Left  { focus-monitor-left; }
    Mod+Shift+Right { focus-monitor-right; }

    // --- screenshots (Mod+Y = region, like hyprshot) ---
    Mod+Y { screenshot; }
    Print { screenshot; }
    Ctrl+Print { screenshot-screen; }

    // --- media / volume / brightness (work when locked) ---
    XF86AudioRaiseVolume allow-when-locked=true { spawn-sh "wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+"; }
    XF86AudioLowerVolume allow-when-locked=true { spawn-sh "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"; }
    XF86AudioMute        allow-when-locked=true { spawn-sh "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"; }
    XF86AudioMicMute     allow-when-locked=true { spawn-sh "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"; }
    XF86AudioPlay        allow-when-locked=true { spawn-sh "playerctl play-pause"; }
    XF86AudioNext        allow-when-locked=true { spawn-sh "playerctl next"; }
    XF86AudioPrev        allow-when-locked=true { spawn-sh "playerctl previous"; }
    XF86MonBrightnessUp   allow-when-locked=true { spawn "brightnessctl" "set" "5%+"; }
    XF86MonBrightnessDown allow-when-locked=true { spawn "brightnessctl" "set" "5%-"; }

    // --- session ---
    Super+Alt+L { spawn "swaylock" "-f"; }
    Mod+Shift+E { quit; }
    Ctrl+Alt+Delete { quit; }
    Mod+Shift+P { power-off-monitors; }
}
