Browse Source

MouseInputSource: Avoid wrong ComponentPeer association

When the mouse moves from one window to another, the mouseExit event
for the old window can occur after the mouseMove event for the new.
Until this commit this would cause the MouseInputSource to be
associated with the old window, and getComponentUnderMouse() would
incorrectly return a nullptr.
v7.0.9
attila 2 years ago
parent
commit
a115c99da4
1 changed files with 14 additions and 13 deletions
  1. +14
    -13
      modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp

+ 14
- 13
modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp View File

@@ -57,18 +57,18 @@ public:
return lastPeer;
}
Component* findComponentAt (Point<float> screenPos)
static Component* findComponentAt (Point<float> screenPos, ComponentPeer* peer)
{
if (auto* peer = getPeer())
{
auto relativePos = ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
peer->globalToLocal (screenPos));
auto& comp = peer->getComponent();
if (! ComponentPeer::isValidPeer (peer))
return nullptr;
// (the contains() call is needed to test for overlapping desktop windows)
if (comp.contains (relativePos))
return comp.getComponentAt (relativePos);
}
auto relativePos = ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
peer->globalToLocal (screenPos));
auto& comp = peer->getComponent();
// (the contains() call is needed to test for overlapping desktop windows)
if (comp.contains (relativePos))
return comp.getComponentAt (relativePos);
return nullptr;
}
@@ -244,11 +244,12 @@ public:
void setPeer (ComponentPeer& newPeer, const PointerState& pointerState, Time time)
{
if (&newPeer != lastPeer)
if (&newPeer != lastPeer && ( findComponentAt (pointerState.position, &newPeer) != nullptr
|| findComponentAt (pointerState.position, lastPeer) == nullptr))
{
setComponentUnderMouse (nullptr, pointerState, time);
lastPeer = &newPeer;
setComponentUnderMouse (findComponentAt (pointerState.position), pointerState, time);
setComponentUnderMouse (findComponentAt (pointerState.position, getPeer()), pointerState, time);
}
}
@@ -257,7 +258,7 @@ public:
const auto& newScreenPos = newPointerState.position;
if (! isDragging())
setComponentUnderMouse (findComponentAt (newScreenPos), newPointerState, time);
setComponentUnderMouse (findComponentAt (newScreenPos, getPeer()), newPointerState, time);
if ((newPointerState != lastPointerState) || forceUpdate)
{


Loading…
Cancel
Save