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")
|
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
|
2012-06-14 01:44:08 +02:00
|
|
|
-- awful.layout
|
|
|
|
local layout = {}
|
|
|
|
layout.suit = require("awful.layout.suit")
|
2008-11-25 17:01:06 +01:00
|
|
|
|
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.
|
2012-06-14 01:44:08 +02:00
|
|
|
function layout.get(screen)
|
2008-11-25 17:01:06 +01:00
|
|
|
local t = tag.selected(screen)
|
2012-06-14 01:44:08 +02:00
|
|
|
return tag.getproperty(t, "layout") or layout.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.
|
2013-02-19 04:53:58 +01:00
|
|
|
-- @param s The screen number.
|
|
|
|
function layout.inc(layouts, i, s)
|
|
|
|
local t = tag.selected(s)
|
2008-11-25 17:01:06 +01:00
|
|
|
if t then
|
2013-02-19 04:53:58 +01:00
|
|
|
local curlayout = layout.get(s)
|
2008-11-25 17:01:06 +01:00
|
|
|
local curindex
|
|
|
|
for k, v in ipairs(layouts) do
|
|
|
|
if v == curlayout then
|
|
|
|
curindex = k
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2014-03-14 17:21:11 +01:00
|
|
|
if not curindex then
|
|
|
|
-- Safety net: handle cases where another reference of the layout
|
|
|
|
-- might be given (e.g. when (accidentally) cloning it).
|
|
|
|
for k, v in ipairs(layouts) do
|
|
|
|
if v.name == curlayout.name then
|
|
|
|
curindex = k
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-11-25 17:01:06 +01:00
|
|
|
if curindex then
|
|
|
|
local newindex = util.cycle(#layouts, curindex + i)
|
2013-02-19 04:53:58 +01:00
|
|
|
layout.set(layouts[newindex], t)
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set the layout function of the current tag.
|
2012-11-19 14:09:10 +01:00
|
|
|
-- @param _layout Layout name.
|
|
|
|
-- @param t The tag to modify, if null tag.selected() is used.
|
2012-06-14 01:44:08 +02:00
|
|
|
function layout.set(_layout, t)
|
2008-12-14 17:09:11 +01:00
|
|
|
t = t or tag.selected()
|
2012-06-14 01:44:08 +02:00
|
|
|
tag.setproperty(t, "layout", _layout)
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
--- Arrange a screen using its current layout.
|
|
|
|
-- @param screen The screen to arrange.
|
2012-06-14 01:44:08 +02:00
|
|
|
function layout.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
|
2012-06-14 01:44:08 +02:00
|
|
|
layout.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.
|
2012-06-14 01:44:08 +02:00
|
|
|
function layout.getname(_layout)
|
|
|
|
local _layout = _layout or layout.get()
|
|
|
|
return _layout.name
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2012-06-14 01:44:08 +02:00
|
|
|
local function arrange_prop(obj) layout.arrange(obj.screen) end
|
2009-08-11 15:27:31 +02:00
|
|
|
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::size_hints_honor", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::struts", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::minimized", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::sticky", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::fullscreen", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::maximized_horizontal", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::maximized_vertical", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::border_width", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::hidden", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::floating", arrange_prop)
|
|
|
|
capi.client.connect_signal("property::geometry", arrange_prop)
|
|
|
|
-- If prop is screen, we do not know what was the previous screen, so
|
|
|
|
-- let's arrange all screens :-(
|
|
|
|
capi.client.connect_signal("property::screen", function(c)
|
2012-06-14 01:44:08 +02:00
|
|
|
for screen = 1, capi.screen.count() do layout.arrange(screen) end 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
|
2012-06-14 01:44:08 +02:00
|
|
|
layout.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
|
2012-10-20 17:33:32 +02:00
|
|
|
local function arrange_tag(t)
|
|
|
|
layout.arrange(tag.getscreen(t))
|
|
|
|
end
|
2009-08-11 15:27:31 +02:00
|
|
|
|
|
|
|
for s = 1, capi.screen.count() do
|
2010-08-25 23:00:36 +02:00
|
|
|
capi.screen[s]:add_signal("arrange")
|
|
|
|
|
2012-10-20 17:33:32 +02:00
|
|
|
tag.attached_connect_signal(s, "property::mwfact", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "property::nmaster", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "property::ncol", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "property::layout", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "property::windowfact", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "property::selected", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "property::activated", arrange_tag)
|
|
|
|
tag.attached_connect_signal(s, "tagged", arrange_tag)
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.screen[s]:connect_signal("property::workarea", function(screen)
|
2012-06-14 01:44:08 +02:00
|
|
|
layout.arrange(screen.index)
|
2009-08-18 15:54:37 +02:00
|
|
|
end)
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.screen[s]:connect_signal("padding", function (screen)
|
2012-06-14 01:44:08 +02:00
|
|
|
layout.arrange(screen.index)
|
2009-10-07 02:20:39 +02:00
|
|
|
end)
|
2009-08-11 15:27:31 +02:00
|
|
|
end
|
|
|
|
|
2012-06-14 01:44:08 +02:00
|
|
|
capi.client.connect_signal("focus", function(c) layout.arrange(c.screen) end)
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.client.connect_signal("list", function()
|
2009-08-11 15:27:31 +02:00
|
|
|
for screen = 1, capi.screen.count() do
|
2012-06-14 01:44:08 +02:00
|
|
|
layout.arrange(screen)
|
2009-08-11 15:27:31 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2012-06-14 01:44:08 +02:00
|
|
|
return layout
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|