juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.65k stars 1.75k forks source link

[Bug]: juce::NSViewComponent doesn't allow keyboard inputs to be used in the view #1262

Open stephenberry opened 1 year ago

stephenberry commented 1 year ago

Detailed steps on how to reproduce the bug

I've tried setting:

setWantsKeyboardFocus(false);
setMouseClickGrabsKeyboardFocus(false);
giveAwayKeyboardFocus();
unfocusAllComponents();
setFocusContainerType(FocusContainerType::none);

But, none of this works because the component still blocks any keyboard inputs from getting through to the underlying NSView.

What is the expected behaviour?

The keyboard should be able to be used on NSView components.

Operating systems

macOS

What versions of the operating systems?

Ventura 13.5.1

Architectures

ARM, 64-bit

Stacktrace

No response

Plug-in formats (if applicable)

AU, Standalone

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct

stephenberry commented 1 year ago

Note that if the following are set (opposites), it also doesn't work.

setWantsKeyboardFocus(true);
setMouseClickGrabsKeyboardFocus(true);
...

I would like to just have JUCE ignore keyboard input for the component, because it works if I run the NSView in its own glfw window.

reuk commented 1 year ago

I don't completely understand the problem. Please can you explain exactly the component and NSView hierarchy, and which component you expect to receive keyboard input?

Note that the AudioPluginHost uses the NSViewComponent to display the UIs of hosted plugins, and the hosted plugin UIs can definitely receive keyboard input. Therefore, this is not a general bug. You might find it helpful to look at the plugin hosting code to see whether there's anything that the AudioPluginHost is doing differently to the approaches that you've tried.

stephenberry commented 1 year ago

It's pretty simple. I have a juce::NSViewComponent ns_view_component{};

I then have a juce::AudioProcessorEditor that adds the component via addAndMakeVisible(ns_view_component);

I set my view via ns_view_component.setView(ns_view); Where ns_view is a void* to my NSView.

If I run my plugin in the AudioPluginHost or Standalone I can't get keystrokes (other than arrow keys, and I get the sound indicating text input isn't allowed).

I'll definitely look at the AudioPluginHost, to see what it is don't to allow inputs. But, I'm at a loss right now. Thanks for the help!

stephenberry commented 1 year ago

@reuk, looking at the AudioPluginHost, it just uses the AudioProcessorEditor from the AudioProcessor, so it doesn't do any of the low level NSView handling. This makes me believe the issue is with juce::NSViewComponent that I am using to display my plugin.

I'll note that I can't get keystrokes when my plugin runs in a DAW or runs in AudioPluginHost, or standalone. So, it seems to make sense that it has to be an issue with juce::NSViewComponent.

stephenberry commented 1 year ago

I'll also note that adding a key listening detects keys, and I can print out what keys are being pressed.

auto& vc = p.ns_view_component;
vc.addKeyListener(&key_listener);
vc.setBounds(getLocalBounds());
vc.setMouseClickGrabsKeyboardFocus(true);
vc.setWantsKeyboardFocus(true);
addAndMakeVisible(vc);

The problem is that these key presses are not being propagated to the NSView