Skip to content

Commit

Permalink
Begin Focus vs Mouse mode
Browse files Browse the repository at this point in the history
1. Add a setSelectionMode with an enum for current FOLLOWS_MOUSE
   or FOLLOWS_FOCUS
2. Unregister / register appropriate focus listener, structure for
   other options
3. Add the listener to update state

With this plus `inspectr->setFocusMode` called explicitly on launch
melatonin is equivalent to the surge focus debugger. Awesome.

The primary thing not done yet is a toggle button in teh UI to swap
modes. You can only swap programatically.

Addresses sudara#97
  • Loading branch information
baconpaul committed Mar 13, 2024
1 parent a06c186 commit 514a15f
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion melatonin_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ END_JUCE_MODULE_DECLARATION

namespace melatonin
{
class Inspector : public juce::ComponentListener, public juce::DocumentWindow, private juce::Timer
class Inspector : public juce::ComponentListener, public juce::DocumentWindow, private juce::Timer, public juce::FocusChangeListener
{
public:
class InspectorKeyCommands : public juce::KeyListener
Expand Down Expand Up @@ -325,6 +325,39 @@ namespace melatonin

std::function<void()> onClose;

enum SelectionMode
{
FOLLOWS_MOUSE,
FOLLOWS_FOCUS
} selectionMode{FOLLOWS_MOUSE};

void setSelectionMode(SelectionMode newSM)
{
if (newSM == selectionMode)
return;
// Out with the old
switch(selectionMode)
{
case FOLLOWS_FOCUS:
juce::Desktop::getInstance().removeFocusChangeListener(this);
break;
case FOLLOWS_MOUSE:
break;
}

// And in with the new
selectionMode = newSM;
switch(selectionMode)
{
case FOLLOWS_FOCUS:
juce::Desktop::getInstance().addFocusChangeListener(this);
break;
case FOLLOWS_MOUSE:
break;
}

}

private:
juce::SharedResourcePointer<InspectorSettings> settings;
melatonin::InspectorLookAndFeel inspectorLookAndFeel;
Expand Down Expand Up @@ -364,6 +397,13 @@ namespace melatonin
}
}

void globalFocusChanged (Component* focusedComponent) override
{
inspectorComponent.toggleOverlayCallback(true);
inspectorComponent.selectComponentCallback(focusedComponent);
}

private:
void timerCallback() override
{
for (auto ms : juce::Desktop::getInstance().getMouseSources())
Expand Down

0 comments on commit 514a15f

Please sign in to comment.