Skip to content

fix(matching): keep restored windows on their own tiles - #222

Merged
PapyElGringo merged 3 commits into
mainfrom
fix/restored-window-matching
Nov 5, 2026
Merged

PapyElGringo merged 3 commits into
mainfrom
fix/restored-window-matching

Conversation

@PapyElGringo

@PapyElGringo PapyElGringo commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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:

    • its title was still generic when the burst settled;
    • the move is among the tiles that burst spread its windows across;
    • the window is still displayed directly by one of those tiles, not as a dialog;
    • it happens within 3 s of the settle;
    • the user hasn't clicked, tapped or typed into the window, or into a dialog of its tile.

    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-foreign importer, 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 check
  • Dart tests for title costs, re-association limits (burst tiles only, fresh app-name tiles, owner outside the burst, expiry, input before and after the settle), and dialog re-parenting
  • Full flutter test: the 6 failures are the same tests that fail without this branch (missing config directory in the test environment)
  • Manual: restore a VS Code session with several workspaces and check that each window lands on its own tile

Closes #146

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.
@PapyElGringo
PapyElGringo merged commit ddd7c2b into main Nov 5, 2026
2 checks passed
@PapyElGringo
PapyElGringo deleted the fix/restored-window-matching branch November 5, 2026 08:34
@PapyElGringo PapyElGringo mentioned this pull request Nov 10, 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.

[IDEA] Use xdg-foreign importer relations to feed dialog matching

1 participant