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:17:04 +02:00
parent cd1a40e6c7
commit 03aa30dfc6
2 changed files with 16 additions and 6 deletions
+14 -3
View File
@@ -11,6 +11,8 @@ import {
Menu, Menu,
MenuItemConstructorOptions, MenuItemConstructorOptions,
nativeTheme, nativeTheme,
Point,
Rectangle,
screen, screen,
session session
} from "electron"; } from "electron";
@@ -186,12 +188,22 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
height: height ?? DEFAULT_HEIGHT height: height ?? DEFAULT_HEIGHT
} as BrowserWindowConstructorOptions; } 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) { const inBounds = screen.getAllDisplays().some(d => isInBounds({ x, y }, d.bounds));
if (inBounds) {
options.x = x; options.x = x;
options.y = y; options.y = y;
} }
}
if (!Settings.store.disableMinSize) { if (!Settings.store.disableMinSize) {
options.minWidth = MIN_WIDTH; options.minWidth = MIN_WIDTH;
@@ -236,7 +248,6 @@ function initWindowBoundsListeners(win: BrowserWindow) {
const saveBounds = () => { const saveBounds = () => {
State.store.windowBounds = win.getBounds(); State.store.windowBounds = win.getBounds();
State.store.displayId = screen.getDisplayMatching(State.store.windowBounds).id;
}; };
win.on("resize", saveBounds); win.on("resize", saveBounds);
-1
View File
@@ -51,7 +51,6 @@ export interface State {
maximized?: boolean; maximized?: boolean;
minimized?: boolean; minimized?: boolean;
windowBounds?: Rectangle; windowBounds?: Rectangle;
displayId: number;
firstLaunch?: boolean; firstLaunch?: boolean;