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

View File

@ -1,8 +1,23 @@
require("awful.widget.layout.horizontal")
require("awful.widget.layout.vertical")
require("awful.widget.layout.default")
local setmetatable = setmetatable
local require = require
-- Widget layouts
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