From a0c30de132a71bb90b2e90607a1fe0a78fd44322 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 19 Apr 2020 14:21:51 +0200 Subject: [PATCH] Clear focus if focused layer surface is unmapped --- src/input_manager.zig | 5 +++++ src/layer_surface.zig | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/input_manager.zig b/src/input_manager.zig index 8cb0aa6..12f4171 100644 --- a/src/input_manager.zig +++ b/src/input_manager.zig @@ -1,6 +1,7 @@ const std = @import("std"); const c = @import("c.zig"); +const Log = @import("log.zig").Log; const Seat = @import("seat.zig").Seat; const Server = @import("server.zig").Server; @@ -83,6 +84,8 @@ pub const InputManager = struct { fn handleInhibitActivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { const self = @fieldParentPtr(Self, "listen_inhibit_activate", listener.?); + Log.Debug.log("Input inhibitor activated", .{}); + // Clear focus of all seats var seat_it = self.seats.first; while (seat_it) |seat_node| : (seat_it = seat_node.next) { @@ -95,6 +98,8 @@ pub const InputManager = struct { fn handleInhibitDeactivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { const self = @fieldParentPtr(Self, "listen_inhibit_deactivate", listener.?); + Log.Debug.log("Input inhibitor deactivated", .{}); + self.exclusive_client = null; // Calling arrangeLayers() like this ensures that any top or overlay, diff --git a/src/layer_surface.zig b/src/layer_surface.zig index 6aa1b9d..0ad76c9 100644 --- a/src/layer_surface.zig +++ b/src/layer_surface.zig @@ -76,6 +76,8 @@ pub const LayerSurface = struct { const layer_surface = @fieldParentPtr(LayerSurface, "listen_map", listener.?); const wlr_layer_surface = layer_surface.wlr_layer_surface; + Log.Debug.log("Layer surface '{}' mapped.", .{wlr_layer_surface.namespace}); + layer_surface.mapped = true; // Add listeners that are only active while mapped @@ -96,12 +98,25 @@ pub const LayerSurface = struct { fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { const layer_surface = @fieldParentPtr(LayerSurface, "listen_unmap", listener.?); + Log.Debug.log("Layer surface '{}' unmapped.", .{layer_surface.wlr_layer_surface.namespace}); + layer_surface.mapped = false; // remove listeners only active while the layer surface is mapped c.wl_list_remove(&layer_surface.listen_commit.link); c.wl_list_remove(&layer_surface.listen_new_popup.link); + // If the unmapped surface is focused, clear focus + var it = layer_surface.output.root.server.input_manager.seats.first; + while (it) |node| : (it = node.next) { + const seat = &node.data; + if (seat.focused_layer) |current_focus| { + if (current_focus == layer_surface) { + seat.setFocusRaw(.{ .none = {} }); + } + } + } + layer_surface.output.arrangeLayers(); }