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

187 lines
5.6 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 Layout = Pinnacle.layout
local Util = Pinnacle.util
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)
--------------------
-- Layouts --
--------------------
local layout_manager = Layout.new_cycling_manager({
2024-03-17 01:58:38 +01:00
Layout.builtins.master_stack(),
Layout.builtins.master_stack({ master_side = "right" }),
Layout.builtins.master_stack({ master_side = "top" }),
Layout.builtins.master_stack({ master_side = "bottom" }),
Layout.builtins.dwindle(),
Layout.builtins.spiral(),
Layout.builtins.corner(),
Layout.builtins.corner({ corner_loc = "top_right" }),
Layout.builtins.corner({ corner_loc = "bottom_left" }),
Layout.builtins.corner({ corner_loc = "bottom_right" }),
Layout.builtins.fair(),
Layout.builtins.fair({ direction = "horizontal" }),
})
Layout.set_manager(layout_manager)
-- mod_key + space = Cycle forward one layout on the focused output
Input.keybind({ mod_key }, key.space, function()
local focused_op = Output.get_focused()
if focused_op then
local tags = focused_op:tags()
local tag = nil
for _, t in ipairs(tags or {}) do
if t:active() then
tag = t
break
end
end
if tag then
layout_manager:cycle_layout_forward(tag)
2024-03-15 01:42:08 +01:00
Layout.request_layout(focused_op)
end
end
end)
-- mod_key + shift + space = Cycle backward one layout on the focused output
Input.keybind({ mod_key, "shift" }, key.space, function()
local focused_op = Output.get_focused()
if focused_op then
local tags = focused_op:tags()
local tag = nil
for _, t in ipairs(tags or {}) do
if t:active() then
tag = t
break
end
end
if tag then
layout_manager:cycle_layout_backward(tag)
2024-03-15 01:42:08 +01:00
Layout.request_layout(focused_op)
end
end
end)
-- Spawning must happen after you add tags, as Pinnacle currently doesn't render windows without tags.
Process.spawn_once(terminal)
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
-- Enable sloppy focus
Window.connect_signal({
pointer_enter = function(window)
window:set_focused(true)
end,
})
end)