Determining a Wayland window ID from Python

David Strauss david at davidstrauss.net
Wed Jul 3 19:08:43 UTC 2019


As part of requesting background/autostart
<https://github.com/flatpak/xdg-desktop-portal/blob/master/data/org.freedesktop.portal.Background.xml>,
I'm attempting to pass a parent window ID, but I cannot find how to obtain
the expected string
<https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#parent_window>
from Python. For X11, it looks like it should be possible with the
following (though I haven't tested):

parent_window_id = 'x11:{}'.format(window.get_property("window").get_xid())

However, on Wayland, I see the following (expected) error, which seems
commonly encountered based on searching for "GdkWaylandWindow":

AttributeError: 'GdkWaylandWindow' object has no attribute 'get_xid'

However, I'm struggling to find documentation on the GdkWaylandWindow class
(as made available in Python). I also haven't been able to find successful
ports of the XID-based window ID code to Wayland in Python-based projects.

Most examples with Python and GTK seem to pass the parent window Python
object itself, like this code from Uberwriter:

filechooser = Gtk.FileChooserDialog(
    _("Open a .md file"),
    self,
    Gtk.FileChooserAction.OPEN,
    ("_Cancel", Gtk.ResponseType.CANCEL,
     "_Open", Gtk.ResponseType.OK)
)

Yet, I've still not found success figuring out how to map that concept to a
Flatpak portal parent window ID string to send over D-Bus. I've seen some
references in Wayland to exporting a handle for interprocess use
<https://github.com/wayland-project/wayland-protocols/blob/master/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml>,
but the APIs have warnings that they're unstable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/flatpak/attachments/20190703/4ee401ef/attachment.html>


More information about the Flatpak mailing list