Skip to content

Add support for XDG Foreign

Kai Uwe Broulik requested to merge work/kbroulik/xdg-foreign into master

This adds a KWindowSystem::setMainWindow overload taking a QString for its parent window which consumes an XDG Foreign handle. This also adds an exportWindow and unexportWindow method to KWaylandExtras.

exportWindow(window) asks the compositor for a handle and emits the windowExported signal once it received one. This token can then be sent to a different application and a window parented to it using setMainWindow(window, handle).

The wayland objects are parented to the respective QWaylandWindow so that they are cleaned up when the window is destroyed.

Calling exportWindow on the same window will re-use the existing exported object. Even though you can technically export the same window multiple times and get a separate token each time, this isn't covered by this API and realistically not its primary use case.

Furthermore, calling unexportWindow(window) will delete the exported object, should one exist on the given window. Calling setMainWindow with an invalid handle will destroy the imported object, severing the parent-child relationship.


Successfully used exportWindow in kauth!57 (merged) and setForeignParent in plasma/polkit-kde-agent-1!36 (merged)

Also tested unexportWindow(window) and setMainWindow(window, QString()). Haven’t tried parenting multiple windows to the same token or changing to a different (non-null) parent.

There’s at least three places (kwin killer, kauth/polkit prompt, colors kcm) where I could already use this. There’s plenty more: xdg desktop portal, window rules, kdialog, keditfiletype, soliduiserver, print-manager stuff, bluetooth kcm (generally any of those KCMs that use external helper apps for certain workflows), kpasswordprompt. Just a quick grep for QWindow::fromWinId and KWindowSystem::setMainWindow.

This is ABI-incompatible but should be source-compatible. In many cases you get the token from QCommandLineParser which you can directly feed into setMainWindow(window, handleString) now and need no specific code for Wayland, pretty nifty.

@davidedmundson @nicolasfella

Edited by Kai Uwe Broulik

Merge request reports

Loading