-- 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/
-- monitor=DP-1,2560x1440@144,0x0,1
-- monitor=DP-3,2560x1440@144,2560x0,1
-- vrr 2 enables vrr if application is fullscreen
-- vrr 3 enables vrr if application is fullscreen and video or game content
-- monitor = DP-1, 3440x1440@240,0x0,1,vrr,3
-- Generated by hyprlang2lua. Review TODOs before reloading Hyprland.

hl.monitor({
	output = "DP-1",
	mode = "3440x1440@240",
	position = "0x0",
	scale = 1,
	vrr = 2,
	cm = srgb,
	-- Optional HDR settings
	-- cm = "hdr",
	bitdepth = 10,
	sdr_min_luminance = 0.005,
	sdr_max_luminance = 200,
	min_luminance = 0,
	max_luminance = 1000,
	max_avg_luminance = 200,
	sdrbrightness = 1.0,
	sdrsaturation = 0.98,
})

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

local rosewater = "rgb(f4dbd6)"
local rosewaterAlpha = "f4dbd6"

local flamingo = "rgb(f0c6c6)"
local flamingoAlpha = "f0c6c6"

local pink = "rgb(f5bde6)"
local pinkAlpha = "f5bde6"

local mauve = "rgb(c6a0f6)"
local mauveAlpha = "c6a0f6"

local red = "rgb(ed8796)"
local redAlpha = "ed8796"

local maroon = "rgb(ee99a0)"
local maroonAlpha = "ee99a0"

local peach = "rgb(f5a97f)"
local peachAlpha = "f5a97f"

local yellow = "rgb(eed49f)"
local yellowAlpha = "eed49f"

local green = "rgb(a6da95)"
local greenAlpha = "a6da95"

local teal = "rgb(8bd5ca)"
local tealAlpha = "8bd5ca"

local sky = "rgb(91d7e3)"
local skyAlpha = "91d7e3"

local sapphire = "rgb(7dc4e4)"
local sapphireAlpha = "7dc4e4"

local blue = "rgb(8aadf4)"
local blueAlpha = "8aadf4"

local lavender = "rgb(b7bdf8)"
local lavenderAlpha = "b7bdf8"

local text = "rgb(cad3f5)"
local textAlpha = "cad3f5"

local subtext1 = "rgb(b8c0e0)"
local subtext1Alpha = "b8c0e0"

local subtext0 = "rgb(a5adcb)"
local subtext0Alpha = "a5adcb"

local overlay2 = "rgb(939ab7)"
local overlay2Alpha = "939ab7"

local overlay1 = "rgb(8087a2)"
local overlay1Alpha = "8087a2"

local overlay0 = "rgb(6e738d)"
local overlay0Alpha = "6e738d"

local surface2 = "rgb(5b6078)"
local surface2Alpha = "5b6078"

local surface1 = "rgb(494d64)"
local surface1Alpha = "494d64"

local surface0 = "rgb(363a4f)"
local surface0Alpha = "363a4f"

local base = "rgb(24273a)"
local baseAlpha = "24273a"

local mantle = "rgb(1e2030)"
local mantleAlpha = "1e2030"

local crust = "rgb(181926)"
local crustAlpha = 181926

-- unscale XWayland

local terminal = "uwsm app -- ghostty +new-window"
local fileManager = "uwsm app -- thunar"
local menu = 'rofi -show drun -run-command "uwsm app -- {cmd}"'
local notification_daemon = "uwsm app -- swaync -c ~/.config/swaync/config.json"

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 = "linear",
	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.layer_rule({
	name = "fix-rofi",
	match = {
		namespace = "rofi",
	},
	-- TODO: manual review — unmapped layer rule: "no_anim"
})

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:
	-- exec-once = dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
	--############################
	--## 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(" .. mauveAlpha .. "ff)" },
				angle = 45,
			},
			inactive_border = "rgba(" .. overlay0Alpha .. "ff)",
		},
		-- 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 = "scrolling",
	},
	-- https://wiki.hyprland.org/Configuring/Variables/#decoration
	decoration = {
		rounding = 10,
		rounding_power = 2,
		-- Change transparency of focused and unfocused windows
		-- active_opacity = 0.88
		active_opacity = 1.0,
		-- inactive_opacity = 0.88
		inactive_opacity = 1.0,
		shadow = {
			enabled = true,
			range = 4,
			render_power = 3,
			color = "rgba(" .. surface0Alpha .. "ff)",
		},
		-- 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 = true,
		-- Default animations, see https://wiki.hyprland.org/Configuring/Animations/ for more
		-- slide, slidevert, fade, slidefade, slidefadevert
		-- 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
	-- See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more
	dwindle = {
		-- pseudotile = false, -- Master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below
		preserve_split = true,
		split_width_multiplier = 1.69,
	},
	scrolling = {
		fullscreen_on_one_column = true,
	},
	-- See https://wiki.hyprland.org/Configuring/Master-Layout/ for more
	master = {
		new_status = "slave",
		allow_small_split = false,
	},
	-- 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 = "Manrope ExtraLight Medium, JetBrainsMono Nerd Font, M PLUS 1",
	},
	--############
	--## INPUT ###
	--############
	-- https://wiki.hyprland.org/Configuring/Variables/#input
	input = {
		kb_layout = "us",
		kb_variant = "",
		kb_model = "pc86",
		kb_options = "caps:escape_shifted_capslock",
		kb_rules = "",
		follow_mouse = 1,
		sensitivity = 0, -- -1.0 - 1.0, 0 means no modification.
		touchpad = {
			natural_scroll = false,
		},
	},
	-- https://wiki.hyprland.org/Configuring/Variables/#gestures
	gestures = {
		-- workspace_swipe = false
	},
	-- Example per-device config
	-- See https://wiki.hyprland.org/Configuring/Keywords/#per-device-input-configs for more
	render = {
		-- explicit_sync = true
	},
	-- {{{ WORKSPACES - HANDLED IN WAYBAR CONFIG
	-- See https://wiki.hyprland.org/Configuring/Window-Rules/ for more
	-- 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
	-- }}}
	-- windowrule = match:class my-window, border_size 10
	debug = {
		disable_logs = true,
		enable_stdout_logs = false,
	},
})

hl.on("hyprland.start", function()
	hl.exec_cmd("uwsm app -sb -- hyprpm update -n")
	hl.exec_cmd("uwsm app -sb -- hyprpm reload -n")
	hl.exec_cmd(notification_daemon)
	hl.exec_cmd(terminal)
	hl.exec_cmd("uwsm app -sb -S both -t scope -- hyprpm update -n")
	hl.exec_cmd("uwsm app -sb -S both -t scope -- hyprpm reload -n")
	hl.exec_cmd("uwsm app -sb -t service -- nm-applet")
	hl.exec_cmd(
		"uwsm app -sb -t service -- waybar -c ~/.config/waybar/catppuccin-macchiato/config.jsonc -s ~/.config/waybar/catppuccin-macchiato/style.css"
	)
	hl.exec_cmd("uwsm app -sb -t service -- /usr/lib/polkit-kde-authentication-agent-1")
	hl.exec_cmd("uwsm app -sb -t service -- gnome-keyring-daemon --start --components=secrets,ssh,pkcs11")
	hl.exec_cmd("uwsm app -sb -t service -- tailscale systray")
	hl.exec_cmd("~/.local/bin/aria")
end)
