Skip to content

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

Open

Description

@PapyElGringo

Is your feature request related to a problem? Please describe.

Dialog matching relies on a client-declared parent as its strongest signal (matching algorithm, Dialog / Child Window → signal 1: client parent via xdg_toplevel.set_parent / X11 transient). But an out-of-process dialog cannot set that parent directly. Sandboxed or separate-process dialogs — a Flatpak app's native file chooser, a portal dialog rendered by another process — reference the owning window through the xdg-foreign protocol instead: the requester exports its toplevel, the dialog's process imports the handle, and it calls zxdg_imported.set_parent_of. That relation is never declared to us today, so the matching engine is left guessing with weaker signals (activatedBy, process sibling, fixed size) exactly where an authoritative one exists.

Describe the solution you'd like

Implement the xdg-foreign importer (v1 and v2) alongside the exporter we already have, and record zxdg_imported.set_parent_of as MetaWindow.parent (emitting parent_changed), so the client-declared surface-to-surface relation feeds dialog routing exactly like xdg_toplevel.set_parent.

This would give dialog matching an authoritative owner for cross-process/sandboxed dialogs (the Dialog / Child Window → signal 1 path) instead of routing them heuristically.

Describe alternatives you've considered

  • Keep relying on activatedBy / process-sibling heuristics for cross-process dialogs (current behaviour). Works for some toolkits but is not authoritative and can misroute.
  • Reuse smithay's bundled wayland::xdg_foreign module. Its handle→surface registry is private with no accessor, so it can serve the protocol but cannot be queried — which is why the exporter we added is in-house. The importer would need to be in-house too unless upstream exposes the registry.

Additional context

  • The exporter (v1 + v2) already lands in src/embedder/wayland/xdg_foreign.rs; it is used to resolve the portal parent_window for the file chooser. The importer is the natural other half of the same module.
  • The protocol specifies set_parent_of with "the same stacking and positioning semantics as xdg_toplevel.set_parent" (wayland.app, xdg-foreign-unstable-v2), so it maps cleanly onto the existing parent signal and XdgShellHandler::parent_changed machinery; no new matching signal is needed, just a new source for the one that already ranks first.
  • Client behaviour: Chromium only exports (v1); GTK binds both and uses import for set_transient_for_exported. So the importer's value is the matching signal, not the file chooser.
  • Spec references: docs/specifications/matching_algorithm.md (Dialog / Child Window, Dialog routing, and the Parent signal under Client / protocol signals).

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaAn idea fora new feature or improvement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions