-- Monitors 
hl.monitor({
	output = "VGA-1",
	mode = "1920x1080@60",
	position = "0x0",
	scale = 1,
})
hl.monitor({
	output = "LVDS-1",
	mode = "1600x900@59.99",
	position = "1920x0",
	scale = 1,
})

-- Programs
local terminal = "kitty"
local menu = "fuzzel"

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

-- Look and feel
hl.config({
	-- General
	general = {
		gaps_in = 0,
		gaps_out = 0,
		border_size = 2,
		col = {
			-- active_border = "rgb(859900)",
			active_border = { colors = {"rgba(33ccffee)", "rgba(00ff99ee)"}, angle = 45 },
			inactive_border = "rgb(839496)",
		},
		resize_on_border = false,
		allow_tearing = false,
		layout = "master",
	},
	-- Layout
	master = {
		mfact = 0.6,
		new_status = "master",
	},
	-- Decoration
	decoration = {
		rounding = 0,
		active_opacity = 1.0,
		inactive_opacity = 1.0,
		shadow = {
			enabled = false,
		},
		blur = {
			enabled = false,
		}
	},
	-- Input
	input = {
		kb_layout = "gb",
		kb_variant = "",
		kb_model = "",
		kb_options = "caps:escape,grp:alt_shift_toggle",
		kb_rules = "",
		follow_mouse = 1,
		sensitivity = 0,
		repeat_rate = 40,
		repeat_delay = 300,
		touchpad = {
			natural_scroll = false,
		}
	},
	-- Animations
	animations = {
		enabled = false,
		-- workspace_wraparound = true,
	},
})
-- hl.animation({ leaf = STRING, enabled = BOOLEAN, speed = FLOAT, curve = STRING[, style = STRING] })
hl.device({
	name = "tpps/2-ibm-trackpoint",
	scroll_method = "on_button_down",
	sensitivity = -0.5,
})
hl.device({
	name = "synps/2-synaptics-touchpad",
	scroll_method = "edge",
})

-- Key binds
local mod = "SUPER"
hl.bind(mod .. " + Q", hl.dsp.exec_cmd(terminal))
hl.bind(mod .. " + SHIFT + Q", hl.dsp.exec_cmd("bash $HOME/code/scripts/new_terminal.sh"))
hl.bind(mod .. " + C", hl.dsp.window.close())
hl.bind(mod .. " + M", hl.dsp.window.fullscreen("maximised", "toggle"))
hl.bind(mod .. " + E", hl.dsp.exit())
hl.bind(mod .. " + Space", hl.dsp.exec_cmd(menu))
hl.bind(mod .. " + F12", hl.dsp.exec_cmd("screenshot-wayland"))
hl.bind(mod .. " + O", hl.dsp.exec_cmd("hyprpicker"))
hl.bind(mod .. " + S", hl.dsp.layout("swapwithmaster master"))
hl.bind(mod .. " + N", hl.dsp.layout("cyclenext"))
hl.bind(mod .. " + P", hl.dsp.layout("cycleprev"))
hl.bind(mod .. " + G", hl.dsp.layout("focusmaster"))
hl.bind(mod .. " + F", hl.dsp.window.move({ monitor = "+1"}))
hl.bind(mod .. " + B", hl.dsp.exec_cmd("dunstify $(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E 'percentage' | sed 's/[ ]*percentage:[ ]*//') --urgency low"))

-- Discord PTT
hl.bind(mod .. " + V", hl.dsp.send_shortcut({window = "class:^vesktop", mods="", key="F12"}))

-- Resizing
hl.bind(mod .. " + L", hl.dsp.layout("mfact +0.01"), { repeating = true })
hl.bind(mod .. " + H", hl.dsp.layout("mfact -0.01"), { repeating = true })

-- Moving
hl.bind(mod .. " + J", hl.dsp.focus({monitor = "-1"}))
hl.bind(mod .. " + K", hl.dsp.focus({monitor = "+1"}))

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


-- Laptop multimedia keys for volume and LCD brightness
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("XF86MonBrightnessUp", hl.dsp.exec_cmd("brightnessctl -e4 -n2 set 5%+"), { locked = true, repeating = true })
hl.bind("XF86MonBrightnessDown",hl.dsp.exec_cmd("brightnessctl -e4 -n2 set 5%-"), { locked = true, repeating = 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 })

-- Autostart
hl.on("hyprland.start", function()
	hl.exec_cmd("hyprpaper")
	hl.exec_cmd("dunst")
	hl.exec_cmd("bash $HOME/code/scripts/dunst-battery.sh")
end)
