Skip to content

Commit

Permalink
Windows Zoom, ScaleFactor (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sickjuicy authored Nov 20, 2023
1 parent 528c353 commit 03dd024
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,28 +176,38 @@ async function createMainWindow() {
});
await loadPlugins(win);


if (windowPosition) {
const { x: windowX, y: windowY } = windowPosition;
const winSize = win.getSize();
const displaySize
= screen.getDisplayNearestPoint(windowPosition).bounds;
const display = screen.getDisplayNearestPoint(windowPosition);
const scaleFactor = display.scaleFactor;

const scaledWidth = Math.floor(windowSize.width / scaleFactor);
const scaledHeight = Math.floor(windowSize.height / scaleFactor);

const scaledX = windowX;
const scaledY = windowY;

if (
windowX + winSize[0] < displaySize.x - 8
|| windowX - winSize[0] > displaySize.x + displaySize.width
|| windowY < displaySize.y - 8
|| windowY > displaySize.y + displaySize.height
scaledX + scaledWidth < display.bounds.x - 8 ||
scaledX - scaledWidth > display.bounds.x + display.bounds.width ||
scaledY < display.bounds.y - 8 ||
scaledY > display.bounds.y + display.bounds.height
) {
// Window is offscreen
if (is.dev()) {
console.log(
`Window tried to render offscreen, windowSize=${String(winSize)}, displaySize=${String(displaySize)}, position=${String(windowPosition)}`,
`Window tried to render offscreen, windowSize=${String(winSize)}, displaySize=${String(display.bounds)}, position=${String(windowPosition)}`,
);
}
} else {
win.setPosition(windowX, windowY);
win.setSize(scaledWidth, scaledHeight);
win.setPosition(scaledX, scaledY);
}
}


if (windowMaximized) {
win.maximize();
}
Expand Down

0 comments on commit 03dd024

Please sign in to comment.