From c4f1c78fcf254bd23196eff3c00bb86d071fe0fd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 10 May 2025 14:50:56 -0700 Subject: [PATCH] macOS: treat C-/ specially again to prevent beep Fixes #7310 --- macos/Sources/Ghostty/SurfaceView_AppKit.swift | 10 ++++++++++ src/input/key.zig | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index af9895c35..8e8838471 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -1066,6 +1066,16 @@ extension Ghostty { equivalent = "\r" + case "/": + // Treat C-/ as C-_. We do this because C-/ makes macOS make a beep + // sound and we don't like the beep sound. + if (!event.modifierFlags.contains(.control) || + !event.modifierFlags.isDisjoint(with: [.shift, .command, .option])) { + return false + } + + equivalent = "_" + default: // It looks like some part of AppKit sometimes generates synthetic NSEvents // with a zero timestamp. We never process these at this point. Concretely, diff --git a/src/input/key.zig b/src/input/key.zig index 831c9f07f..9dad37d78 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -149,9 +149,6 @@ pub const Mods = packed struct(Mods.Backing) { pub fn translation(self: Mods, option_as_alt: config.OptionAsAlt) Mods { var result = self; - // Control is never used for translation. - result.ctrl = false; - // macos-option-as-alt for darwin if (comptime builtin.target.os.tag.isDarwin()) alt: { // Alt has to be set only on the correct side @@ -187,14 +184,6 @@ pub const Mods = packed struct(Mods.Backing) { ); } - test "translation removes control" { - const testing = std.testing; - - const mods: Mods = .{ .ctrl = true }; - const result = mods.translation(.true); - try testing.expectEqual(Mods{}, result); - } - test "translation macos-option-as-alt" { if (comptime !builtin.target.os.tag.isDarwin()) return error.SkipZigTest;