bound check entire window area instead of only top left corner

Co-Authored-By: MBStarup <mavi.nexu@gmail.com>
This commit is contained in:
Vendicated
2025-10-23 21:17:17 +02:00
parent b75ed0766d
commit a242d5d694

View File

@@ -11,7 +11,6 @@ import {
Menu, Menu,
MenuItemConstructorOptions, MenuItemConstructorOptions,
nativeTheme, nativeTheme,
Point,
Rectangle, Rectangle,
screen, screen,
session session
@@ -280,24 +279,21 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
// We want the default window behaviour to apply in game mode since it expects everything to be fullscreen and maximized. // We want the default window behaviour to apply in game mode since it expects everything to be fullscreen and maximized.
if (isDeckGameMode) return {}; if (isDeckGameMode) return {};
const { x, y, width, height } = State.store.windowBounds ?? {}; const { x, y, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT } = State.store.windowBounds ?? {};
const options = { const options = { width, height } as BrowserWindowConstructorOptions;
width: width ?? DEFAULT_WIDTH,
height: height ?? DEFAULT_HEIGHT
} as BrowserWindowConstructorOptions;
if (x != null && y != null) { if (x != null && y != null) {
function isInBounds(point: Point, rect: Rectangle) { function isInBounds(rect: Rectangle, display: Rectangle) {
return ( return !(
point.x >= rect.x && rect.x + rect.width < display.x ||
point.x <= rect.x + rect.width && rect.x > display.x + display.width ||
point.y >= rect.y && rect.y + rect.height < display.y ||
point.y <= rect.y + rect.height rect.y > display.y + display.height
); );
} }
const inBounds = screen.getAllDisplays().some(d => isInBounds({ x, y }, d.bounds)); const inBounds = screen.getAllDisplays().some(d => isInBounds({ x, y, width, height }, d.bounds));
if (inBounds) { if (inBounds) {
options.x = x; options.x = x;
options.y = y; options.y = y;