1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Windows: Ensure modifier keys are left in a consistent state after a nonclient button press

This commit is contained in:
reuk 2025-06-25 20:15:00 +01:00
parent 803ab31d21
commit be489028dc
No known key found for this signature in database

View file

@ -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: