From 472e2b2624d9fe3b92f2139fbd53771f4e9709b3 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 19 Apr 2020 15:15:50 +0200 Subject: [PATCH] Fix layer sufaces holding focus after unmap --- src/layer_surface.zig | 10 ++++++++++ src/output.zig | 5 ++++- src/seat.zig | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/layer_surface.zig b/src/layer_surface.zig index 0ad76c9..650fdb2 100644 --- a/src/layer_surface.zig +++ b/src/layer_surface.zig @@ -117,7 +117,17 @@ pub const LayerSurface = struct { } } + // This gives exclusive focus to a keyboard interactive top or overlay layer + // surface if there is one. layer_surface.output.arrangeLayers(); + + // Ensure that focus is given to the appropriate view if there is no + // other top/overlay layer surface to grab focus. + it = layer_surface.output.root.server.input_manager.seats.first; + while (it) |node| : (it = node.next) { + const seat = &node.data; + seat.focus(null); + } } fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { diff --git a/src/output.zig b/src/output.zig index fa09b07..34769f1 100644 --- a/src/output.zig +++ b/src/output.zig @@ -259,7 +259,10 @@ pub const Output = struct { var it = self.layers[layer].last; while (it) |node| : (it = node.prev) { const layer_surface = &node.data; - if (layer_surface.wlr_layer_surface.current.keyboard_interactive) { + // Only mapped surfaces may gain focus + if (layer_surface.mapped and + layer_surface.wlr_layer_surface.current.keyboard_interactive) + { break :outer layer_surface; } } diff --git a/src/seat.zig b/src/seat.zig index 6b7539e..9d13257 100644 --- a/src/seat.zig +++ b/src/seat.zig @@ -161,7 +161,8 @@ pub const Seat = struct { std.debug.assert(self.focused_layer == null); current_focus.setActivated(false); self.focused_view = null; - } else if (self.focused_layer) |current_focus| { + } + if (self.focused_layer) |current_focus| { std.debug.assert(self.focused_view == null); self.focused_layer = null; }