allow non-printables even if modifiers are pressed

This commit is contained in:
Mitchell Hashimoto
2022-08-28 21:12:58 -07:00
parent 672f6e720c
commit 28e9619361

View File

@ -669,18 +669,14 @@ fn keyCallback(
}
// Handle non-printables
const char: u8 = switch (@bitCast(u8, mods)) {
// No modifiers pressed at all
0 => @as(u8, switch (key) {
.backspace => 0x7F,
.enter => '\r',
.tab => '\t',
.escape => 0x1B,
else => 0,
}),
const char: u8 = char: {
const mods_int = @bitCast(u8, mods);
const ctrl_only = @bitCast(u8, glfw.Mods{ .control = true });
// Control only
@bitCast(u8, glfw.Mods{ .control = true }) => @as(u8, switch (key) {
// If we're only pressing control, check if this is a character
// we convert to a non-printable.
if (mods_int == ctrl_only) {
const val: u8 = switch (key) {
.a => 0x01,
.b => 0x02,
.c => 0x03,
@ -708,9 +704,19 @@ fn keyCallback(
.y => 0x19,
.z => 0x1A,
else => 0,
}),
};
if (val > 0) break :char val;
}
// Otherwise, we don't care what modifiers we press we do this.
break :char @as(u8, switch (key) {
.backspace => 0x7F,
.enter => '\r',
.tab => '\t',
.escape => 0x1B,
else => 0,
});
};
if (char > 0) {
win.queueWrite(&[1]u8{char}) catch |err|