1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

NSViewComponentPeer: Avoid triggering NSBeeps on unhandled key presses

This commit is contained in:
reuk 2022-01-05 15:22:44 +00:00
parent b53b5f14a1
commit e730962921
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -2317,6 +2317,8 @@ struct JuceNSWindowClass : public NSViewComponentPeerWrapper<ObjCClass<NSWindo
addMethod (@selector (accessibilityRole), getAccessibilityRole);
addMethod (@selector (accessibilitySubrole), getAccessibilitySubrole);
addMethod (@selector (keyDown:), keyDown);
addMethod (@selector (window:shouldDragDocumentWithEvent:from:withPasteboard:), shouldAllowIconDrag);
addProtocol (@protocol (NSWindowDelegate));
@ -2328,6 +2330,29 @@ private:
//==============================================================================
static BOOL isFlipped (id, SEL) { return true; }
// Key events will be processed by the peer's component.
// If the component is unable to use the event, it will be re-sent
// to performKeyEquivalent.
// performKeyEquivalent will send the event to the view's superclass,
// which will try passing the event to the main menu.
// If the event still hasn't been processed, it will be passed to the
// next responder in the chain, which will be the NSWindow for a peer
// that is on the desktop.
// If the NSWindow still doesn't handle the event, the Apple docs imply
// that the event should be sent to the NSApp for processing, but this
// doesn't seem to happen for keyDown events.
// Instead, the NSWindow attempts to process the event, fails, and
// triggers an annoying NSBeep.
// Overriding keyDown to "handle" the event seems to suppress the beep.
static void keyDown (id, SEL, NSEvent* ev)
{
ignoreUnused (ev);
#if JUCE_DEBUG_UNHANDLED_KEYPRESSES
DBG ("unhandled key down event with keycode: " << [ev keyCode]);
#endif
}
static NSRect windowWillUseStandardFrame (id self, SEL, NSWindow*, NSRect)
{
if (auto* owner = getOwner (self))