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
|
2009-07-10 12:19:08 +02:00
|
|
|
local capi = { screen = screen, client = client }
|
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-05-04 11:09:19 +02:00
|
|
|
local ascreen = require("awful.screen")
|
2009-07-13 01:13:21 +02:00
|
|
|
local capi = {
|
|
|
|
screen = screen,
|
2009-08-11 15:27:31 +02:00
|
|
|
awesome = awesome,
|
2009-07-13 01:13:21 +02:00
|
|
|
client = client
|
|
|
|
}
|
|
|
|
local client = require("awful.client")
|
2008-11-25 17:01:06 +01:00
|
|
|
|
|
|
|
--- Layout module for awful
|
|
|
|
module("awful.layout")
|
|
|
|
|
2009-09-18 11:31:49 +02:00
|
|
|
-- This is a special lock used by the arrange function.
|
|
|
|
-- This avoids recurring call by emitted signals.
|
|
|
|
local arrange_lock = false
|
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
--- Arrange a screen using its current layout.
|
|
|
|
-- @param screen The screen to arrange.
|
|
|
|
function arrange(screen)
|
2009-09-18 11:31:49 +02:00
|
|
|
if arrange_lock then return end
|
|
|
|
arrange_lock = true
|
2009-02-24 21:50:46 +01:00
|
|
|
local p = {}
|
2009-08-18 15:45:17 +02:00
|
|
|
p.workarea = capi.screen[screen].workarea
|
2009-05-04 11:09:19 +02:00
|
|
|
-- Handle padding
|
2009-10-07 02:20:39 +02:00
|
|
|
local padding = ascreen.padding(capi.screen[screen])
|
2009-05-04 11:09:19 +02:00
|
|
|
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)
|
2009-03-13 22:23:35 +01:00
|
|
|
p.screen = screen
|
2009-02-24 21:50:46 +01:00
|
|
|
get(screen).arrange(p)
|
2009-11-06 12:39:48 +01:00
|
|
|
capi.screen[screen]:emit_signal("arrange")
|
2009-09-18 11:31:49 +02:00
|
|
|
arrange_lock = false
|
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-08-11 15:27:31 +02:00
|
|
|
local function arrange_prop(obj) arrange(obj.screen) end
|
|
|
|
|
|
|
|
capi.client.add_signal("new", function(c)
|
|
|
|
c:add_signal("property::size_hints_honor", arrange_prop)
|
|
|
|
c:add_signal("property::struts", arrange_prop)
|
|
|
|
c:add_signal("property::minimized", arrange_prop)
|
|
|
|
c:add_signal("property::sticky", arrange_prop)
|
|
|
|
c:add_signal("property::fullscreen", arrange_prop)
|
|
|
|
c:add_signal("property::maximized_horizontal", arrange_prop)
|
|
|
|
c:add_signal("property::maximized_vertical", arrange_prop)
|
|
|
|
c:add_signal("property::border_width", arrange_prop)
|
|
|
|
c:add_signal("property::hidden", arrange_prop)
|
|
|
|
c:add_signal("property::titlebar", arrange_prop)
|
|
|
|
c:add_signal("property::floating", arrange_prop)
|
2009-09-18 11:31:49 +02:00
|
|
|
c:add_signal("property::geometry", arrange_prop)
|
2009-08-11 15:27:31 +02:00
|
|
|
-- If prop is screen, we do not know what was the previous screen, so
|
|
|
|
-- let's arrange all screens :-(
|
|
|
|
c:add_signal("property::screen", function(c)
|
|
|
|
for screen = 1, capi.screen.count() do arrange(screen) end end)
|
2009-05-05 17:32:53 +02:00
|
|
|
end)
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
local function arrange_on_tagged(c, tag)
|
2009-07-13 01:13:21 +02:00
|
|
|
if not tag.screen then return end
|
2009-08-11 15:27:31 +02:00
|
|
|
arrange(tag.screen)
|
2009-07-14 19:59:29 +02:00
|
|
|
if not capi.client.focus or not capi.client.focus:isvisible() then
|
2009-07-13 01:13:21 +02:00
|
|
|
local c = client.focus.history.get(tag.screen, 0)
|
|
|
|
if c then capi.client.focus = c end
|
|
|
|
end
|
2009-08-11 15:27:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
for s = 1, capi.screen.count() do
|
2009-08-18 16:46:30 +02:00
|
|
|
tag.attached_add_signal(s, "property::mwfact", arrange_prop)
|
|
|
|
tag.attached_add_signal(s, "property::nmaster", arrange_prop)
|
|
|
|
tag.attached_add_signal(s, "property::ncol", arrange_prop)
|
|
|
|
tag.attached_add_signal(s, "property::layout", arrange_prop)
|
|
|
|
tag.attached_add_signal(s, "property::windowfact", arrange_prop)
|
|
|
|
tag.attached_add_signal(s, "property::selected", arrange_prop)
|
|
|
|
tag.attached_add_signal(s, "tagged", arrange_prop)
|
2009-08-18 15:54:37 +02:00
|
|
|
capi.screen[s]:add_signal("property::workarea", function(screen)
|
|
|
|
arrange(screen.index)
|
|
|
|
end)
|
2009-08-11 15:27:31 +02:00
|
|
|
capi.screen[s]:add_signal("tag::attach", function (screen, tag)
|
|
|
|
arrange(screen.index)
|
|
|
|
end)
|
|
|
|
capi.screen[s]:add_signal("tag::detach", function (screen, tag)
|
|
|
|
arrange(screen.index)
|
|
|
|
end)
|
2009-10-07 02:20:39 +02:00
|
|
|
capi.screen[s]:add_signal("padding", function (screen)
|
|
|
|
arrange(screen.index)
|
|
|
|
end)
|
2009-08-11 15:27:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
capi.client.add_signal("focus", function(c) arrange(c.screen) end)
|
|
|
|
capi.client.add_signal("list", function()
|
|
|
|
for screen = 1, capi.screen.count() do
|
|
|
|
arrange(screen)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2012-03-25 17:41:12 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|