OpenProgram Docs

Desktop window state

The main window stores its last normal size apart from maximize and fullscreen. A normal window never opens flush with the menu bar, Dock or screen sides, where no edge is left to grab.

FailureGuard
Quit while zoomed or filling the work areaCreate a smaller normal window, then reapply maximize
Old flush {{x,y,width,height}} fileMigrated as maximized plus the inset default
Saved display unpluggedCentered default on the primary work area
Corrupt or tiny fileMinimum size and centered default
Tab row swallows the top edge5px no-drag strips
Torn-off window closedTorn-off windows are not saved

Code: apps/desktop/main/windows/window-state.js, apps/desktop/main.js, apps/web/app/styles/base/desktop-chrome.css, apps/web/components/app-shell.tsx. How many windows exist and who creates them: Window lifecycle.

Persisted schema

window-state.json in the desktop userData directory (app.getPath("userData"), desktop name openprogram-desktop).

{
  "version": 2,
  "x": 160, "y": 90, "width": 1280, "height": 800,
  "isMaximized": false,
  "isFullScreen": false,
  "displayId": 1,
  "displayWorkArea": { "x": 0, "y": 38, "width": 1512, "height": 851 }
}
FieldRole
x,y,width,heightLast normal bounds; never a rectangle that fills the work area
isMaximizedLast zoom or maximize
isFullScreenLast macOS native fullscreen
displayIdElectron display id, tried first while that screen is connected
displayWorkAreaMatches a reconnected display whose id changed
LimitValue
Minimum800×500; no maximum
First run1440×900, centered on the primary work area
Inset default24px inside each edge when 1440×900 would fill the work area
FillingWithin 8 CSS pixels of the work area; checked on save and restore
Version 1The old {{x,y,width,height}} object; migrates on load

Restore

StepAction
1. Read and migrateCorrupt JSON, missing width or height, NaN or a tiny size: centered default
2. Find the displaydisplayId, then work area (2px tolerance), then bounds overlapping a work area. None: primary work area, centered default, maximize and fullscreen dropped
3. Check for a filled work areaSaved rectangle fills a connected work area: treat as maximized, normal size becomes the inset default. BrowserWindow is never constructed at work-area size
4. ClampThe normal rectangle onto the work area
5. Create hiddenAt normal size with minWidth and minHeight. If maximized, setBounds to the work area, then maximize() or setFullScreen(true), still hidden
6. ShowOn ready-to-show, so macOS never animates from the small first frame

The green Zoom button therefore returns to the remembered normal size.

Stretched to the work area without Zoom

Saved as maximized. The normal size kept is the first that does not fill the work area: getNormalBounds(), the in-memory last good rectangle, the inset default.

Save timing

EventWrite
resize, moveDebounced 300ms
maximize, unmaximize, enter-full-screen, leave-full-screen, closeWritten at once
While maximized, fullscreen or fillingOnly flags and display identity change; the normal rectangle stays

Torn-off windows

Size min(1100, normal width) × min(720, normal height), no parent x/y, no inherited maximize or fullscreen. Placed at the drop point by centerHiddenWindowOnCursor.

Titlebar hit testing

AreaBehaviour
40px tab row-webkit-app-region: drag, so empty space moves the window
Top, left and right edges5px no-drag strips (.desktop-resize-edge), corners included, for native resize
macOS traffic lightstrafficLightPosition centers them on the row: {{x:13,y:12}} at zoom 1
Tabs6px below the top; the strips do not cover them, the lights, + or the main menu
Why a flush normal window cannot be resized

Electron's window stays resizable, but on a 1512-wide display {x:0,y:38,width:1512,height:851} leaves nothing to grab, and Zoom has no size to return to. A drag region running edge to edge also takes the top-edge and corner resize targets. Setting resizable: true or deleting the file changes neither; the stored model has to separate normal bounds from maximize.

Implementation status

Implemented, checked by apps/desktop/tests/windows/check-window-state.js. Window chrome colour follows the Web theme (theme-chrome.js, see Unification work); bounds persistence stores no background colour.

Last updated · 2026-11-25