Determining a Wayland window ID from Python

Matthias Clasen mclasen at redhat.com
Wed Jul 3 21:11:43 UTC 2019


On Wed, Jul 3, 2019 at 3:09 PM David Strauss <david at davidstrauss.net> wrote:

> 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.
>


Wayland surfaces don't have a public ID unless you explicitly create one
using the zxdg_exporter protocol.
The client-side api for this is gdk_wayland_window_export_handle. If this
seems too much hassle, just
passing an empty string will work fine for most purposes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/flatpak/attachments/20190703/5398fce2/attachment.html>


More information about the Flatpak mailing list