apprt/gtk: do not encode control characters into utf8 event field

This commit is contained in:
Mitchell Hashimoto
2023-12-13 10:45:47 -08:00
parent b3522f548e
commit 08e0d0b836

View File

@ -1444,8 +1444,13 @@ fn keyEvent(
// a text value. We have to do this because GTK will not process // a text value. We have to do this because GTK will not process
// "Ctrl+Shift+1" (on US keyboards) as "Ctrl+!" but instead as "". // "Ctrl+Shift+1" (on US keyboards) as "Ctrl+!" but instead as "".
// But the keyval is set correctly so we can at least extract that. // But the keyval is set correctly so we can at least extract that.
if (self.im_len == 0 and keyval_unicode > 0) { if (self.im_len == 0 and keyval_unicode > 0) im: {
if (std.math.cast(u21, keyval_unicode)) |cp| { if (std.math.cast(u21, keyval_unicode)) |cp| {
// We don't want to send control characters as IM
// text. Control characters are handled already by
// the encoder directly.
if (cp < 0x20) break :im;
if (std.unicode.utf8Encode(cp, &self.im_buf)) |len| { if (std.unicode.utf8Encode(cp, &self.im_buf)) |len| {
self.im_len = len; self.im_len = len;
} else |_| {} } else |_| {}