1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

Windows: Fix mouse position reporting for maximised windows with non-native titlebars

Previously, windows with non-native titlebars but with native shadows
would misreport mouse-down and mouse-up positions when maximised.
This commit is contained in:
reuk 2024-11-05 12:53:13 +00:00
parent 90fbdfeb00
commit 24ab3cb6a3
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -2784,7 +2784,7 @@ private:
ReleaseCapture();
}
void doMouseDown (LPARAM lParam, const WPARAM wParam, WindowArea area)
void doMouseDown (LPARAM lParam, const WPARAM wParam)
{
// this will be handled by WM_TOUCH
if (isTouchEvent() || areOtherTouchSourcesActive())
@ -2793,7 +2793,7 @@ private:
if (GetCapture() != hwnd)
SetCapture (hwnd);
doMouseMove (lParam, true, area);
doMouseMove (lParam, true, WindowArea::client);
if (isValidPeer (this))
{
@ -2801,9 +2801,7 @@ private:
isDragging = true;
const auto position = area == WindowArea::client ? getPointFromLocalLParam (lParam)
: getLocalPointFromScreenLParam (lParam);
doMouseEvent (position, MouseInputSource::defaultPressure);
doMouseEvent (clientLparamToPoint (lParam), MouseInputSource::defaultPressure);
}
}
@ -3707,21 +3705,11 @@ private:
return globalToLocal (convertPhysicalScreenPointToLogical (globalPos, hwnd).toFloat());
}
Point<float> getPointFromLocalLParam (LPARAM lParam) noexcept
Point<float> clientLparamToPoint (LPARAM lParam)
{
auto p = D2DUtilities::toPoint (getPOINTFromLParam (lParam));
if (isPerMonitorDPIAwareWindow (hwnd))
{
// LPARAM is relative to this window's top-left but may be on a different monitor so we need to calculate the
// physical screen position and then convert this to local logical coordinates
auto r = getWindowScreenRect (hwnd);
const auto windowBorder = findPhysicalBorderSize();
return globalToLocal (Desktop::getInstance().getDisplays().physicalToLogical (D2DUtilities::toPoint ({ r.left + p.x + windowBorder.getLeft(),
r.top + p.y + windowBorder.getTop() })).toFloat());
}
return p.toFloat();
auto point = getPOINTFromLParam (lParam);
ClientToScreen (hwnd, &point);
return getLocalPointFromScreenLParam (MAKELPARAM (point.x, point.y));
}
Point<float> getCurrentMousePos() noexcept
@ -3959,13 +3947,13 @@ private:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
doMouseDown (lParam, wParam, WindowArea::client);
doMouseDown (lParam, wParam);
return 0;
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
doMouseUp (getPointFromLocalLParam (lParam), wParam);
doMouseUp (clientLparamToPoint (lParam), wParam);
return 0;
case WM_POINTERWHEEL: