Cleaned up layoutmanager code

This commit is contained in:
2022-04-24 13:26:02 -07:00
parent 9a13f2406d
commit 1c5d1dc553
8 changed files with 129 additions and 107 deletions

View File

@ -0,0 +1,7 @@
local P = require("desktop/layoutmanager/layoutmanager")
local F = function(args)
return P:new(args)
end
return F

View File

@ -0,0 +1,99 @@
local P = {}
local Widget = require("desktop.layoutmanager.widget")
P.__index = P
-- screen.layouts, awful.layouts, and tag.layouts are all ignored.
-- This module replaces the standard layout functions.
function P:new(screen)
local l = {
layouts = conf.layouts,
screen = screen.screen
}
setmetatable(l, self)
l._widget = Widget:new(l)
l.widget = l._widget.widget
return l
--[[ Example
conf.layouts = {
{
awful.layout.suit.tile.left,
awful.layout.suit.tile,
},
{
awful.layout.suit.fair,
awful.layout.suit.fair.horizontal,
},
{
awful.layout.suit.floating,
}
}
--]]
end
-- Find layout in self.layouts
-- Returns group index, alt index
function P:find_layout(layout)
for k, v in pairs(self.layouts) do
for l, m in pairs(v) do
if (layout == m) then
return k, l
end
end
end
end
function P:get_default_layout()
return self.layouts[1][1]
end
-- Change layout group
function P:change_group(step)
local tag = self.screen.selected_tag -- Multiple selected tags are NOT supported!
local layout = tag.layout
-- Subtract 1, lua doesn't start at 0
local g, a
g, a = self:find_layout(layout)
g = g - 1
g = ((g + step) % #self.layouts) + 1
awful.layout.set(self.layouts[g][1], tag)
end
-- Change layout alternate
function P:change_alt(step)
local tag = self.screen.selected_tag -- Multiple selected tags are NOT supported!
local layout = tag.layout
-- Subtract 1, lua doesn't start at 0
local g, a
g, a = self:find_layout(layout)
a = a - 1
a = ((a + step) % #self.layouts[g]) + 1
awful.layout.set(self.layouts[g][a], tag)
end
function P:next()
self:change_group(1)
end
function P:prev()
self:change_group(-1)
end
function P:next_alt()
self:change_alt(1)
end
function P:prev_alt()
self:change_alt(-1)
end
return P

View File

@ -0,0 +1,38 @@
local P = {}
P.__index = P
function P:new(layoutmanager)
local widget = {}
setmetatable(widget, self)
widget.widget = wibox.widget {
{
awful.widget.layoutbox(layoutmanager.screen),
margins = beautiful.dpi(3),
layout = wibox.container.margin,
},
layout = wibox.container.background,
}
widget.widget:buttons(
gears.table.join(
awful.button({ }, 1, function () layoutmanager:next_alt() end),
awful.button({ }, 3, function () layoutmanager:prev_alt() end),
awful.button({ }, 4, function () layoutmanager:next() end),
awful.button({ }, 5, function () layoutmanager:prev() end)
)
)
widget.widget:connect_signal("mouse::enter", function(result)
widget.bg = beautiful.color.bar.hover_bg
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.bg = beautiful.color.transparent
end)
return widget
end
return P