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; }