fix: use clientX/Y for mouse coordinates#696
Merged
mattgodbolt merged 3 commits intoMay 13, 2026
Merged
Conversation
Calculate mouse coordinates using evt.clientX/clientY against the screen canvas rect directly, rather than mixing evt.offsetX/offsetY with bounding rect positions. The previous approach failed when the canvas was inset within the monitor image (e.g., with display filters that add non-zero canvasLeft/canvasTop). The new calculation correctly handles all display filter scenarios. Fixes mattgodbolt#631
mattgodbolt
reviewed
May 12, 2026
Owner
mattgodbolt
left a comment
There was a problem hiding this comment.
Thank you! And for the lovely tests - just a couple tweaks, I don't think we should test the old behaviour though I appreciate you demonstrating it was broken in test form; and I think we should test the code we execute and not a copy paste of it. Thnk you!
Extract calculateMouseCoordinates into a shared module so tests exercise the actual production code. Remove old-behavior tests.
Contributor
Author
|
OK removed old tests && extracted shared module. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #631.
Mouse coordinates were calculated incorrectly when the canvas was inset within the monitor image (e.g., with display filters that add non-zero canvasLeft/canvasTop). The previous approach mixed evt.offsetX/offsetY with bounding rect positions, which failed in these scenarios.
Switched to calculating mouse coordinates using evt.clientX/clientY against the screen canvas rect directly. This correctly handles all display filter scenarios and eliminates the incorrect mixing of coordinate systems.
Includes a regression test that reproduces the original issue.