Implement libinput device configuration

We need to defer config application to the first manage_start event
using a should_manage flag so that all *_support events have arrived
before we try applying the configs

This commit also has two other fixes
- fixes a potential use-after-free by telling InputDevice when a
 LibinputDevice is .removed.
- fix logFn (removed "if (scope != .default) return;")

I used kwm to help figure out the manage pattern for the input config.
Link to kwm: https://github.com/kewuaa/kwm
This commit is contained in:
Ben Buhse 2026-02-10 20:06:17 -06:00
commit 296f875993
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
5 changed files with 184 additions and 22 deletions

View file

@ -36,6 +36,12 @@ pub fn create(river_input_device_v1: *river.InputDeviceV1) !*InputDevice {
}
pub fn destroy(input_device: *InputDevice) void {
if (input_device.libinput_device) |libinput_device| {
libinput_device.input_device = null;
}
if (input_device.name) |name| {
utils.allocator.free(name);
}
input_device.link.remove();
utils.allocator.destroy(input_device);
}
@ -47,16 +53,8 @@ fn riverInputDeviceV1Listener(river_input_device_v1: *river.InputDeviceV1, event
river_input_device_v1.destroy();
input_device.destroy();
},
.type => |ev| {
// This event is only sent once when the object is created
assert(input_device.type == null);
input_device.type = ev.type;
},
.name => |ev| {
// This event is only sent once when the object is created
assert(input_device.name == null);
input_device.name = mem.span(ev.name);
},
.type => |ev| input_device.type = ev.type,
.name => |ev| input_device.name = utils.allocator.dupe(u8, mem.span(ev.name)) catch @panic("Out of memory"),
}
}