Skip to content

fix(window): restore the toggle when the maximized flag is lost on Windows - #2420

Merged
vastsa merged 7 commits into
vastsa:mainfrom
skyler-developer:fix/issue-1993-maximize-flag
Nov 23, 2026
Merged

vastsa merged 7 commits into
vastsa:mainfrom
skyler-developer:fix/issue-1993-maximize-flag

Conversation

@skyler-developer

@skyler-developer skyler-developer commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 概要

On Windows, frame:false + thickFrame:false windows can lose the native maximized flag (IsZoomed = false) while the window still fills the work area, so toggleMaximize kept calling maximize() on an already-full window and the title-bar button went dead (#1993).

The toggle now decides through a shared plan (window-maximize.ts):

  • isMaximized() → unmaximize() (unchanged)
  • not maximized, but bounds cover the work area of the display the window is on (8px slack for DPI rounding), on win32 only → pseudo-maximized: explicit setBounds restore
  • otherwise → maximize() (unchanged)

Per the review on this PR, the restore is an explicit rect rather than a maximize()+unmaximize() resync: on the transparent Win10 main window Electron records the current bounds as the restore bounds, so the resync returned the window to the same full rect. The main window is restored to its last persisted normal bounds (state.workPanelLastAppliedBounds, already maintained by persistNormalWindowState()) when they are a real windowed size for the current work area — in the flag-lost state Win32 reports the full rect as the normal position, so recorded bounds are validated (min size, not covering the work area, fully inside it) and otherwise rejected. Plugin panel windows, which have no persisted bounds, get two thirds of the work area, centered.

The geometric fallback is Windows-only: elsewhere a work-area-filling window is an ordinary user-resized window and must keep the plain behavior. Fullscreen windows never take the fallback, preserving the exit-fullscreen-then-maximize interlock from #1655 (its regression contract in window-fullscreen-maximize.test.mjs is updated to the decision shape and still asserts the interlock).

A known trade-off, from the review: a manually resized window that happens to fill the work area is indistinguishable from the flag-loss state at toggle time (both have normal bounds == current bounds). The interception now always has a visible outcome — the window shrinks to the restored rect, and the next click maximizes normally — where the old code did nothing.

Requirement link / 需求关联

  • Linked requirement issue: fixes #1993
  • Issue explains the background and the expected outcome
  • UI screenshots: not applicable — no visual layout change; the button only regains its normal maximize/restore function (behavior fix in the main-process toggle logic)

Validation / 验证

Task candidate: fix/issue-1993-maximize-flag @ b4bae22, based on origin/main @ 0ca8112 (merge-base verified).

  • pnpm build:js — pass
  • pnpm --filter @pi-desktop/desktop typecheck — pass
  • pnpm lint — pass
  • node --test test/window-maximize-toggle.test.mjs test/window-fullscreen-maximize.test.mjs — 27 pass, 0 fail (flag-loss geometry, win32 gating, restore-rect selection incl. flag-loss pollution of the persisted bounds, fullscreen interlock, missing work area; updated: [Bug] 双屏显示器,F11全屏后pi-desktop白屏 #1655 contract)
  • Full apps/desktop node --test suite: 26 failures, all environmental in this workspace — 23× "Electron binary missing" (install ran with --ignore-scripts, which skips the Electron postinstall) and 3× host-app-dependent tests; the affected files are untouched by this branch. Task-candidate E2E on a real Windows host: pass — manually verified on Windows 11 (single display, run from source at this branch): normal maximize/restore cycles regress-clean; the flag-loss recovery shrinks the window back to a normal windowed size and the toggle keeps working; the manually-resized full-coverage trade-off behaves as documented; plugin panels unchanged. Details in the verification comment on this PR.

Environment: macOS arm64, pnpm 12.8.1 (--ignore-scripts).

Rollback / 回滚

Revert the two commits; window-maximize.ts is new and both call sites fall back to the previous isMaximized()-only toggle.


(Drafted via an AI assistant at my direction; I own the content.)

…ndows

With frame:false + thickFrame:false, Windows can drop the native
maximized flag while the window keeps its work-area size, so
isMaximized() reads false and every toggle-maximize click calls
maximize() on a window that already fills the screen: the button goes
dead (vastsa#1993).

Decide the toggle through a shared plan: a non-maximized window whose
bounds cover the work area of its display is pseudo-maximized and gets
a maximize+unmaximize resync so the restore path has a real maximized
state to come back from. Fullscreen windows stay on the existing
exit-fullscreen-then-maximize interlock (vastsa#1655).

fixes vastsa#1993
@vastsa

vastsa commented Nov 20, 2026

Copy link
Copy Markdown
Owner

The resyncUnmaximize path calls maximize() then unmaximize() on a window whose current bounds already fill the work area. On the Windows Win10 path the main window is transparent (window-background.ts:36), where Electron's Maximize() stores the current bounds as the restore bounds and Unmaximize() restores exactly those bounds — so the window returns to the same full-size rect and the button still appears dead. For opaque windows, SW_RESTORE returns to the normal placement, which in the flag-lost state is likely that same full rect.

The PR doesn't identify why the flag is lost and has no Windows runtime evidence that the window actually shrinks. It also changes behavior for an ordinary user-sized window that covers the work area (within the 8px tolerance): it can no longer be maximized.

Please root-cause the flag loss, or restore to a real normal size (e.g. an explicit fallback setBounds, as #1993 suggests), and verify on Windows. The current unit tests only cover the pure planMaximizeToggle decision.

@skyler-developer

Copy link
Copy Markdown
Contributor Author

Thanks for the review — the restore-bounds point is the key one and I agree: on the transparent Win10 path (transparent: true when Windows 11 native corners are off, window-background.ts) the maximize()+unmaximize() resync restores into the same full-work-area rect, so the button stays dead. The 8px-tolerance interception of manually resized windows is also a fair hit.

Revising the PR along the lines you and #1993 suggest: drop the resync entirely and, on the pseudo-maximized decision (now win32-gated), do an explicit setBounds restore — to the main window's last persisted normal bounds (persistNormalWindowState() in bootstrap/window.ts already tracks those) when available and sane for the current work area, otherwise to a computed windowed size. Plugin panel windows, which have no persisted bounds, use the computed size.

On verification: I don't have CI coverage for the flag-loss state, but I do have a Windows machine available and will report the manual test results (normal maximize/restore cycles, manually resized full-coverage windows, and the flag-loss recovery path) back on this PR.

(Drafted via an AI assistant at my direction; I own the content.)

… rect

Review on PR vastsa#2420: on the transparent Win10 main window
(window-background.ts), Electron records the current bounds as the
restore bounds, so maximize()+unmaximize() returns the window to the
same full-work-area rect and the resync could not revive the dead
toggle. A work-area-filling window is also an ordinary user-resized
window in some cases, and intercepting it needs a visible outcome.

Restore via explicit setBounds instead: the main window goes back to
its last persisted normal bounds (state.workPanelLastAppliedBounds)
when they are a real windowed size for the current work area — in the
flag-lost state Win32 reports the full rect as the normal position, so
recorded bounds are validated and otherwise rejected — and plugin
panel windows, which have no persisted bounds, get two thirds of the
work area, centered.
@skyler-developer

Copy link
Copy Markdown
Contributor Author

Revised as promised in the earlier comment, pushed as b4bae22:

  • Dropped the maximize()+unmaximize() resync — you are right that on the transparent Win10 main window the recorded restore bounds are the full rect, so it could not revive the toggle.
  • Pseudo-maximized windows (win32-gated) now get an explicit setBounds: the main window to its last persisted normal bounds (state.workPanelLastAppliedBounds from persistNormalWindowState()), validated because in the flag-lost state Win32 reports the full rect as the normal position; plugin panel windows get two thirds of the work area, centered.
  • The interception of manually-resized full-coverage windows now always has a visible outcome (the window shrinks), which addresses the "no longer maximizable" concern as far as the two states are distinguishable — at toggle time they are not.

Unit tests cover the decision and the restore-rect selection including the polluted-bounds case (27 pass). Windows manual verification is next on my side — results will follow on this PR.

(Drafted via an AI assistant at my direction; I own the content.)

@vastsa

vastsa commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks for the follow-up on #1993. The main-window fix looks reasonable, and macOS/Linux and the fullscreen interlock are unaffected. Two things before landing:

  1. Please drop the plugin-panel-host.ts change. Only the main window sets thickFrame: false (bootstrap/window.ts). Plugin panels use the default thickFrame and are opaque, and the transparent widget is maximizable: false, so panels never had this bug. Changing them only adds the documented tradeoff: on Windows, a panel the user dragged to fill the work area restores to 2/3 instead of maximizing. It also duplicates workAreaForWindow.
  2. Windows verification is still pending. The previous maximize()+unmaximize() approach was shown not to work on a transparent Win10 main window. Please post a Windows 10/11 result for this setBounds path, covering both a lost-flag restore and a normal maximize/restore. The new unit tests cover only the pure planner, and the app-lifecycle.ts wiring is checked only by a source regex.

Review on PR vastsa#2420: only the main window sets thickFrame:false
(bootstrap/window.ts), so plugin panels keep the default opaque frame
and never lose the maximized flag; the transparent widget is
maximizable:false and does not reach the toggle. Revert the
plugin-panel-host.ts wiring to keep the flag-loss restore out of the
panels, which would otherwise inherit the documented trade-off where a
manually resized full-coverage panel shrinks instead of maximizing.
@skyler-developer

Copy link
Copy Markdown
Contributor Author

Both points addressed:

  1. Panel change dropped in a1c9770. You are right: thickFrame: false is only set for the main window (bootstrap/window.ts:253), panels keep the default opaque frame and never lose the flag, and the transparent widget is maximizable: false and does not reach the toggle. plugin-panel-host.ts is back at its origin/main state, and workAreaForWindow now lives only next to its single caller.
  2. Windows verification is what remains — my Windows test run is in progress and I will post the results here (lost-flag restore on the transparent Win10 main window, plus normal maximize/restore cycles).

On the app-lifecycle.ts wiring note: the toggle path runs inside the Electron main process, so the node-only test runner cannot exercise it; the #1655 source contract is the node-side guard there, and the Windows manual run covers the wiring end-to-end. Happy to extract more of the wiring into a testable seam if you'd prefer a different shape.

(Drafted via an AI assistant at my direction; I own the content.)

@skyler-developer

Copy link
Copy Markdown
Contributor Author

Windows verification done, as requested.

Environment: Windows 11, single display, run from source at b4bae22 + a1c9770 (fix/issue-1993-maximize-flag, pnpm install && pnpm build:js && pnpm dev).

Results, all as expected:

  1. Normal maximize/restore cycles (regression): the toggle works on every click, behavior matches the released build.
  2. Flag-loss recovery: maximized state combined with a display-settings change (scaling) / sleep-wake, then clicking the toggle — the window visibly shrinks back to a normal windowed size, and the next click maximizes normally. The button no longer goes dead.
  3. Manually resized full-coverage window: clicking the toggle shrinks the window to the restored rect and the next click maximizes — the documented trade-off, acceptable in practice.
  4. Plugin panels: unchanged, as intended after scoping the fix to the main window.

No multi-display machine was available, so the display-switch variant of scenario 2 was exercised through scaling changes and sleep-wake only.

(Drafted via an AI assistant at my direction; I own the content.)

@vastsa
vastsa merged commit b3d9de9 into vastsa:main Nov 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants