Skip to content

Commit

Permalink
fix: divide click coordinates by display scale on Windows
Browse files Browse the repository at this point in the history
Closes #40.
  • Loading branch information
dessant committed Mar 8, 2019
1 parent 59d4366 commit 0db060d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/solve/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,15 @@ async function messageClientApp(message) {
return rsp;
}

async function getOsScale() {
const zoom = await browser.runtime.sendMessage({id: 'getTabZoom'});
return window.devicePixelRatio / zoom;
}

async function getBrowserBorder(clickEvent) {
const framePos = await getFrameClientPos();
const scale = window.devicePixelRatio;
const zoom = await browser.runtime.sendMessage({id: 'getTabZoom'});
const osScale = scale / zoom;
const osScale = await getOsScale();

return {
left:
Expand Down Expand Up @@ -218,7 +222,7 @@ async function getFrameClientPos() {

return {x: 0, y: 0};
}
// window.devicePixelRatio

async function getElementScreenRect(node, browserBorder) {
let {left: x, top: y, width, height} = node.getBoundingClientRect();

Expand All @@ -231,6 +235,13 @@ async function getElementScreenRect(node, browserBorder) {
x += data.x + browserBorder.left + window.screenX * scale;
y += data.y + browserBorder.top + window.screenY * scale;

const {os} = await browser.runtime.sendMessage({id: 'getPlatform'});
if (os === 'windows') {
const osScale = await getOsScale();
x /= osScale;
y /= osScale;
}

return {x, y, width: width * scale, height: height * scale};
}

Expand Down

0 comments on commit 0db060d

Please sign in to comment.