-- ~/.config/hypr/hyprland.lua
hl.on("hyprland.start", function()
hl.exec_cmd('gsettings set org.gnome.desktop.interface color-scheme "prefer-dark"')
hl.exec_cmd('gsettings set org.gnome.desktop.interface gtk-theme "Adwaita-dark"')
end)
hl.bind("SUPER + L", hl.dsp.exec_cmd("pidof hyprlock || hyprlock"))
hl.env("GTK_THEME", "Adwaita-dark")

-- WARNING THIS CONFIG IS MADE SPECIFICALLY FOR MY SETUP!!!! REVIEW BEFORE COPYING

hl.env("QT_QPA_PLATFORMTHEME", "kde")
hl.window_rule({
    name = "ytmdesktop-always-on-top",
    match = { class = "^(ytmdesktop2)$" },
               pin = true,
})


for i = 1, 10 do
    local key = i % 10
    hl.bind("SUPER + " .. key, hl.dsp.focus({ workspace = i }))
    end


hl.monitor({
    output = "DP-1",
    mode = "1920x1080@144",
    position = "auto",
    scale = 1,
})
hl.monitor({
    output = "HDMI-A-1",
    mode = "preferred",
    position = "auto-right",
    scale = 1.25,
})
hl.env("LIBVA_DRIVER_NAME", "nvidia")
hl.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia")
hl.env("NVD_BACKEND", "direct")
hl.env("__GL_MaxFramesAllowed", "1")


hl.env("XCURSOR_SIZE", "24")
hl.env("HYPRCURSOR_SIZE", "24")


-- Autostart core utilities
hl.on("hyprland.start", function()
hl.exec_cmd("waybar")
hl.exec_cmd("mako")
hl.exec_cmd("hyprpaper")
hl.exec_cmd("systemctl --user start hyprpolkitagent")
end)

-- Purple visual theme & input settings
hl.config({
    general = {
        gaps_in = 4,
        gaps_out = 5,
        border_size = 1,5,
        col = {
            active_border = { colors = { "rgba(b471f0ff)", "rgba(e879f9ee)" }, angle = 45 },
          inactive_border = "rgba(3e0f66ff)",
        },
        layout = "dwindle",
    },

    decoration = {
        rounding = 1,4,
        blur = {
            enabled = true,
            size = 2,
            passes = 2,
        },
        shadow = {
            enabled = true,
            range = 5,
            render_power = 3,
            color = "rgba(7e22ce66)",
        },
    },

    animations = {
        enabled = true,
    },

    input = {
        kb_layout = "us",
        follow_mouse = 1,
        touchpad = {
            natural_scroll = true,
        },
    },
})


local mainMod = "SUPER"



-- shortcuts
hl.bind(mainMod .. " + Q", hl.dsp.exec_cmd("kitty"))
hl.bind(mainMod .. " + M", hl.dsp.exit())
hl.bind(mainMod .. " + V", hl.dsp.window.float({ action = "toggle" }))
hl.bind(mainMod .. " + F", hl.dsp.window.fullscreen({ mode = "fullscreen", action = "toggle" }))
hl.bind(mainMod .. " + SHIFT + R", hl.dsp.exec_cmd("hyprctl reload"))
hl.bind(mainMod .. " + SHIFT + S", hl.dsp.exec_cmd("flameshot gui"))
hl.bind("SUPER + SHIFT + 4", hl.dsp.window.move({ workspace = 4, follow = true }))
-- language changer English -> Russian -> Ukrainian -> German
hl.config({
    input = {
        kb_layout = "us,ru,ua,de",
        kb_options = "grp:ctrl_shift_toggle",
    }
})
hl.on("window.active", function(window)
if window and window.class == "kitty" then
    hl.config({ input = { kb_options = "" } })
    else
        hl.config({ input = { kb_options = "grp:ctrl_shift_toggle" } })
        end
        end)

-- Fast animation curves
hl.curve("snappy", { type = "bezier", points = { { 0.05, 0.9 }, { 0.1, 1.0 } } })
hl.curve("instant", { type = "bezier", points = { { 0, 0 }, { 0.15, 1 } } })
hl.curve("fastOvershot", { type = "bezier", points = { { 0.05, 0.95 }, { 0.1, 1.03 } } })

-- idk
hl.animation({ leaf = "global", enabled = true, speed = 2, bezier = "snappy" })
hl.animation({ leaf = "border", enabled = true, speed = 3, bezier = "snappy" })
hl.animation({ leaf = "windows", enabled = true, speed = 2, bezier = "fastOvershot", style = "popin 88%" })
hl.animation({ leaf = "windowsIn", enabled = true, speed = 2, bezier = "fastOvershot", style = "popin 88%" })
hl.animation({ leaf = "windowsOut", enabled = true, speed = 1.5, bezier = "instant", style = "popin 88%" })
hl.animation({ leaf = "windowsMove", enabled = true, speed = 2, bezier = "snappy" })
hl.animation({ leaf = "fade", enabled = true, speed = 1.5, bezier = "instant" })
hl.animation({ leaf = "layers", enabled = true, speed = 1.5, bezier = "instant", style = "fade" })
hl.animation({ leaf = "workspaces", enabled = true, speed = 2, bezier = "snappy", style = "slide" })

-- super for wofi
hl.bind("SUPER_L", hl.dsp.exec_cmd("pkill wofi || wofi --show drun"), { release = true })

-- alt to close a window
hl.bind("ALT_L", hl.dsp.window.close(), { release = true })



for i = 1, 5 do
    hl.bind(mainMod .. " + " .. i, hl.dsp.focus({ workspace = i }))
    hl.bind(mainMod .. " + SHIFT + " .. i, hl.dsp.window.move({ workspace = i }))
    end


    -- Move & resize windows with Super + Left/Right Mouse Button
    hl.bind(mainMod .. " + mouse:272", hl.dsp.window.drag(), { mouse = true })
    hl.bind(mainMod .. " + mouse:273", hl.dsp.window.resize(), { mouse = true })
