2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
2016-12-10 02:24:22 +01:00
|
|
|
--- Fair layouts module for awful.
|
2014-05-20 12:44:21 +02:00
|
|
|
--
|
2012-11-06 00:57:59 +01:00
|
|
|
-- @author Josh Komoroske
|
|
|
|
-- @copyright 2012 Josh Komoroske
|
2016-12-10 02:24:22 +01:00
|
|
|
-- @module awful.layout
|
2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local ipairs = ipairs
|
|
|
|
local math = math
|
|
|
|
|
2016-08-14 07:34:43 +02:00
|
|
|
--- The fairh layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_fairh
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- The fairv layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_fairv
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
local fair = {}
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
local function do_fair(p, orientation)
|
2009-02-24 21:50:46 +01:00
|
|
|
local wa = p.workarea
|
|
|
|
local cls = p.clients
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2012-11-06 00:57:59 +01:00
|
|
|
-- Swap workarea dimensions, if our orientation is "east"
|
|
|
|
if orientation == 'east' then
|
|
|
|
wa.width, wa.height = wa.height, wa.width
|
|
|
|
wa.x, wa.y = wa.y, wa.x
|
|
|
|
end
|
|
|
|
|
2008-11-25 17:01:06 +01:00
|
|
|
if #cls > 0 then
|
2016-02-07 15:24:08 +01:00
|
|
|
local rows, cols
|
2012-11-06 00:57:59 +01:00
|
|
|
if #cls == 2 then
|
|
|
|
rows, cols = 1, 2
|
|
|
|
else
|
|
|
|
rows = math.ceil(math.sqrt(#cls))
|
|
|
|
cols = math.ceil(#cls / rows)
|
|
|
|
end
|
2008-11-25 17:01:06 +01:00
|
|
|
|
|
|
|
for k, c in ipairs(cls) do
|
2012-11-06 00:57:59 +01:00
|
|
|
k = k - 1
|
2008-11-25 17:01:06 +01:00
|
|
|
local g = {}
|
2012-11-06 00:57:59 +01:00
|
|
|
|
2016-02-07 15:24:08 +01:00
|
|
|
local row, col
|
2012-11-06 00:57:59 +01:00
|
|
|
row = k % rows
|
|
|
|
col = math.floor(k / rows)
|
|
|
|
|
2016-02-07 15:24:08 +01:00
|
|
|
local lrows, lcols
|
2012-11-06 00:57:59 +01:00
|
|
|
if k >= rows * cols - rows then
|
|
|
|
lrows = #cls - (rows * cols - rows)
|
|
|
|
lcols = cols
|
2008-11-25 17:01:06 +01:00
|
|
|
else
|
2012-11-06 00:57:59 +01:00
|
|
|
lrows = rows
|
|
|
|
lcols = cols
|
|
|
|
end
|
|
|
|
|
|
|
|
if row == lrows - 1 then
|
|
|
|
g.height = wa.height - math.ceil(wa.height / lrows) * row
|
|
|
|
g.y = wa.height - g.height
|
|
|
|
else
|
|
|
|
g.height = math.ceil(wa.height / lrows)
|
|
|
|
g.y = g.height * row
|
|
|
|
end
|
|
|
|
|
|
|
|
if col == lcols - 1 then
|
|
|
|
g.width = wa.width - math.ceil(wa.width / lcols) * col
|
|
|
|
g.x = wa.width - g.width
|
|
|
|
else
|
|
|
|
g.width = math.ceil(wa.width / lcols)
|
|
|
|
g.x = g.width * col
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2012-11-06 00:57:59 +01:00
|
|
|
g.y = g.y + wa.y
|
|
|
|
g.x = g.x + wa.x
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2012-11-06 00:57:59 +01:00
|
|
|
-- Swap window dimensions, if our orientation is "east"
|
|
|
|
if orientation == 'east' then
|
|
|
|
g.width, g.height = g.height, g.width
|
|
|
|
g.x, g.y = g.y, g.x
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
2012-11-06 00:57:59 +01:00
|
|
|
|
2015-02-15 17:25:11 +01:00
|
|
|
p.geometries[c] = g
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-02-24 21:46:29 +01:00
|
|
|
|
2008-11-25 17:01:06 +01:00
|
|
|
--- Horizontal fair layout.
|
|
|
|
-- @param screen The screen to arrange.
|
2012-06-14 02:45:17 +02:00
|
|
|
fair.horizontal = {}
|
|
|
|
fair.horizontal.name = "fairh"
|
|
|
|
function fair.horizontal.arrange(p)
|
|
|
|
return do_fair(p, "east")
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Vertical fair layout.
|
2008-11-25 17:01:06 +01:00
|
|
|
-- @param screen The screen to arrange.
|
2012-06-14 02:45:17 +02:00
|
|
|
fair.name = "fairv"
|
|
|
|
function fair.arrange(p)
|
|
|
|
return do_fair(p, "south")
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
2012-06-14 02:45:17 +02:00
|
|
|
|
|
|
|
return fair
|
2015-12-12 17:42:33 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|