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")
|
2015-02-12 23:09:27 +01:00
|
|
|
local timer = require("gears.timer")
|
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
|
|
|
|
2014-03-26 23:56:10 +01:00
|
|
|
-- The default list of layouts
|
|
|
|
layout.layouts = {
|
|
|
|
layout.suit.floating,
|
|
|
|
layout.suit.tile,
|
|
|
|
layout.suit.tile.left,
|
|
|
|
layout.suit.tile.bottom,
|
|
|
|
layout.suit.tile.top,
|
|
|
|
layout.suit.fair,
|
|
|
|
layout.suit.fair.horizontal,
|
|
|
|
layout.suit.spiral,
|
|
|
|
layout.suit.spiral.dwindle,
|
|
|
|
layout.suit.max,
|
|
|
|
layout.suit.max.fullscreen,
|
|
|
|
layout.suit.magnifier
|
|
|
|
}
|
|
|
|
|
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
|
2015-02-15 00:46:38 +01:00
|
|
|
-- Delay one arrange call per screen.
|
|
|
|
local delayed_arrange = {}
|
2009-09-18 11:31:49 +02:00
|
|
|
|
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 i Relative index.
|
2013-02-19 04:53:58 +01:00
|
|
|
-- @param s The screen number.
|
2014-03-28 13:29:16 +01:00
|
|
|
-- @param layouts A table of layouts. (optional)
|
|
|
|
function layout.inc(i, s, layouts)
|
2013-02-19 04:53:58 +01:00
|
|
|
local t = tag.selected(s)
|
2014-03-28 13:29:16 +01:00
|
|
|
local layouts = layouts or layout.layouts
|
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)
|
2015-02-22 23:32:16 +01:00
|
|
|
if not screen or delayed_arrange[screen] then return end
|
2015-02-15 00:46:38 +01:00
|
|
|
delayed_arrange[screen] = true
|
2015-02-12 23:09:27 +01:00
|
|
|
|
|
|
|
timer.delayed_call(function()
|
2015-02-15 00:46:38 +01:00
|
|
|
if arrange_lock then return end
|
|
|
|
arrange_lock = true
|
|
|
|
|
2015-02-12 23:09:27 +01:00
|
|
|
local p = {}
|
|
|
|
p.workarea = capi.screen[screen].workarea
|
|
|
|
-- Handle padding
|
|
|
|
local padding = ascreen.padding(capi.screen[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
|
|
|
|
p.geometry = capi.screen[screen].geometry
|
|
|
|
p.clients = client.tiled(screen)
|
|
|
|
p.screen = screen
|
2015-02-15 17:25:11 +01:00
|
|
|
p.geometries = setmetatable({}, {__mode = "k"})
|
2015-02-12 23:09:27 +01:00
|
|
|
layout.get(screen).arrange(p)
|
2015-02-15 17:25:11 +01:00
|
|
|
for c, g in pairs(p.geometries) do
|
|
|
|
g.width = g.width - c.border_width * 2
|
|
|
|
g.height = g.height - c.border_width * 2
|
|
|
|
c:geometry(g)
|
|
|
|
end
|
2015-02-12 23:09:27 +01:00
|
|
|
capi.screen[screen]:emit_signal("arrange")
|
|
|
|
|
|
|
|
arrange_lock = false
|
2015-02-15 00:46:38 +01:00
|
|
|
delayed_arrange[screen] = nil
|
2015-02-12 23:09:27 +01:00
|
|
|
end)
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the current layout name.
|
2014-04-13 18:06:49 +02: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)
|
2015-01-31 22:34:43 +01:00
|
|
|
capi.client.connect_signal("property::screen", function(c, old_screen)
|
|
|
|
if old_screen then
|
|
|
|
layout.arrange(old_screen)
|
|
|
|
end
|
|
|
|
layout.arrange(c.screen)
|
|
|
|
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
|
|
|
|
2014-03-30 16:37:19 +02:00
|
|
|
capi.screen.add_signal("arrange")
|
2009-08-11 15:27:31 +02:00
|
|
|
for s = 1, capi.screen.count() do
|
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
|