From 37c243bb491e31e84fa13ccbecbab5b6c51ebb28 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 31 Aug 2017 12:04:07 +0100 Subject: [PATCH] Fixed a bug in plug-ins on Mac where mouse exit events weren't being sent when the mouse cursor left the plug-in window --- .../utility/juce_FakeMouseMoveGenerator.h | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h b/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h index c9559cc725..d78d3bd10d 100644 --- a/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h +++ b/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h @@ -41,24 +41,48 @@ public: void timerCallback() override { // Workaround for windows not getting mouse-moves... - const Point screenPos (Desktop::getInstance().getMainMouseSource().getScreenPosition()); + auto screenPos = Desktop::getInstance().getMainMouseSource().getScreenPosition(); if (screenPos != lastScreenPos) { lastScreenPos = screenPos; - const ModifierKeys mods (ModifierKeys::getCurrentModifiers()); + auto mods = ModifierKeys::getCurrentModifiers(); if (! mods.isAnyMouseButtonDown()) - if (Component* const comp = Desktop::getInstance().findComponentAt (screenPos.roundToInt())) - if (ComponentPeer* const peer = comp->getPeer()) + { + if (auto* comp = Desktop::getInstance().findComponentAt (screenPos.roundToInt())) + { + safeOldComponent = comp; + + if (auto* peer = comp->getPeer()) + { if (! peer->isFocused()) + { peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, peer->globalToLocal (screenPos), mods, MouseInputSource::invalidPressure, MouseInputSource::invalidOrientation, Time::currentTimeMillis()); + } + } + } + else + { + if (safeOldComponent != nullptr) + { + if (auto* peer = safeOldComponent->getPeer()) + { + peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, { -1.0f, -1.0f }, mods, + MouseInputSource::invalidPressure, MouseInputSource::invalidOrientation, Time::currentTimeMillis()); + } + } + + safeOldComponent = nullptr; + } + } } } private: Point lastScreenPos; + WeakReference safeOldComponent; }; #else