-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayout.lua
72 lines (68 loc) · 2 KB
/
layout.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- You can define your global state here
local main_ratio = 0.65
local gaps = 10
local smart_gaps = false
-- The most important function - the actual layout generator
--
-- The argument is a table with:
-- * Focused tags (`args.tags`)
-- * Window count (`args.count`)
-- * Output width (`args.width`)
-- * Output height (`args.height`)
-- * Output name (`args.output`)
--
-- The return value must be a table with exactly `count` entries. Each entry is a table with four
-- numbers:
-- * X coordinate
-- * Y coordinate
-- * Window width
-- * Window height
--
-- This example is a simplified version of `rivertile`
function handle_layout(args)
local retval = {}
if args.count == 1 then
if smart_gaps then
table.insert(retval, { 0, 0, args.width, args.height })
else
table.insert(retval, { gaps, gaps, args.width - gaps * 2, args.height - gaps * 2 })
end
elseif args.count > 1 then
local main_w = (args.width - gaps * 3) * main_ratio
local side_w = (args.width - gaps * 3) - main_w
local main_h = args.height - gaps * 2
local side_h = (args.height - gaps) / (args.count - 1) - gaps
table.insert(retval, {
gaps,
gaps,
main_w,
main_h,
})
for i = 0, (args.count - 2) do
table.insert(retval, {
main_w + gaps * 2,
gaps + i * (side_h + gaps),
side_w,
side_h,
})
end
end
return retval
end
-- This optional function returns the metadata for the current layout.
-- Currently only `name` is supported, the name of the layout. It get's passed
-- the same `args` as handle_layout()
function handle_metadata(args)
return { name = "rivertile-simple" }
end
-- IMPORTANT: User commands send via `riverctl send-layout-cmd` are treated as lua code.
-- Active tags are stored in `CMD_TAGS` global variable.
-- Output name is stored in `CMD_OUTPUT` global variable.
-- Here is an example of a function that can be mapped to some key
-- Run with `riverctl send-layout-cmd luatile "toggle_gaps()"`
local gaps_alt = 0
function toggle_gaps()
local tmp = gaps
gaps = gaps_alt
gaps_alt = tmp
end