Cleaned up layoutmanager code

master
Mark 2022-04-24 13:26:02 -07:00
parent 9a13f2406d
commit 1c5d1dc553
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
8 changed files with 129 additions and 107 deletions

View File

@ -61,7 +61,7 @@ return gears.table.join(
awful.key( {"Mod4"}, "l",
function ()
layoutmanager:next()
awful.screen.focused().layoutmanager:next()
end,
{
description = "select layouts",
@ -71,7 +71,7 @@ return gears.table.join(
awful.key( {"Mod4"}, "k",
function ()
layoutmanager:next_alt()
awful.screen.focused().layoutmanager:next_alt()
end,
{
description = "cycle alt layouts",

View File

@ -1,5 +1,6 @@
local desktop = {
Tagger = require("desktop.tagger"),
LayoutManager = require("desktop.layoutmanager"),
popup = {
language = require("desktop.popups.language")
@ -8,7 +9,6 @@ local desktop = {
widgets = {
tasklist = require("desktop.widgets.tasklist"),
textclock = require("desktop.widgets.textclock"),
layoutbox = require("desktop.widgets.layoutbox"),
keymap = require("desktop.widgets.keymap"),
launcher = require("desktop.widgets.launcher"),
shortcut = require("desktop.widgets.shortcut"),
@ -87,7 +87,11 @@ awful.screen.connect_for_each_screen(
function(s)
-- s: the screen this function is being called for
-- Create tag table
s.tagger = desktop.Tagger{screen = s}
s.layoutmanager = desktop.LayoutManager{screen = s}
s.tagger = desktop.Tagger{
screen = s,
layoutmanager = s.layoutmanager
}
-- Create a promptbox for each s
s.mypromptbox = awful.widget.prompt()
@ -195,7 +199,7 @@ awful.screen.connect_for_each_screen(
desktop.widgets.space(18),
s.tagger.widget.widget,
desktop.widgets.layoutbox(s),
s.layoutmanager.widget,
s.shortcuts,

View File

@ -1,86 +0,0 @@
-- 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

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

@ -1,19 +1,20 @@
local layoutbox = {}
local P = {}
P.__index = P
layoutbox.make = function(screen)
local widget
function P:new(layoutmanager)
local widget = {}
setmetatable(widget, self)
widget = wibox.widget {
widget.widget = wibox.widget {
{
awful.widget.layoutbox(screen),
awful.widget.layoutbox(layoutmanager.screen),
margins = beautiful.dpi(3),
layout = wibox.container.margin,
},
layout = wibox.container.background,
}
-- Setup buttons
widget:buttons(
widget.widget:buttons(
gears.table.join(
awful.button({ }, 1, function () layoutmanager:next_alt() end),
awful.button({ }, 3, function () layoutmanager:prev_alt() end),
@ -22,17 +23,16 @@ layoutbox.make = function(screen)
)
)
-- Change background when mouse is over widget
widget:connect_signal("mouse::enter", function(result)
widget.widget:connect_signal("mouse::enter", function(result)
widget.bg = beautiful.color.bar.hover_bg
end)
widget:connect_signal("mouse::leave", function(result)
widget.widget:connect_signal("mouse::leave", function(result)
widget.bg = beautiful.color.transparent
end)
return widget
end
return layoutbox.make
return P

View File

@ -9,6 +9,7 @@ Tagger.__index = Tagger
function Tagger:new(args)
local t = {
screen = args.screen,
layoutmanager = args.layoutmanager,
rows = args.rows or 2,
cols = args.cols or 4,
}
@ -20,7 +21,7 @@ function Tagger:new(args)
awful.tag.add(
"(" .. tostring(r) .. ", " .. tostring(c) .. ")",
{
layout = layoutmanager:default_layout(),
layout = t.layoutmanager:get_default_layout(),
screen = t.screen,
gap_single_client = false,

3
rc.lua
View File

@ -27,9 +27,6 @@ conf = require("conf")
conf.sound_dir = configuration_dir .. "theme/resources/sounds/"
conf.icon_dir = configuration_dir .. "theme/resources/icons/"
layoutmanager = require("desktop.layoutmanager")
layoutmanager.layouts = conf.layouts
bin = require("bin")
wrapper = require("wrapper")
wrapper.ibus.set(1)