local var_color_active_border = "rgba(74c7ecee)"
local var_color_inactive_border = "rgba(45475aee)"
local var_color_decoration_shadow = "rgba(74c7ecee)"
local var_mainMod = "SUPER"
local var_terminal = "kitty"
local var_fileManager = "dolphin"
local var_menu = "wofi --show drun"
local var_screenshot_folder = "~/Bilder/Screenshots/"

-- #######################################################################################

-- AUTOGENERATED HYPRLAND CONFIG.

-- EDIT THIS CONFIG ACCORDING TO THE WIKI INSTRUCTIONS.

-- #######################################################################################

-- This is an example Hyprland config file.

-- Refer to the wiki for more information.

-- https://wiki.hypr.land/Configuring/

-- Please note not all available settings / options are set here.

-- For a full list, see the wiki

-- You can split this configuration into multiple files

-- Create your files separately and then link them to this file like this:

-- source = ~/.config/hypr/myColors.conf
require("env")
hl.exec_cmd("bash ~/.config/hypr/env.sh")

-- ###############

-- ## MONITORS ###

-- ###############
-- See https://wiki.hypr.land/Configuring/Monitors/

-- monitor=,preferred,auto,auto
require("modules.monitor_setup_buntes_monster")

-- source = ~/.config/hypr/modules/monitor_setup_buntes_monster.conf

-- unscale XWayland
hl.config({
    xwayland = {
        force_zero_scaling = true,
    },
})

-- ##################

-- ## MY PROGRAMS ###

-- ##################

-- See https://wiki.hypr.land/Configuring/Keywords/

-- Set programs that you use

-- $menu = hyprlauncher

-- ################

-- ## AUTOSTART ###

-- ################

-- Autostart necessary processes (like notifications daemons, status bars, etc.)

-- Or execute your favorite apps at launch like this:

-- exec = bash ~/.config/wpaperd/link_wallpapers.sh
hl.on("hyprland.start", function()
    hl.exec_cmd("waybar &")
end)

-- exec-one = hyprpaper &
hl.on("hyprland.start", function()
    hl.exec_cmd("wpaperd &")
    hl.exec_cmd("swaync &")
    hl.exec_cmd("hypridle &")
    hl.exec_cmd("nextcloud &")
    hl.exec_cmd("sh ~/.config/hypr/scripts/portal-host-override.sh")
    hl.exec_cmd("sh ~/.config/hypr/scripts/ensure-mime-defaults.sh")
end)

-- exec-once = dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE XDG_MENU_PREFIX

-- exec-once = systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE XDG_MENU_PREFIX

-- exec = gsettings set org.gnome.desktop.interface gtk-theme "Breeze-Dark"   # for GTK3 apps

-- exec = gsettings set org.gnome.desktop.interface color-scheme "prefer-dark"   # for GTK4 apps

-- env = QT_QPA_PLATFORMTHEME,qt6ct   # for Qt apps

-- ############################

-- ## ENVIRONMENT VARIABLES ###

-- ############################

-- See https://wiki.hypr.land/Configuring/Environment-variables/
hl.env("XCURSOR_SIZE", "24")
hl.env("HYPRCURSOR_SIZE", "24")
hl.env("XDG_CURRENT_DESKTOP", "Hyprland")
hl.env("XDG_SESSION_DESKTOP", "Hyprland")
hl.env("XDG_SESSION_TYPE", "wayland")
hl.env("XDG_MENU_PREFIX", "plasma-")
hl.env("GTK_USE_PORTAL", "1")
hl.env("GTK_THEME", "Adwaita:dark")
hl.env("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1")
hl.env("QT_QPA_PLATFORMTHEME", "kde")

-- env = QT_AUTO_SCREEN_SCALE_FACTOR,0.75

-- env = QT_SCALE_FACTOR,0.75

-- env = GDK_SCALE,1.5

-- env = GDK_DPI_SCALE,0.75

-- ##################

-- ## PERMISSIONS ###

-- ##################

-- See https://wiki.hypr.land/Configuring/Permissions/

-- Please note permission changes here require a Hyprland restart and are not applied on-the-fly

-- for security reasons

-- ecosystem {

-- enforce_permissions = 1

-- }

-- permission = /usr/(bin|local/bin)/grim, screencopy, allow

-- permission = /usr/(lib|libexec|lib64)/xdg-desktop-portal-hyprland, screencopy, allow

-- permission = /usr/(bin|local/bin)/hyprpm, plugin, allow

-- ####################

-- ## COLOR SCHEMES ###

-- ####################
require("themes.mocha")

-- ####################

-- ## LOOK AND FEEL ###

-- ####################

-- Refer to https://wiki.hypr.land/Configuring/Variables/

-- https://wiki.hypr.land/Configuring/Variables/#general
hl.config({
    general = {
        gaps_in = 3,
        gaps_out = 4,
        border_size = 3,
    },
})

-- https://wiki.hypr.land/Configuring/Variables/#variable-types for info about colors
hl.config({
    general = {
        col = {
            active_border = var_color_active_border,
            inactive_border = var_color_inactive_border,
        },
    },
})

-- Set to true enable resizing windows by clicking and dragging on borders and gaps
hl.config({
    general = {
        resize_on_border = true,
    },
})

-- Please see https://wiki.hypr.land/Configuring/Tearing/ before you turn this on
hl.config({
    general = {
        allow_tearing = false,
        layout = "dwindle",
    },
})

-- https://wiki.hypr.land/Configuring/Variables/#decoration
hl.config({
    decoration = {
        rounding = 5,
        rounding_power = 2,
    },
})

-- Change transparency of focused and unfocused windows
hl.config({
    decoration = {
        active_opacity = 1.0,
        inactive_opacity = 1.0,
        shadow = {
            enabled = true,
            range = 10,
            render_power = 3,
            color = var_color_decoration_shadow,
        },
    },
})

-- https://wiki.hypr.land/Configuring/Variables/#blur
hl.config({
    decoration = {
        blur = {
            enabled = true,
            size = 10,
            passes = 2,
            vibrancy = 0.1696,
        },
    },
})

-- https://wiki.hypr.land/Configuring/Variables/#animations
hl.config({
    animations = {
        enabled = true,
    },
})

-- Default curves, see https://wiki.hypr.land/Configuring/Animations/#curves

-- NAME,           X0,   Y0,   X1,   Y1
hl.curve("easeOutQuint", { type = "bezier", points = { {0.23, 1}, {0.32, 1} } })
hl.curve("easeInOutCubic", { type = "bezier", points = { {0.65, 0.05}, {0.36, 1} } })
hl.curve("linear", { type = "bezier", points = { {0, 0}, {1, 1} } })
hl.curve("almostLinear", { type = "bezier", points = { {0.5, 0.5}, {0.75, 1} } })
hl.curve("quick", { type = "bezier", points = { {0.15, 0}, {0.1, 1} } })

-- Default animations, see https://wiki.hypr.land/Configuring/Animations/

-- NAME,          ONOFF, SPEED, CURVE,        [STYLE]
hl.animation({
    leaf = "global",
    enabled = true,
    speed = 10,
    bezier = "default",
})
hl.animation({
    leaf = "border",
    enabled = true,
    speed = 5.39,
    bezier = "easeOutQuint",
})
hl.animation({
    leaf = "windows",
    enabled = true,
    speed = 4.79,
    bezier = "easeOutQuint",
})
hl.animation({
    leaf = "windowsIn",
    enabled = true,
    speed = 4.1,
    bezier = "easeOutQuint",
    style = "popin 87%",
})
hl.animation({
    leaf = "windowsOut",
    enabled = true,
    speed = 1.49,
    bezier = "linear",
    style = "popin 87%",
})
hl.animation({
    leaf = "fadeIn",
    enabled = true,
    speed = 1.73,
    bezier = "almostLinear",
})
hl.animation({
    leaf = "fadeOut",
    enabled = true,
    speed = 1.46,
    bezier = "almostLinear",
})
hl.animation({
    leaf = "fade",
    enabled = true,
    speed = 3.03,
    bezier = "quick",
})
hl.animation({
    leaf = "layers",
    enabled = true,
    speed = 3.81,
    bezier = "easeOutQuint",
})
hl.animation({
    leaf = "layersIn",
    enabled = true,
    speed = 4,
    bezier = "easeOutQuint",
    style = "fade",
})
hl.animation({
    leaf = "layersOut",
    enabled = true,
    speed = 1.5,
    bezier = "linear",
    style = "fade",
})
hl.animation({
    leaf = "fadeLayersIn",
    enabled = true,
    speed = 1.79,
    bezier = "almostLinear",
})
hl.animation({
    leaf = "fadeLayersOut",
    enabled = true,
    speed = 1.39,
    bezier = "almostLinear",
})
hl.animation({
    leaf = "workspaces",
    enabled = true,
    speed = 1.94,
    bezier = "almostLinear",
    style = "fade",
})
hl.animation({
    leaf = "workspacesIn",
    enabled = true,
    speed = 1.21,
    bezier = "almostLinear",
    style = "fade",
})
hl.animation({
    leaf = "workspacesOut",
    enabled = true,
    speed = 1.94,
    bezier = "almostLinear",
    style = "fade",
})
hl.animation({
    leaf = "zoomFactor",
    enabled = true,
    speed = 7,
    bezier = "quick",
})

-- Ref https://wiki.hypr.land/Configuring/Workspace-Rules/

-- "Smart gaps" / "No gaps when only"

-- uncomment all if you wish to use that.
hl.workspace_rule({
    workspace = "w[tv1]",
    gaps_out = 0,
    gaps_in = 0,
})
hl.workspace_rule({
    workspace = "f[1]",
    gaps_out = 0,
    gaps_in = 0,
})
hl.window_rule({
    name = "no-gaps-wtv1",
    match = {
        float = false,
        workspace = "w[tv1]",
    },
    border_size = 0,
    rounding = 0,
})
hl.window_rule({
    name = "no-gaps-f1",
    match = {
        float = false,
        workspace = "f[1]",
    },
    border_size = 0,
    rounding = 0,
})

-- See https://wiki.hypr.land/Configuring/Dwindle-Layout/ for more
hl.config({
    dwindle = {
        preserve_split = true,
    },
})

-- See https://wiki.hypr.land/Configuring/Master-Layout/ for more
hl.config({
    master = {
        new_status = "master",
    },
})

-- https://wiki.hypr.land/Configuring/Variables/#misc
hl.config({
    misc = {
        force_default_wallpaper = -1,
        disable_hyprland_logo = false,
    },
})

-- ############

-- ## INPUT ###

-- ############

-- https://wiki.hypr.land/Configuring/Variables/#input
hl.config({
    input = {
        kb_layout = "de",
        kb_variant = "",
        kb_model = "",
        kb_options = "grp:alt_shift_toggle",
        kb_rules = "",
        follow_mouse = 1,
        numlock_by_default = true,
        sensitivity = 0,
        touchpad = {
            natural_scroll = true,
        },
    },
})

-- See https://wiki.hypr.land/Configuring/Gestures
hl.gesture({
    fingers = 3,
    direction = "horizontal",
    action = "workspace",
})

-- Example per-device config

-- See https://wiki.hypr.land/Configuring/Keywords/#per-device-input-configs for more
hl.device({
    name = "epic-mouse-v1",
    sensitivity = -0.5,
})

-- ##################

-- ## KEYBINDINGS ###

-- ##################

-- See https://wiki.hypr.land/Configuring/Keywords/

-- Example binds, see https://wiki.hypr.land/Configuring/Binds/ for more
hl.bind(var_mainMod .. " + RETURN", hl.dsp.exec_cmd(var_terminal))
hl.bind(var_mainMod .. " + Q", hl.dsp.window.close())
hl.bind(var_mainMod .. " + ESCAPE", hl.dsp.exec_cmd("hyprshutdown"))
hl.bind(var_mainMod .. " + SHIFT + ESCAPE", hl.dsp.exec_cmd("command -v hyprshutdown >/dev/null 2>&1 && hyprshutdown || hyprctl dispatch exit"))
hl.bind(var_mainMod .. " + CTRL + ESCAPE", hl.dsp.exec_cmd("hyprshutdown -t 'Shutting down...' --post-cmd 'shutdown -P 0'"))
hl.bind(var_mainMod .. " + ALT + ESCAPE", hl.dsp.exec_cmd("hyprshutdown -t 'Restarting...' --post-cmd 'reboot'"))
hl.bind(var_mainMod .. " + E", hl.dsp.exec_cmd(var_fileManager))
hl.bind(var_mainMod .. " + V", hl.dsp.window.float({ action = "toggle" }))
hl.bind(var_mainMod .. " + SPACE", hl.dsp.exec_cmd(var_menu))
hl.bind(var_mainMod .. " + SHIFT + SPACE", hl.dsp.exec_cmd("nwg-drawer"))
hl.bind(var_mainMod .. " + P", hl.dsp.window.pseudo())
hl.bind(var_mainMod .. " + SHIFT + J", hl.dsp.layout("togglesplit"))
hl.bind(var_mainMod .. " + I", hl.dsp.exec_cmd("firefox &"))
hl.bind(var_mainMod .. " + n", hl.dsp.exec_cmd("~/.local/bin/hyprltm-net"))

