Repository navigation
feat(desktop): persist and restore main window geometry and maximized state - #29
Conversation
6059e9a to
7a703bf
Compare
thtbee
left a comment
There was a problem hiding this comment.
Thanks for this. It's a big step up from today, where nothing is saved at all. A few things before it can go in:
- The minimum size differs between QML and Rust.
Tokens.qmlhasminWindow: [880, 600], butMIN_WINDOW_WIDTHandMIN_WINDOW_HEIGHTare 900 and 620, and bothsave_window_geometryandset_window_geometryclamp to them. A window sized to 880 wide is saved as 900, so it grows a little every time. I'd keep one source: the Rust side can store what it gets, with only a sanity range. - Which monitor it was on. As we discussed on #26, the position should be kept per monitor (its name, plus the offset on it). Right now it's stored in desktop coordinates, so after monitors are rearranged or swapped,
restoreAndBringToFronteither keeps a spot on the wrong monitor or falls back. The fallback also clamps againstScreen.desktopAvailableWidth, which is the screen the window is on right now rather than the primary one, and letsxgo down to-targetW + 120, so the window can open mostly off screen. Opening centered on the primary screen in that case would be safer. - The
wantBackdropchange is already part of #23, so the two would conflict. Could you leave it out here? - The test changes global state.
window_geometry_sanitization_and_runtime_statesetsWINDOW_GEOMETRY, and another test insettings.rscallsapply_runtime()on defaults in parallel, which resets it. Testingsanitized()and the clamping without touching the static would avoid flaky runs.
On Wayland, x and y read as 0 and setting them does nothing, so only size and maximized come back. That's fine, but a short comment in restoreAndBringToFront saying so would help the next reader.
|
Hi @thtbee Ahh yes, I was too quick on the Request Review button(s). Cheers |
4597b69 to
972e2da
Compare
972e2da to
7432cf4
Compare
… state Signed-off-by: Jochen Kirstätter <7329802+jochenkirstaetter@users.noreply.github.com>
7432cf4 to
42190b6
Compare
thtbee
left a comment
There was a problem hiding this comment.
Thanks for working through all of that so quickly. Saving the monitor with a position relative to it, centering on the primary when it's gone, one minimum size, and the Wayland note all look right, and the test no longer touches global state.
One thing I checked on Windows: Qt names monitors there \.\DISPLAY1, \.\DISPLAY2 and so on. Those numbers are assigned by Windows and can swap when monitors are reconnected or a laptop docks, so the window could come back on the wrong monitor. On this PC the same screen reports a manufacturer and a serial number (BOE, 103), which stay with the monitor. Could screenKey prefer manufacturer, model and serial when they're there, and fall back to the name? Linux's connector names (DP-1, HDMI-A-1) have the same issue to a lesser degree, so it helps there too.
With that, this looks ready to me.
Windows assigns display numbers (\.\DISPLAY1, \.\DISPLAY2) dynamically and Linux connector names (DP-1, HDMI-A-1) can change across ports. Prefer the monitor's EDID-backed manufacturer, model, and serialNumber when available, falling back to s.name. Signed-off-by: Jochen Kirstätter <7329802+jochenkirstaetter@users.noreply.github.com>
Signed-off-by: Bee <302257494+thtbee@users.noreply.github.com>
thtbee
left a comment
There was a problem hiding this comment.
Looks good to me now. I pushed one small commit on top: the restore code read desktopAvailableWidth/Height, which covers the whole virtual desktop, so with two monitors the first start centered across both. It uses each monitor's own size now. Everything else from the earlier review is sorted, thanks for working through all of it.
The window position change (#29) used two things NativeWindow's QML type doesn't expose: an onWindowVisibilityChanged handler, which stopped MainWindow.qml from loading at all, and the `screen` property, which stopped the restore before the window was shown. Visibility is now followed through Connections, and the position alone picks the monitor. On Windows a size set before the first show comes out taller by the title bar, so the window grew on every start; it's set again once shown. Maximizing changes the size before the visibility, so the normal size was overwritten by the maximized one; it's now taken only when the save runs, which checks the visibility. Checked on a test copy: same place and size over restarts, maximized reopens maximized, and un-maximizing returns to the saved size.
persist and restore main window geometry and maximized state
What and why
Referring #26 and how this fixes matters.
It was part of other commits and this is the isolated PR.
How it was tested
Includes round-trip persistence assertions in save_and_load_round_trip plus a dedicated window_geometry_sanitization_and_runtime_state test covering min/max dimension clamping (MIN_WINDOW_WIDTH..=7680, MIN_WINDOW_HEIGHT..=4320), partial coordinate sanitization, and set_window_geometry / window_geometry.
Checklist
./scripts/check.ps1passes (or the CI equivalent for the parts I changed)git commit -s), see CONTRIBUTING.md