apprt/gtk: use gtk_keyval_to_lower to get unshifted

map_keycode was not respecting the keyboard layout!
This commit is contained in:
Mitchell Hashimoto
2023-09-19 17:44:18 -07:00
parent ff74f27b99
commit 1f7d567f29

View File

@ -743,25 +743,12 @@ fn keyEvent(
// Get the unshifted unicode value of the keyval. This is used // Get the unshifted unicode value of the keyval. This is used
// by the Kitty keyboard protocol. // by the Kitty keyboard protocol.
const keyval_unicode_unshifted: u21 = unshifted: { const keyval_unicode_unshifted: u21 = unshifted: {
var n: c_int = undefined; // Note: this can't possibly always be right, specifically in the
var keys: [*c]c.GdkKeymapKey = undefined; // case of multi-level/group keyboards. But, this works for Dvorak,
var keyvals: [*c]c.guint = undefined; // Norwegian, and French layouts and thats what we have real users for
if (c.gdk_display_map_keycode( // right now.
c.gdk_event_get_display(event), const lower = c.gdk_keyval_to_lower(keyval);
keycode, if (std.math.cast(u21, lower)) |val| break :unshifted val;
&keys,
&keyvals,
&n,
) == 0) break :unshifted 0;
defer c.g_free(keys);
defer c.g_free(keyvals);
for (keys[0..@intCast(n)], 0..) |key, i| {
if (key.group == 0 and key.level == 0) {
break :unshifted @intCast(c.gdk_keyval_to_unicode(keyvals[i]));
}
}
break :unshifted 0; break :unshifted 0;
}; };
@ -828,7 +815,7 @@ fn keyEvent(
} }
} }
// If that doesn't work then we try to translate they kevval.. // If that doesn't work then we try to translate the kevval..
if (keyval_unicode != 0) { if (keyval_unicode != 0) {
if (std.math.cast(u8, keyval_unicode)) |byte| { if (std.math.cast(u8, keyval_unicode)) |byte| {
if (input.Key.fromASCII(byte)) |key| { if (input.Key.fromASCII(byte)) |key| {
@ -837,6 +824,13 @@ fn keyEvent(
} }
} }
// If that doesn't work we use the unshifted value...
if (std.math.cast(u8, keyval_unicode_unshifted)) |ascii| {
if (input.Key.fromASCII(ascii)) |key| {
break :key key;
}
}
break :key physical_key; break :key physical_key;
} else .invalid; } else .invalid;