awful.widget.layout: add support for margins

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-24 18:23:32 +02:00
parent 1337129191
commit 53ca058ebb
2 changed files with 53 additions and 7 deletions

View File

@ -11,6 +11,7 @@ local table = table
local math = math local math = math
local util = require("awful.util") local util = require("awful.util")
local default = require("awful.widget.layout.default") local default = require("awful.widget.layout.default")
local margins = awful.widget.layout.margins
--- Horizontal widget layout --- Horizontal widget layout
module("awful.widget.layout.horizontal") module("awful.widget.layout.horizontal")
@ -26,17 +27,34 @@ local function horizontal(direction, bounds, widgets, screen)
local v = widgets[k] local v = widgets[k]
if type(v) == "table" then if type(v) == "table" then
local layout = v.layout or default local layout = v.layout or default
if margins[v] then
bounds.width = bounds.width - (margins[v].left or 0) - (margins[v].right or 0)
bounds.height = bounds.height - (margins[v].top or 0) - (margins[v].bottom or 0)
end
local g = layout(bounds, v, screen) local g = layout(bounds, v, screen)
if margins[v] then
x = x + (margins[v].left or 0)
end
for _, v in ipairs(g) do for _, v in ipairs(g) do
v.x = v.x + x v.x = v.x + x
table.insert(geometries, v) table.insert(geometries, v)
end end
bounds = g.free bounds = g.free
if margins[v] then
x = x + g.free.x + (margins[v].right or 0)
y = y + (margins[v].top or 0)
bounds.width = bounds.width - (margins[v].right or 0) - (margins[v].left or 0)
else
x = x + g.free.x x = x + g.free.x
end
elseif type(v) == "widget" then elseif type(v) == "widget" then
local g local g
if v.visible then if v.visible then
g = v:extents(screen) g = v:extents(screen)
if margins[v] then
g.width = g.width + (margins[v].left or 0) + (margins[v].right or 0)
g.height = g.height + (margins[v].top or 0) + (margins[v].bottom or 0)
end
else else
g = { g = {
width = 0, width = 0,
@ -51,18 +69,31 @@ local function horizontal(direction, bounds, widgets, screen)
g.width = bounds.width g.width = bounds.width
end end
g.height = bounds.height g.height = bounds.height
if margins[v] then
g.y = (margins[v].top or 0)
else
g.y = 0 g.y = 0
end
if v.resize and g.width > 0 then if v.resize and g.width > 0 then
g.width = math.floor(g.height * g.ratio) g.width = math.floor(g.height * g.ratio)
end end
if direction == "leftright" then if direction == "leftright" then
if margins[v] then
g.x = x + (margins[v].left or 0)
else
g.x = x g.x = x
end
x = x + g.width x = x + g.width
else
if margins[v] then
g.x = x + bounds.width - g.width + (margins[v].left or 0)
else else
g.x = x + bounds.width - g.width g.x = x + bounds.width - g.width
end end
end
bounds.width = bounds.width - g.width bounds.width = bounds.width - g.width
table.insert(geometries, g) table.insert(geometries, g)

View File

@ -1,8 +1,23 @@
require("awful.widget.layout.horizontal") local setmetatable = setmetatable
require("awful.widget.layout.vertical") local require = require
require("awful.widget.layout.default")
-- Widget layouts -- Widget layouts
module("awful.widget.layout") module("awful.widget.layout")
--- Widgets margins.
-- <p>In this table you can set the margin you want the layout to use when
-- positionning your widgets.
-- For example, if you want to put 10 pixel free on left on a widget, add this:
-- <code>
-- awful.widget.layout.margins[mywidget] = { left = 10 }
-- </code>
-- </p>
-- @name margins
-- @class table
margins = setmetatable({}, { __mode = 'k' })
require("awful.widget.layout.horizontal")
require("awful.widget.layout.vertical")
require("awful.widget.layout.default")
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80