dexed icon indicating copy to clipboard operation
dexed copied to clipboard

Add option to keep keyboard focussed on the MIDI keyboard

Open francoiswnel opened this issue 5 years ago • 8 comments

While browsing through patches and carts, I figured it would be very convenient for the computer keyboard to remain focussed on the on-screen MIDI keyboard component so that I could play notes as I clicked through patches. So I've added this functionality, as well as a toggle to configure it on and off. It was mostly for myself, but I figured that others might find it useful too!

Please let me know if you require any changes!

DexedParameterDialog

francoiswnel avatar May 26 '19 20:05 francoiswnel

I've fixed the Linux build, but haven't had a chance to look at the macOS build yet!

francoiswnel avatar May 26 '19 21:05 francoiswnel

I have also fixed the macOS build by simply referencing the two new files I added in the project, but for some reason it shuffled around the project file, creating a huge diff! Please let me know if I should revert.

francoiswnel avatar May 27 '19 18:05 francoiswnel

@asb2m10 Any feedback? No rush! Just curious to hear your thoughts.

francoiswnel avatar Jun 06 '19 18:06 francoiswnel

Good implementation and it is a good idea. The only issue is that Dexed keeps the focus all the time, at least here on Linux. I cannot even rename a cartridge name.

Can we check on what we have lost the focus ? So if it is a sub-component of Dexed, we keep it, but if it an top level window change, we give it...

asb2m10 avatar Jun 11 '19 02:06 asb2m10

Sounds good! I'll implement the suggestion.

francoiswnel avatar Jun 11 '19 05:06 francoiswnel

I've found a way to check which component grabbed focus. Works well on Linux from my tests, but I still want to do a thorough check before updating the PR.

Similar to how I'm checking if the parameters window took focus, I also want to see if the store dialog took focus, since I've noticed that also gets pushed to the back. Will make that change and then do some more testing across platforms when I have some time.

Here is the updated method so far:

void DexedMidiKeyboardComponent::focusLost(FocusChangeType focusChangeType) {
    MidiKeyboardComponent::focusLost(focusChangeType);

    /* Get the component that grabbed focus away from the keyboard.
     * If the method returns null, it is not a Dexed component.
     */
    Component *currentlyFocusedComponent = getCurrentlyFocusedComponent();
    bool currentlyFocusedComponentIsNotADexedComponent = currentlyFocusedComponent == NULL;

    // Return early if focus was lost to another application.
    if (currentlyFocusedComponentIsNotADexedComponent == true) {
        return;
    }

    // If the parameters window is opened, grabbing keyboard focus back can push it behind the Dexed window.
    bool parmButtonClicked = currentlyFocusedComponent->getName() == "parmButton";

    bool shouldGrabKeyboardFocus =
        parmButtonClicked != true
        && showKeyboard == true
        && preferMidiKeyboardFocus == true;

    if (shouldGrabKeyboardFocus == true) {
        grabKeyboardFocus();
    }
}

francoiswnel avatar Jun 12 '19 20:06 francoiswnel

I've updated the focusLost method to check if the keyboard lost focus to a Dexed component, and if it did, only keep focus if the component it lost focus to shouldn't have focus instead. Tested on Windows, Linux and macOS and it seems to be working well!

francoiswnel avatar Jun 15 '19 11:06 francoiswnel

Also it shouldn't steal the whole keyboard, but just keys used to operate the virtual MIDI keyboard, IMHO.

For example, you should still be able to use arrows and Enter to move around in the browser.

mkruselj avatar Apr 27 '20 11:04 mkruselj