diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index b8100bbce..93315a439 100644 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -269,6 +269,12 @@ capi.tag.connect_signal("tagged", arrange_tag) capi.screen.connect_signal("property::workarea", layout.arrange) capi.screen.connect_signal("padding", layout.arrange) +capi.client.connect_signal("focus", function(c) + local screen = c.screen + if layout.get(screen).need_focus_update then + layout.arrange(screen) + end +end) capi.client.connect_signal("raised", function(c) layout.arrange(c.screen) end) capi.client.connect_signal("lowered", function(c) layout.arrange(c.screen) end) capi.client.connect_signal("list", function() diff --git a/lib/awful/layout/suit/magnifier.lua b/lib/awful/layout/suit/magnifier.lua index fb4df4c86..94177229a 100644 --- a/lib/awful/layout/suit/magnifier.lua +++ b/lib/awful/layout/suit/magnifier.lua @@ -146,6 +146,10 @@ end magnifier.name = "magnifier" +-- This layout handles the currently focused client specially and needs to be +-- called again when the focus changes. +magnifier.need_focus_update = true + return magnifier -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-awful-layout.lua b/tests/test-awful-layout.lua index 430546936..6f9a12418 100644 --- a/tests/test-awful-layout.lua +++ b/tests/test-awful-layout.lua @@ -29,6 +29,67 @@ local steps = { } +-- Test if layouts are called +do + local c1, c2 + local arrange_expected = false + local fake_layout = { + arrange = function() + assert(arrange_expected) + arrange_expected = false + end, + name = "fake", + } + + table.insert(steps, function() + c1, c2 = client.get()[1], client.get()[2] + client.focus = c1 + + arrange_expected = true + awful.layout.set(fake_layout) + return true + end) + + table.insert(steps, function() + assert(arrange_expected == false) + + arrange_expected = false + client.focus = c2 + return true + end) + + table.insert(steps, function() + -- This sync is needed to avoid a race: Consider the code + -- client.focus = c2 + -- gears.timer.start_new(0, function() + -- client.focus = c1 + -- end) + -- The C code would focus c2, but Lua would then change the focus to c1 + -- before the X11 server acknowledged the focus change (FocusIn event). + -- Thus, when that event comes in, the C code things that c1 currently + -- has the focus and thus would do c2:emit_signal("focus"). Then, when + -- the FocusIn event for c1 comes, it would do c1:emit_signal("focus"). + awesome.sync() + return true + end) + + table.insert(steps, function() + assert(arrange_expected == false) + + arrange_expected = true + fake_layout.need_focus_update = true + client.focus = c1 + return true + end) + + table.insert(steps, function() + assert(arrange_expected == false) + + awful.layout.set(awful.layout.suit.floating) + return true + end) +end + local function next_layout() awful.layout.inc(1)