input: printable, comment on what magic indexes mean

This commit is contained in:
Mitchell Hashimoto
2023-08-11 09:16:29 -07:00
parent 1ded176377
commit e787a79702
2 changed files with 79 additions and 8 deletions

View File

@ -243,4 +243,77 @@ pub const Key = enum(c_int) {
else => null,
};
}
/// True if this key represents a printable character.
pub fn printable(self: Key) bool {
return switch (self) {
.a,
.b,
.c,
.d,
.e,
.f,
.g,
.h,
.i,
.j,
.k,
.l,
.m,
.n,
.o,
.p,
.q,
.r,
.s,
.t,
.u,
.v,
.w,
.x,
.y,
.z,
.zero,
.one,
.two,
.three,
.four,
.five,
.six,
.seven,
.eight,
.nine,
.semicolon,
.space,
.apostrophe,
.comma,
.grave_accent,
.period,
.slash,
.minus,
.equal,
.left_bracket,
.right_bracket,
.backslash,
.kp_0,
.kp_1,
.kp_2,
.kp_3,
.kp_4,
.kp_5,
.kp_6,
.kp_7,
.kp_8,
.kp_9,
.kp_decimal,
.kp_divide,
.kp_multiply,
.kp_subtract,
.kp_add,
.kp_equal,
=> true,
else => false,
};
}
};

View File

@ -8,14 +8,12 @@ const Key = @import("key.zig").Key;
/// The full list of entries for the current platform.
pub const entries: []const Entry = entries: {
const native_idx = if (builtin.target.isDarwin())
4
else if (builtin.target.isWindows())
3
else if (builtin.target.isLinux())
2
else
@compileError("unsupported platform");
const native_idx = switch (builtin.os.tag) {
.macos => 4, // mac
.windows => 3, // win
.linux => 2, // xkb
else => @compileError("unsupported platform"),
};
var result: [raw_entries.len]Entry = undefined;
for (raw_entries, 0..) |raw, i| {