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
|
2009-05-18 16:42:03 +02:00
|
|
|
local type = type
|
2008-11-25 17:01:06 +01:00
|
|
|
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")
|
2009-05-05 17:32:53 +02:00
|
|
|
local wibox = require("awful.wibox")
|
2009-05-04 11:09:19 +02:00
|
|
|
local ascreen = require("awful.screen")
|
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 = {}
|
2009-05-05 17:32:53 +02:00
|
|
|
p.workarea = wibox.get_workarea(screen)
|
2009-05-04 11:09:19 +02:00
|
|
|
-- Handle padding
|
|
|
|
local padding = ascreen.padding(screen)
|
|
|
|
if padding then
|
|
|
|
p.workarea.x = p.workarea.x + (padding.left or 0)
|
|
|
|
p.workarea.y = p.workarea.y + (padding.top or 0)
|
|
|
|
p.workarea.width = p.workarea.width - ((padding.left or 0 ) + (padding.right or 0))
|
|
|
|
p.workarea.height = p.workarea.height - ((padding.top or 0) + (padding.bottom or 0))
|
|
|
|
end
|
2009-02-24 21:50:46 +01:00
|
|
|
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)
|
2009-04-17 23:43:05 +02:00
|
|
|
if type(c) == "client" and c:isvisible()
|
|
|
|
and (prop == "size_hints_honor"
|
2009-04-17 23:46:03 +02:00
|
|
|
or prop == "struts"
|
2009-04-17 23:46:31 +02:00
|
|
|
or prop == "minimized"
|
2009-04-17 23:47:03 +02:00
|
|
|
or prop == "sticky"
|
|
|
|
or prop == "fullscreen") then
|
2009-04-17 11:43:56 +02:00
|
|
|
on_arrange(c.screen)
|
|
|
|
end
|
|
|
|
end)
|
2009-05-05 17:32:53 +02:00
|
|
|
hooks.wibox_position.register(function(wibox)
|
|
|
|
on_arrange(wibox.screen)
|
|
|
|
end)
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2009-05-04 11:09:19 +02:00
|
|
|
hooks.padding.register(function(screen) on_arrange(screen) end)
|
2009-04-17 23:44:47 +02:00
|
|
|
hooks.focus.register(function(c) on_arrange(c.screen) end)
|
2009-05-04 11:09:19 +02:00
|
|
|
|
2008-11-25 17:01:06 +01:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|