-- Move focus with mainMod + WASD or Vim-style
hl.bind(var_mainMod .. " + a", hl.dsp.focus({ direction = "left" }))
hl.bind(var_mainMod .. " + d", hl.dsp.focus({ direction = "right" }))
hl.bind(var_mainMod .. " + w", hl.dsp.focus({ direction = "up" }))
hl.bind(var_mainMod .. " + s", hl.dsp.focus({ direction = "down" }))
hl.bind(var_mainMod .. " + h", hl.dsp.focus({ direction = "left" }))
hl.bind(var_mainMod .. " + l", hl.dsp.focus({ direction = "right" }))
hl.bind(var_mainMod .. " + k", hl.dsp.focus({ direction = "up" }))
hl.bind(var_mainMod .. " + j", hl.dsp.focus({ direction = "down" }))

-- Move windows with mainMod + WASD or Vim-style
hl.bind(var_mainMod .. " + SHIFT + a", hl.dsp.window.move({ direction = "left" }))
hl.bind(var_mainMod .. " + SHIFT + d", hl.dsp.window.move({ direction = "right" }))
hl.bind(var_mainMod .. " + SHIFT + w", hl.dsp.window.move({ direction = "up" }))
hl.bind(var_mainMod .. " + SHIFT + s", hl.dsp.window.move({ direction = "down" }))
hl.bind(var_mainMod .. " + SHIFT + h", hl.dsp.window.move({ direction = "left" }))
hl.bind(var_mainMod .. " + SHIFT + l", hl.dsp.window.move({ direction = "right" }))
hl.bind(var_mainMod .. " + SHIFT + k", hl.dsp.window.move({ direction = "up" }))
hl.bind(var_mainMod .. " + SHIFT + j", hl.dsp.window.move({ direction = "down" }))

-- Resize focused window with mainMod + Arrows
hl.bind(var_mainMod .. " + left", hl.dsp.window.resize({ x = -10, y = 0, relative = true }))
hl.bind(var_mainMod .. " + right", hl.dsp.window.resize({ x = 10, y = 0, relative = true }))
hl.bind(var_mainMod .. " + up", hl.dsp.window.resize({ x = 0, y = -10, relative = true }))
hl.bind(var_mainMod .. " + down", hl.dsp.window.resize({ x = 0, y = 10, relative = true }))

-- Switch workspaces with mainMod + [0-9]
hl.bind(var_mainMod .. " + 1", hl.dsp.focus({ workspace = 1 }))
hl.bind(var_mainMod .. " + 2", hl.dsp.focus({ workspace = 2 }))
hl.bind(var_mainMod .. " + 3", hl.dsp.focus({ workspace = 3 }))
hl.bind(var_mainMod .. " + 4", hl.dsp.focus({ workspace = 4 }))
hl.bind(var_mainMod .. " + 5", hl.dsp.focus({ workspace = 5 }))
hl.bind(var_mainMod .. " + 6", hl.dsp.focus({ workspace = 6 }))
hl.bind(var_mainMod .. " + 7", hl.dsp.focus({ workspace = 7 }))
hl.bind(var_mainMod .. " + 8", hl.dsp.focus({ workspace = 8 }))
hl.bind(var_mainMod .. " + 9", hl.dsp.focus({ workspace = 9 }))
hl.bind(var_mainMod .. " + 0", hl.dsp.focus({ workspace = 10 }))
hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+"), {
    repeating = true,
})
hl.bind("XF86AudioLowerVolume", hl.dsp.exec_cmd("wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"), {
    locked = true,
})

-- Move active window to a workspace with mainMod + SHIFT + [0-9]
hl.bind(var_mainMod .. " + SHIFT + 1", hl.dsp.window.move({ workspace = 1 }))
hl.bind(var_mainMod .. " + SHIFT + 2", hl.dsp.window.move({ workspace = 2 }))
hl.bind(var_mainMod .. " + SHIFT + 3", hl.dsp.window.move({ workspace = 3 }))
hl.bind(var_mainMod .. " + SHIFT + 4", hl.dsp.window.move({ workspace = 4 }))
hl.bind(var_mainMod .. " + SHIFT + 5", hl.dsp.window.move({ workspace = 5 }))
hl.bind(var_mainMod .. " + SHIFT + 6", hl.dsp.window.move({ workspace = 6 }))
hl.bind(var_mainMod .. " + SHIFT + 7", hl.dsp.window.move({ workspace = 7 }))
hl.bind(var_mainMod .. " + SHIFT + 8", hl.dsp.window.move({ workspace = 8 }))
hl.bind(var_mainMod .. " + SHIFT + 9", hl.dsp.window.move({ workspace = 9 }))
hl.bind(var_mainMod .. " + SHIFT + 0", hl.dsp.window.move({ workspace = 10 }))

