2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 12:44:21 +02:00
|
|
|
--- Layout module for awful
|
|
|
|
--
|
2008-11-25 17:01:06 +01:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
2014-05-20 12:44:21 +02:00
|
|
|
-- @module awful.layout
|
2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- 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 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,
|
2015-02-22 20:51:10 +01:00
|
|
|
client = client,
|
|
|
|
tag = tag
|
2009-07-13 01:13:21 +02:00
|
|
|
}
|
2015-02-22 20:51:10 +01:00
|
|
|
local tag = require("awful.tag")
|
2009-07-13 01:13:21 +02:00
|
|
|
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
|
|
|
|
2012-06-14 01:44:08 +02:00
|
|
|
local layout = {}
|
2014-05-20 12:44:21 +02:00
|
|
|
|
|
|
|
--- Default predefined layouts
|
|
|
|
--
|
|
|
|
-- @fixme Add documentation on available layouts as all of them are hidden
|
2012-06-14 01:44:08 +02:00
|
|
|
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,
|
2015-05-25 17:09:43 +02:00
|
|
|
layout.suit.magnifier,
|
|
|
|
layout.suit.corner.nw,
|
|
|
|
layout.suit.corner.ne,
|
|
|
|
layout.suit.corner.sw,
|
|
|
|
layout.suit.corner.se,
|
2014-03-26 23:56:10 +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
|
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.
|
2015-03-29 17:50:11 +02:00
|
|
|
-- @param s The screen number.
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] layouts A table of layouts.
|
2014-03-28 13:29:16 +01:00
|
|
|
function layout.inc(i, s, layouts)
|
2015-06-12 19:07:31 +02:00
|
|
|
if type(i) == "table" then
|
|
|
|
-- Older versions of this function had arguments (layouts, i, s), but
|
|
|
|
-- this was changed so that 'layouts' can be an optional parameter
|
|
|
|
layouts, i, s = i, s, layouts
|
|
|
|
end
|
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
|
2015-11-22 00:30:18 +01:00
|
|
|
local useless_gap = tag.getgap(tag.selected(screen),
|
|
|
|
#client.tiled(screen))
|
2015-02-12 23:09:27 +01:00
|
|
|
-- Handle padding
|
2015-07-03 02:15:52 +02:00
|
|
|
local padding = ascreen.padding(capi.screen[screen]) or {}
|
|
|
|
p.workarea.x = p.workarea.x + (padding.left or 0) + useless_gap
|
|
|
|
p.workarea.y = p.workarea.y + (padding.top or 0) + useless_gap
|
|
|
|
p.workarea.width = p.workarea.width - ((padding.left or 0 ) +
|
|
|
|
(padding.right or 0) + useless_gap * 2)
|
|
|
|
p.workarea.height = p.workarea.height - ((padding.top or 0) +
|
|
|
|
(padding.bottom or 0) + useless_gap * 2)
|
|
|
|
|
2015-02-12 23:09:27 +01:00
|
|
|
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
|
2015-07-02 22:06:06 +02:00
|
|
|
g.width = g.width - c.border_width * 2 - useless_gap * 2
|
|
|
|
g.height = g.height - c.border_width * 2 - useless_gap * 2
|
|
|
|
g.x = g.x + useless_gap
|
|
|
|
g.y = g.y + useless_gap
|
2015-02-15 17:25:11 +01:00
|
|
|
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
|
|
|
|
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")
|
2015-02-22 20:51:10 +01:00
|
|
|
|
|
|
|
capi.tag.connect_signal("property::mwfact", arrange_tag)
|
|
|
|
capi.tag.connect_signal("property::nmaster", arrange_tag)
|
|
|
|
capi.tag.connect_signal("property::ncol", arrange_tag)
|
|
|
|
capi.tag.connect_signal("property::layout", arrange_tag)
|
|
|
|
capi.tag.connect_signal("property::windowfact", arrange_tag)
|
|
|
|
capi.tag.connect_signal("property::selected", arrange_tag)
|
|
|
|
capi.tag.connect_signal("property::activated", arrange_tag)
|
2015-07-02 22:06:06 +02:00
|
|
|
capi.tag.connect_signal("property::useless_gap", arrange_tag)
|
2015-07-15 15:24:08 +02:00
|
|
|
capi.tag.connect_signal("property::master_fill_policy", arrange_tag)
|
2015-02-22 20:51:10 +01:00
|
|
|
capi.tag.connect_signal("tagged", arrange_tag)
|
|
|
|
|
2009-08-11 15:27:31 +02:00
|
|
|
for s = 1, capi.screen.count() do
|
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
|