| 1 |
--- |
| 2 |
layout: default |
| 3 |
--- |
| 4 |
<picture class="full pixels"> |
| 5 |
<source srcset="assets/splash-dark.png" media="(prefers-color-scheme: dark)"> |
| 6 |
<img src="assets/splash.png"> |
| 7 |
</picture> |
| 8 |
|
| 9 |
|
| 10 |
# XDG Desktop Portal |
| 11 |
|
| 12 |
A portal frontend service for [Flatpak](https://flatpak.org) and other |
| 13 |
desktop containment frameworks. |
| 14 |
|
| 15 |
xdg-desktop-portal works by exposing a series of D-Bus interfaces known as |
| 16 |
_portals_ under a well-known name (`org.freedesktop.portal.Desktop`) and object |
| 17 |
path (`/org/freedesktop/portal/desktop`). |
| 18 |
|
| 19 |
The portal interfaces include APIs for file access, opening URIs, printing |
| 20 |
and others. |
| 21 |
|
| 22 |
|
| 23 |
<a href="https://flatpak.github.io/xdg-desktop-portal/docs" class="pixelbutton"><picture> |
| 24 |
<source srcset="assets/docs-button-dark.png" media="(prefers-color-scheme: dark)"> |
| 25 |
<img alt="Documentation for the available D-Bus interfaces" src="assets/docs-button.png"> |
| 26 |
</picture></a> |
| 27 |
|
| 28 |
## Version Numbering |
| 29 |
|
| 30 |
xdg-desktop-portal uses even minor version numbers for stable versions, and odd |
| 31 |
minor version numbers for unstable versions. During an unstable version cycle, |
| 32 |
portal APIs can make backward incompatible changes, meaning that applications |
| 33 |
should only depend on APIs defined in stable xdg-desktop-portal versions in |
| 34 |
production. |
| 35 |
|
| 36 |
## Building xdg-desktop-portal |
| 37 |
|
| 38 |
xdg-desktop-portal depends on GLib and Flatpak. To build the documentation, you |
| 39 |
will need xmlto and the docbook stylesheets. For more instructions, please read |
| 40 |
[CONTRIBUTING.md](https://github.com/flatpak/xdg-desktop-portal/blob/main/CONTRIBUTING.md). |
| 41 |
|
| 42 |
## Using Portals |
| 43 |
|
| 44 |
Flatpak grants sandboxed applications _talk_ access to names in the |
| 45 |
org.freedesktop.portal.\* prefix. One possible way to use the portal APIs |
| 46 |
is thus just to make D-Bus calls. For many of the portals, toolkits (e.g. |
| 47 |
GTK) are expected to support portals transparently if you use suitable |
| 48 |
high-level APIs. |
| 49 |
|
| 50 |
To implement most portals, xdg-desktop-portal relies on a backend |
| 51 |
that provides implementations of the org.freedesktop.impl.portal.\* interfaces. |
| 52 |
|
| 53 |
Here are some examples of available backends: |
| 54 |
|
| 55 |
- GTK [xdg-desktop-portal-gtk](http://github.com/flatpak/xdg-desktop-portal-gtk) |
| 56 |
- GNOME [xdg-desktop-portal-gnome](https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/) |
| 57 |
- KDE [xdg-desktop-portal-kde](https://invent.kde.org/plasma/xdg-desktop-portal-kde) |
| 58 |
- LXQt [xdg-desktop-portal-lxqt](https://github.com/lxqt/xdg-desktop-portal-lxqt) |
| 59 |
- Pantheon (elementary OS) [xdg-desktop-portal-pantheon](https://github.com/elementary/portals) |
| 60 |
- wlroots [xdg-desktop-portal-wlr](https://github.com/emersion/xdg-desktop-portal-wlr) |
| 61 |
- Deepin [xdg-desktop-portal-dde](https://github.com/linuxdeepin/xdg-desktop-portal-dde) |
| 62 |
- Xapp (Cinnamon, MATE, Xfce) [xdg-desktop-portal-xapp](https://github.com/linuxmint/xdg-desktop-portal-xapp) |
| 63 |
- COSMIC [xdg-desktop-portal-cosmic](https://github.com/pop-os/xdg-desktop-portal-cosmic) |
| 64 |
|
| 65 |
## Design Considerations |
| 66 |
|
| 67 |
There are several reasons for the frontend/backend separation of the portal |
| 68 |
code: |
| 69 |
- We want to have _native_ portal dialogs that match the session desktop (i.e. |
| 70 |
GTK dialogs for GNOME, Qt dialogs for KDE) |
| 71 |
- One of the limitations of the D-Bus proxying in flatpak is that allowing a |
| 72 |
sandboxed app to talk to a name implicitly also allows it to talk to any other |
| 73 |
name owned by the same unique name. Therefore, sandbox-facing D-Bus APIs |
| 74 |
should generally be hosted on a dedicated bus connection. For portals, the |
| 75 |
frontend takes care of this for us. |
| 76 |
- The frontend can handle all the interaction with _portal infrastructure_, such |
| 77 |
as the permission store and the document store, freeing the backends to focus |
| 78 |
on just providing a user interface. |
| 79 |
- The frontend can also handle argument validation, and be strict about only |
| 80 |
letting valid requests through to the backend. |
| 81 |
|
| 82 |
The portal apis are all following the pattern of an initial method call, whose |
| 83 |
response returns an object handle for an _org.freedesktop.portal.Request_ object |
| 84 |
that represents the portal interaction. The end of the interaction is done via a |
| 85 |
_Response_ signal that gets emitted on that object. This pattern was chosen over |
| 86 |
a simple method call with return, since portal APIs are expected to show dialogs |
| 87 |
and interact with the user, which may well take longer than the maximum method |
| 88 |
call timeout of D-Bus. Another advantage is that the caller can cancel an |
| 89 |
ongoing interaction by calling the _Cancel_ method on the request object. |
| 90 |
|
| 91 |
One consideration for deciding the shape of portal APIs is that we want them to |
| 92 |
'hide' behind existing library APIs where possible, to make it as easy as |
| 93 |
possible to have apps use them _transparently_. For example, the OpenFile portal |
| 94 |
is working well as a backend for the GtkFileChooserNative API. |
| 95 |
|
| 96 |
When it comes to files, we need to be careful to not let portal APIs subvert the |
| 97 |
limited filesystem view that apps have in their sandbox. Therefore, files should |
| 98 |
only be passed into portal APIs in one of two forms: |
| 99 |
- As a document ID referring to a file that has been exported in the document |
| 100 |
portal |
| 101 |
- As an open fd. The portal can work its way back to a file path from the fd, |
| 102 |
and passing an fd proves that the app inside the sandbox has access to the |
| 103 |
file to open it. |
| 104 |
|
| 105 |
When it comes to processes, passing PIDs around is not useful in a sandboxed |
| 106 |
world where apps are likely in their own PID namespace. And passing PIDs from |
| 107 |
inside the sandbox is problematic, since the app can just lie. |
| 108 |
|
| 109 |
## Contributing |
| 110 |
|
| 111 |
XDG Desktop Portals is [Free Software](https://www.gnu.org/philosophy/free-sw.html). Contributions [welcome](https://github.com/flatpak/xdg-desktop-portal/blob/main/CONTRIBUTING.md). |
| 112 |
|