From ff7f097fb99432433d2eb24371e9f96082f1da8c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 23 Apr 2021 18:31:44 -0700 Subject: [PATCH] macos: fix "reflected" mouse x coordinate values We were getting abs() of the backing-rect-adjusted value, so we need to restore the sign to avoid what should be logically cell position "-1" being treated as cell position "1" and so on. With this change, the logic in the gui layer successfully clamps the x coordinate to zero when trying to drag left off the window. --- window/src/os/macos/window.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 8d2f9385b..6f44e80c8 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -1473,7 +1473,12 @@ impl WindowView { let point = NSView::convertPoint_fromView_(view, nsevent.locationInWindow(), nil); let rect = NSRect::new(NSPoint::new(0., 0.), NSSize::new(point.x, point.y)); let backing_rect = NSView::convertRectToBacking(view, rect); - coords = NSPoint::new(backing_rect.size.width, backing_rect.size.height); + // backing_rect computes abs() values, so we need to restore the sign + // from the original point + coords = NSPoint::new( + f64::copysign(backing_rect.size.width, point.x), + f64::copysign(backing_rect.size.height, point.y), + ); mouse_buttons = decode_mouse_buttons(NSEvent::pressedMouseButtons(nsevent)); modifiers = key_modifiers(nsevent.modifierFlags()); screen_coords = NSEvent::mouseLocation(nsevent);