Skip to content

topbar: keep maximized windows maximized and inside the work area - #293

Closed
2sulraw wants to merge 1 commit into
Lemxy:mainfrom
2sulraw:fix/topbar-maximized-restore
Closed

2sulraw wants to merge 1 commit into
Lemxy:mainfrom
2sulraw:fix/topbar-maximized-restore

Conversation

@2sulraw

@2sulraw 2sulraw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

When the bar reserves a strip of the screen (the work area is smaller than the monitor), windows can end up with a restore rectangle (rcNormalPosition) taken from a maximized window — the full monitor plus the frame border. Restoring such a window then places it past the screen edge and under the bar (#268). Hiding a maximized window with its bar button and bringing it back could likewise return it un-maximized (and oversized).

Reproduced with Chromium windows (Chrome, Helium) and Discord on a 1920x1080 monitor with a bottom bar: a maximized window's normal rect was 1936x1096 against a 1920x1040 work area.

Changes

plugins/topbar/src/main.rs:

  • fit_normal: clamp a maximized window's restore rectangle into its monitor's work area, so a later restore lands inside it. Runs on work-area changes and on the regular window refresh.
  • fit_restored: a restored window still carrying the maximized frame (larger than the monitor on both axes, but only by the invisible border) is shrunk back to the work area. Only that exact shape is touched, so a window spanning two monitors or one genuinely larger is left alone.
  • bring: a window that was maximized before it was hidden now comes back maximized in a single step (SetWindowPlacement with SW_SHOWMAXIMIZED) instead of restore-then-maximize, which visibly flickered. The pre-minimize maximized state is recorded where the bar minimizes the window, so it also works when the placement flag (WPF_RESTORETOMAXIMIZED) is missing.

Borderless fullscreen games and windows spanning monitors are not maximized, so they are left untouched; other minimized windows keep the existing SwitchToThisWindow path.

Refs #268

Testing

Windows 11, two monitors, bottom bar reserving 40 px:

  • maximized Chrome/Discord: rcNormalPosition clamped to the work area (1920x1040);
  • a window forced to the buggy restored rect (1936x1096, not maximized) snapped back to 1920x1040 on the next refresh;
  • maximize -> hide via the bar -> show via the bar: returns maximized directly, no un-maximized flash.

A window maximized while the work area was the whole monitor keeps that size as its restore rectangle, so restoring it later leaves it past the screen edge and under the bar (Lemxy#268). Clamp a maximized window's normal placement into its monitor's work area, and shrink a restored window still carrying the maximized frame. Hiding a maximized window from the bar and bringing it back now restores it maximized in one step, without the restore-then-maximize flicker.
Lemxy added a commit that referenced this pull request Dec 1, 2026
Restore rectangles are clamped into the work area; a maximized window hidden from the bar comes back maximized.

Co-authored-by: 2sulraw <306633824+2sulraw@users.noreply.github.com>
@Lemxy Lemxy closed this Dec 1, 2026
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