From 4fdb8d474647a3c234a1489b485b0db250b5acc8 Mon Sep 17 00:00:00 2001 From: Richard Higgins Date: Thu, 17 Sep 2026 12:37:18 -0700 Subject: [PATCH 1/2] Use button event positions for mouse clicks --- src/windy/platforms/macos/platform.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/windy/platforms/macos/platform.nim b/src/windy/platforms/macos/platform.nim index 0b86d90d..bb1f7008 100644 --- a/src/windy/platforms/macos/platform.nim +++ b/src/windy/platforms/macos/platform.nim @@ -346,6 +346,13 @@ proc handleMouseDelta(window: Window, event: NSEvent) = if window.onMouseMove != nil: window.onMouseMove() +proc updateMousePosition(window: Window, event: NSEvent) = + ## Button events carry the authoritative pointer location. + let location = event.locationInWindow() + let height = window.inner.contentView.bounds.size.height + window.state.mousePos = (vec2(round(location.x), round(height - location.y)) * + window.contentScale).ivec2 + proc handleButtonPress(window: Window, button: Button) = handleButtonPressTemplate() @@ -699,24 +706,28 @@ proc mouseDown(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = let window = windows.forNSWindow(self.NSView.window) if window == nil: return + window.updateMousePosition(event) window.handleButtonPress(MouseLeft) proc mouseUp(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = let window = windows.forNSWindow(self.NSView.window) if window == nil: return + window.updateMousePosition(event) window.handleButtonRelease(MouseLeft) proc rightMouseDown(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = let window = windows.forNSWindow(self.NSView.window) if window == nil: return + window.updateMousePosition(event) window.handleButtonPress(MouseRight) proc rightMouseUp(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = let window = windows.forNSWindow(self.NSView.window) if window == nil: return + window.updateMousePosition(event) window.handleButtonRelease(MouseRight) proc otherMouseDown(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = @@ -726,10 +737,13 @@ proc otherMouseDown(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = case event.buttonNumber: of 2: + window.updateMousePosition(event) window.handleButtonPress(MouseMiddle) of 3: + window.updateMousePosition(event) window.handleButtonPress(MouseButton4) of 4: + window.updateMousePosition(event) window.handleButtonPress(MouseButton5) else: discard @@ -741,10 +755,13 @@ proc otherMouseUp(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = case event.buttonNumber: of 2: + window.updateMousePosition(event) window.handleButtonRelease(MouseMiddle) of 3: + window.updateMousePosition(event) window.handleButtonRelease(MouseButton4) of 4: + window.updateMousePosition(event) window.handleButtonRelease(MouseButton5) else: discard From 7a05286830202ce746bc05dde6bb75a07cbd2554 Mon Sep 17 00:00:00 2001 From: Richard Higgins Date: Thu, 17 Sep 2026 12:37:38 -0700 Subject: [PATCH 2/2] Indent other mouse event updates --- src/windy/platforms/macos/platform.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/windy/platforms/macos/platform.nim b/src/windy/platforms/macos/platform.nim index bb1f7008..bad2e49b 100644 --- a/src/windy/platforms/macos/platform.nim +++ b/src/windy/platforms/macos/platform.nim @@ -737,13 +737,13 @@ proc otherMouseDown(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = case event.buttonNumber: of 2: - window.updateMousePosition(event) + window.updateMousePosition(event) window.handleButtonPress(MouseMiddle) of 3: - window.updateMousePosition(event) + window.updateMousePosition(event) window.handleButtonPress(MouseButton4) of 4: - window.updateMousePosition(event) + window.updateMousePosition(event) window.handleButtonPress(MouseButton5) else: discard @@ -755,13 +755,13 @@ proc otherMouseUp(self: ID, cmd: SEL, event: NSEvent): ID {.cdecl.} = case event.buttonNumber: of 2: - window.updateMousePosition(event) + window.updateMousePosition(event) window.handleButtonRelease(MouseMiddle) of 3: - window.updateMousePosition(event) + window.updateMousePosition(event) window.handleButtonRelease(MouseButton4) of 4: - window.updateMousePosition(event) + window.updateMousePosition(event) window.handleButtonRelease(MouseButton5) else: discard