apprt/embedded: do not translate control characters

macOS translates inputs such as shift+tab into the control character tab
(ascii 0x09). Linux/GTK does not translate character inputs except to
printable characters. We don't want control character translations
because these are all handled manually by our key encoder (i.e.
translating ctrl+c to 0x03).
This commit is contained in:
Mitchell Hashimoto
2023-08-24 15:00:35 -07:00
parent 0ffbab00a4
commit 3a93aaf9cf
2 changed files with 27 additions and 0 deletions

View File

@ -480,6 +480,13 @@ pub const Surface = struct {
// If we aren't composing, then we set our preedit to // If we aren't composing, then we set our preedit to
// empty no matter what. // empty no matter what.
self.core_surface.preeditCallback(null) catch {}; self.core_surface.preeditCallback(null) catch {};
// If the text is just a single non-printable ASCII character
// then we clear the text. We handle non-printables in the
// key encoder manual (such as tab, ctrl+c, etc.)
if (result.text.len == 1 and result.text[0] < 0x20) {
break :translate .{ .composing = false, .text = "" };
}
} }
break :translate result; break :translate result;

View File

@ -15,6 +15,8 @@ const KittyEntry = @import("kitty.zig").Entry;
const kitty_entries = @import("kitty.zig").entries; const kitty_entries = @import("kitty.zig").entries;
const KittyFlags = terminal.kitty.KeyFlags; const KittyFlags = terminal.kitty.KeyFlags;
const log = std.log.scoped(.key_encoder);
event: key.KeyEvent, event: key.KeyEvent,
/// The state of various modes of a terminal that impact encoding. /// The state of various modes of a terminal that impact encoding.
@ -29,6 +31,8 @@ pub fn encode(
self: *const KeyEncoder, self: *const KeyEncoder,
buf: []u8, buf: []u8,
) ![]const u8 { ) ![]const u8 {
// log.debug("encode {}", .{self.*});
if (self.kitty_flags.int() != 0) return try self.kitty(buf); if (self.kitty_flags.int() != 0) return try self.kitty(buf);
return try self.legacy(buf); return try self.legacy(buf);
} }
@ -863,6 +867,22 @@ test "kitty: up arrow with utf8" {
try testing.expectEqualStrings("\x1b[A", actual); try testing.expectEqualStrings("\x1b[A", actual);
} }
test "kitty: shift+tab" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
.event = .{
.key = .tab,
.mods = .{ .shift = true },
.utf8 = "", // tab
},
.kitty_flags = .{ .disambiguate = true, .report_alternates = true },
};
const actual = try enc.kitty(&buf);
try testing.expectEqualStrings("\x1b[9;2u", actual);
}
test "legacy: ctrl+alt+c" { test "legacy: ctrl+alt+c" {
var buf: [128]u8 = undefined; var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{ var enc: KeyEncoder = .{