From f6ea15dd21e976af7cdf4ee7236447479ab8fef8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Nov 2024 10:12:04 -0800 Subject: [PATCH] macos: allow additional modifiers through for ctrl+enter The bug: ctrl+shift+enter on macOS 15 shows a context menu and doesn't encode to the terminal. This avoids a system-wide keybind that shows a context menu in macOS 15+. In general Ghostty doesn't try to override system-wide keybinds but this one is particularly annoying and not useful to terminal users. We've discussed making this logic configurable for all system level keybinds but for now this is a quick fix specifically for ctrl+shift+enter. --- .../Sources/Ghostty/SurfaceView_AppKit.swift | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 872ce17ec..512a5239b 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -704,12 +704,6 @@ extension Ghostty { /// Special case handling for some control keys override func performKeyEquivalent(with event: NSEvent) -> Bool { - // Only process keys when Control is the only modifier - if (!event.modifierFlags.contains(.control) || - !event.modifierFlags.isDisjoint(with: [.shift, .command, .option])) { - return false - } - // Only process key down events if (event.type != .keyDown) { return false @@ -722,11 +716,23 @@ extension Ghostty { return false } + // Only process keys when Control is active. All known issues we're + // resolving happen only in this scenario. This probably isn't fully robust + // but we can broaden the scope as we find more cases. + if (!event.modifierFlags.contains(.control)) { + return false + } + let equivalent: String switch (event.charactersIgnoringModifiers) { 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 = "_" case "\r": @@ -742,7 +748,7 @@ extension Ghostty { let newEvent = NSEvent.keyEvent( with: .keyDown, location: event.locationInWindow, - modifierFlags: .control, + modifierFlags: event.modifierFlags, timestamp: event.timestamp, windowNumber: event.windowNumber, context: nil,