awesome/lib/awful/layout/suit/spiral.lua.in

78 lines
2.0 KiB
Lua
Raw Normal View History

---------------------------------------------------------------------------
-- @author Uli Schlachter <psychon@znc.in>
-- @copyright 2009 Uli Schlachter
-- @copyright 2008 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
-- Grab environment we need
local ipairs = ipairs
module("awful.layout.suit.spiral")
local function spiral(p, dwindle)
local wa = p.workarea
local cls = p.clients
local n = #cls
local nx = wa.x
local ny = wa.y
local nw = wa.width
local nh = wa.height
for k, c in ipairs(cls) do
if (k % 2 == 0 and nh / 2 > 2 * c.border_width)
or (k % 2 == 1 and nw / 2 > 2 * c.border_width) then
if k < n then
if k % 2 == 0 then
nh = nh / 2
else
nw = nw / 2
end
if k % 4 == 3 and not dwindle then
nx = nx + nw
elseif k % 4 == 0 and not dwindle then
ny = ny + nh
end
end
if k % 4 == 1 then
if dwindle then
ny = ny + nh
else
ny = ny - nh
end
elseif k % 4 == 2 then
nx = nx + nw
elseif k % 4 == 3 then
ny = ny + nh
elseif k % 4 == 0 then
if dwindle then
nx = nx + nw
else
nx = nx - nw
end
end
if k == 1 then
ny = wa.y
end
end
local geom = { x = nx, y = ny, width = nw, height = nh }
c:geometry(geom)
end
end
--- Dwindle layout
dwindle = {}
dwindle.name = "dwindle"
function dwindle.arrange(p)
return spiral(p, true)
end
--- Spiral layout
name = "spiral"
function arrange(p)
return spiral(p, false)
end
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80