Skip to content

Fix mouse event coordinates on high-DPI displays - #169

Merged
timzifer merged 1 commit into
mainfrom
claude/scale-canvas-dpr-ahnfs
Apr 21, 2026
Merged

timzifer merged 1 commit into
mainfrom
claude/scale-canvas-dpr-ahnfs

Conversation

@timzifer

Copy link
Copy Markdown
Owner

Summary

This PR fixes mouse event coordinate handling on high-DPI displays (devices with devicePixelRatio > 1). Previously, mouse coordinates were not being scaled by the device pixel ratio, causing clicks and mouse movements to be misaligned with rendered content on high-DPI screens.

The changes:

  1. Read the devicePixelRatio from the window object during resize events and store it in p.dpr
  2. Scale mouse event coordinates (offsetX and offsetY) by the device pixel ratio in the canvasPos method

This ensures that mouse input coordinates are properly mapped to the canvas coordinate system on all display densities.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing users to change their code)
  • Docs / tests / chore only

Testing

  • go build -tags nogui ./... passes
  • go vet -tags nogui ./... passes
  • Unit tests pass
  • UI golden-file tests pass (if relevant)
  • Manually verified on: Web platform with high-DPI display

Checklist

  • I have read CONTRIBUTING.md
  • I have signed the CLA (the bot will post a link on first PR)
  • Documentation updated (docs/, README.md, inline comments)
  • Related issue linked below (if applicable)

Fixes #

https://claude.ai/code/session_011ES5S83Xfs7uwCjPbkBnj8

offsetX/Y are CSS pixels, but hit-testing operates in framebuffer
coords (OnResize reports p.fbWidth/p.fbHeight). Multiply canvasPos
by p.dpr so click targets land where the user sees them.

Re-read devicePixelRatio in the resize handler so runtime DPR changes
(monitor switch, browser zoom) update fbWidth/fbHeight correctly.

https://claude.ai/code/session_011ES5S83Xfs7uwCjPbkBnj8
@timzifer
timzifer merged commit fc87ee3 into main Apr 21, 2026
1 of 2 checks passed
@github-actions

Copy link
Copy Markdown

Thank you for your contribution to lux! Before we can merge this pull request, we need you to agree to the Contributor License Agreement (CLA). It grants the Project the rights needed to distribute your contribution under both the noncommercial and commercial licenses.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@github-actions github-actions Bot locked and limited conversation to collaborators Apr 21, 2026
Repository owner unlocked this conversation Apr 21, 2026
@timzifer

Copy link
Copy Markdown
Owner Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants