Skip to content

Window: open on one screen at a size that fits, like any other window - #259

Merged
elripalda merged 2 commits into
elripalda:mainfrom
Felitendo:fix/window-huge-across-monitors
Nov 17, 2026
Merged

elripalda merged 2 commits into
elripalda:mainfrom
Felitendo:fix/window-huge-across-monitors

Conversation

@Felitendo

@Felitendo Felitendo commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

The launcher window now opens like any other window:

  • Back where you left it. It reopens on the screen where it was closed, at the same size, and never bigger than that screen's free area (the screen without its taskbar). Before, with two monitors it sometimes opened huge, wider than one screen and reaching across both, and then came back that way at every start.
  • First start fits the screen. The first window (1360x860 from tauri.conf.json) wasn't fitted to the screen. At 150% on a 1080p laptop that's 2040x1290 pixels, bigger than the screen. It now shrinks to fit when it's too big. The same goes when the screen it was kept on is no longer there.
  • Maximized stays on its screen. A window maximized on another screen (moved there with Win+Shift+arrow, or dragged) reopened on the old one. It now reopens maximized on the screen where it was.

Why

The huge window. restore_window_place set the kept size first and moved the window to its kept place second. The window starts on the main screen, so when the kept place is on a screen with another scale (100% and 150%, say), the move makes Windows rescale the window to keep its logical size. tao does this in its WM_DPICHANGED handler. The physical size we had just set grew by the scale ratio, past the screen. The 700 ms save after a move or resize then wrote that grown size to window.json. The only check on restore was that the title bar is on some screen, so the oversized window came back at every start. That explains the "sometimes": it starts after the window was last closed on the other screen. tauri-plugin-window-state restores in the other order (place, then size) for this reason.

The first window. center: true centres the configured size on the main screen but doesn't shrink it, and nothing else looked at it.

Maximized on another screen. While maximized, keep_window_place kept the normal place from before, so the screen it was maximized on was never saved.

How

All in lib.rs unless noted.

  • restore_window_place: sets the place first, then the size. It uses the kept place if its title bar is on a screen (same check as before), otherwise first_place.
  • fit_on_screen: caps the kept size at that screen's work area and moves the window in only as far as needed for all of it to show. This also repairs a window.json that already holds an oversized window, so players who hit the bug before don't keep the giant window after updating.
  • first_place / centred_on_screen: when the window as it first opened doesn't fit its screen, it shrinks to nine tenths of the free area and is centred. Nine tenths keeps it looking like a window rather than a maximized one. A window that fits isn't touched.
  • keep_window_place / normal_place_on: while maximized, the kept normal place moves to the screen the window is maximized on (centred there) if it isn't on it already. On the next start the place goes there first, so maximize() lands on that screen.
  • display.rs, leave_tv_mode: same order swap (place, then size) when coming back from Big Picture on another screen.

One change in behaviour: a window that was left hanging off a screen edge, or across two screens, now comes back fully on the screen its title bar was on.

Tests

  • 7 new unit tests:
    • fit_on_screen: a window that fits is unchanged, one wider than both screens shrinks to one, one hanging off the edge moves back on, one on a second screen stays there.
    • centred_on_screen: a too-big first window shrinks and centres.
    • normal_place_on: a window maximized on its own screen keeps its place, and one maximized on another screen moves there.
  • cargo test: 660 passed. node --test tests/*.test.cjs: 280 passed.
  • Not tried yet in the running app, and not on a real Windows PC with two screens at different scales. The tests cover the placement math, not Windows' rescale itself.

The kept window place was restored size first, place second. The window
starts on the main screen, so moving it onto a screen with another scale
made Windows rescale the size just set: it grew past the screen, across
both monitors, and that size was kept for every later start.

Now the place goes first and the size second (as tauri-plugin-window-state
does), and the kept place is fitted to the free area of the screen its
title bar is on, which also repairs a window.json that already holds a
size wider than the screen. Leaving Big Picture gets the same order.
…screen

The first window (1360x860 from tauri.conf.json, centred on the main
screen) was never fitted to it: at 150% on a 1080p laptop that's
2040x1290 pixels, bigger than the screen. When it doesn't fit (also when
the kept screen is gone), it now shrinks to nine tenths of the screen's
free area and is centred. A window that fits stays exactly as it opened.

While maximized, the kept place wasn't updated, so a window maximized
on another screen (Win+Shift+arrow, or dragged there) reopened on the
old one. Its normal place now moves to the screen it's maximized on,
centred there, so it reopens maximized on that screen.
@Felitendo Felitendo changed the title Window: don't open wider than the screen on multi-monitor setups Window: open on one screen at a size that fits, like any other window Nov 16, 2026
@elripalda
elripalda merged commit e8e0828 into elripalda:main Nov 17, 2026
5 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