87 lines
1.7 KiB
Lua
87 lines
1.7 KiB
Lua
|
-- Client layout manager
|
||
|
|
||
|
local LayoutManager = {
|
||
|
layouts = nil, -- Table of groups
|
||
|
-- current state is kept in each tag, as tag.layout.
|
||
|
}
|
||
|
|
||
|
-- screen.layouts, awful.layouts, and tag.layouts are all ignored.
|
||
|
-- This module replaces the standard layout functions.
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
-- Get group from layout
|
||
|
-- We assume that this layout is in LayoutManager.layouts
|
||
|
function LayoutManager:get_group(layout)
|
||
|
for k, v in pairs(self.layouts) do
|
||
|
for l, m in pairs(v) do
|
||
|
if (layout == m) then
|
||
|
return k
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function LayoutManager:get_alt(layout)
|
||
|
for k, v in pairs(self.layouts) do
|
||
|
for l, m in pairs(v) do
|
||
|
if (layout == m) then
|
||
|
return l
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
function LayoutManager:default_layout()
|
||
|
return self.layouts[1][1]
|
||
|
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
|
||
|
|
||
|
|
||
|
group = ((group + step) % #self.layouts) + 1
|
||
|
|
||
|
awful.layout.set(self.layouts[group][1], tag)
|
||
|
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)
|
||
|
|
||
|
|
||
|
alt = ((alt + step) % #self.layouts[group]) + 1
|
||
|
|
||
|
awful.layout.set(self.layouts[group][alt], tag)
|
||
|
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
|