-- This is an example Hyprland config file.
-- Refer to the wiki for more information.
-- https://wiki.hyprland.org/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

--###############
--## MONITORS ###
--###############

-- See https://wiki.hyprland.org/Configuring/Monitors/
-- Generated by hyprlang2lua. Review TODOs before reloading Hyprland.

hl.monitor({
    output = "eDP-1",
    mode = "3840x2160@60",
    position = "0x0",
    scale = "2",
    vrr = 0,
})

-- Source: ~/.config/hypr/keybindings.conf — convert this file to Lua and ensure it is on Lua's package.path.
require("keybindings")
-- source = ~/.config/hypr/env.conf
-- unscale XWayland

local terminal = "uwsm app -- ghostty"
local fileManager = "uwsm app -- dolphin"
local menu = "rofi -show drun -run-command \"uwsm app -- {cmd}\""
local notification_daemon = "uwsm app -- swaync"

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.0 } } })
hl.curve("quick", { type = "bezier", points = { { 0.15, 0 }, { 0.1, 1 } } })
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 = "slide",
})
hl.animation({
    leaf = "windowsOut",
    enabled = true,
    speed = 1.49,
    bezier = "easeOutQuint",
    style = "slide",
})
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 = "slidefade",
})
hl.animation({
    leaf = "workspacesIn",
    enabled = true,
    speed = 1.21,
    bezier = "almostLinear",
    style = "slidefade",
})
hl.animation({
    leaf = "workspacesOut",
    enabled = true,
    speed = 1.94,
    bezier = "almostLinear",
    style = "slidefade",
})

hl.device({
    name = "epic-mouse-v1",
    sensitivity = -0.5,
})

hl.workspace_rule({
    workspace = "w[1-10]",
    monitor = "eDP-1",
    persistent = false,
})

hl.window_rule({
    match = {
        class = "discord",
    },
    float = true,
})

hl.window_rule({
    match = {
        class = "mpv",
    },
    float = true,
})

hl.window_rule({
    match = {
        class = "discord",
    },
    workspace = "10 silent",
})

hl.window_rule({
    match = {
        class = ".* fullscreen:0",
    },
    opacity = 0.88,
})

hl.window_rule({
    match = {
        class = "mpv fullscreen:0",
    },
    opacity = 1,
})

hl.window_rule({
    match = {
        class = "anki fullscreen:0",
    },
    opacity = 1,
})

hl.window_rule({
    match = {
        class = "remote-viewer",
    },
    opacity = 1,
})

hl.window_rule({
    match = {
        class = ".*",
    },
    suppress_event = "maximize",
})

hl.window_rule({
    match = {
        class = "^$",
        title = "^$",
        xwayland = 1,
        floating = 1,
        fullscreen = 0,
        pinned = 0,
    },
    no_focus = true,
})

hl.window_rule({
    match = {
        class = "^(zen)$",
    },
    suppress_event = "maximize",
})

hl.window_rule({
    match = {
        class = "^(xwaylandvideobridge)$",
    },
    opacity = "0.0 override",
    no_anim = true,
    no_initial_focus = true,
    -- TODO: manual review — unmapped window rule action: "maxsize 1 1"
    blur = false,
    no_focus = true,
})

