1 -------------------------------------------------
2 -- @author Gregor Best <farhaven@googlemail.com>
3 -- @copyright 2009 Gregor Best
4 -- @release @AWESOME_VERSION@
5 -------------------------------------------------
12 local util
= require("awful.util")
13 local default
= require("awful.widget.layout.default")
14 local margins
= awful
.widget
.layout
.margins
16 --- Horizontal widget layout
17 module("awful.widget.layout.horizontal")
19 local function horizontal(direction
, bounds
, widgets
, screen
)
20 local geometries
= { }
23 -- we are only interested in tables and widgets
24 local keys
= util
.table.keys_filter(widgets
, "table", "widget")
26 for _
, k
in ipairs(keys
) do
28 if type(v
) == "table" then
29 local layout
= v
.layout
or default
31 bounds
.width
= bounds
.width
- (margins
[v
].left
or 0) - (margins
[v
].right
or 0)
32 bounds
.height
= bounds
.height
- (margins
[v
].top
or 0) - (margins
[v
].bottom
or 0)
34 local g
= layout(bounds
, v
, screen
)
36 x
= x
+ (margins
[v
].left
or 0)
38 for _
, v
in ipairs(g
) do
40 table.insert(geometries
, v
)
44 x
= x
+ g
.free
.x
+ (margins
[v
].right
or 0)
45 y
= y
+ (margins
[v
].top
or 0)
46 bounds
.width
= bounds
.width
- (margins
[v
].right
or 0) - (margins
[v
].left
or 0)
50 elseif type(v
) == "widget" then
55 g
.width
= g
.width
+ (margins
[v
].left
or 0) + (margins
[v
].right
or 0)
56 g
.height
= g
.height
+ (margins
[v
].top
or 0) + (margins
[v
].bottom
or 0)
66 g
.ratio
= g
.width
/ g
.height
68 if g
.width
> bounds
.width
then
69 g
.width
= bounds
.width
71 g
.height
= bounds
.height
74 g
.y
= (margins
[v
].top
or 0)
79 if v
.resize
and g
.width
> 0 then
80 g
.width
= math
.floor(g
.height
* g
.ratio
)
83 if direction
== "leftright" then
85 g
.x
= x
+ (margins
[v
].left
or 0)
92 g
.x
= x
+ bounds
.width
- g
.width
+ (margins
[v
].left
or 0)
94 g
.x
= x
+ bounds
.width
- g
.width
97 bounds
.width
= bounds
.width
- g
.width
99 table.insert(geometries
, g
)
103 geometries
.free
= util
.table.clone(bounds
)
104 geometries
.free
.x
= x
105 geometries
.free
.y
= 0
110 function flex(bounds
, widgets
, screen
)
112 free
= util
.table.clone(bounds
)
114 -- the flex layout always uses the complete available place, thus we return
115 -- no usable free area
116 geometries
.free
.width
= 0
118 -- we are only interested in tables and widgets
119 local keys
= util
.table.keys_filter(widgets
, "table", "widget")
122 for _
, k
in ipairs(keys
) do
124 if type(v
) == "table" then
125 nelements
= nelements
+ 1
126 elseif type(v
) == "widget" then
127 local g
= v
:extents()
128 if v
.resize
and g
.width
> 0 and g
.height
> 0 then
129 bounds
.width
= bounds
.width
- bounds
.height
130 elseif g
.width
> 0 and g
.height
> 0 then
131 nelements
= nelements
+ 1
136 nelements
= (nelements
== 0) and 1 or nelements
139 local width
= bounds
.width
/ nelements
141 for _
, k
in ipairs(util
.table.keys(widgets
)) do
143 if type(v
) == "table" then
144 local layout
= v
.layout
or default
145 local g
= layout(bounds
, v
, screen
)
146 for _
, v
in ipairs(g
) do
148 table.insert(geometries
, v
)
151 elseif type(v
) == "widget" then
152 local g
= v
:extents(screen
)
155 if v
.resize
and g
.width
> 0 and g
.height
> 0 then
156 g
.width
= bounds
.height
157 g
.height
= bounds
.height
161 elseif g
.width
> 0 and g
.height
> 0 then
164 g
.width
= math
.floor(width
+ 0.5)
165 g
.height
= bounds
.height
174 table.insert(geometries
, g
)
181 function leftright(...)
182 return horizontal("leftright", ...)
185 function rightleft(...)
186 return horizontal("rightleft", ...)
189 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80