From 5b5651ca7d45e03eb1e59d2bb72b1eec74e98066 Mon Sep 17 00:00:00 2001 From: pagedown Date: Thu, 13 Jan 2022 21:49:52 +0800 Subject: [PATCH] macOS: Suppress the key combinations beep sound --- glfw/cocoa_window.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index cbed80768..1db363c8c 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -753,6 +753,20 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; @end // }}} +// Text input context class for the GLFW content view {{{ + +@interface GLFWTextInputContext : NSTextInputContext +@end + +@implementation GLFWTextInputContext +- (void)doCommandBySelector:(SEL)selector +{ + // interpretKeyEvents: May call insertText: or doCommandBySelector:. + // With the default macOS keybindings, pressing certain key combinations + // (e.g. Ctrl+/, Ctrl+Cmd+Down/Left/Right) will produce a beep sound. + debug_key("\n\tTextInputCtx: doCommandBySelector: (%s)\n", [NSStringFromSelector(selector) UTF8String]); +} +@end // }}} // Content view class for the GLFW window {{{ @@ -760,6 +774,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; { _GLFWwindow* window; NSTrackingArea* trackingArea; + GLFWTextInputContext* input_context; NSMutableAttributedString* markedText; NSRect markedRect; bool marked_text_cleared_by_insert; @@ -780,6 +795,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; { window = initWindow; trackingArea = nil; + input_context = [[GLFWTextInputContext alloc] initWithClient:self]; markedText = [[NSMutableAttributedString alloc] init]; markedRect = NSMakeRect(0.0, 0.0, 0.0, 0.0); input_source_at_last_key_event = nil; @@ -1035,6 +1051,11 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; [super updateTrackingAreas]; } +- (NSTextInputContext *)inputContext +{ + return input_context; +} + static UInt32 convert_cocoa_to_carbon_modifiers(NSUInteger flags) { UInt32 mods = 0;