From 2094f81e53bd85f9957552b80a030133100a9fba Mon Sep 17 00:00:00 2001 From: Abhishek B R Date: Sun, 1 Nov 2026 17:21:05 +0530 Subject: [PATCH] fix(desktop): a window saved 1px past a display edge reopens where it was Saved main window bounds had to sit entirely inside one display, so a window snapped to a display edge and persisted 1px past it was thrown away and reopened at the default size on the primary display. Allow 1px of overhang on each edge when validating saved bounds. Refs #21563 --- apps/desktop/src/window/DesktopWindow.test.ts | 24 +++++++++++++++++++ apps/desktop/src/window/DesktopWindow.ts | 12 ++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/window/DesktopWindow.test.ts b/apps/desktop/src/window/DesktopWindow.test.ts index 0dcb2b85ac2c5..1d684bbc4bd74 100644 --- a/apps/desktop/src/window/DesktopWindow.test.ts +++ b/apps/desktop/src/window/DesktopWindow.test.ts @@ -479,6 +479,30 @@ describe("DesktopWindow", () => { ); }); + it("restores a window saved 1px past a display edge, and nothing further out", () => { + const displays = [ + { x: 0, y: 0, width: 1920, height: 1280 }, + { x: 1920, y: 0, width: 1280, height: 1920 }, + ]; + const snappedBounds = { x: 1921, y: 30, width: 1280, height: 945 }; + + assert.strictEqual( + DesktopWindow.resolveInitialMainWindowBounds(snappedBounds, displays), + snappedBounds, + ); + for (const bounds of [ + { x: 1922, y: 30, width: 1280, height: 945 }, + { x: 1918, y: 30, width: 1280, height: 945 }, + { x: 1921, y: -2, width: 1279, height: 945 }, + { x: 1920, y: 976, width: 1280, height: 946 }, + ]) { + assert.deepEqual( + DesktopWindow.resolveInitialMainWindowBounds(bounds, displays), + DesktopAppSettings.DEFAULT_MAIN_WINDOW_SIZE, + ); + } + }); + it("rejects renderer navigations whose origin only serializes as null", () => { for (const applicationUrl of ["t3code://app/", "t3code-dev://app/"]) { assert.isTrue( diff --git a/apps/desktop/src/window/DesktopWindow.ts b/apps/desktop/src/window/DesktopWindow.ts index 10801089841d1..a9abed72d91d7 100644 --- a/apps/desktop/src/window/DesktopWindow.ts +++ b/apps/desktop/src/window/DesktopWindow.ts @@ -137,15 +137,19 @@ function getInitialWindowBackgroundColor(shouldUseDarkColors: boolean): string { type DisplayBounds = Pick; +// A window snapped to a display edge can be reported 1px past that edge. +const SAVED_BOUNDS_EDGE_TOLERANCE_PX = 1; + function windowFitsWithinDisplay( windowBounds: DesktopAppSettings.DesktopWindowBounds, displayBounds: DisplayBounds, ): boolean { + const tolerance = SAVED_BOUNDS_EDGE_TOLERANCE_PX; return ( - windowBounds.x >= displayBounds.x && - windowBounds.y >= displayBounds.y && - windowBounds.x + windowBounds.width <= displayBounds.x + displayBounds.width && - windowBounds.y + windowBounds.height <= displayBounds.y + displayBounds.height + windowBounds.x >= displayBounds.x - tolerance && + windowBounds.y >= displayBounds.y - tolerance && + windowBounds.x + windowBounds.width <= displayBounds.x + displayBounds.width + tolerance && + windowBounds.y + windowBounds.height <= displayBounds.y + displayBounds.height + tolerance ); }