Created "core" module
This commit is contained in:
84
core/layouts/layoutmanager.lua
Normal file
84
core/layouts/layoutmanager.lua
Normal file
@ -0,0 +1,84 @@
|
||||
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
|
36
core/layouts/widget.lua
Executable file
36
core/layouts/widget.lua
Executable file
@ -0,0 +1,36 @@
|
||||
local make = function(screen)
|
||||
local widget
|
||||
|
||||
widget = wibox.widget {
|
||||
{
|
||||
awful.widget.layoutbox(screen),
|
||||
margins = beautiful.dpi(3),
|
||||
layout = wibox.container.margin,
|
||||
},
|
||||
layout = wibox.container.background,
|
||||
}
|
||||
|
||||
-- Setup buttons
|
||||
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)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
-- Change background when mouse is over widget
|
||||
widget:connect_signal("mouse::enter", function(result)
|
||||
widget.bg = beautiful.color.bar.hover_bg
|
||||
end)
|
||||
|
||||
widget:connect_signal("mouse::leave", function(result)
|
||||
widget.bg = beautiful.color.transparent
|
||||
end)
|
||||
|
||||
return widget
|
||||
end
|
||||
|
||||
return make
|
Reference in New Issue
Block a user