-- # Example special workspace (scratchpad)

-- bind = $mainMod, S, togglespecialworkspace, magic

-- bind = $mainMod SHIFT, S, movetoworkspace, special:magic

-- Scroll through existing workspaces with mainMod + scroll
hl.bind(var_mainMod .. " + mouse_down", hl.dsp.focus({ workspace = "e+1" }))
hl.bind(var_mainMod .. " + mouse_up", hl.dsp.focus({ workspace = "e-1" }))

-- Move/resize windows with mainMod + LMB/RMB and dragging
hl.bind(var_mainMod .. " + mouse:272", hl.dsp.window.drag(), {
    mouse = true,
})
hl.bind(var_mainMod .. " + mouse:273", hl.dsp.window.resize(), {
    mouse = true,
})

-- Laptop multimedia keys for volume and LCD brightness
hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+"), {
    repeating = true,
    locked = true,
})
hl.bind("XF86AudioLowerVolume", hl.dsp.exec_cmd("wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"), {
    repeating = true,
    locked = true,
})
hl.bind("XF86AudioMute", hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"), {
    repeating = true,
    locked = true,
})
hl.bind("XF86AudioMicMute", hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"), {
    repeating = true,
    locked = true,
})
hl.bind("XF86MonBrightnessUp", hl.dsp.exec_cmd("brightnessctl -e4 -n2 set 5%+"), {
    repeating = true,
    locked = true,
})
hl.bind("XF86MonBrightnessDown", hl.dsp.exec_cmd("brightnessctl -e4 -n2 set 5%-"), {
    repeating = true,
    locked = true,
})

-- Requires playerctl
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,
})

-- Screenshots
hl.bind("PRINT", hl.dsp.exec_cmd("hyprshot -m region --output-folder " .. var_screenshot_folder), {
    locked = true,
})
hl.bind("CTRL + PRINT", hl.dsp.exec_cmd("hyprshot -m window --output-folder " .. var_screenshot_folder), {
    locked = true,
})
hl.bind("SHIFT + PRINT", hl.dsp.exec_cmd("hyprshot -m active --output-folder " .. var_screenshot_folder), {
    locked = true,
})

-- Screenlock
hl.bind("CTRL + ALT + L", hl.dsp.exec_cmd("hyprlock"), {
    locked = true,
})

-- #############################

-- ## WINDOWS AND WORKSPACES ###

-- #############################

-- See https://wiki.hypr.land/Configuring/Window-Rules/ for more

-- See https://wiki.hypr.land/Configuring/Workspace-Rules/ for workspace rules

-- Example windowrules that are useful

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

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

-- Hyprland-run windowrule
hl.config({
    decoration = {
        blur = {
            size = 8,
            passes = 2,
        },
    },
})

hl.window_rule({
    name = "move-hyprland-run",
    match = {
        class = "hyprland-run",
    },
    move = "20 monitor_h-120",
    float = true,
})
hl.window_rule({
    name = "opacity-kitty-dolphin",
    match = {
        class = ".*(kitty|dolphin).*",
    },
    opacity = "0.90 0.80",
})
hl.layer_rule({
    match = {
        namespace = "waybar",
    },
    blur = true,
})
hl.layer_rule({
    match = {
        namespace = "waybar",
    },
    blur_popups = true,
})
hl.window_rule({
    name = "no-rounding-fullscreen",
    match = {
        fullscreen = 1,
    },
    rounding = 0,
    border_size = 0,
})

-- windowrule {

-- name = no-rounding-steam-games

-- match:class = ^steam_app_.*$

-- rounding = 0

-- border_size = 0

-- }

-- windowrule {

-- name = no-rounding-gamescope

-- match:class = ^gamescope$

-- rounding = 0

-- border_size = 0

-- }

-- HyprMod managed settings
require("hyprland-gui")
