pinnacle/api/lua/example_config.lua

156 lines
5.7 KiB
Lua
Raw Normal View History

-- SPDX-License-Identifier: MIT
2023-06-22 01:03:27 +02:00
-- Just like in Awesome, if you want access to Luarocks packages, this needs to be called.
-- NOTE: The loader doesn't load from the local Luarocks directory (probably in ~/.luarocks),
-- | so if you have any rocks installed with --local,
-- | you may need to add those paths to package.path and package.cpath.
-- Alternatively, you can add
-- eval $(luarocks path --bin)
-- to your shell's startup script to permanently have access to Luarocks in all your Lua files.
pcall(require, "luarocks.loader")
-- Neovim users be like:
2023-06-20 02:09:05 +02:00
require("pinnacle").setup(function(pinnacle)
2023-07-11 18:59:38 +02:00
local input = pinnacle.input -- Key and mouse binds
local window = pinnacle.window -- Window management
local process = pinnacle.process -- Process spawning
2023-07-11 18:59:38 +02:00
local tag = pinnacle.tag -- Tag management
local output = pinnacle.output -- Output management
-- Every key supported by xkbcommon.
local keys = input.keys
---@type Modifier
local mod_key = "Ctrl" -- This is set to `Ctrl` instead of `Super` to not conflict with your WM/DE keybinds
-- ^ Add type annotations for that sweet, sweet autocomplete
local terminal = "alacritty"
2023-09-10 11:49:31 +02:00
process.set_env("MOZ_ENABLE_WAYLAND", "1")
2023-08-05 00:01:37 +02:00
-- Outputs -----------------------------------------------------------------------
-- You can set your own monitor layout as I have done below for my monitors.
-- local lg = output.get_by_name("DP-2") --[[@as Output]]
-- local dell = output.get_by_name("DP-3") --[[@as Output]]
--
-- dell:set_loc_left_of(lg, "bottom")
-- Keybinds ----------------------------------------------------------------------
2023-07-11 18:59:38 +02:00
2023-08-14 21:44:10 +02:00
-- mod_key + Alt + q quits the compositor
input.keybind({ mod_key, "Alt" }, keys.q, pinnacle.quit)
2023-06-22 02:12:27 +02:00
2023-08-14 21:44:10 +02:00
-- mod_key + Alt + c closes the focused window
2023-07-18 22:12:23 +02:00
input.keybind({ mod_key, "Alt" }, keys.c, function()
-- The commented out line may crash the config process if you have no windows open.
-- There is no nil warning here due to limitations in Lua LS type checking, so check for nil as shown below.
-- window.get_focused():close()
local win = window.get_focused()
if win ~= nil then
win:close()
end
end)
2023-08-14 21:44:10 +02:00
-- mod_key + return spawns a terminal
input.keybind({ mod_key }, keys.Return, function()
process.spawn(terminal, function(stdout, stderr, exit_code, exit_msg)
-- do something with the output here
end)
end)
-- mod_key + Alt + Space toggle floating on the focused window
2023-07-19 04:10:43 +02:00
input.keybind({ mod_key, "Alt" }, keys.space, function()
local win = window.get_focused()
if win ~= nil then
win:toggle_floating()
2023-07-19 04:10:43 +02:00
end
end)
2023-06-21 21:48:38 +02:00
2023-08-14 21:44:10 +02:00
-- mod_key + f toggles fullscreen on the focused window
2023-08-13 00:43:37 +02:00
input.keybind({ mod_key }, keys.f, function()
local win = window.get_focused()
if win ~= nil then
win:toggle_fullscreen()
2023-08-13 00:43:37 +02:00
end
end)
2023-08-13 00:43:37 +02:00
2023-08-14 21:44:10 +02:00
-- mod_key + m toggles maximized on the focused window
2023-08-13 00:43:37 +02:00
input.keybind({ mod_key }, keys.m, function()
local win = window.get_focused()
if win ~= nil then
win:toggle_maximized()
2023-08-13 00:43:37 +02:00
end
end)
2023-07-01 04:34:07 +02:00
-- Tags ---------------------------------------------------------------------------
2023-07-11 18:59:38 +02:00
2023-09-10 02:27:05 +02:00
local tags = { "1", "2", "3", "4", "5" }
2023-07-11 18:59:38 +02:00
output.connect_for_all(function(op)
2023-08-14 21:44:10 +02:00
-- Add tags 1, 2, 3, 4 and 5 on all monitors, and toggle tag 1 active by default
2023-09-10 02:27:05 +02:00
op:add_tags(tags)
2023-07-18 17:31:08 +02:00
-- Same as tag.add(op, "1", "2", "3", "4", "5")
2023-09-08 03:36:49 +02:00
tag.toggle({ name = "1", output = op })
2023-09-06 06:18:44 +02:00
-- Window rules
2023-09-08 03:56:43 +02:00
-- Add your own window rules here. Below is an example.
--
-- These currently need to be added inside of `connect_for_all` because
2023-09-08 04:00:00 +02:00
-- it only runs after the whole config is parsed, so any specified tags won't be available outside
-- of this function. This means that if you have multiple monitors,
-- these rules will be duplicated unless you write in some logic to prevent that.
--
2023-09-08 03:56:43 +02:00
-- window.rules.add({
-- cond = { class = "kitty" },
-- rule = { size = { 300, 300 }, location = { 50, 50 } },
-- }, {
-- cond = {
-- class = "XTerm",
-- tag = "4",
-- },
-- rule = { size = { 500, 800 }, floating_or_tiled = "Floating" },
-- })
2023-07-11 18:59:38 +02:00
end)
2023-07-01 04:34:07 +02:00
-- Layout cycling
-- Create a layout cycler to cycle your tag layouts. This will store which layout each tag has
-- and change to the next or previous one in the array when the respective function is called.
local layout_cycler = tag.layout_cycler({
2023-07-18 03:40:56 +02:00
"MasterStack",
"Dwindle",
"Spiral",
"CornerTopLeft",
"CornerTopRight",
"CornerBottomLeft",
"CornerBottomRight",
})
2023-07-13 01:50:41 +02:00
2023-09-10 03:41:21 +02:00
input.keybind({ mod_key }, keys.space, layout_cycler.next)
input.keybind({ mod_key, "Shift" }, keys.space, layout_cycler.prev)
2023-07-13 01:50:41 +02:00
-- Tag manipulation
2023-09-10 02:27:05 +02:00
for _, tag_name in pairs(tags) do
2023-09-10 03:41:21 +02:00
-- mod_key + 1-5 switches tags
2023-09-10 02:27:05 +02:00
input.keybind({ mod_key }, tag_name, function()
tag.switch_to(tag_name)
end)
2023-09-10 03:41:21 +02:00
-- mod_key + Shift + 1-5 toggles tags
2023-09-10 02:27:05 +02:00
input.keybind({ mod_key, "Shift" }, tag_name, function()
tag.toggle(tag_name)
end)
2023-09-10 03:41:21 +02:00
-- mod_key + Alt + 1-5 moves windows to tags
2023-09-10 02:27:05 +02:00
input.keybind({ mod_key, "Alt" }, tag_name, function()
local _ = window.get_focused() and window:get_focused():move_to_tag(tag_name)
end)
2023-09-10 03:41:21 +02:00
-- mod_key + Shift + Alt + 1-5 toggles tags on windows
2023-09-10 02:27:05 +02:00
input.keybind({ mod_key, "Shift", "Alt" }, tag_name, function()
local _ = window.get_focused() and window.get_focused():toggle_tag(tag_name)
end)
end
2023-06-20 02:09:05 +02:00
end)