Files
hyprland-dotfiles/config/keybinds.lua
T
2026-08-12 23:15:12 -07:00

168 lines
6.2 KiB
Lua

-- All keybindings live in this module so conflicts can be audited in one
-- place. Shared values come from settings; command wrapping comes from lib.
local commands = require("lib.commands")
local settings = require("config.settings")
local main = settings.modifiers.main
local hyper = settings.modifiers.hyper
-- Build normalized bind strings and avoid hand-written separator mistakes such
-- as doubled `+` characters.
local function chord(...)
return table.concat({ ... }, " + ")
end
-- Generate matching focus/move bindings for numbered workspaces. Workspace 10
-- maps to the 0 key because `% 10` returns zero.
local function bind_numbered_workspaces(modifier, move_modifier, count)
for workspace = 1, count do
local key = workspace % 10
hl.bind(
chord(modifier, key),
hl.dsp.focus({ workspace = workspace }),
{ description = "Switch to workspace " .. workspace }
)
hl.bind(
chord(modifier, move_modifier, key),
hl.dsp.window.move({ workspace = workspace }),
{ description = "Send focused window to workspace " .. workspace }
)
end
end
-- Core application and window-management shortcuts.
hl.bind(
chord(main, "SPACE"),
hl.dsp.exec_cmd("noctalia msg panel-toggle launcher"),
{ description = "Toggle Noctalia launcher" }
)
hl.bind(chord(main, "W"), hl.dsp.window.close())
hl.bind(chord(main, "Q"), hl.dsp.exec_cmd(commands.uwsm(settings.programs.terminal)))
hl.bind(chord(main, "E"), hl.dsp.exec_cmd(commands.uwsm(settings.programs.file_manager)))
hl.bind(chord(main, "V"), hl.dsp.window.float({ action = "toggle" }))
hl.bind(chord(main, "R"), hl.dsp.exec_cmd(settings.programs.launcher))
hl.bind(chord(main, "P"), hl.dsp.window.pseudo())
hl.bind(chord(main, "J"), hl.dsp.layout("togglesplit"))
-- One direction table drives arrow-key focus, Hyper+WASD focus/movement, and
-- moving the active workspace between adjacent monitors.
local directions = {
{ arrow = "left", key = "A", direction = "l" },
{ arrow = "right", key = "D", direction = "r" },
{ arrow = "up", key = "W", direction = "u" },
{ arrow = "down", key = "S", direction = "d" },
}
for _, direction in ipairs(directions) do
hl.bind(
chord(main, direction.arrow),
hl.dsp.focus({ direction = direction.arrow })
)
hl.bind(
chord(hyper, direction.key),
hl.dsp.focus({ direction = direction.direction })
)
hl.bind(
chord(hyper, "CTRL", direction.key),
hl.dsp.window.move({ direction = direction.direction })
)
hl.bind(
chord(hyper, main, direction.key),
hl.dsp.workspace.move({ monitor = direction.direction }),
{ description = "Move workspace " .. direction.direction }
)
end
bind_numbered_workspaces(main, "SHIFT", 10)
bind_numbered_workspaces(hyper, "CTRL", 9)
-- Cycle workspaces with the wheel and manipulate windows with mouse buttons.
hl.bind(chord(main, "mouse_down"), hl.dsp.focus({ workspace = "e+1" }))
hl.bind(chord(main, "mouse_up"), hl.dsp.focus({ workspace = "e-1" }))
hl.bind(chord(main, "mouse:272"), hl.dsp.window.drag(), { mouse = true })
hl.bind(chord(main, "mouse:273"), hl.dsp.window.resize(), { mouse = true })
-- Locked media keys also work while the session is locked. Volume and
-- brightness binds repeat while held; playback controls fire once.
local media_binds = {
{ "XF86AudioRaiseVolume", "wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+", { locked = true, repeating = true } },
{ "XF86AudioLowerVolume", "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-", { locked = true, repeating = true } },
{ "XF86AudioMute", "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle", { locked = true, repeating = true } },
{ "XF86AudioMicMute", "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle", { locked = true, repeating = true } },
{ "XF86MonBrightnessUp", "brightnessctl -e4 -n2 set 5%+", { locked = true, repeating = true } },
{ "XF86MonBrightnessDown", "brightnessctl -e4 -n2 set 5%-", { locked = true, repeating = true } },
{ "XF86AudioNext", "playerctl next", { locked = true } },
{ "XF86AudioPause", "playerctl play-pause", { locked = true } },
{ "XF86AudioPlay", "playerctl play-pause", { locked = true } },
{ "XF86AudioPrev", "playerctl previous", { locked = true } },
}
for _, bind in ipairs(media_binds) do
hl.bind(bind[1], hl.dsp.exec_cmd(bind[2]), bind[3])
end
-- Generate focus/move shortcuts for every named workspace in settings.lua.
for _, workspace in ipairs(settings.named_workspaces) do
hl.bind(
chord(hyper, workspace.key),
hl.dsp.focus({ workspace = workspace.selector }),
{ description = "Switch to " .. workspace.name .. " workspace" }
)
hl.bind(
chord(hyper, "CTRL", workspace.key),
hl.dsp.window.move({ workspace = workspace.selector }),
{ description = "Send focused window to " .. workspace.name .. " workspace" }
)
end
-- Promote the focused client when a workspace is using master layout.
hl.bind(
chord(hyper, "M"),
hl.dsp.layout("swapwithmaster master ignoremaster"),
{ description = "Promote to master" }
)
-- Hyprtasking provides a visual overview of windows on all workspaces.
hl.bind(
chord(hyper, "SPACE"),
function()
hl.plugin.hyprtasking.toggle("all")
end
)
-- Toggle a focused client into an 80%-sized centered floating mode. Returning
-- it to tiled mode lets the active layout restore its previous geometry.
hl.bind(chord(hyper, "F"), function()
local window = hl.get_active_window()
local monitor = hl.get_active_monitor()
if not window or not monitor then
return
end
local was_tiled = not window.floating
hl.dispatch(hl.dsp.window.float({ action = "toggle" }))
if not was_tiled then
return
end
hl.dispatch(hl.dsp.window.resize({
x = math.floor(monitor.width * 0.80),
y = math.floor(monitor.height * 0.80),
relative = false,
}))
hl.dispatch(hl.dsp.window.center())
hl.dispatch(hl.dsp.window.alter_zorder({ mode = "top" }))
end, {
description = "Toggle focused floating window",
})
-- Open the HyprCapture plugin's interactive region/window picker.
hl.bind(
chord(main, "SHIFT", "S"),
hl.plugin.hyprcapture.open,
{ description = "HyprCapture window capture" }
)