awesomewm/core/layouts/layoutmanager.lua

82 lines
1.6 KiB
Lua
Raw Normal View History

2022-07-16 17:41:00 -07:00
local LayoutManager = {}
2021-08-01 07:24:26 -07:00
-- screen.layouts, awful.layouts, and tag.layouts are all ignored.
-- This module replaces the standard layout functions.
-- Get group from layout
2022-07-16 17:41:00 -07:00
-- We assume that this layout is in conf.layouts
2021-08-01 07:24:26 -07:00
function LayoutManager:get_group(layout)
2022-07-16 17:41:00 -07:00
for k, v in pairs(conf.layouts) do
2021-08-01 07:24:26 -07:00
for l, m in pairs(v) do
if (layout == m) then
return k
end
end
end
end
function LayoutManager:get_alt(layout)
2022-07-16 17:41:00 -07:00
for k, v in pairs(conf.layouts) do
2021-08-01 07:24:26 -07:00
for l, m in pairs(v) do
if (layout == m) then
return l
end
end
end
end
function LayoutManager:default_layout()
2022-07-16 17:41:00 -07:00
return conf.layouts[1][1]
2021-08-01 07:24:26 -07:00
end
-- Change layout group
function LayoutManager:group(step)
local s = awful.screen.focused()
local tag = s.selected_tag -- Multiple selected tags are NOT supported!
local layout = tag.layout
-- Subtract 1, 'cuz lua doesn't start at 0
local group = self:get_group(layout) - 1
2022-07-16 17:41:00 -07:00
group = ((group + step) % #conf.layouts) + 1
2021-08-01 07:24:26 -07:00
2022-07-16 17:41:00 -07:00
awful.layout.set(conf.layouts[group][1], tag)
2021-08-01 07:24:26 -07:00
end
-- Change layout alternate
function LayoutManager:alt(step)
local s = awful.screen.focused()
local tag = s.selected_tag -- Multiple selected tags are NOT supported!
local layout = tag.layout
-- Subtract 1, 'cuz lua doesn't start at 0
local alt = self:get_alt(layout) - 1
local group = self:get_group(layout)
2022-07-16 17:41:00 -07:00
alt = ((alt + step) % #conf.layouts[group]) + 1
2021-08-01 07:24:26 -07:00
2022-07-16 17:41:00 -07:00
awful.layout.set(conf.layouts[group][alt], tag)
2021-08-01 07:24:26 -07:00
end
function LayoutManager:next()
self:group(1)
end
function LayoutManager:prev()
self:group(-1)
end
function LayoutManager:next_alt()
self:alt(1)
end
function LayoutManager:prev_alt()
self:alt(-1)
end
return LayoutManager