Skip to content

Commit

Permalink
Virtual keyboard always gets key events (#5003)
Browse files Browse the repository at this point in the history
If Surge doesn't eat em, give the keyboard a try. Also
take focus in the MiniEdit.

Closes #4930
  • Loading branch information
baconpaul authored Sep 6, 2021
1 parent fc7f635 commit 6dc4b74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/gui/overlays/MiniEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MiniEdit::MiniEdit()
typein->setJustification(juce::Justification::centred);
typein->setFont(Surge::GUI::getFontManager()->getLatoAtSize(10, juce::Font::bold));
typein->setSelectAllWhenFocused(true);
typein->setWantsKeyboardFocus(true);
typein->addListener(this);
addAndMakeVisible(*typein);

Expand Down
23 changes: 23 additions & 0 deletions src/surge_synth_juce/SurgeSynthEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ SurgeSynthEditor::SurgeSynthEditor(SurgeSynthProcessor &p) : AudioProcessorEdito
{
surgeLF = std::make_unique<SurgeJUCELookAndFeel>();
juce::LookAndFeel::setDefaultLookAndFeel(surgeLF.get());

addKeyListener(this);

adapter = std::make_unique<SurgeGUIEditor>(this, processor.surge.get());

int yExtra = 0;
Expand Down Expand Up @@ -227,3 +230,23 @@ juce::PopupMenu SurgeSynthEditor::hostMenuForMacro(int macro)

return juce::PopupMenu();
}

bool SurgeSynthEditor::keyPressed(const juce::KeyPress &key, juce::Component *orig)
{
if (adapter->getShowVirtualKeyboard() && orig != keyboard.get())
{
return keyboard->keyPressed(key);
}

return false;
}

bool SurgeSynthEditor::keyStateChanged(bool isKeyDown, juce::Component *originatingComponent)
{
if (adapter->getShowVirtualKeyboard() && originatingComponent != keyboard.get())
{
return keyboard->keyStateChanged(isKeyDown);
}

return false;
}
6 changes: 5 additions & 1 deletion src/surge_synth_juce/SurgeSynthEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class SurgeJUCELookAndFeel;
*/
class SurgeSynthEditor : public juce::AudioProcessorEditor,
public juce::AsyncUpdater,
public juce::FileDragAndDropTarget
public juce::FileDragAndDropTarget,
public juce::KeyListener
{
public:
SurgeSynthEditor(SurgeSynthProcessor &);
Expand All @@ -49,6 +50,9 @@ class SurgeSynthEditor : public juce::AudioProcessorEditor,
void beginMacroEdit(long macroNum);
void endMacroEdit(long macroNum);

bool keyPressed(const juce::KeyPress &key, juce::Component *originatingComponent) override;
bool keyStateChanged(bool isKeyDown, juce::Component *originatingComponent) override;

struct IdleTimer : juce::Timer
{
IdleTimer(SurgeSynthEditor *ed) : ed(ed) {}
Expand Down

0 comments on commit 6dc4b74

Please sign in to comment.