Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(window): drop a saved position whose title bar lands off the screen

Shoguned8fed975adb
diff --git a/CLAUDE.md b/CLAUDE.md
index c0772937e..a1369d56a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -3597,8 +3597,15 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea
monitor its window was on would otherwise reopen the app off-screen: running, focusable from the
dock, visible nowhere, with no gesture that rescues it. Reachable means a real overlap with some
work area (`MIN_VISIBLE_WIDTH`/`HEIGHT`), judged against the CLAMPED size — a few pixels on
- screen is not a title bar anyone can grab. Dropping keeps the user's size and lets the platform
- place a window it knows how to place; inventing a corner for it is the guess.
+ screen is not a title bar anyone can grab. **Overlap alone is not enough, because it is
+ symmetric**: a monitor mounted ABOVE the laptop and then unplugged leaves a record whose BOTTOM
+ edge clips the laptop's work area by enough to clear the height floor while the title bar sits
+ hundreds of px above the screen — and under `titleBarStyle: 'hiddenInset'` the title bar is the
+ whole drag region. So the window's TOP edge must also land on that work area, within
+ `TOP_OVERHANG_SLACK` (24px, because window managers report decorations inconsistently and a few
+ pixels of overhang must not cost the user their position every launch). The rule is per-display,
+ like the overlap it joins. Dropping keeps the user's size and lets the platform place a window it
+ knows how to place; inventing a corner for it is the guess.
- **No capture while minimized or fullscreen.** `isMaximized()` is FALSE while a macOS window is
fullscreen, so capturing there records `maximized: false` and erases exactly the preference this
exists to remember. The last non-fullscreen state stands, which also means the app never reopens
diff --git a/src/main/window-state.test.ts b/src/main/window-state.test.ts
index 78171af97..f70af8ede 100644
--- a/src/main/window-state.test.ts
+++ b/src/main/window-state.test.ts
@@ -135,6 +135,36 @@ describe('resolveWindowBounds', () => {
})
})
+ it('drops a position whose overlap is its BOTTOM edge, leaving the title bar above the screen', () => {
+ // An external monitor mounted ABOVE the laptop, then unplugged. The bottom 173px of the window
+ // still overlaps the laptop's work area, which clears the height floor — but the title bar sits
+ // 527px above the top of the screen, and under `titleBarStyle: 'hiddenInset'` the title bar is
+ // the only drag region there is. Symmetric overlap cannot see this; the top-edge rule can.
+ const saved: WindowState = { x: 200, y: -500, width: 1000, height: 700, maximized: false }
+ expect(resolveWindowBounds(saved, ONE_SCREEN, DEFAULTS).bounds).toEqual({
+ width: 1000,
+ height: 700
+ })
+ })
+
+ it('keeps a position overhanging the top by a few pixels — that is decoration, not a lost window', () => {
+ // Window managers report decorations inconsistently, so a small overhang is ordinary and must
+ // not cost the user their position on every launch. TOP_OVERHANG_SLACK is far smaller than a
+ // title bar, which is the thing the rule above protects.
+ const saved: WindowState = { x: 200, y: 27 - 10, width: 1000, height: 700, maximized: false }
+ expect(resolveWindowBounds(saved, ONE_SCREEN, DEFAULTS).bounds).toMatchObject({ x: 200, y: 17 })
+ })
+
+ it('judges the top edge against the display the window is ON, not the primary one', () => {
+ // The second screen's work area starts at y: 0, so a window at y: 0 is reachable there even
+ // though it is above the laptop's y: 27. The rule is per-display, like the overlap it joins.
+ const saved: WindowState = { x: -2000, y: 0, width: 1000, height: 700, maximized: false }
+ expect(resolveWindowBounds(saved, TWO_SCREENS, DEFAULTS).bounds).toMatchObject({
+ x: -2000,
+ y: 0
+ })
+ })
+
it('never clamps a dropped position into a corner — the platform places it instead', () => {
const saved: WindowState = { x: 99999, y: 99999, width: 1000, height: 700, maximized: false }
const { bounds } = resolveWindowBounds(saved, ONE_SCREEN, DEFAULTS)
diff --git a/src/main/window-state.ts b/src/main/window-state.ts
index 4a57506f1..df0fc16fe 100644
--- a/src/main/window-state.ts
+++ b/src/main/window-state.ts
@@ -53,6 +53,20 @@ export const MIN_HEIGHT = 360
export const MIN_VISIBLE_WIDTH = 120
export const MIN_VISIBLE_HEIGHT = 80
+/**
+ * How far ABOVE a work area's top edge the window's own top edge may sit and still count as
+ * reachable. The overlap test on its own is symmetric, so it passes a window whose BOTTOM edge
+ * dips into the work area while the title bar sits hundreds of px higher, off-screen: unplug an
+ * external monitor mounted above the laptop and a record of `y: -500, height: 700` keeps 173px of
+ * overlap against a screen starting at `y: 27`, which is enough for the height floor and not
+ * enough to grab. Under `titleBarStyle: 'hiddenInset'` the title bar IS the drag region, so there
+ * is nothing else to take hold of.
+ *
+ * The slack exists because window managers report decorations inconsistently and a few pixels of
+ * overhang is ordinary; it is far smaller than a title bar, which is the thing being protected.
+ */
+export const TOP_OVERHANG_SLACK = 24
+
/** The debounce on save. `resize`/`move` fire continuously through a drag. */
export const SAVE_DEBOUNCE_MS = 400
@@ -91,11 +105,16 @@ export function parseWindowState(raw: string): WindowState | null {
return state
}
-/** Visible overlap between a window rect and one display's work area. */
+/**
+ * Visible overlap between a window rect and one display's work area, plus the one thing overlap
+ * alone cannot say: that the overlapping part includes the window's TOP. See `TOP_OVERHANG_SLACK`.
+ */
function reachableOn(r: Rect, area: Rect): boolean {
const w = Math.min(r.x + r.width, area.x + area.width) - Math.max(r.x, area.x)
const h = Math.min(r.y + r.height, area.y + area.height) - Math.max(r.y, area.y)
- return w >= MIN_VISIBLE_WIDTH && h >= MIN_VISIBLE_HEIGHT
+ return (
+ w >= MIN_VISIBLE_WIDTH && h >= MIN_VISIBLE_HEIGHT && r.y >= area.y - TOP_OVERHANG_SLACK
+ )
}
function clamp(v: number, lo: number, hi: number): number {