diff --git a/src/Surface.zig b/src/Surface.zig index 4af32922e..5aeecf2d4 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1134,6 +1134,13 @@ pub fn keyCallback( const tracy = trace(@src()); defer tracy.end(); + // log.warn("KEY CALLBACK action={} key={} physical_key={} mods={}", .{ + // action, + // key, + // physical_key, + // mods, + // }); + // Dev Mode if (DevMode.enabled and DevMode.instance.visible) { // If the event was handled by imgui, ignore it. diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index e9f2a403c..2612022f5 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -422,10 +422,11 @@ pub const Surface = struct { self.core_surface.preeditCallback(null) catch {}; } - // log.warn("TRANSLATE: action={} keycode={x} dead={} key={any} key_str={s} mods={}", .{ + // log.warn("TRANSLATE: action={} keycode={x} dead={} key_len={} key={any} key_str={s} mods={}", .{ // action, // keycode, // result.composing, + // result.text.len, // result.text, // result.text, // mods, @@ -444,8 +445,29 @@ pub const Surface = struct { // We also only do key translation if this is not a dead key. const key = if (!result.composing and result.text.len == 1) key: { // A completed key. If the length of the key is one then we can - // attempt to translate it to a key enum and call the key callback. - break :key input.Key.fromASCII(result.text[0]) orelse physical_key; + // attempt to translate it to a key enum and call the key + // callback. First try plain ASCII. + if (input.Key.fromASCII(result.text[0])) |key| { + break :key key; + } + + // If that doesn't work then we try to translate without + // any modifiers and convert that. + var nomod_buf: [128]u8 = undefined; + var nomod_state: input.Keymap.State = undefined; + const nomod = try self.app.keymap.translate( + &nomod_buf, + &nomod_state, + @intCast(keycode), + .{}, + ); + if (nomod.text.len == 1) { + if (input.Key.fromASCII(nomod.text[0])) |key| { + break :key key; + } + } + + break :key physical_key; } else .invalid; // If both keys are invalid then we won't call the key callback. But