InputDevice: use "switch" in input device names

Currently we use "switch_device" because that's what the enum variant
happens to be named in zig-wlroots so that it doesn't conflict with the
switch keyword.

This however wasn't really thought through and "switch" makes more sense
to expose to the user.
This commit is contained in:
Isaac Freund 2022-06-20 19:51:34 +02:00
parent c40dc5ee75
commit 67d07e84b0
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -36,18 +36,23 @@ destroy: wl.Listener(*wlr.InputDevice) = wl.Listener(*wlr.InputDevice).init(hand
identifier: []const u8, identifier: []const u8,
pub fn init(self: *InputDevice, device: *wlr.InputDevice) !void { pub fn init(self: *InputDevice, device: *wlr.InputDevice) !void {
const device_type: []const u8 = switch (device.type) {
.switch_device => "switch",
else => @tagName(device.type),
};
const identifier = try std.fmt.allocPrint( const identifier = try std.fmt.allocPrint(
util.gpa, util.gpa,
"{s}-{}-{}-{s}", "{s}-{}-{}-{s}",
.{ .{
@tagName(device.type), device_type,
device.vendor, device.vendor,
device.product, device.product,
mem.trim(u8, mem.span(device.name), &ascii.spaces), mem.trim(u8, mem.span(device.name), &ascii.spaces),
}, },
); );
for (identifier) |*char| { for (identifier) |*char| {
if (char.* == ' ' or !ascii.isPrint(char.*)) { if (!ascii.isGraph(char.*)) {
char.* = '_'; char.* = '_';
} }
} }