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-07-13 01:13:21 +02:00
|
|
|
local capi = {
|
|
|
|
screen = screen,
|
2016-01-16 10:01:29 +01:00
|
|
|
mouse = mouse,
|
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")
|
2016-04-05 09:02:00 +02:00
|
|
|
local ascreen = require("awful.screen")
|
2015-02-12 23:09:27 +01:00
|
|
|
local timer = require("gears.timer")
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2016-02-26 19:08:35 +01:00
|
|
|
local function get_screen(s)
|
|
|
|
return s and capi.screen[s]
|
|
|
|
end
|
|
|
|
|
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.
|
2016-02-26 19:08:35 +01:00
|
|
|
-- @param screen The screen.
|
2008-11-25 17:01:06 +01:00
|
|
|
-- @return The layout function.
|
2012-06-14 01:44:08 +02:00
|
|
|
function layout.get(screen)
|
2016-04-05 09:02:00 +02:00
|
|
|
screen = screen or capi.mouse.screen
|
|
|
|
local t = get_screen(screen).selected_tag
|
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.
|
2016-02-26 19:08:35 +01:00
|
|
|
-- @param s The screen.
|
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
|
2016-04-05 09:02:00 +02:00
|
|
|
s = get_screen(s or ascreen.focused())
|
|
|
|
local t = s.selected_tag
|
2016-02-07 15:24:08 +01:00
|
|
|
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
|
2016-01-16 10:01:29 +01:00
|
|
|
if v == curlayout or curlayout._type == v then
|
2008-11-25 17:01:06 +01:00
|
|
|
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.
|
2016-04-05 09:02:00 +02:00
|
|
|
-- @tparam[opt=mouse.screen.selected_tag] tag t The tag to modify.
|
2012-06-14 01:44:08 +02:00
|
|
|
function layout.set(_layout, t)
|
2016-04-05 09:02:00 +02:00
|
|
|
t = t or capi.mouse.screen.selected_tag
|
|
|
|
t.layout = _layout
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2016-01-16 10:01:29 +01:00
|
|
|
--- Get the layout parameters used for the screen
|
|
|
|
--
|
|
|
|
-- This should give the same result as "arrange", but without the "geometries"
|
|
|
|
-- parameter, as this is computed during arranging.
|
|
|
|
--
|
|
|
|
-- If `t` is given, `screen` is ignored, if none are given, the mouse screen is
|
|
|
|
-- used.
|
|
|
|
--
|
|
|
|
-- @tparam[opt] tag t The tag to query
|
|
|
|
-- @param[opt] screen The screen
|
|
|
|
-- @treturn table A table with the workarea (x, y, width, height), the screen
|
|
|
|
-- geometry (x, y, width, height), the clients, the screen and sometime, a
|
|
|
|
-- "geometries" table with client as keys and geometry as value
|
|
|
|
function layout.parameters(t, screen)
|
2016-02-26 19:08:35 +01:00
|
|
|
screen = get_screen(screen)
|
2016-04-05 09:02:00 +02:00
|
|
|
t = t or screen.selected_tag
|
2016-01-16 10:01:29 +01:00
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
screen = get_screen(t and t.screen or 1)
|
2016-01-16 10:01:29 +01:00
|
|
|
|
|
|
|
local p = {}
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
local useless_gap = t and t.gap or 0
|
2016-01-16 10:01:29 +01:00
|
|
|
|
2016-04-05 05:35:03 +02:00
|
|
|
p.workarea = screen:get_bounding_geometry {
|
2016-03-26 08:22:20 +01:00
|
|
|
honor_padding = true,
|
|
|
|
honor_workarea = true,
|
|
|
|
margins = useless_gap,
|
2016-04-05 05:35:03 +02:00
|
|
|
}
|
2016-01-16 10:01:29 +01:00
|
|
|
|
2016-02-26 19:08:35 +01:00
|
|
|
p.geometry = screen.geometry
|
2016-01-16 10:01:29 +01:00
|
|
|
p.clients = client.tiled(screen)
|
2016-02-26 19:08:35 +01:00
|
|
|
p.screen = screen.index
|
2016-04-05 05:35:03 +02:00
|
|
|
p.padding = screen.padding
|
2016-01-16 10:01:29 +01:00
|
|
|
p.useless_gap = useless_gap
|
|
|
|
|
|
|
|
return p
|
|
|
|
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)
|
2016-02-26 19:08:35 +01:00
|
|
|
screen = get_screen(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()
|
2016-04-17 15:38:11 +02:00
|
|
|
if not screen.valid then
|
|
|
|
-- Screen was removed
|
|
|
|
delayed_arrange[screen] = nil
|
|
|
|
return
|
|
|
|
end
|
2015-02-15 00:46:38 +01:00
|
|
|
if arrange_lock then return end
|
|
|
|
arrange_lock = true
|
|
|
|
|
2016-01-16 10:01:29 +01:00
|
|
|
local p = layout.parameters(nil, screen)
|
|
|
|
|
|
|
|
local useless_gap = p.useless_gap
|
|
|
|
|
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
|
2016-04-18 07:24:12 +02:00
|
|
|
g.width = math.max(1, g.width - c.border_width * 2 - useless_gap * 2)
|
|
|
|
g.height = math.max(1, g.height - c.border_width * 2 - useless_gap * 2)
|
2015-07-02 22:06:06 +02:00
|
|
|
g.x = g.x + useless_gap
|
|
|
|
g.y = g.y + useless_gap
|
2015-02-15 17:25:11 +01:00
|
|
|
c:geometry(g)
|
|
|
|
end
|
2016-02-26 19:08:35 +01:00
|
|
|
screen:emit_signal("arrange")
|
2015-02-12 23:09:27 +01:00
|
|
|
|
|
|
|
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)
|
2016-02-07 15:24:08 +01:00
|
|
|
_layout = _layout or layout.get()
|
2012-06-14 01:44:08 +02:00
|
|
|
return _layout.name
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
|
2016-06-27 08:13:52 +02:00
|
|
|
local function arrange_prop_nf(obj)
|
|
|
|
if not client.object.get_floating(obj) then
|
|
|
|
layout.arrange(obj.screen)
|
|
|
|
end
|
|
|
|
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
|
|
|
|
2016-06-27 08:13:52 +02:00
|
|
|
capi.client.connect_signal("property::size_hints_honor", arrange_prop_nf)
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::struts", arrange_prop)
|
2016-06-27 08:13:52 +02:00
|
|
|
capi.client.connect_signal("property::minimized", arrange_prop_nf)
|
|
|
|
capi.client.connect_signal("property::sticky", arrange_prop_nf)
|
|
|
|
capi.client.connect_signal("property::fullscreen", arrange_prop_nf)
|
|
|
|
capi.client.connect_signal("property::maximized_horizontal", arrange_prop_nf)
|
|
|
|
capi.client.connect_signal("property::maximized_vertical", arrange_prop_nf)
|
|
|
|
capi.client.connect_signal("property::border_width", arrange_prop_nf)
|
|
|
|
capi.client.connect_signal("property::hidden", arrange_prop_nf)
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::floating", arrange_prop)
|
2016-06-27 08:13:52 +02:00
|
|
|
capi.client.connect_signal("property::geometry", arrange_prop_nf)
|
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)
|
2016-04-05 09:02:00 +02:00
|
|
|
layout.arrange(t.screen)
|
2012-10-20 17:33:32 +02:00
|
|
|
end
|
2009-08-11 15:27:31 +02:00
|
|
|
|
2016-04-11 06:30:05 +02:00
|
|
|
capi.tag.connect_signal("property::master_width_factor", arrange_tag)
|
2016-04-11 06:50:46 +02:00
|
|
|
capi.tag.connect_signal("property::master_count", arrange_tag)
|
2016-04-11 06:30:05 +02:00
|
|
|
capi.tag.connect_signal("property::column_count", arrange_tag)
|
2015-02-22 20:51:10 +01:00
|
|
|
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)
|
|
|
|
|
2016-03-06 11:38:52 +01:00
|
|
|
capi.screen.connect_signal("property::workarea", layout.arrange)
|
|
|
|
capi.screen.connect_signal("padding", layout.arrange)
|
2009-08-11 15:27:31 +02:00
|
|
|
|
2016-01-03 09:29:21 +01:00
|
|
|
capi.client.connect_signal("raised", function(c) layout.arrange(c.screen) end)
|
|
|
|
capi.client.connect_signal("lowered", function(c) layout.arrange(c.screen) end)
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.client.connect_signal("list", function()
|
2016-03-06 13:31:30 +01:00
|
|
|
for screen in capi.screen do
|
2012-06-14 01:44:08 +02:00
|
|
|
layout.arrange(screen)
|
2009-08-11 15:27:31 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-05-03 12:06:50 +02:00
|
|
|
--- Default handler for `request::geometry` signals for tiled clients with
|
|
|
|
-- the "mouse.move" context.
|
2016-04-28 22:47:29 +02:00
|
|
|
-- @tparam client c The client
|
|
|
|
-- @tparam string context The context
|
|
|
|
-- @tparam table hints Additional hints
|
|
|
|
function layout.move_handler(c, context, hints) --luacheck: no unused args
|
|
|
|
-- Quit if it isn't a mouse.move on a tiled layout, that's handled elsewhere
|
|
|
|
if c.floating then return end
|
|
|
|
if context ~= "mouse.move" then return end
|
2016-06-06 06:18:16 +02:00
|
|
|
|
|
|
|
if capi.mouse.screen ~= c.screen then
|
|
|
|
c.screen = capi.mouse.screen
|
|
|
|
end
|
|
|
|
|
2016-04-28 22:47:29 +02:00
|
|
|
local l = c.screen.selected_tag and c.screen.selected_tag.layout or nil
|
|
|
|
if l == layout.suit.floating then return end
|
|
|
|
|
|
|
|
local c_u_m = capi.mouse.current_client
|
|
|
|
if c_u_m and not c_u_m.floating then
|
|
|
|
if c_u_m ~= c then
|
|
|
|
c:swap(c_u_m)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
capi.client.connect_signal("request::geometry", layout.move_handler)
|
|
|
|
|
2016-07-24 16:36:03 +02:00
|
|
|
-- When a screen is moved, make (floating) clients follow it
|
|
|
|
capi.screen.connect_signal("property::geometry", function(s, old_geom)
|
|
|
|
local geom = s.geometry
|
|
|
|
local xshift = geom.x - old_geom.x
|
|
|
|
local yshift = geom.y - old_geom.y
|
|
|
|
for _, c in ipairs(capi.client.get(s)) do
|
|
|
|
local cgeom = c:geometry()
|
|
|
|
c:geometry({
|
|
|
|
x = cgeom.x + xshift,
|
|
|
|
y = cgeom.y + yshift
|
|
|
|
})
|
|
|
|
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
|