Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to keep keyboard focussed on the MIDI keyboard #181

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

francoiswnel
Copy link

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

…rd component.

* Add toggle to parameters dialog for setting user preference for keyboard focus.
* Add derived MIDI keyboard component with states for visibility and focus preference.
* Add method to retain keyboard focus on the keyboard component when focus is lost.
@francoiswnel
Copy link
Author

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

@francoiswnel
Copy link
Author

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
Copy link
Author

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

@asb2m10
Copy link
Owner

asb2m10 commented Jun 11, 2019

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...

@francoiswnel
Copy link
Author

Sounds good! I'll implement the suggestion.

…ttempt to take focus back if the component that took focus is also a Dexed component.
…ke focus back if focus was lost to parameters button.
@francoiswnel
Copy link
Author

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
Copy link
Author

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!

@mkruselj
Copy link
Contributor

mkruselj commented Apr 27, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants