awesome/lib/awful/layout/init.lua.in

93 lines
2.5 KiB
Lua
Raw Normal View History

---------------------------------------------------------------------------
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
-- Grab environment we need
local ipairs = ipairs
local type = type
local tag = require("awful.tag")
local util = require("awful.util")
local suit = require("awful.layout.suit")
local client = require("awful.client")
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)
return tag.getproperty(t, "layout") or suit.floating
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.
function set(layout, t)
t = t or tag.selected()
tag.setproperty(t, "layout", layout)
capi.hooks.arrange()(t.screen)
end
-- Register an arrange hook.
local function on_arrange (screen)
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)
p.screen = screen
get(screen).arrange(p)
end
--- Get the current layout name.
-- @param layout The layout.
-- @return The layout name.
function getname(layout)
local layout = layout or get()
return layout.name
end
hooks.arrange.register(on_arrange)
hooks.property.register(function (c, prop)
if type(c) == "client" and c:isvisible() and prop == "size_hints_honor" then
on_arrange(c.screen)
end
end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80