---------------------
---- KEYBINDINGS ----
---------------------

local mainMod  = "SUPER"
local secondMod = "CTRL + ALT"

-- Switch workspaces with mainMod + [0-9]
-- Move active window to a workspace with mainMod + SHIFT + [0-9]
for i = 1, 10 do
    local key = i % 10
    hl.bind(mainMod .. " + " .. key,         hl.dsp.focus({ workspace = i }))
    hl.bind(mainMod .. " + SHIFT + " .. key, hl.dsp.window.move({ workspace = i }))
end

-- Shell Binds
hl.bind("SUPER + SUPER_L",         hl.dsp.exec_cmd("dms ipc call spotlight toggle"), { release = true })
hl.bind(mainMod .. " + P",         hl.dsp.exec_cmd("dms ipc call clipboard toggle"))
hl.bind(mainMod .. " + M",         hl.dsp.exec_cmd("dms ipc call processlist toggle"))
hl.bind(mainMod .. " + SHIFT + N", hl.dsp.exec_cmd("dms ipc call notifications toggle"))
hl.bind(mainMod .. " + N",         hl.dsp.exec_cmd("dms ipc call notepad toggle"))
hl.bind(mainMod .. " + S",         hl.dsp.exec_cmd("dms ipc call settings toggle"))
hl.bind(mainMod .. " + Y",         hl.dsp.exec_cmd("dms ipc call dankdash wallpaper"))

-- RaveSwitch
hl.bind("SUPER + TAB",             hl.dsp.exec_cmd([[raveswitch socat '{"OpenSwitch":{"reverse":false}}']]))

-- Apps
hl.bind(secondMod .. " + T",        hl.dsp.exec_cmd("kitty"))
hl.bind(secondMod .. " + F",        hl.dsp.exec_cmd("freetube"))
hl.bind(secondMod .. " + D",        hl.dsp.exec_cmd("discord"))
hl.bind(secondMod .. " + G",        hl.dsp.exec_cmd("gedit"))
hl.bind(secondMod .. " + P",        hl.dsp.exec_cmd("pavucontrol"))

-- Power
hl.bind("CTRL + SUPER + Home", hl.dsp.exec_cmd("reboot"))
hl.bind("CTRL + SUPER + End",  hl.dsp.exec_cmd("poweroff"))

-- Window management
hl.bind(mainMod .. " + Q",   hl.dsp.window.kill())
hl.bind(mainMod .. " + V",   hl.dsp.window.float())
hl.bind(mainMod .. " + SHIFT + Tab", hl.dsp.exec_cmd([[raveswitch socat '{"OpenSwitch":{"reverse":true}}']]))

-- Move focus with mainMod + arrow keys
hl.bind(mainMod .. " + left",  hl.dsp.focus({ direction = "left" }))
hl.bind(mainMod .. " + right", hl.dsp.focus({ direction = "right" }))
hl.bind(mainMod .. " + up",    hl.dsp.focus({ direction = "up" }))
hl.bind(mainMod .. " + down",  hl.dsp.focus({ direction = "down" }))

-- Move/resize windows with mainMod + mouse
hl.bind(mainMod .. " + mouse:272", hl.dsp.window.drag())
hl.bind(mainMod .. " + mouse:273", hl.dsp.window.resize())

-- Screenshots (Hyprshot)
hl.bind("Print",           hl.dsp.exec_cmd("hyprshot -m output"))
hl.bind("SHIFT + Print",   hl.dsp.exec_cmd("hyprshot -m region"))
hl.bind(mainMod .. " + Print", hl.dsp.exec_cmd("hyprshot -m window"))

-- Laptop multimedia keys
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 })

-- Media keys (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 })
