2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local ipairs = ipairs
|
|
|
|
local tag = require("awful.tag")
|
|
|
|
local util = require("awful.util")
|
|
|
|
local suit = require("awful.layout.suit")
|
2009-02-24 21:50:46 +01:00
|
|
|
local client = require("awful.client")
|
2008-11-25 17:01:06 +01:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
hooks = hooks,
|
|
|
|
screen = screen
|
|
|
|
}
|
|
|
|
local hooks = require("awful.hooks")
|
|
|
|
|
|
|
|
--- Layout module for awful
|
|
|
|
module("awful.layout")
|
|
|
|
|
|
|
|
--- Get the current layout.
|
|
|
|
-- @param screen The screen number.
|
|
|
|
-- @return The layout function.
|
|
|
|
function get(screen)
|
|
|
|
local t = tag.selected(screen)
|
2009-01-28 12:00:34 +01:00
|
|
|
return tag.getproperty(t, "layout") or suit.floating
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Change the layout of the current tag.
|
|
|
|
-- @param layouts A table of layouts.
|
|
|
|
-- @param i Relative index.
|
|
|
|
function inc(layouts, i)
|
|
|
|
local t = tag.selected()
|
|
|
|
if t then
|
|
|
|
local curlayout = get()
|
|
|
|
local curindex
|
|
|
|
local rev_layouts = {}
|
|
|
|
for k, v in ipairs(layouts) do
|
|
|
|
if v == curlayout then
|
|
|
|
curindex = k
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if curindex then
|
|
|
|
local newindex = util.cycle(#layouts, curindex + i)
|
|
|
|
set(layouts[newindex])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set the layout function of the current tag.
|
|
|
|
-- @param layout Layout name.
|
2008-12-14 17:09:11 +01:00
|
|
|
function set(layout, t)
|
|
|
|
t = t or tag.selected()
|
2008-11-25 17:01:06 +01:00
|
|
|
tag.setproperty(t, "layout", layout)
|
|
|
|
capi.hooks.arrange()(t.screen)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Register an arrange hook.
|
|
|
|
local function on_arrange (screen)
|
2009-02-24 21:50:46 +01:00
|
|
|
local t = tag.selected(screen)
|
|
|
|
local p = {}
|
|
|
|
p.workarea = capi.screen[screen].workarea
|
|
|
|
p.geometry = capi.screen[screen].geometry
|
|
|
|
p.clients = client.tiled(screen)
|
|
|
|
p.ncol = tag.getncol(t)
|
|
|
|
p.nmaster = tag.getnmaster(t)
|
|
|
|
p.mwfact = tag.getmwfact(t)
|
|
|
|
p.tagdata = tag.getdata(t)
|
2009-03-13 22:23:35 +01:00
|
|
|
p.screen = screen
|
2009-02-24 21:50:46 +01:00
|
|
|
get(screen).arrange(p)
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the current layout name.
|
2009-02-27 15:40:01 +01:00
|
|
|
-- @param layout The layout.
|
2008-11-25 17:01:06 +01:00
|
|
|
-- @return The layout name.
|
|
|
|
function getname(layout)
|
2009-02-27 15:40:01 +01:00
|
|
|
local layout = layout or get()
|
2009-02-24 21:46:29 +01:00
|
|
|
return layout.name
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
hooks.arrange.register(on_arrange)
|
2009-04-17 11:43:56 +02:00
|
|
|
hooks.property.register(function (c, prop)
|
|
|
|
if c:isvisible() and prop == "size_hints_honor" then
|
|
|
|
on_arrange(c.screen)
|
|
|
|
end
|
|
|
|
end)
|
2008-11-25 17:01:06 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|