Skip to content

Fit the main window to the monitor's work area at startup - #4

Merged
arithex merged 2 commits into
mainfrom
claude/affectionate-goodall-gn2lqa
Oct 29, 2026
Merged

arithex merged 2 commits into
mainfrom
claude/affectionate-goodall-gn2lqa

Conversation

@arithex

@arithex arithex commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Testers reported that on some displays the window opens bigger than the screen and the title bar can't be reached. One case was 2560×1440.

Cause

WPF sizes are in 1/96-inch units, and the display's scale setting multiplies them. The window's nominal size of 1600×1000 therefore grows with the scale. On 2560×1440 at 150%, the work area (the screen minus the taskbar) is only about 1707×928 units, so the window is too tall to fit. CenterScreen then centers it anyway, which puts the title bar above the top of the screen.

Fix

New WindowFitting.FitToWorkArea(). It is pure WPF, with no P/Invoke, so the code stays portable. The constructor calls it before the window is created. It:

  • reads SystemParameters.WorkArea, the work area of the primary monitor, which is where new windows open by default;
  • shrinks the window so it takes at most 80% of the work area;
  • lowers MinWidth and MinHeight when they're bigger than the work area, so a small, high-scale screen can't still clip the window;
  • centers the window in the work area itself, replacing CenterScreen.

Known limitation: on a multi-monitor setup where the app opens on a secondary screen with a different scale from the primary, the size is worked out from the primary screen. The first push on this PR handled that case with MonitorFromWindow and GetMonitorInfo. That code was dropped in favour of portability.

Expected sizes:

Display Work area (units) Window opens at
2560×1440 @ 150% ~1707×928 ~1365×742
1920×1080 @ 175% ~1097×590 1000×590; the minimum height drops to 590
1920×1080 @ 100% ~1920×1032 ~1536×826

Testing

  • The C# compiles against the .NET 4.8 reference assemblies, using stand-ins for the code the XAML generates.
  • Windows CI build.
  • Testers on high-DPI displays confirm the title bar is reachable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KaEsnLMDyw72GZ8a6ZxAGq

WPF sizes are DPI-scaled, so the nominal 1600x1000 window overflowed the
screen at high display scaling (eg. 2560x1440 at 150% is ~1707x920 units),
hiding the titlebar. On startup, shrink the window (and its minimum size,
if needed) to fit the work area of its monitor, and center it there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaEsnLMDyw72GZ8a6ZxAGq
Drop the MonitorFromWindow/GetMonitorInfo interop in favour of pure WPF,
to keep the windowing code portable. Size and position are now set in
the constructor, before the window is created. Caps the startup size at
80% of the work area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaEsnLMDyw72GZ8a6ZxAGq
@arithex
arithex merged commit 08857c9 into main Oct 29, 2026
2 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