Skip to content

Commit

Permalink
NSViewComponentPeer: Allow mouse events to reach unfocused windows
Browse files Browse the repository at this point in the history
This change allows mouse events (including enter and exit events) to
reach unfocused views on macOS. This matches the behaviour of unfocused
windows on Linux and Windows, where components paint in their "hovered"
states even when the application window is in the background.

As a byproduct of using tracking areas on macOS, we can remove the fake
mouse move generator.
  • Loading branch information
reuk committed Oct 27, 2021
1 parent eeeeb11 commit 4ca923a
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 190 deletions.
4 changes: 0 additions & 4 deletions modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp
Expand Up @@ -31,7 +31,6 @@
#include "../utility/juce_IncludeSystemHeaders.h"
#include "../utility/juce_IncludeModuleHeaders.h"
#include "../utility/juce_WindowsHooks.h"
#include "../utility/juce_FakeMouseMoveGenerator.h"

#include <juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp>

Expand Down Expand Up @@ -592,8 +591,6 @@ namespace AAXClasses
setBounds (lastValidSize);
pluginEditor->addMouseListener (this, true);
}

ignoreUnused (fakeMouseGenerator);
}

~ContentWrapperComponent() override
Expand Down Expand Up @@ -673,7 +670,6 @@ namespace AAXClasses
#if JUCE_WINDOWS
WindowsHooks hooks;
#endif
FakeMouseMoveGenerator fakeMouseGenerator;
juce::Rectangle<int> lastValidSize;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentWrapperComponent)
Expand Down
4 changes: 0 additions & 4 deletions modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm
Expand Up @@ -81,7 +81,6 @@ Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
#define JUCE_CORE_INCLUDE_OBJC_HELPERS 1

#include "../utility/juce_IncludeModuleHeaders.h"
#include "../utility/juce_FakeMouseMoveGenerator.h"
#include "../utility/juce_CarbonVisibility.h"

#include <juce_audio_basics/native/juce_mac_CoreAudioLayouts.h>
Expand Down Expand Up @@ -1482,7 +1481,6 @@ OSStatus NewFactoryPresetSet (const AUPreset& inNewFactoryPreset) override
setWantsKeyboardFocus (true);
#endif

ignoreUnused (fakeMouseGenerator);
setBounds (getSizeToContainChild());

lastBounds = getBounds();
Expand Down Expand Up @@ -1594,7 +1592,6 @@ void resizeHostWindow()
}

private:
FakeMouseMoveGenerator fakeMouseGenerator;
Rectangle<int> lastBounds;

JUCE_DECLARE_NON_COPYABLE (EditorCompHolder)
Expand Down Expand Up @@ -2432,7 +2429,6 @@ ComponentResult CreateUI (Float32 /*inXOffset*/, Float32 /*inYOffset*/) override
//==============================================================================
AudioProcessor* juceFilter;
std::unique_ptr<Component> windowComp;
FakeMouseMoveGenerator fakeMouseGenerator;

void deleteUI()
{
Expand Down
Expand Up @@ -28,7 +28,6 @@

#include "../utility/juce_IncludeSystemHeaders.h"
#include "../utility/juce_IncludeModuleHeaders.h"
#include "../utility/juce_FakeMouseMoveGenerator.h"
#include "../utility/juce_WindowsHooks.h"

#include <juce_audio_devices/juce_audio_devices.h>
Expand Down
3 changes: 0 additions & 3 deletions modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp
Expand Up @@ -103,7 +103,6 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE

using namespace juce;

#include "../utility/juce_FakeMouseMoveGenerator.h"
#include "../utility/juce_WindowsHooks.h"
#include "../utility/juce_LinuxMessageThread.h"

Expand Down Expand Up @@ -984,7 +983,6 @@ class JuceVSTWrapper : public AudioProcessorListener,
#endif

setOpaque (true);
ignoreUnused (fakeMouseGenerator);
}

~EditorCompWrapper() override
Expand Down Expand Up @@ -1291,7 +1289,6 @@ class JuceVSTWrapper : public AudioProcessorListener,

