From d8a309c734dcf001d172804fa8d707e00479edd1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 13 Aug 2025 09:06:03 -0700 Subject: [PATCH] apprt/gtk-ng: split tree active focus should be last focused fallback Co-authored-by: Jeffrey C. Ollie --- src/apprt/gtk-ng/class/split_tree.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/apprt/gtk-ng/class/split_tree.zig b/src/apprt/gtk-ng/class/split_tree.zig index 10815bb0a..1da0896a2 100644 --- a/src/apprt/gtk-ng/class/split_tree.zig +++ b/src/apprt/gtk-ng/class/split_tree.zig @@ -418,6 +418,20 @@ pub const SplitTree = extern struct { if (entry.view.getFocused()) return entry.handle; } + // If none are currently focused, the most previously focused + // surface (if it exists) is our active surface. This lets things + // like apprt actions and bell ringing continue to work in the + // background. + if (self.private().last_focused.get()) |v| { + defer v.unref(); + + // We need to find the handle of the last focused surface. + it = tree.iterator(); + while (it.next()) |entry| { + if (entry.view == v) return entry.handle; + } + } + return null; }