From c52d9e160874e811da8115e89e10aeaa35bb7f1b Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Tue, 19 Sep 2023 18:17:22 +0200 Subject: [PATCH] [layout] Improve focus management --- layout.lua | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/layout.lua b/layout.lua index 82b4f72..c7366d9 100644 --- a/layout.lua +++ b/layout.lua @@ -14,7 +14,6 @@ local BASE = (...):gsub('layout$', '') local Widget = require(BASE..'widget') -local core = require(BASE..'core') local gear = require 'lib.gear' @@ -126,12 +125,21 @@ function Layout:layoutWidgets() self.y = ry self.w = math.max(rw, 0) self.h = math.max(rh, 0) + + -- A Layout ignores focus if empty or containing only nofocus widgets + self.nofocus = true + for _,w in ipairs(self) do + if not w.nofocus then + self.nofocus = false + break + end + end end -- Find layout's child containing the provided widget. local function childof(layout, widget) local parent = widget.parent - while parent ~= layout do + while not rawequal(parent, layout) do widget = parent parent = widget.parent end @@ -173,16 +181,6 @@ function Layout:new(args) self.padding = self.padding or 0 self.stack = {} - - -- A Layout ignores focus if empty or containing only nofocus widgets - self.nofocus = true - for _,w in ipairs(self) do - if not w.nofocus then - self.nofocus = false - break - end - end - return self end @@ -201,7 +199,7 @@ function Layout:after(widget) widget = childof(self, widget) for i = 1,#self do - if self[i] == widget then + if rawequal(self[i], widget) then -- Search to the right/down return scanforward(self, i+1) end @@ -213,7 +211,7 @@ function Layout:before(widget) widget = childof(self, widget) for i = 1,#self do - if self[i] == widget then + if rawequal(self[i], widget) then -- Search to the left/up return scanbackwards(self, i-1) end