hl.config({
    xwayland = {
        force_zero_scaling = true,
    },
    --##################
    --## MY PROGRAMS ###
    --##################
    -- See https://wiki.hyprland.org/Configuring/Keywords/
    -- Set programs that you use
    -- $notification_daemon = dunst
    --################
    --## AUTOSTART ###
    --################
    -- Autostart necessary processes (like notifications daemons, status bars, etc.)
    -- Or execute your favorite apps at launch like this:
    --############################
    --## ENVIRONMENT VARIABLES ###
    --############################
    -- See https://wiki.hyprland.org/Configuring/Environment-variables/
    -- env = XCURSOR_SIZE,24
    -- env = HYPRCURSOR_SIZE,24
    -- done in ../uswm/env and ../uswm/env-hyprland
    --####################
    --## LOOK AND FEEL ###
    --####################
    -- Refer to https://wiki.hyprland.org/Configuring/Variables/
    -- https://wiki.hyprland.org/Configuring/Variables/#general
    general = {
        gaps_in = 5,
        gaps_out = 8,
        border_size = 2,
        -- https://wiki.hyprland.org/Configuring/Variables/#variable-types for info about colors
        col = {
            active_border = { colors = { "rgba(33ccffee)", "rgba(00ff99ee)" }, angle = 45 },
            inactive_border = "rgba(595959aa)",
        },
        -- Set to true enable resizing windows by clicking and dragging on borders and gaps
        resize_on_border = false,
        -- Please see https://wiki.hyprland.org/Configuring/Tearing/ before you turn this on
        allow_tearing = false,
        layout = "dwindle",
    },
    -- https://wiki.hyprland.org/Configuring/Variables/#decoration
    decoration = {
        rounding = 10,
        rounding_power = 2,
        -- Change transparency of focused and unfocused windows
        active_opacity = 1.0,
        inactive_opacity = 1.0,
        shadow = {
            enabled = true,
            range = 4,
            render_power = 3,
            color = "rgba(1a1a1aee)",
        },
        -- https://wiki.hyprland.org/Configuring/Variables/#blur
        blur = {
            enabled = true,
            size = 7,
            passes = 2,
            xray = true,
            vibrancy = 0.1696,
        },
    },
    -- https://wiki.hyprland.org/Configuring/Variables/#animations
    animations = {
        enabled = "yes, please :)",
        -- Default animations, see https://wiki.hyprland.org/Configuring/Animations/ for more
        -- animation = windowsIn, 1, 4.1, easeOutQuint, popin 87%
        -- animation = windowsOut, 1, 1.49, linear, popin 87%
    },
    -- Ref https://wiki.hyprland.org/Configuring/Workspace-Rules/
    -- "Smart gaps" / "No gaps when only"
    -- uncomment all if you wish to use that.
    -- workspace = w[tv1], gapsout:0, gapsin:0
    -- workspace = f[1], gapsout:0, gapsin:0
    -- windowrulev2 = bordersize 0, floating:0, onworkspace:w[tv1]
    -- windowrulev2 = rounding 0, floating:0, onworkspace:w[tv1]
    -- windowrulev2 = bordersize 0, floating:0, onworkspace:f[1]
    -- windowrulev2 = rounding 0, floating:0, onworkspace:f[1]
    -- See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more
    dwindle = {
        pseudotile = true, -- Master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below
        preserve_split = true, -- You probably want this
    },
    -- See https://wiki.hyprland.org/Configuring/Master-Layout/ for more
    master = {
        new_status = "master",
    },
    -- https://wiki.hyprland.org/Configuring/Variables/#misc
    misc = {
        force_default_wallpaper = -1, -- Set to 0 or 1 to disable the anime mascot wallpapers
        disable_hyprland_logo = false, -- If true disables the random hyprland logo / anime girl background. :(
        font_family = "JetBrainsMono Nerd Font",
    },
    --############
    --## INPUT ###
    --############
    -- https://wiki.hyprland.org/Configuring/Variables/#input
    input = {
        kb_layout = "us",
        kb_variant = "",
        kb_model = "pc104",
        kb_options = "caps:escape_shifted_capslock",
        kb_rules = "",
        follow_mouse = 1,
        sensitivity = 0, -- -1.0 - 1.0, 0 means no modification.
        touchpad = {
            natural_scroll = true,
        },
    },
    -- https://wiki.hyprland.org/Configuring/Variables/#gestures
    gestures = {
        workspace_swipe = true,
        workspace_swipe_fingers = 3,
    },
    -- Example per-device config
    -- See https://wiki.hyprland.org/Configuring/Keywords/#per-device-input-configs for more
    render = {
        explicit_sync = true,
    },
    -- {{{ WORKSPACES
    -- workspace = name:,monitor:DP-1
    -- workspace = 2,monitor:DP-1,defaultName:
    -- workspace = 2,monitor:DP-1,persistent:false
    -- workspace = 3,monitor:DP-1,persistent:false
    -- workspace = 4,monitor:DP-1,persistent:false
    -- workspace = 5,monitor:DP-1,persistent:false
    -- workspace = 6,monitor:DP-3,persistent:false,default:true
    -- workspace = 7,monitor:DP-3,persistent:false
    -- workspace = 8,monitor:DP-3,persistent:false
    -- workspace = 9,monitor:DP-3,persistent:false
    -- workspace = 10,monitor:DP-3,persistent:false
    -- }}}
    --#############################
    --## WINDOWS AND WORKSPACES ###
    --#############################
    -- See https://wiki.hyprland.org/Configuring/Window-Rules/ for more
    -- See https://wiki.hyprland.org/Configuring/Workspace-Rules/ for workspace rules
    -- Example windowrule v1
    -- windowrulev2 = float, class:com.mitchellh.ghostty
    -- windowrulev2 = opacity 1, class:.* fullscreen:0
    -- Example windowrule v2
    -- windowrulev2 = float,class:^(kitty)$,title:^(kitty)$
    -- Ignore maximize requests from apps. You'll probably like this.
    -- Fix some dragging issues with XWayland
    -- https://github.com/hyprwm/Hyprland/issues/3835#issuecomment-2004448245
    -- exec-once = $HOME/.local/bin/bitwarden-nofloat.sh
    -- ENABLE_HDR_WSI=1 mpv --vo=gpu-next --target-colorspace-hint --gpu-api=vulkan --gpu-context=waylandvk "filename"
    -- {{{ Screen sharing workaround: https://wiki.hyprland.org/Useful-Utilities/Screen-Sharing/#xwayland
    -- }}}
})

hl.on("hyprland.start", function()
    hl.exec_cmd("uwsm app -sb -- hyprpm update -nn")
    hl.exec_cmd("uwsm app -sb -- hyprpm reload -nn")
    hl.exec_cmd(notification_daemon)
    hl.exec_cmd(terminal)
    hl.exec_cmd("uwsm app -sb -S both -t scope -- hyprpm update -nn")
    hl.exec_cmd("uwsm app -sb -S both -t scope -- hyprpm reload -nn")
    hl.exec_cmd("uwsm app -sb -t service -- nm-applet")
    hl.exec_cmd("uwsm app -sb -t service -- hyprsunset")
    hl.exec_cmd("uwsm app -sb -t service -- polkit-kde-authentication-agent-1.desktop")
    hl.exec_cmd("uwsm app -sb -t service -- variety")
    hl.exec_cmd("uwsm app -sb -t service -- fcitx5")
    hl.exec_cmd("waybar -c " .. HOME .. "/.config/waybar/catppuccin-macchiato/config-battery.jsonc -s " .. HOME .. "/.config/waybar/catppuccin-macchiato/style.css")
end)

