DISTRHO / DPF

DISTRHO Plugin Framework
ISC License
629 stars 91 forks source link

Make keyboard focus a compile time macro #415

Open dromer opened 1 year ago

dromer commented 1 year ago

As discussed on IRC. Forcing focus may not always be wanted.

MattKuebrich commented 5 months ago

I think this is the same issue I came to report.

When the plugin UI is selected, it blocks the keyboard presses from being sent to the DAW. For example, you can't hit spacebar to start the timeline or use the computer keyboard to play notes, etc. That's usually not ideal, so I'd support an option to disable this as well.

For Mac, I was able to accomplish this by switching acceptsFirstResponder to NO in mac.m

falkTX commented 5 months ago

DPF does not do automatic focus, the ticket is to add some way for plugins to request it. The DPF stealing keyboard input from the DAW is likely due to something "returning true" for keyboard events, and thus not having them propagate on the OS level anymore. But this varies wildly between hosts, there is no consistency afaik

MattKuebrich commented 5 months ago

Ah okay, sorry for jumping in on the wrong issue. I don't totally understand the original ticket (I assume dromer wants to use the keyboard to control his plugin?), but thanks for the info about DPF stealing focus. You're right about different hosts - the acceptsFirstResponder fix above works in Bitwig, but not in Ableton Live (on MacOS). Thanks for your help. This stuff sure is fiddly!

dromer commented 5 months ago

I actually don't remember what this was about, I created the ticket as a result from a discussion on IRC.

Could've put some more context to remember -_-

lucianoiam commented 5 months ago

Try this for Live on Mac

- (void)keyDown:(NSEvent *)event
{
    if (shouldMyPluginConsumeKeystrokes) {
        [super keyDown:event];
    } else {
        [self.superview keyDown:event];
    }
}

self.superview might be self.superview.superview depending the view hierarchy

Repeat for keyUp and flagsChanged

It might be worth checking what JUCE does about this.

MattKuebrich commented 5 months ago

Thank you!

Before I saw your message I tried adding this to mac.m and it seems to be working (not blocking the keyboard) in Ableton Live, Bitwig and Reaper on MacOS.

- (BOOL) becomeFirstResponder
{
    BOOL ret = [self acceptsFirstResponder];
    return ret;
}
- (BOOL) resignFirstResponder
{
    BOOL ret = [self acceptsFirstResponder];
    return ret;
}

I found that from this JUCE thread.