diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-03-23 21:51:46 +0100 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-03-24 02:00:58 +0100 |
| commit | a5a84d816468fa255a4dd30b5dadf026ba29594f (patch) | |
| tree | 56423c41b3748ae23e240be928d396e84097cb85 /src/seat.zig | |
| parent | 523d629fe0f4fdcf01ba31e0787f277555ece90d (diff) | |
| download | river-a5a84d816468fa255a4dd30b5dadf026ba29594f.tar.gz river-a5a84d816468fa255a4dd30b5dadf026ba29594f.tar.xz | |
Rework things to stop invalidating pointers
Diffstat (limited to 'src/seat.zig')
| -rw-r--r-- | src/seat.zig | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/seat.zig b/src/seat.zig index 10e6ec2..df54684 100644 --- a/src/seat.zig +++ b/src/seat.zig @@ -8,41 +8,48 @@ const Server = @import("server.zig").Server; // TODO: InputManager and multi-seat support pub const Seat = struct { server: *Server, - wlr_seat: *c.wlr_seat, listen_new_input: c.wl_listener, // Multiple mice are handled by the same Cursor cursor: Cursor, // Mulitple keyboards are handled separately - keyboards: std.ArrayList(Keyboard), + keyboards: std.TailQueue(Keyboard), - pub fn init(server: *Server, allocator: *std.mem.Allocator) !@This() { + pub fn create(server: *Server) !@This() { var seat = @This(){ .server = server, - // This seems to be the default seat name used by compositors - .wlr_seat = c.wlr_seat_create(server.*.wl_display, "seat0"), - .cursor = undefined, - .keyboards = std.ArrayList(Keyboard).init(allocator), - + .wlr_seat = undefined, .listen_new_input = c.wl_listener{ .link = undefined, .notify = handle_new_input, }, + .cursor = undefined, + .keyboards = std.TailQueue(Keyboard).init(), }; - seat.cursor = try Cursor.init(&seat); + // This seems to be the default seat name used by compositors + seat.wlr_seat = c.wlr_seat_create(server.*.wl_display, "seat0") orelse + return error.CantCreateWlrSeat; + + return seat; + } + + pub fn init(self: *@This()) !void { + self.cursor = try Cursor.create(self); + self.cursor.init(); // Set up handler for all new input devices made available. This // includes keyboards, pointers, touch, etc. - c.wl_signal_add(&server.wlr_backend.events.new_input, &seat.listen_new_input); - - return seat; + c.wl_signal_add(&self.server.wlr_backend.events.new_input, &self.listen_new_input); } fn add_keyboard(self: *@This(), device: *c.wlr_input_device) !void { - try self.keyboards.append(Keyboard.init(self, device)); c.wlr_seat_set_keyboard(self.wlr_seat, device); + + var node = try self.keyboards.allocateNode(self.server.allocator); + try node.data.init(self, device); + self.keyboards.append(node); } fn add_pointer(self: *@This(), device: *c.struct_wlr_input_device) void { @@ -69,7 +76,7 @@ pub const Seat = struct { // there are no pointer devices, so we always include that capability. var caps: u32 = @intCast(u32, c.WL_SEAT_CAPABILITY_POINTER); // if list not empty - if (seat.keyboards.span().len > 0) { + if (seat.keyboards.len > 0) { caps |= @intCast(u32, c.WL_SEAT_CAPABILITY_KEYBOARD); } c.wlr_seat_set_capabilities(seat.wlr_seat, caps); |
