summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
authorMitchell Hashimoto <m@mitchellh.com>2025-02-13 14:45:31 -0800
committerMitchell Hashimoto <m@mitchellh.com>2025-02-13 14:58:41 -0800
commitb44b1086d355fc269dde5979bc69e85cdf1990b2 (patch)
tree64eafc1b9508af3c8c688ec76dcb5b65d53005e8 /src/input
parent9978ea3b9c0312fe4a27bf818d8fc988441bcaba (diff)
apprt/embedded: proper consumed modifier state for ctrl keys
Diffstat (limited to 'src/input')
-rw-r--r--src/input/KeymapDarwin.zig25
-rw-r--r--src/input/KeymapNoop.zig5
2 files changed, 24 insertions, 6 deletions
diff --git a/src/input/KeymapDarwin.zig b/src/input/KeymapDarwin.zig
index 3d81b0f4b..154f648a6 100644
--- a/src/input/KeymapDarwin.zig
+++ b/src/input/KeymapDarwin.zig
@@ -50,10 +50,13 @@ pub const State = struct {
pub const Translation = struct {
/// The translation result. If this is a dead key state, then this will
/// be pre-edit text that can be displayed but will ultimately be replaced.
- text: []const u8,
+ text: []const u8 = "",
/// Whether the text is still composing, i.e. this is a dead key state.
- composing: bool,
+ composing: bool = false,
+
+ /// The mods that were consumed to produce this translation
+ mods: Mods = .{},
};
pub fn init() !Keymap {
@@ -122,8 +125,18 @@ pub fn translate(
out: []u8,
state: *State,
code: u16,
- mods: Mods,
+ input_mods: Mods,
) !Translation {
+ // On macOS we strip ctrl because UCKeyTranslate
+ // converts to the masked values (i.e. ctrl+c becomes 3)
+ // and we don't want that behavior in Ghostty ever. This makes
+ // this file not a general-purpose keymap implementation.
+ const mods: Mods = mods: {
+ var v = input_mods;
+ v.ctrl = false;
+ break :mods v;
+ };
+
// Get the keycode for the space key, using comptime.
const code_space: u16 = comptime space: for (codes) |entry| {
if (std.mem.eql(u8, entry.code, "Space"))
@@ -183,7 +196,11 @@ pub fn translate(
// Convert the utf16 to utf8
const len = try std.unicode.utf16leToUtf8(out, char[0..char_count]);
- return .{ .text = out[0..len], .composing = composing };
+ return .{
+ .text = out[0..len],
+ .composing = composing,
+ .mods = mods,
+ };
}
/// Map to the modifiers format used by the UCKeyTranslate function.
diff --git a/src/input/KeymapNoop.zig b/src/input/KeymapNoop.zig
index 414c52954..b6a9d57b9 100644
--- a/src/input/KeymapNoop.zig
+++ b/src/input/KeymapNoop.zig
@@ -6,8 +6,9 @@ const Mods = @import("key.zig").Mods;
pub const State = struct {};
pub const Translation = struct {
- text: []const u8,
- composing: bool,
+ text: []const u8 = "",
+ composing: bool = false,
+ mods: Mods = .{},
};
pub fn init() !KeymapNoop {