Repository navigation
fix(matching): keep restored windows on their own tiles - #222
Merged
Merged
Conversation
Chromium/Electron renders native GTK dialogs (the About box, message boxes) in a different Wayland client. GTK cannot set an xdg_toplevel parent on Chromium's surface, so Chromium exports its toplevel and GDK imports the handle and calls zxdg_imported.set_parent_of. We only advertised the exporter, so the importer request never reached the compositor: a dialog opened from one of several windows of a single-instance application mapped as a regular toplevel and the matcher guessed its owner (two Code OSS windows, About attached to the wrong one). Advertise zxdg_importer_v1 and v2, resolve the imported handle back to the exported surface, and record set_parent_of as an authoritative client parent: patch the dialog's MetaWindow when it already exists or keep the relation in pending_foreign_parent until its toplevel is created. Destroying the imported object drops the relation again. The custom exporter is kept: the portal resolves its handles to the requesting window through it.
A restored session can report the generic application title for several seconds after the launch burst has settled and spread the windows (VS Code opens every restored window as "Code - OSS"). The title discriminator is not available yet, so two windows of the same single-instance application end up on each other's tiles and stay there: each tile then adopts the swapped title. Treat a title that covers less than half of the stored title and is contained in it as the application name, not an instance identity. It is weak in both directions and never overwrites a tile's durable stored title. When a displayed window's title becomes specific within MAX_TITLE_REASSOCIATION_TIME_MS of being owned, re-run the by-title ownership comparison against the tiles' stored identities and move it to a strictly better sibling; the destination redistributes what it was displaying. Also let a late authoritative parent re-parent an existing dialog. The GTK About box is created before its xdg-foreign parent arrives, so the matcher first attaches it to a same-process sibling; when UpdateParent lands, move the dialog to the real owner instead of dropping the reroute because the current owner is already a DialogWindow.
The late title re-association moved any displayed window whose title changed within 10 s of being owned, against every tile of the application. A terminal changing directory or a browser navigating could land on another tile, and a fresh launcher tile lost its windows. Re-association is now limited to what a restored session needs: - only windows whose title is still generic at the burst settle, so a fresh tile storing the application name qualifies and an already specific title never moves; - only among the tiles the burst settled across, and only while the window is still displayed directly by one of them (a dialog's root tile no longer stands in for its owner); - only after the gather finished, for at most 3 s after the settle; - never once the user clicked, tapped or typed into the window or a dialog of its tile, including before the settle. A comparison that does not move the window keeps it pending, since the first specific title can be transient. Entries expire on a timer, are dropped when the window becomes a dialog, and forgotten on removal. A stored application name is no longer penalized against a specific window title: it keeps the graded near match, so a fresh tile does not hand its windows to siblings sharing the application suffix. The persistent tile's tab renders the live window title, falling back to the stored one, while properties.title stays protected from generic startup titles so a shell restart mid-restore still finds the right tile. Moving a window out explicitly refreshes the source tile's display.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A restored session (VS Code) maps every window with the generic application title (
Code - OSS) and only reports the workspace title after the launch burst has settled. With no title to tell them apart, windows of the same application ended up on each other's tiles, and each tile then adopted the swapped title.Generic titles are weak. A window title that covers less than half of a tile's stored title and is contained in it counts as the application name, not an instance identity. It never replaces a tile's stored title for matching or persistence. It also can't outrank a sibling whose stored title is specific.
Late title re-association, tightly bounded. After the burst settles, a window can still move to a strictly better tile when its specific title arrives, but only if all of these hold:
Any other title change, such as a terminal
cd, a browser navigating or a renamed document, never moves a window.Tab title. The persistent tile's tab shows the live window title, falling back to the stored title when it's missing or empty.
Dialog re-parenting. When an out-of-process dialog's parent arrives late (the GTK About box via
xdg-foreign), the existing dialog is re-parented to its real owner instead of being left on the tile the matcher guessed.xdg-foreign importer. The compositor now advertises the
xdg-foreignimporter, so out-of-process dialogs can declare their parent at all.The spec (
docs/specifications/matching_algorithm.md) is updated to match.Test plan
cargo checkflutter test: the 6 failures are the same tests that fail without this branch (missing config directory in the test environment)Closes #146