Files
dotfiles/hypr/hyprland/binds.lua

193 lines
6.3 KiB
Lua

function bind(keys, dispatcher, flags)
if flags == nil then
flags = {}
end
flags.submap_universal = true
hl.bind(keys, dispatcher, flags)
end
-- Workspaces
-- Super + num goes to workspace #num
for i = 1, 9 do
bind('SUPER + ' .. tostring(i), hl.dsp.focus({workspace = i}))
end
-- Super + num moves focused window to workspace #num
for i = 1, 9 do
bind("SUPER + SHIFT + " .. tostring(i), hl.dsp.window.move({workspace = i}))
end
-- Select windows ordered top to bottom, left to right
local function select_window(n)
local workspace = hl.get_active_special_workspace()
if workspace == nil then
workspace = hl.get_active_workspace()
end
local windows = hl.get_windows({workspace = workspace})
-- fuckass language doesn't have normal for loops
local i = 1
while i <= #windows do
if windows[i].pinned then
table.remove(windows, i)
else
i=i+1
end
end
table.sort(
windows,
function (a, b)
return ((a.at.x^2 + a.at.y^2) * 1)
< ((b.at.x^2 + b.at.y^2) * 1)
end
)
return windows[n]
end
local function focus_window(n)
local window = select_window(n)
if window ~= nil then
hl.dispatch(hl.dsp.focus({window = window}))
end
end
local focus_window_keys = {
'A',
'O',
'E',
'U',
'SHIFT + A',
'SHIFT + O',
'SHIFT + E',
'SHIFT + U',
}
for i, key in ipairs(focus_window_keys) do
bind('SUPER + ' .. key, function() focus_window(i) end)
end
-- Move/resize windows
bind("SUPER + H", hl.dsp.window.move({direction = "l"}))
bind("SUPER + T", hl.dsp.window.move({direction = "u"}))
bind("SUPER + N", hl.dsp.window.move({direction = "d"}))
bind("SUPER + S", hl.dsp.window.move({direction = "r"}))
bind("SUPER + ALT + H", hl.dsp.window.resize({x = -50, y = 0, relative = true}),
{repeating = true})
bind("SUPER + ALT + T", hl.dsp.window.resize({x = 0, y = -50, relative = true}),
{repeating = true})
bind("SUPER + ALT + N", hl.dsp.window.resize({x = 0, y = 50, relative = true}),
{repeating = true})
bind("SUPER + ALT + S", hl.dsp.window.resize({x = 50, y = 0, relative = true}),
{repeating = true})
bind("SUPER + mouse:272", hl.dsp.window.drag(), ({mouse = true}))
bind("SUPER + mouse:273", hl.dsp.window.resize(), ({mouse = true}))
-- Window management
bind('SUPER + APOSTROPHE', hl.dsp.window.close())
bind('SUPER + COMMA', hl.dsp.window.fullscreen())
bind('SUPER + PERIOD', function()
-- Float window, resize to 90%, and center it
hl.dispatch(hl.dsp.window.float())
local monitor = hl.get_active_monitor()
local window = hl.get_active_window()
if (monitor == nil or window == nil) then return end
if not window.floating then return end
hl.dispatch(hl.dsp.window.resize({
x = monitor.width - monitor.height * 0.1,
y = monitor.height * 0.9
}))
hl.dispatch(hl.dsp.window.center())
end)
bind('SUPER + P', hl.dsp.layout('togglesplit'))
bind('SUPER + Y', hl.dsp.layout('swapsplit'))
-- Special workspace
bind("SUPER + SEMICOLON", function ()
if hl.get_active_special_workspace() == nil then
hl.dispatch(hl.dsp.window.move({workspace = "special"}))
else
hl.dispatch(hl.dsp.window.move({workspace = hl.get_active_workspace()}))
end
end)
bind('SUPER + Q', hl.dsp.workspace.toggle_special())
-- Multi monitor
bind("SUPER + J", hl.dsp.focus({monitor = -1}))
bind("SUPER + SHIFT + J", hl.dsp.window.move({monitor = -1}))
-- Screen locking
bind("SUPER + ESCAPE", hl.dsp.exec_cmd("~/.config/scripts/lock.sh"), {locked = true})
bind("SUPER + SHIFT + ESCAPE", hl.dsp.exec_cmd("quickshell ipc call lock open"))
bind("XF86Go", hl.dsp.exec_cmd("~/.config/scripts/idle-toggle.sh"))
bind("switch:on:Lid Switch", hl.dsp.exec_cmd(
"quickshell ipc call lock instalock; sleep 0.5; systemctl suspend"
))
-- Open favourites
bind("SUPER + G", hl.dsp.exec_cmd("zen-browser"))
bind("SUPER + R", hl.dsp.exec_cmd("keepassxc"))
bind("SUPER + L", hl.dsp.exec_cmd("kitty"))
-- Screen capturing
local zoom = 1
bind("SUPER + Z", function()
zoom = zoom + 1
hl.config({cursor = {zoom_factor = zoom, invisible = true}})
end)
bind ("SUPER + SHIFT + Z", function()
zoom = 1
hl.config({cursor = {zoom_factor = 1, invisible = false}})
end)
bind('SUPER + V', hl.dsp.exec_cmd(
'pgrep slurp || hyprshot -o ~/Pictures/Screenshots -z -s -m region'
))
bind('SUPER + ALT + V', hl.dsp.exec_cmd(
'pgrep slurp || hyprshot -o ~/Pictures/Screenshots -z -s -m window'
))
bind('SUPER + SHIFT + V', hl.dsp.exec_cmd(
'pgrep slurp || hyprshot -o ~/Pictures/Screenshots -z -s -m active -m output'
))
bind('SUPER + W', hl.dsp.exec_cmd('quickshell ipc call overlay open'))
bind('SUPER + M', hl.dsp.exec_cmd('wayscriber --active'))
bind('SUPER + ALT + M', hl.dsp.exec_cmd('wl-paste | satty -f -'))
bind("SHIFT + XF86Display", hl.dsp.exec_cmd("~/.config/scripts/vnc-toggle.sh"))
bind("XF86Display", hl.dsp.exec_cmd("pkill -x quickshell; quickshell"))
-- Adjust brightness
bind(
"XF86MonBrightnessUp",
hl.dsp.global("quickshell:increase_brightness"),
{locked = true, repeating = true}
)
bind(
"XF86MonBrightnessDown",
hl.dsp.global("quickshell:decrease_brightness"),
{locked = true, repeating = true}
)
bind(
"SHIFT + XF86MonBrightnessDown",
hl.dsp.exec_cmd("brillo -S 0% -q -u 1000000"),
{locked = true, repeating = true}
)
-- Adjust volume and media
bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd(
"pactl set-sink-volume @DEFAULT_SINK@ +1%"
))
bind("XF86AudioLowerVolume", hl.dsp.exec_cmd(
"pactl set-sink-volume @DEFAULT_SINK@ -1%"
))
bind("XF86AudioMicMute", hl.dsp.exec_cmd("playerctl next"))
bind("XF86AudioMute", hl.dsp.exec_cmd("playerctl play-pause"))
-- Toggle bar
bind("SUPER + SPACE", hl.dsp.global("quickshell:peek_bar"))
bind("SUPER + SPACE", hl.dsp.global("quickshell:peek_bar"), {release = true})
bind("SUPER + SUPER_L", hl.dsp.exec_cmd("quickshell ipc call topbar toggle"), {device = {inclusive = false, list = {"zikway-hid-gamepad-keyboard"}}})
bind("SUPER + SUPER_R", hl.dsp.workspace.toggle_special(), {device = {inclusive = true, list = {"zikway-hid-gamepad-keyboard"}}})
-- Global back and forward binds
bind('ALT + SLASH', hl.dsp.send_shortcut({mods = 'ALT', key = 'LEFT'}))
bind('ALT + EQUAL', hl.dsp.send_shortcut({mods = 'ALT', key = 'RIGHT'}))