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")
|
2009-05-18 17:13:51 +02:00
|
|
|
local capi = { screen = screen }
|
2008-11-25 17:01:06 +01:00
|
|
|
local hooks = require("awful.hooks")
|
|
|
|
|
|
|
|
--- Layout module for awful
|
|
|
|
module("awful.layout")
|
|
|
|
|
2009-05-18 16:18:14 +02:00
|
|
|
-- Create a hook to call when changing layout
|
|
|
|
hooks.user.create("layout")
|
|
|
|
|
2008-11-25 17:01:06 +01:00
|
|
|
--- 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)
|
2009-05-18 16:18:14 +02:00
|
|
|
hooks.user.call("layout", t, layout)
|
2008-11-25 17:01:06 +01:00
|
|
|
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
|
|
|
|
|
2009-05-10 16:41:28 +02:00
|
|
|
hooks.property.register(function (obj, prop)
|
|
|
|
local objtype = type(obj)
|
|
|
|
if objtype == "client" then
|
|
|
|
if prop == "size_hints_honor"
|
|
|
|
or prop == "struts"
|
|
|
|
or prop == "minimized"
|
|
|
|
or prop == "sticky"
|
|
|
|
or prop == "fullscreen"
|
|
|
|
or prop == "maximized_horizontal"
|
|
|
|
or prop == "maximized_vertical"
|
|
|
|
or prop == "border_width"
|
2009-05-10 16:43:36 +02:00
|
|
|
or prop == "hide"
|
2009-05-18 17:13:00 +02:00
|
|
|
or prop == "titlebar"
|
|
|
|
or prop == "floating" then
|
2009-05-10 16:41:28 +02:00
|
|
|
on_arrange(obj.screen)
|
|
|
|
elseif prop == "screen" then
|
|
|
|
-- If prop is screen, we do not know what was the previous screen, so
|
|
|
|
-- let's arrange all screens :-(
|
|
|
|
for screen = 1, capi.screen.count() do
|
|
|
|
on_arrange(screen)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif objtype == "wibox" then
|
2009-05-10 16:46:08 +02:00
|
|
|
if prop == "screen"
|
|
|
|
or prop == "visible" then
|
2009-05-10 16:41:28 +02:00
|
|
|
on_arrange(obj.screen)
|
2009-04-17 23:54:08 +02:00
|
|
|
end
|
2009-05-18 16:39:38 +02:00
|
|
|
elseif objtype == "tag" then
|
|
|
|
if prop == "mwfact"
|
|
|
|
or prop == "nmaster"
|
2009-05-18 17:13:51 +02:00
|
|
|
or prop == "ncol"
|
|
|
|
or prop == "layout"
|
|
|
|
or prop == "windowfact" then
|
2009-05-18 16:39:38 +02:00
|
|
|
on_arrange(obj.screen)
|
|
|
|
end
|
2009-04-17 11:43:56 +02:00
|
|
|
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-04-17 23:50:13 +02:00
|
|
|
hooks.clients.register(function()
|
|
|
|
for screen = 1, capi.screen.count() do
|
|
|
|
on_arrange(screen)
|
|
|
|
end
|
|
|
|
end)
|
2009-04-17 23:56:54 +02:00
|
|
|
hooks.tags.register(function(screen, tag, action) on_arrange(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
|