Skip to content

core: make Window.close() return whether the close was accepted - #12685

Merged
tronical merged 1 commit into
slint-ui:masterfrom
tilladam:docs/window-close-return-value
Jul 30, 2026
Merged

core: make Window.close() return whether the close was accepted#12685
tronical merged 1 commit into
slint-ui:masterfrom
tilladam:docs/window-close-return-value

Conversation

@tilladam

@tilladam tilladam commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Previously Window.close() returned true for any top-level window regardless
of the outcome, so callers could not tell whether the close-requested
callback actually let the window close.

WindowItem::close() now returns the result of the close request:

  • true when the callback accepted the close (the window is hidden),
  • false when the callback kept the window shown,
  • false when called on a child Window element that can't be closed independently.

The builtin docs are updated to match (using the wording from review), and the
window_actions test now covers both the accepted and rejected paths.

Tests: env RUSTC_WRAPPER= SLINT_TEST_FILTER=window_actions cargo test --manifest-path tests/Cargo.toml -p test-driver-rust

@ogoffart

Copy link
Copy Markdown
Member

Why don't we fix the implementation to do the right thing instead of changing the docs.
In this case, i'd say that we're more likely to want to know if the app is closed or not rather than figuring whether we are top level or not.

Comment thread internal/compiler/builtins.slint Outdated
@tilladam
tilladam force-pushed the docs/window-close-return-value branch from 8e65557 to ae2e97e Compare July 30, 2026 13:03
Comment thread CHANGELOG.md Outdated
`WindowItem::close()` previously returned `true` for any top-level window
regardless of the outcome, so callers could not tell whether the
`close-requested` callback actually let the window close. It now returns the
result of the close request: `true` when the callback accepted (the window is
hidden), `false` when it kept the window shown, and `false` when called on a
child `Window` element that can't be closed independently.

Update the builtin docs and the window_actions test to cover both the
accepted and rejected paths.

changelog: Window: `close()` now returns `true` only when the application accepted the close request, instead of `true` for any top-level window.

Tests: env RUSTC_WRAPPER= SLINT_TEST_FILTER=window_actions cargo test --manifest-path tests/Cargo.toml -p test-driver-rust
@tilladam
tilladam force-pushed the docs/window-close-return-value branch from f42416b to 1ebd82a Compare July 30, 2026 13:16
@tronical
tronical enabled auto-merge (rebase) July 30, 2026 13:42
@tronical
tronical merged commit 76667ef into slint-ui:master Jul 30, 2026
48 checks passed
@tilladam tilladam changed the title docs: clarify Window.close() return value core: make Window.close() return whether the close was accepted Jul 30, 2026
@tilladam

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Fixed the implementation per @ogoffart's point instead of just the docs: WindowItem::close() now returns the result of the close request (true only when the close-requested callback accepts), applied your suggested doc wording, and extended the window_actions test to cover both the accepted and rejected paths.

Also moved the changelog entry into the commit message as a changelog: line and dropped the direct CHANGELOG.md edit, per your note. Sorry for the force-push over your approval — mind re-approving when you get a chance? 🙏

@tronical

Copy link
Copy Markdown
Member

It's already merged ;)

@tilladam
tilladam deleted the docs/window-close-return-value branch July 30, 2026 16:28
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.

3 participants