-- environment variables
hl.env("XCURSOR_SIZE", "24")
hl.env("HYPRCURSOR_SIZE", "24")

-- General config

hl.config({
    general = {
        border_size = 2,
        gaps_in = 0,
        gaps_out = 5,
        layout = "dwindle",
        allow_tearing = false,
        resize_on_border = true,
    },
    decoration = {
        shadow = { enabled = false, },
        blur = { enabled = true, },
        active_opacity = 0.8,
        inactive_opacity = 0.8,
    },
    animations = { 
        enabled = false,
    },
    misc = {
        disable_hyprland_logo = true;
    },
    cursor = {
        inactive_timeout = 3,
    },
    ecosystem = {
        no_update_news = true,
        no_donation_nag = true,
    },
})

local mod = "SUPER"
local term = "kitty"
local browser = "zen"

-- Input config

hl.config({
    input = {
        kb_layout = "de",

        follow_mouse = 1,
    }
})

-- Keybinds

--- Apps
hl.bind(mod .. " + Return", hl.dsp.exec_cmd(term))
hl.bind(mod .. " + D", hl.dsp.exec_cmd("rofi -show drun -modes drun,calc"))
hl.bind(mod .. " + F2", hl.dsp.exec_cmd(browser))

--- Window manipulation
hl.bind(mod .. " + C", hl.dsp.window.close())
hl.bind(mod .. " + f", hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'toggle'}))
hl.bind(mod .. " + SHIFT + Space", hl.dsp.window.float({ action = "toggle" }))
hl.bind(mod .. " + H",  hl.dsp.focus({ direction = "left" }))
hl.bind(mod .. " + L", hl.dsp.focus({ direction = "right" }))
hl.bind(mod .. " + K",    hl.dsp.focus({ direction = "up" }))
hl.bind(mod .. " + J",  hl.dsp.focus({ direction = "down" }))
hl.bind(mod .. " + mouse:272", hl.dsp.window.drag(),   { mouse = true })
hl.bind(mod .. " + mouse:273", hl.dsp.window.resize(), { mouse = true })

--- Workspace handling
for i = 1, 10 do
    local key = i % 10 -- 10 maps to key 0
    hl.bind(mod .. " + " .. key,             hl.dsp.focus({ workspace = i}))
    hl.bind(mod .. " + SHIFT + " .. key,     hl.dsp.window.move({ workspace = i }))
end

hl.gesture({
    fingers = 3,
    direction = "horizontal",
    action = "workspace"
})

--- Media handling
hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+"), { locked = true, repeating = true })
hl.bind("XF86AudioLowerVolume", hl.dsp.exec_cmd("wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"),      { locked = true, repeating = true })
hl.bind("XF86AudioMute",        hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"),     { locked = true, repeating = true })
hl.bind("XF86AudioMicMute",     hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"),   { locked = true, repeating = true })
hl.bind("XF86AudioNext",  hl.dsp.exec_cmd("playerctl next"),       { locked = true })
hl.bind("XF86AudioPause", hl.dsp.exec_cmd("playerctl play-pause"), { locked = true })
hl.bind("XF86AudioPlay",  hl.dsp.exec_cmd("playerctl play-pause"), { locked = true })
hl.bind("XF86AudioPrev",  hl.dsp.exec_cmd("playerctl previous"),   { locked = true })

-- Window rules

hl.window_rule({
    -- Ignore maximize requests from all apps. You'll probably like this.
    name  = "suppress-maximize-events",
    match = { class = ".*" },

    suppress_event = "maximize",
})

hl.window_rule({
    -- Fix some dragging issues with XWayland
    name  = "fix-xwayland-drags",
    match = {
        class      = "^$",
        title      = "^$",
        xwayland   = true,
        float      = true,
        fullscreen = false,
        pin        = false,
    },

    no_focus = true,
})

-- Monitor handling

-- automatically add new monitors and lay them out horizontally
hl.monitor({ output = "", mode = "preferred", position = "auto", scale = 1 })

