pinnacle/api/lua/examples/default/default_config.lua

146 lines
4.3 KiB
Lua
Raw Normal View History

require("pinnacle").setup(function(Pinnacle)
local Input = Pinnacle.input
local Process = Pinnacle.process
local Output = Pinnacle.output
local Tag = Pinnacle.tag
local Window = Pinnacle.window
local key = Input.key
---@type Modifier
local mod_key = "ctrl"
local terminal = "alacritty"
2024-01-16 06:37:17 +01:00
--------------------
-- Mousebinds --
--------------------
2024-02-08 04:39:56 +01:00
Input.mousebind({ mod_key }, "btn_left", "press", function()
Window.begin_move("btn_left")
end)
2024-02-08 04:39:56 +01:00
Input.mousebind({ mod_key }, "btn_right", "press", function()
Window.begin_resize("btn_right")
end)
2024-01-16 06:37:17 +01:00
--------------------
-- Keybinds --
--------------------
2024-01-16 06:37:17 +01:00
-- mod_key + alt + q = Quit Pinnacle
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "alt" }, "q", function()
Pinnacle.quit()
end)
2024-01-16 06:37:17 +01:00
-- mod_key + alt + c = Close window
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "alt" }, "c", function()
local focused = Window.get_focused()
if focused then
focused:close()
end
end)
2024-01-16 06:37:17 +01:00
-- mod_key + alt + Return = Spawn `terminal`
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key }, key.Return, function()
Process.spawn(terminal)
end)
2024-01-16 06:37:17 +01:00
-- mod_key + alt + space = Toggle floating
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "alt" }, key.space, function()
local focused = Window.get_focused()
if focused then
focused:toggle_floating()
end
end)
2024-01-16 06:37:17 +01:00
-- mod_key + f = Toggle fullscreen
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key }, "f", function()
local focused = Window.get_focused()
if focused then
focused:toggle_fullscreen()
end
end)
2024-01-16 06:37:17 +01:00
-- mod_key + m = Toggle maximized
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key }, "m", function()
local focused = Window.get_focused()
if focused then
focused:toggle_maximized()
end
end)
2024-01-16 06:37:17 +01:00
--------------------
-- Tags --
--------------------
local tag_names = { "1", "2", "3", "4", "5" }
2024-01-16 06:37:17 +01:00
-- `connect_for_all` is useful for performing setup on every monitor you have.
-- Here, we add tags with names 1-5 and set tag 1 as active.
2024-02-08 04:39:56 +01:00
Output.connect_for_all(function(op)
local tags = Tag.add(op, tag_names)
tags[1]:set_active(true)
end)
2024-01-16 06:37:17 +01:00
-- Spawning must happen after you add tags, as Pinnacle currently doesn't render windows without tags.
2024-02-08 04:39:56 +01:00
Process.spawn_once(terminal)
2024-01-16 06:37:17 +01:00
-- Create a layout cycler to cycle layouts on an output.
2024-02-08 04:39:56 +01:00
local layout_cycler = Tag.new_layout_cycler({
"master_stack",
"dwindle",
"spiral",
"corner_top_left",
"corner_top_right",
"corner_bottom_left",
"corner_bottom_right",
})
2024-01-16 06:37:17 +01:00
-- mod_key + space = Cycle forward one layout on the focused output
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key }, key.space, function()
local focused_op = Output.get_focused()
if focused_op then
layout_cycler.next(focused_op)
end
end)
2024-01-16 06:37:17 +01:00
-- mod_key + shift + space = Cycle backward one layout on the focused output
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "shift" }, key.space, function()
local focused_op = Output.get_focused()
if focused_op then
layout_cycler.prev(focused_op)
end
end)
for _, tag_name in ipairs(tag_names) do
-- nil-safety: tags are guaranteed to be on the outputs due to connect_for_all above
2024-01-16 06:37:17 +01:00
-- mod_key + 1-5 = Switch to tags 1-5
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key }, tag_name, function()
Tag.get(tag_name):switch_to()
end)
2024-01-16 06:37:17 +01:00
-- mod_key + shift + 1-5 = Toggle tags 1-5
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "shift" }, tag_name, function()
Tag.get(tag_name):toggle_active()
end)
2024-01-16 06:37:17 +01:00
-- mod_key + alt + 1-5 = Move window to tags 1-5
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "alt" }, tag_name, function()
local focused = Window.get_focused()
if focused then
2024-02-08 04:39:56 +01:00
focused:move_to_tag(Tag.get(tag_name) --[[@as TagHandle]])
end
end)
2024-01-16 06:37:17 +01:00
-- mod_key + shift + alt + 1-5 = Toggle tags 1-5 on window
2024-02-08 04:39:56 +01:00
Input.keybind({ mod_key, "shift", "alt" }, tag_name, function()
local focused = Window.get_focused()
if focused then
2024-02-08 04:39:56 +01:00
focused:toggle_tag(Tag.get(tag_name) --[[@as TagHandle]])
end
end)
end
end)