From 0db060da2653872f277b8ab263953ab8fdc57a2b Mon Sep 17 00:00:00 2001 From: dessant Date: Fri, 8 Mar 2019 11:51:35 +0200 Subject: [PATCH] fix: divide click coordinates by display scale on Windows Closes #40. --- src/solve/main.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/solve/main.js b/src/solve/main.js index 2bba4f9..ac9803e 100644 --- a/src/solve/main.js +++ b/src/solve/main.js @@ -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: @@ -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(); @@ -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}; }