mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-11-16 07:48:11 +01:00
Support Lua down to 5.2
This commit is contained in:
parent
ef47a9f8c5
commit
3e7ef6d079
8 changed files with 52 additions and 214 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
|
||||
"workspace.library": ["./"],
|
||||
"runtime.version": "Lua 5.4",
|
||||
"runtime.version": "Lua 5.2",
|
||||
|
||||
"--comment": "Format using Stylua instead",
|
||||
"format.enable": false,
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
local inspect = require("inspect")
|
||||
|
||||
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"
|
||||
|
||||
Output:connect_for_all(function(output)
|
||||
local tags = Tag:add(output, "1", "2", "3", "4", "5")
|
||||
tags[1]:set_active(true)
|
||||
end)
|
||||
|
||||
local output = Output:get_all()[1]
|
||||
|
||||
Process:spawn("alacritty")
|
||||
|
||||
Input:keybind({}, "q", function()
|
||||
print("Keybind: q")
|
||||
end)
|
||||
Input:keybind({ "shift" }, "q", function()
|
||||
-- Should not happen, overridden by shift Q
|
||||
print("Keybind: shift q")
|
||||
end)
|
||||
Input:keybind({}, "Q", function()
|
||||
print("Keybind: Q")
|
||||
end)
|
||||
Input:keybind({ "shift" }, "Q", function()
|
||||
print("Keybind: shift Q")
|
||||
end)
|
||||
Input:keybind({}, "@", function()
|
||||
-- Should not happen, can't get @ without shift
|
||||
print("Keybind: @")
|
||||
end)
|
||||
Input:keybind({ "ctrl" }, "@", function()
|
||||
--- Should not happen, same as above
|
||||
print("Keybind: ctrl @")
|
||||
end)
|
||||
|
||||
Input:keybind({ "shift" }, "a", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_fullscreen(true)
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "s", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_fullscreen(false)
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "d", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_maximized(true)
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "f", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_maximized(false)
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "g", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_floating(true)
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "h", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_floating(false)
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "j", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:toggle_fullscreen()
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "k", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:toggle_maximized()
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "shift" }, "l", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:toggle_floating()
|
||||
end
|
||||
end)
|
||||
|
||||
Input:keybind({ "shift" }, "z", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_geometry({ x = 100, y = 200, width = 500, height = 200 })
|
||||
end
|
||||
end)
|
||||
Input:keybind({ "ctrl" }, "z", function()
|
||||
local win = Window:get_focused()
|
||||
if win then
|
||||
win:set_geometry({ width = 500, height = 200 })
|
||||
end
|
||||
end)
|
||||
|
||||
Input:keybind({ "ctrl" }, key.Return, function()
|
||||
Process:spawn("alacritty")
|
||||
end)
|
||||
Input:keybind({ "shift" }, "x", function()
|
||||
print(inspect(Output:get_focused():props()))
|
||||
print(inspect(Window:get_focused():props()))
|
||||
print(inspect(Tag:get("1"):props()))
|
||||
end)
|
||||
end)
|
|
@ -1,50 +0,0 @@
|
|||
# This metaconfig.toml file dictates what config Pinnacle will run.
|
||||
#
|
||||
# When running Pinnacle, the compositor will look in the following directories for a metaconfig.toml file,
|
||||
# in order from top to bottom:
|
||||
# $PINNACLE_CONFIG_DIR
|
||||
# $XDG_CONFIG_HOME/pinnacle/
|
||||
# ~/.config/pinnacle/
|
||||
#
|
||||
# When Pinnacle finds a metaconfig.toml file, it will execute the command provided to `command`.
|
||||
# For now, the only thing that should be here is `lua` with a path to the main config file.
|
||||
# In the future, there will be a Rust API that can be run using `cargo run`.
|
||||
#
|
||||
# Because configuration is done using an external process, if it ever crashes, you lose all of your keybinds.
|
||||
# In order prevent you from getting stuck in the compositor, you must define keybinds to reload your config
|
||||
# and kill Pinnacle.
|
||||
#
|
||||
# More details on each setting can be found below.
|
||||
|
||||
# The command Pinnacle will run on startup and when you reload your config.
|
||||
# Paths are relative to the directory the metaconfig.toml file is in.
|
||||
# This must be an array.
|
||||
command = ["lua", "init.lua"]
|
||||
|
||||
### Keybinds ###
|
||||
# Each keybind takes in a table with two fields: `modifiers` and `key`.
|
||||
# - `modifiers` can be one of "Ctrl", "Alt", "Shift", or "Super".
|
||||
# - `key` can be a string of any lowercase letter, number,
|
||||
# "numN" where N is a number for numpad keys, or "esc"/"escape".
|
||||
# Support for any xkbcommon key is planned for a future update.
|
||||
|
||||
# The keybind that will reload your config.
|
||||
reload_keybind = { modifiers = ["Ctrl", "Alt"], key = "r" }
|
||||
# The keybind that will kill Pinnacle.
|
||||
kill_keybind = { modifiers = ["Ctrl", "Alt", "Shift"], key = "escape" }
|
||||
|
||||
### Socket directory ###
|
||||
# Pinnacle will open a Unix socket at `$XDG_RUNTIME_DIR` by default, falling back to `/tmp` if it doesn't exist.
|
||||
# If you want/need to change this, use the `socket_dir` setting set to the directory of your choosing.
|
||||
#
|
||||
# socket_dir = "/your/dir/here/"
|
||||
|
||||
### Environment Variables ###
|
||||
# You may need to specify to Lua where Pinnacle's Lua API library is.
|
||||
# This is currently done using the `envs` table, with keys as the name of the environment variable and
|
||||
# the value as the variable value. This supports $var expansion, and paths are relative to this metaconfig.toml file.
|
||||
#
|
||||
# Pinnacle will run your config with the additional PINNACLE_DIR environment variable.
|
||||
#
|
||||
# Here, LUA_PATH and LUA_CPATH are used to tell Lua the path to the library.
|
||||
[envs]
|
|
@ -8,10 +8,11 @@ description = {
|
|||
license = "MPL 2.0",
|
||||
}
|
||||
dependencies = {
|
||||
"lua ~> 5.4",
|
||||
"lua >= 5.2",
|
||||
"cqueues ~> 20200726",
|
||||
"http ~> 0.4",
|
||||
"lua-protobuf ~> 0.5",
|
||||
"compat53 ~> 0.13",
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
-- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
require("compat53")
|
||||
|
||||
local socket = require("cqueues.socket")
|
||||
local headers = require("http.headers")
|
||||
local h2_connection = require("http.h2_connection")
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
-- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
require("compat53")
|
||||
|
||||
local pb = require("pb")
|
||||
|
||||
local protobuf = {}
|
||||
|
@ -23,7 +25,9 @@ function protobuf.build_protos()
|
|||
PINNACLE_PROTO_DIR .. "/google/protobuf/empty.proto",
|
||||
}
|
||||
|
||||
local cmd = "protoc --descriptor_set_out=/tmp/pinnacle.pb --proto_path=" .. PINNACLE_PROTO_DIR .. " "
|
||||
local cmd = "protoc --descriptor_set_out=/tmp/pinnacle.pb --proto_path="
|
||||
.. PINNACLE_PROTO_DIR
|
||||
.. " "
|
||||
|
||||
for _, file_path in ipairs(proto_file_paths) do
|
||||
cmd = cmd .. file_path .. " "
|
||||
|
|
|
@ -2,6 +2,8 @@ local client = require("pinnacle.grpc.client")
|
|||
local protobuf = require("pinnacle.grpc.protobuf")
|
||||
local layout_service = require("pinnacle.grpc.defs").pinnacle.layout.v0alpha1.LayoutService
|
||||
|
||||
local mfloor = math.floor
|
||||
|
||||
---@class LayoutArgs
|
||||
---@field output OutputHandle
|
||||
---@field windows WindowHandle[]
|
||||
|
@ -130,16 +132,16 @@ function MasterStack:layout(args)
|
|||
|
||||
if self.master_side == "left" then
|
||||
master_rect, stack_rect =
|
||||
rect:split_at("vertical", math.floor(width * master_factor) - gaps // 2, gaps)
|
||||
rect:split_at("vertical", mfloor(width * master_factor) - mfloor(gaps / 2), gaps)
|
||||
elseif self.master_side == "right" then
|
||||
stack_rect, master_rect =
|
||||
rect:split_at("vertical", math.floor(width * master_factor) - gaps // 2, gaps)
|
||||
rect:split_at("vertical", mfloor(width * master_factor) - mfloor(gaps / 2), gaps)
|
||||
elseif self.master_side == "top" then
|
||||
master_rect, stack_rect =
|
||||
rect:split_at("horizontal", math.floor(height * master_factor) - gaps // 2, gaps)
|
||||
rect:split_at("horizontal", mfloor(height * master_factor) - mfloor(gaps / 2), gaps)
|
||||
else
|
||||
stack_rect, master_rect =
|
||||
rect:split_at("horizontal", math.floor(height * master_factor) - gaps // 2, gaps)
|
||||
rect:split_at("horizontal", mfloor(height * master_factor) - mfloor(gaps / 2), gaps)
|
||||
end
|
||||
|
||||
if not master_rect then
|
||||
|
@ -166,17 +168,17 @@ function MasterStack:layout(args)
|
|||
|
||||
if self.master_side == "left" or self.master_side == "right" then
|
||||
coord = master_rect.y
|
||||
len = master_rect.height // (master_slice_count + 1)
|
||||
len = mfloor(master_rect.height / (master_slice_count + 1))
|
||||
axis = "horizontal"
|
||||
else
|
||||
coord = master_rect.x
|
||||
len = master_rect.width // (master_slice_count + 1)
|
||||
len = mfloor(master_rect.width / (master_slice_count + 1))
|
||||
axis = "vertical"
|
||||
end
|
||||
|
||||
for i = 1, master_slice_count do
|
||||
local slice_point = coord + math.floor(len * i + 0.5)
|
||||
slice_point = slice_point - gaps // 2
|
||||
local slice_point = coord + mfloor(len * i + 0.5)
|
||||
slice_point = slice_point - mfloor(gaps / 2)
|
||||
local to_push, rest = master_rect:split_at(axis, slice_point, gaps)
|
||||
table.insert(geos, to_push)
|
||||
master_rect = rest
|
||||
|
@ -203,8 +205,8 @@ function MasterStack:layout(args)
|
|||
end
|
||||
|
||||
for i = 1, stack_slice_count do
|
||||
local slice_point = coord + math.floor(len * i + 0.5)
|
||||
slice_point = slice_point - gaps // 2
|
||||
local slice_point = coord + mfloor(len * i + 0.5)
|
||||
slice_point = slice_point - mfloor(gaps / 2)
|
||||
local to_push, rest = stack_rect:split_at(axis, slice_point, gaps)
|
||||
table.insert(geos, to_push)
|
||||
stack_rect = rest
|
||||
|
@ -341,12 +343,12 @@ function Dwindle:layout(args)
|
|||
local split_coord
|
||||
if i % 2 == 1 then
|
||||
axis = "vertical"
|
||||
split_coord = rest.x + math.floor(rest.width * factor + 0.5)
|
||||
split_coord = rest.x + mfloor(rest.width * factor + 0.5)
|
||||
else
|
||||
axis = "horizontal"
|
||||
split_coord = rest.y + math.floor(rest.height * factor + 0.5)
|
||||
split_coord = rest.y + mfloor(rest.height * factor + 0.5)
|
||||
end
|
||||
split_coord = split_coord - gaps // 2
|
||||
split_coord = split_coord - mfloor(gaps / 2)
|
||||
|
||||
local to_push
|
||||
|
||||
|
@ -493,13 +495,13 @@ function Corner:layout(args)
|
|||
|
||||
if self.corner_loc == "top_left" or self.corner_loc == "bottom_left" then
|
||||
local x_slice_point = rect.x
|
||||
+ math.floor(rect.width * self.corner_width_factor + 0.5)
|
||||
- gaps // 2
|
||||
+ mfloor(rect.width * self.corner_width_factor + 0.5)
|
||||
- mfloor(gaps / 2)
|
||||
corner_rect, vert_stack_rect = rect:split_at("vertical", x_slice_point, gaps)
|
||||
else
|
||||
local x_slice_point = rect.x
|
||||
+ math.floor(rect.width * (1 - self.corner_width_factor) + 0.5)
|
||||
- gaps // 2
|
||||
+ mfloor(rect.width * (1 - self.corner_width_factor) + 0.5)
|
||||
- mfloor(gaps / 2)
|
||||
vert_stack_rect, corner_rect = rect:split_at("vertical", x_slice_point, gaps)
|
||||
end
|
||||
|
||||
|
@ -513,14 +515,14 @@ function Corner:layout(args)
|
|||
|
||||
if self.corner_loc == "top_left" or self.corner_loc == "top_right" then
|
||||
local y_slice_point = rect.y
|
||||
+ math.floor(rect.height * self.corner_height_factor + 0.5)
|
||||
- gaps // 2
|
||||
+ mfloor(rect.height * self.corner_height_factor + 0.5)
|
||||
- mfloor(gaps / 2)
|
||||
corner_rect, horiz_stack_rect =
|
||||
corner_rect:split_at("horizontal", y_slice_point, gaps)
|
||||
else
|
||||
local y_slice_point = rect.y
|
||||
+ math.floor(rect.height * (1 - self.corner_height_factor) + 0.5)
|
||||
- gaps // 2
|
||||
+ mfloor(rect.height * (1 - self.corner_height_factor) + 0.5)
|
||||
- mfloor(gaps / 2)
|
||||
horiz_stack_rect, corner_rect =
|
||||
corner_rect:split_at("horizontal", y_slice_point, gaps)
|
||||
end
|
||||
|
@ -539,14 +541,14 @@ function Corner:layout(args)
|
|||
local horiz_geos = {}
|
||||
|
||||
local vert_stack_count = math.ceil((win_count - 1) / 2)
|
||||
local horiz_stack_count = math.floor((win_count - 1) / 2)
|
||||
local horiz_stack_count = mfloor((win_count - 1) / 2)
|
||||
|
||||
local vert_stack_y = vert_stack_rect.y
|
||||
local vert_win_height = vert_stack_rect.height / vert_stack_count
|
||||
|
||||
for i = 1, vert_stack_count - 1 do
|
||||
local slice_point = vert_stack_y + math.floor(vert_win_height * i + 0.5)
|
||||
slice_point = slice_point - gaps // 2
|
||||
local slice_point = vert_stack_y + mfloor(vert_win_height * i + 0.5)
|
||||
slice_point = slice_point - mfloor(gaps / 2)
|
||||
local to_push, rest = vert_stack_rect:split_at("horizontal", slice_point, gaps)
|
||||
table.insert(vert_geos, to_push)
|
||||
vert_stack_rect = rest
|
||||
|
@ -558,8 +560,8 @@ function Corner:layout(args)
|
|||
local horiz_win_width = horiz_stack_rect.width / horiz_stack_count
|
||||
|
||||
for i = 1, horiz_stack_count - 1 do
|
||||
local slice_point = horiz_stack_x + math.floor(horiz_win_width * i + 0.5)
|
||||
slice_point = slice_point - gaps // 2
|
||||
local slice_point = horiz_stack_x + mfloor(horiz_win_width * i + 0.5)
|
||||
slice_point = slice_point - mfloor(gaps / 2)
|
||||
local to_push, rest = horiz_stack_rect:split_at("vertical", slice_point, gaps)
|
||||
table.insert(horiz_geos, to_push)
|
||||
horiz_stack_rect = rest
|
||||
|
@ -707,12 +709,12 @@ function Spiral:layout(args)
|
|||
local split_coord
|
||||
if i % 2 == 1 then
|
||||
axis = "vertical"
|
||||
split_coord = rest.x + math.floor(rest.width * factor + 0.5)
|
||||
split_coord = rest.x + mfloor(rest.width * factor + 0.5)
|
||||
else
|
||||
axis = "horizontal"
|
||||
split_coord = rest.y + math.floor(rest.height * factor + 0.5)
|
||||
split_coord = rest.y + mfloor(rest.height * factor + 0.5)
|
||||
end
|
||||
split_coord = split_coord - gaps // 2
|
||||
split_coord = split_coord - mfloor(gaps / 2)
|
||||
|
||||
local to_push
|
||||
|
||||
|
@ -856,13 +858,14 @@ function Fair:layout(args)
|
|||
coord = rect.y
|
||||
end
|
||||
-- Two windows is special cased to create a new line rather than increase to 2 in a line
|
||||
local rect1, rect2 = rect:split_at(self.direction, coord + len // 2 - gaps // 2, gaps)
|
||||
local rect1, rect2 =
|
||||
rect:split_at(self.direction, coord + mfloor(len / 2) - mfloor(gaps / 2), gaps)
|
||||
if rect1 and rect2 then
|
||||
table.insert(geos, rect1)
|
||||
table.insert(geos, rect2)
|
||||
end
|
||||
else
|
||||
local line_count = math.floor(math.sqrt(win_count) + 0.5)
|
||||
local line_count = mfloor(math.sqrt(win_count) + 0.5)
|
||||
local wins_per_line = {}
|
||||
local max_per_line = line_count
|
||||
if win_count > line_count * line_count then
|
||||
|
@ -895,8 +898,8 @@ function Fair:layout(args)
|
|||
end
|
||||
|
||||
for i = 1, line_count - 1 do
|
||||
local slice_point = coord + math.floor(len * i + 0.5)
|
||||
slice_point = slice_point - gaps // 2
|
||||
local slice_point = coord + mfloor(len * i + 0.5)
|
||||
slice_point = slice_point - mfloor(gaps / 2)
|
||||
local to_push, rest = rect:split_at(axis, slice_point, gaps)
|
||||
table.insert(line_rects, to_push)
|
||||
if not rest then
|
||||
|
@ -922,8 +925,8 @@ function Fair:layout(args)
|
|||
end
|
||||
|
||||
for j = 1, wins_per_line[i] - 1 do
|
||||
local slice_point = coord + math.floor(len * j + 0.5)
|
||||
slice_point = slice_point - gaps // 2
|
||||
local slice_point = coord + mfloor(len * j + 0.5)
|
||||
slice_point = slice_point - mfloor(gaps / 2)
|
||||
local to_push, rest = line_rect:split_at(axis, slice_point, gaps)
|
||||
table.insert(geos, to_push)
|
||||
if not rest then
|
||||
|
|
6
justfile
6
justfile
|
@ -5,6 +5,8 @@ xdg_data_dir := `echo "${XDG_DATA_HOME:-$HOME/.local/share}/pinnacle"`
|
|||
root_xdg_data_dir := "/usr/share/pinnacle"
|
||||
root_xdg_config_dir := "/etc/xdg/pinnacle"
|
||||
|
||||
lua_version := "5.4"
|
||||
|
||||
list:
|
||||
@just --list --unsorted
|
||||
|
||||
|
@ -36,7 +38,7 @@ install-protos:
|
|||
install-lua-lib:
|
||||
#!/usr/bin/env bash
|
||||
cd "{{rootdir}}/api/lua"
|
||||
luarocks make --local
|
||||
luarocks make --local --lua-version "{{lua_version}}"
|
||||
|
||||
# Remove installed configs and the Lua API (requires Luarocks)
|
||||
clean:
|
||||
|
@ -77,7 +79,7 @@ install-protos-root:
|
|||
install-lua-lib-root:
|
||||
#!/usr/bin/env bash
|
||||
cd "{{rootdir}}/api/lua"
|
||||
luarocks make
|
||||
luarocks make --lua-version "{{lua_version}}"
|
||||
|
||||
# Run `cargo build`
|
||||
build *args:
|
||||
|
|
Loading…
Reference in a new issue