From 3bb8efd2db6a786e838a7320729b8997dd537094 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 9 Jun 2017 10:13:14 +0200 Subject: [PATCH] Re-arrange the magnifier layout on focus changes Just re-arranging on every focus change would cause useless/needless re-arranges (which have no effect except to waste CPU time). Thus, this adds a special (undocumented) flag on layouts that makes sure that a rearrange occurs when the focus changes. Fixes: https://github.com/awesomeWM/awesome/issues/1799 Signed-off-by: Uli Schlachter --- lib/awful/layout/init.lua | 6 +++ lib/awful/layout/suit/magnifier.lua | 4 ++ tests/test-awful-layout.lua | 61 +++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index b8100bbc..93315a43 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 fb4df4c8..94177229 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 43054693..6f9a1241 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)