//==============================================================================
JuceVSTWrapper& wrapper;
FakeMouseMoveGenerator fakeMouseGenerator;
bool resizingChild = false, resizingParent = false;

float editorScaleFactor = 1.0f;
Expand Down
1 change: 0 additions & 1 deletion modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.mm
Expand Up @@ -35,7 +35,6 @@ Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).

#include "../utility/juce_IncludeSystemHeaders.h"
#include "../utility/juce_IncludeModuleHeaders.h"
#include "../utility/juce_FakeMouseMoveGenerator.h"
#include "../utility/juce_CarbonVisibility.h"

//==============================================================================
Expand Down
4 changes: 0 additions & 4 deletions modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
Expand Up @@ -48,7 +48,6 @@ JUCE_BEGIN_NO_SANITIZE ("vptr")
#include "../utility/juce_IncludeSystemHeaders.h"
#include "../utility/juce_IncludeModuleHeaders.h"
#include "../utility/juce_WindowsHooks.h"
#include "../utility/juce_FakeMouseMoveGenerator.h"
#include "../utility/juce_LinuxMessageThread.h"
#include <juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp>
#include <juce_audio_processors/format_types/juce_VST3Common.h>
Expand Down Expand Up @@ -1929,8 +1928,6 @@ class JuceVST3EditController : public Vst::EditController,
{
setOpaque (true);
setBroughtToFrontOnMouseClick (true);

ignoreUnused (fakeMouseGenerator);
}

~ContentWrapperComponent() override
Expand Down Expand Up @@ -2100,7 +2097,6 @@ class JuceVST3EditController : public Vst::EditController,
private:
JuceVST3Editor& owner;
std::unique_ptr<EditorHostContext> editorHostContext;
FakeMouseMoveGenerator fakeMouseGenerator;
Rectangle<int> lastBounds;
bool resizingChild = false, resizingParent = false;

Expand Down
119 changes: 0 additions & 119 deletions modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h

This file was deleted.

14 changes: 7 additions & 7 deletions modules/juce_gui_basics/components/juce_Component.cpp
Expand Up @@ -301,11 +301,11 @@ struct Component::ComponentHelpers
}

//==============================================================================
static bool hitTest (Component& comp, Point<int> localPoint)
static bool hitTest (Component& comp, Point<float> localPoint)
{
return isPositiveAndBelow (localPoint.x, comp.getWidth())
&& isPositiveAndBelow (localPoint.y, comp.getHeight())
&& comp.hitTest (localPoint.x, localPoint.y);
const auto intPoint = localPoint.roundToInt();
return Rectangle<int> { comp.getWidth(), comp.getHeight() }.toFloat().contains (localPoint)
&& comp.hitTest (intPoint.x, intPoint.y);
}

// converts an unscaled position within a peer to the local position within that peer's component
Expand Down Expand Up @@ -1376,7 +1376,7 @@ bool Component::hitTest (int x, int y)
auto& child = *childComponentList.getUnchecked (i);

if (child.isVisible()
&& ComponentHelpers::hitTest (child, ComponentHelpers::convertFromParentSpace (child, Point<int> (x, y))))
&& ComponentHelpers::hitTest (child, ComponentHelpers::convertFromParentSpace (child, Point<int> (x, y).toFloat())))
return true;
}
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ bool Component::contains (Point<int> point)

bool Component::containsInternal (Point<float> point)
{
if (ComponentHelpers::hitTest (*this, point.roundToInt()))
if (ComponentHelpers::hitTest (*this, point))
{
if (parentComponent != nullptr)
return parentComponent->containsInternal (ComponentHelpers::convertToParentSpace (*this, point));
Expand Down Expand Up @@ -1441,7 +1441,7 @@ Component* Component::getComponentAt (Point<int> position)

Component* Component::getComponentAtInternal (Point<float> position)
{
if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position.roundToInt()))
if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position))
{
for (int i = childComponentList.size(); --i >= 0;)
{
Expand Down

0 comments on commit 4ca923a

Please sign in to comment.