From 803ab31d21aa79d5e814d46a3e5f3c45527c93e1 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Jun 2025 18:36:36 +0100 Subject: [PATCH] Windows: Fix bug where stale mouse button state could get sent to windows after a window move handlePositionChanged() is called when the window changes z-order, which may cause a new mouse event to be synthesised if the mouse is over the window after the z-order is updated. In this situation, we may not have received a mouse up/down/move event to update the current modifier flags, so we need to update them ourselves. --- .../juce_gui_basics/native/juce_Windowing_windows.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index b418afbb58..76fc92b465 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -3555,7 +3555,14 @@ private: const ScopedValueSetter scope (inHandlePositionChanged, true); if (! areOtherTouchSourcesActive()) - doMouseEvent (pos, MouseInputSource::defaultPressure); + { + auto modsToSend = ModifierKeys::getCurrentModifiers(); + + if (! Desktop::getInstance().getMainMouseSource().isDragging()) + modsToSend = modsToSend.withoutMouseButtons(); + + doMouseEvent (pos, MouseInputSource::defaultPressure, 0.0f, modsToSend); + } if (! isValidPeer (this)) return true;