From de05ee6678554845486362de3c1f5444835a2b1a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 20 Jun 2017 09:40:31 +0200 Subject: [PATCH 1/2] awful.layout: Apply layouts in a protected context If an error occurs while a layout is being applied, arrange_lock could get stuck at true, meaning that no more re-arranges will happen, thus breaking the whole layout machinery. Such errors could happen because the layout itself produces an error, but also because a width is too large and c:geometry() throws an error. Thus, this commit moves all of the actual "apply a layout"-code into a protected context. Fixes: https://github.com/awesomeWM/awesome/issues/1853 Signed-off-by: Uli Schlachter --- lib/awful/layout/init.lua | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index 93315a43..e4547393 100644 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -21,6 +21,7 @@ local client = require("awful.client") local ascreen = require("awful.screen") local timer = require("gears.timer") local gmath = require("gears.math") +local protected_call = require("gears.protected_call") local function get_screen(s) return s and capi.screen[s] @@ -197,19 +198,22 @@ function layout.arrange(screen) if arrange_lock then return end arrange_lock = true - local p = layout.parameters(nil, screen) + -- protected call to ensure that arrange_lock will be reset + protected_call(function() + local p = layout.parameters(nil, screen) - local useless_gap = p.useless_gap + local useless_gap = p.useless_gap - 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 + 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) arrange_lock = false delayed_arrange[screen] = nil From 20d15b8be6bbfc00d101d41da205e680e810207d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 20 Jun 2017 09:42:45 +0200 Subject: [PATCH 2/2] awful.tag.new: Handle too few given layouts When awful.tag.new() got a list of layouts shorter than the list of names, it would previously create tags with nil as their layout. This commit changes this so that the first layout is repeated if necessary. Related-to: https://github.com/awesomeWM/awesome/issues/1853 Signed-off-by: Uli Schlachter --- lib/awful/tag.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua index 431e8e6e..17ee0fb1 100644 --- a/lib/awful/tag.lua +++ b/lib/awful/tag.lua @@ -240,11 +240,15 @@ end -- @return A table with all created tags. function tag.new(names, screen, layout) screen = get_screen(screen or 1) + -- True if `layout` should be used as the layout of each created tag + local have_single_layout = (not layout) or (layout.arrange and layout.name) local tags = {} for id, name in ipairs(names) do - table.insert(tags, id, tag.add(name, {screen = screen, - layout = (layout and layout[id]) or - layout})) + local l = layout + if not have_single_layout then + l = layout[id] or layout[1] + end + table.insert(tags, id, tag.add(name, {screen = screen, layout = l})) -- Select the first tag. if id == 1 then tags[id].selected = true