From 807d4a4212a2cc14203d63376895cc36072ff1a2 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 29 Nov 2020 21:05:27 +0100 Subject: [PATCH] keyboard: handle destruction --- deps/zig-wayland | 2 +- river/Keyboard.zig | 17 +++++++++++++++++ river/Seat.zig | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/deps/zig-wayland b/deps/zig-wayland index 181f934..ba49b2b 160000 --- a/deps/zig-wayland +++ b/deps/zig-wayland @@ -1 +1 @@ -Subproject commit 181f9344b23504080be5cec676e4c4adebcd1f96 +Subproject commit ba49b2b6f984b788aea5e752bfeb64e3381472e7 diff --git a/river/Keyboard.zig b/river/Keyboard.zig index 06bdf90..9fe876d 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -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. diff --git a/river/Seat.zig b/river/Seat.zig index 198cd7c..eaed5fc 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -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);