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
|
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
|
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")
|
2017-03-06 17:15:40 +01:00
|
|
|
local gmath = require("gears.math")
|
2018-08-18 23:57:23 +02:00
|
|
|
local gtable = require("gears.table")
|
2018-12-25 05:04:44 +01:00
|
|
|
local gdebug = require("gears.debug")
|
2017-06-20 09:40:31 +02:00
|
|
|
local protected_call = require("gears.protected_call")
|
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
|
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-10 02:24:22 +01:00
|
|
|
--- The default list of layouts.
|
|
|
|
--
|
|
|
|
-- The default value is:
|
|
|
|
--
|
|
|
|
-- awful.layout.suit.floating,
|
|
|
|
-- awful.layout.suit.tile,
|
|
|
|
-- awful.layout.suit.tile.left,
|
|
|
|
-- awful.layout.suit.tile.bottom,
|
|
|
|
-- awful.layout.suit.tile.top,
|
|
|
|
-- awful.layout.suit.fair,
|
|
|
|
-- awful.layout.suit.fair.horizontal,
|
|
|
|
-- awful.layout.suit.spiral,
|
|
|
|
-- awful.layout.suit.spiral.dwindle,
|
|
|
|
-- awful.layout.suit.max,
|
|
|
|
-- awful.layout.suit.max.fullscreen,
|
|
|
|
-- awful.layout.suit.magnifier,
|
|
|
|
-- awful.layout.suit.corner.nw,
|
|
|
|
-- awful.layout.suit.corner.ne,
|
|
|
|
-- awful.layout.suit.corner.sw,
|
|
|
|
-- awful.layout.suit.corner.se,
|
|
|
|
--
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @field awful.layout.layouts
|
2016-12-10 02:24:22 +01:00
|
|
|
|
2018-08-18 23:57:23 +02:00
|
|
|
--- Return the tag layout index (from `awful.layout.layouts`).
|
|
|
|
--
|
|
|
|
-- If the layout isn't part of `awful.layout.layouts`, this function returns
|
|
|
|
-- nil.
|
|
|
|
--
|
|
|
|
-- @tparam tag t The tag.
|
|
|
|
-- @treturn nil|number The layout index.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.get_tag_layout_index
|
2018-08-18 23:57:23 +02:00
|
|
|
function layout.get_tag_layout_index(t)
|
|
|
|
return gtable.hasitem(layout.layouts, t.layout)
|
|
|
|
end
|
2016-12-10 02:24:22 +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.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.get
|
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.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.inc
|
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
|
2018-12-25 05:04:44 +01:00
|
|
|
gdebug.deprecate("Use awful.layout.inc(increment, screen, layouts) instead"..
|
|
|
|
" of awful.layout.inc(layouts, increment, screen)", {deprecated_in=5})
|
|
|
|
|
2015-06-12 19:07:31 +02:00
|
|
|
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
|
2018-12-25 05:01:13 +01:00
|
|
|
|
|
|
|
if not t then return end
|
|
|
|
|
|
|
|
layouts = layouts or t.layouts or {}
|
|
|
|
|
|
|
|
if #layouts == 0 then
|
|
|
|
layouts = layout.layouts
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
2018-12-25 05:01:13 +01:00
|
|
|
|
|
|
|
local cur_l = layout.get(s)
|
|
|
|
|
|
|
|
-- First try to match the object
|
|
|
|
local cur_idx = gtable.find_first_key(
|
|
|
|
layouts, function(_, v) return v == cur_l or cur_l._type == v end, true
|
|
|
|
)
|
|
|
|
|
|
|
|
-- Safety net: handle cases where another reference of the layout
|
|
|
|
-- might be given (e.g. when (accidentally) cloning it).
|
|
|
|
cur_idx = cur_idx or gtable.find_first_key(
|
|
|
|
layouts, function(_, v) return v.name == cur_l.name end, true
|
|
|
|
)
|
|
|
|
|
|
|
|
-- Trying to come up with some kind of fallback layouts to iterate would
|
|
|
|
-- never produce a result the user expect, so if there is nothing to
|
|
|
|
-- iterate over, do not iterate.
|
|
|
|
if not cur_idx then return end
|
|
|
|
|
|
|
|
local newindex = gmath.cycle(#layouts, cur_idx + i)
|
|
|
|
layout.set(layouts[newindex], t)
|
2008-11-25 17:01:06 +01:00
|
|
|
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.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.set
|
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
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.parameters
|
2016-01-16 10:01:29 +01:00
|
|
|
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-08-30 18:25:05 +02:00
|
|
|
local clients = client.tiled(screen)
|
|
|
|
local gap_single_client = true
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-09-14 23:11:00 +02:00
|
|
|
if(t and t.gap_single_client ~= nil) then
|
2016-08-30 18:25:05 +02:00
|
|
|
gap_single_client = t.gap_single_client
|
|
|
|
end
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2017-07-20 21:21:51 +02:00
|
|
|
local useless_gap = 0
|
|
|
|
if t then
|
|
|
|
local skip_gap = layout.get(screen).skip_gap or function(nclients)
|
|
|
|
return nclients < 2
|
|
|
|
end
|
|
|
|
if gap_single_client or not skip_gap(#clients, t) then
|
|
|
|
useless_gap = t.gap
|
|
|
|
end
|
|
|
|
end
|
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-08-30 18:25:05 +02:00
|
|
|
p.clients = clients
|
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.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.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
|
|
|
|
|
2017-06-20 09:40:31 +02:00
|
|
|
-- protected call to ensure that arrange_lock will be reset
|
|
|
|
protected_call(function()
|
|
|
|
local p = layout.parameters(nil, screen)
|
2016-01-16 10:01:29 +01:00
|
|
|
|
2017-06-20 09:40:31 +02:00
|
|
|
local useless_gap = p.useless_gap
|
2016-01-16 10:01:29 +01:00
|
|
|
|
2017-06-20 09:40:31 +02:00
|
|
|
p.geometries = setmetatable({}, {__mode = "k"})
|
|
|
|
layout.get(screen).arrange(p)
|
|
|
|
for c, g in pairs(p.geometries) do
|
|
|
|
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)
|
|
|
|
g.x = g.x + useless_gap
|
|
|
|
g.y = g.y + useless_gap
|
|
|
|
c:geometry(g)
|
|
|
|
end
|
|
|
|
end)
|
2015-02-12 23:09:27 +01:00
|
|
|
arrange_lock = false
|
2015-02-15 00:46:38 +01:00
|
|
|
delayed_arrange[screen] = nil
|
2016-10-26 16:20:34 +02:00
|
|
|
|
|
|
|
screen:emit_signal("arrange")
|
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.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.layout.getname
|
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
|
|
|
|
2017-06-09 10:13:14 +02:00
|
|
|
capi.client.connect_signal("focus", function(c)
|
|
|
|
local screen = c.screen
|
|
|
|
if layout.get(screen).need_focus_update then
|
|
|
|
layout.arrange(screen)
|
|
|
|
end
|
|
|
|
end)
|
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
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @signalhandler awful.layout.move_handler
|
2016-04-28 22:47:29 +02:00
|
|
|
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
|