keyboard: handle destruction

This commit is contained in:
Isaac Freund 2020-11-29 21:05:27 +01:00
parent f1e5f1aacb
commit 807d4a4212
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 22 additions and 2 deletions

2
deps/zig-wayland vendored

@ -1 +1 @@
Subproject commit 181f9344b23504080be5cec676e4c4adebcd1f96
Subproject commit ba49b2b6f984b788aea5e752bfeb64e3381472e7

View file

@ -31,6 +31,7 @@ wlr_keyboard: *c.wlr_keyboard,
listen_key: c.wl_listener = undefined,
listen_modifiers: c.wl_listener = undefined,
listen_destroy: c.wl_listener = undefined,
pub fn init(self: *Self, seat: *Seat, wlr_input_device: *c.wlr_input_device) !void {
self.* = .{
@ -67,6 +68,15 @@ pub fn init(self: *Self, seat: *Seat, wlr_input_device: *c.wlr_input_device) !vo
self.listen_modifiers.notify = handleModifiers;
c.wl_signal_add(&self.wlr_keyboard.events.modifiers, &self.listen_modifiers);
self.listen_destroy.notify = handleDestroy;
c.wl_signal_add(&self.wlr_keyboard.events.destroy, &self.listen_destroy);
}
pub fn deinit(self: *Self) void {
c.wl_list_remove(&self.listen_key.link);
c.wl_list_remove(&self.listen_modifiers.link);
c.wl_list_remove(&self.listen_destroy.link);
}
fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
@ -157,6 +167,13 @@ fn handleModifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void
// Send modifiers to the client.
c.wlr_seat_keyboard_notify_modifiers(self.seat.wlr_seat, &self.wlr_keyboard.modifiers);
}
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
self.deinit();
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.seat.keyboards.remove(node);
util.gpa.destroy(node);
}
/// Handle any builtin, harcoded compsitor mappings such as VT switching.
/// Returns true if the keysym was handled.

View file

@ -101,7 +101,10 @@ pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !voi
pub fn deinit(self: *Self) void {
self.cursor.deinit();
while (self.keyboards.pop()) |node| util.gpa.destroy(node);
while (self.keyboards.pop()) |node| {
node.data.deinit();
util.gpa.destroy(node);
}
while (self.focus_stack.first) |node| {
self.focus_stack.remove(node);