do window bound checks without relying on displayId

Fixes Vesktop not remembering its position correctly.
Seems like the display ids aren't consistent on some windows systems...
This commit is contained in:
Vendicated
2025-10-23 18:16:30 +02:00
parent cd1a40e6c7
commit 03aa30dfc6
2 changed files with 16 additions and 6 deletions

View File

@@ -11,6 +11,8 @@ import {
Menu,
MenuItemConstructorOptions,
nativeTheme,
Point,
Rectangle,
screen,
session
} from "electron";
@@ -186,11 +188,21 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
height: height ?? DEFAULT_HEIGHT
} as BrowserWindowConstructorOptions;
const storedDisplay = screen.getAllDisplays().find(display => display.id === State.store.displayId);
if (x != null && y != null) {
function isInBounds(point: Point, rect: Rectangle) {
return (
point.x >= rect.x &&
point.x <= rect.x + rect.width &&
point.y >= rect.y &&
point.y <= rect.y + rect.height
);
}
if (x != null && y != null && storedDisplay) {
options.x = x;
options.y = y;
const inBounds = screen.getAllDisplays().some(d => isInBounds({ x, y }, d.bounds));
if (inBounds) {
options.x = x;
options.y = y;
}
}
if (!Settings.store.disableMinSize) {
@@ -236,7 +248,6 @@ function initWindowBoundsListeners(win: BrowserWindow) {
const saveBounds = () => {
State.store.windowBounds = win.getBounds();
State.store.displayId = screen.getDisplayMatching(State.store.windowBounds).id;
};
win.on("resize", saveBounds);

View File

@@ -51,7 +51,6 @@ export interface State {
maximized?: boolean;
minimized?: boolean;
windowBounds?: Rectangle;
displayId: number;
firstLaunch?: boolean;