diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index 76fc92b465..047c32cfda 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -2760,19 +2760,7 @@ private: if (area == WindowArea::nonclient && captionMouseDown.has_value() && *captionMouseDown != lParam) { captionMouseDown.reset(); - - // When clicking and dragging on the caption area, a new modal loop is started - // inside DefWindowProc. This modal loop appears to consume some mouse events, - // without forwarding them back to our own window proc. In particular, we never - // get to see the WM_NCLBUTTONUP event with the HTCAPTION argument, or any other - // kind of mouse-up event to signal that the loop exited, so - // ModifierKeys::currentModifiers gets left in the wrong state. As a workaround, we - // manually update the modifier keys after DefWindowProc exits, and update the - // capture state if necessary. - const auto result = DefWindowProc (hwnd, WM_NCLBUTTONDOWN, HTCAPTION, lParam); - getMouseModifiers(); - releaseCaptureIfNecessary(); - return result; + return handleNcMouseEventThenFixModifiers (WM_NCLBUTTONDOWN, HTCAPTION, lParam); } const auto position = area == WindowArea::client ? getPointFromLocalLParam (lParam) @@ -2781,6 +2769,22 @@ private: return doMouseMoveAtPoint (isMouseDownEvent, area, position); } + LRESULT handleNcMouseEventThenFixModifiers (UINT msg, WPARAM wParam, LPARAM lParam) + { + // When clicking and dragging on the caption area (including in the edge resize areas), a + // new modal loop is started inside DefWindowProc. This modal loop appears to consume some + // mouse events, without forwarding them back to our own window proc. In particular, we + // never get to see the WM_NCLBUTTONUP event with the HTCAPTION argument, or any other + // kind of mouse-up event to signal that the loop exited, so + // ModifierKeys::currentModifiers gets left in the wrong state. As a workaround, we + // manually update the modifier keys after DefWindowProc exits, and update the + // capture state if necessary. + const auto result = DefWindowProc (hwnd, msg, wParam, lParam); + getMouseModifiers(); + releaseCaptureIfNecessary(); + return result; + } + void updateModifiersFromModProvider() const { #if JUCE_MODULE_AVAILABLE_juce_audio_plugin_client @@ -4354,7 +4358,7 @@ private: if (auto result = onNcLButtonDown (wParam, lParam)) return *result; - break; + return handleNcMouseEventThenFixModifiers (WM_NCLBUTTONDOWN, wParam, lParam); } case WM_NCLBUTTONUP: