XDG桌面門户

出自 Arch Linux 中文维基

本文或本節需要翻譯。要貢獻翻譯,請訪問簡體中文翻譯團隊

附註: 需要進行翻譯。(在 Talk:XDG桌面門户# 中討論)

引自Flatpak文檔:

門户是一種用於安全地訪問應用程式沙箱外部資源的框架。它們為應用程式提供了一系列常見的功能,包括:確定網絡狀態、使用文件選擇器打開文件、打開URI、進行屏幕截圖或錄屏[...]

門户(Portals)是為了 Flatpak 應用程式使用而設計的,但是任何應用程式都可以使用門户來統一訪問獨立於桌面和工具包的功能。例如,在Wayland上通過 PipeWire 實現 屏幕共享 ,在 Firefox 上使用和您當前的 桌面環境 相同的 打開和保存文件對話框

Installation[編輯 | 編輯原始碼]

Install xdg-desktop-portal and one or more backends. The package includes a systemd/User service that will be automatically started via D-Bus.

Backends[編輯 | 編輯原始碼]

When an application makes a request through a portal, it is handled by xdg-desktop-portal, which then forwards it to a backend implementation. This allows a clean way to provide suitable user interfaces that fit into different desktop environments, and access environment-specific APIs for requests like showing notifications or recording the screen. Multiple backends can be installed: for example, a Sway user may use xdg-desktop-portal-wlr for screen sharing support and xdg-desktop-portal-gtk as a fallback for all other interfaces that xdg-desktop-portal-wlr does not implement.

Portal backend definitions are located in /usr/share/xdg-desktop-portal/portals/*.portal. Each portal backend file contains a list of interfaces that it can handle, and the desktop environments that it can be used in.

List of backends and interfaces[編輯 | 編輯原始碼]

The following table lists all backends available and their support for certain common interfaces.

Backend File chooser Screenshot and screen cast
xdg-desktop-portal-dde Yes Yes, on Deepin Desktop Environment
xdg-desktop-portal-gnome Yes Yes, on GNOME
xdg-desktop-portal-gtk
xdg-desktop-portal-kde Yes, on KDE
xdg-desktop-portal-hyprland1 Yes, on wlroots
xdg-desktop-portal-lxqt
xdg-desktop-portal-wlr Yes, on wlroots
xdg-desktop-portal-xapp Yes, on Cinnamon
xdg-desktop-portal-liri-gitAUR Yes, on Liri
xdg-desktop-portal-shanaAUR 2
xdg-desktop-portal-tdAUR
xdg-desktop-portal-termfilechooser-gitAUR 3
  1. works with all wlroots-based compositors, but provides extra functionality when used with Hyprland such as sharing individual windows.
  2. redirects requests to GNOME/GTK/KDE/LXQt backends
  3. allows using a terminal file manager as a file chooser

Configuration[編輯 | 編輯原始碼]

When a request is made, xdg-desktop-portal will use the /usr/share/xdg-desktop-portal/DE-portals.conf file, where DE is based on the XDG_CURRENT_DESKTOP environment variable. These files are provided by the desktop environments themselves and determine which backends should be used when a specific environment is running.

If you want to override the desktop environment defaults, or your desktop environment does not provide a default configuration, you may create a portal configuration file at $XDG_CONFIG_HOME/xdg-desktop-portal/portals.conf to determine which backends you want to use, either generally or for each individual interface. If you use multiple desktop environments, you may also create multiple $XDG_CONFIG_HOME/xdg-desktop-portal/DE-portals.conf files for each environment.

For example, if your desktop environment does not have a portal backend, and you want to use xdg-desktop-portal-gtk as a generic fallback but also use the LXQt file picker through xdg-desktop-portal-lxqt, you can use the following configuration:

~/.config/xdg-desktop-portal/portals.conf
[preferred]
default=gtk
org.freedesktop.impl.portal.FileChooser=lxqt

See portals.conf(5) for more information.

Force desktop environment[編輯 | 編輯原始碼]

In some cases, such as when you have a standalone window manager, you might want to make xdg-desktop-portal to think you are using a specific desktop environment. This can be achieved by setting the XDG_CURRENT_DESKTOP environment variable for the xdg-desktop-portal.service user unit using a drop-in snippet. For example, to use the backend associated with KDE:

~/.config/systemd/user/xdg-desktop-portal.service.d/override.conf
[Service]
Environment="XDG_CURRENT_DESKTOP=KDE"

If you create the file manually instead of using systemctl, do a daemon-reload.

Troubleshooting[編輯 | 編輯原始碼]

xdg-desktop-portal-wlr does not start automatically on sway[編輯 | 編輯原始碼]

For xdg-desktop-portal-wlr to work, the XDG_CURRENT_DESKTOP and WAYLAND_DISPLAY environment variables have to be set in the systemd user session. XDG_CURRENT_DESKTOP has to be set to the name of your compositor, e.g. XDG_CURRENT_DESKTOP=sway. WAYLAND_DISPLAY is set automatically by the compositor.

Check whether these variables are set with systemctl --user show-environment. If they are not set, import these environment variables into the systemd user session and dbus by running the following commands after launching the compositor (e.g., include them in the compositor's configuration file).

$ systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
$ dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=compositor_name
提示:Sway provides a drop-in file which does this automatically, see Sway#Configuration.

See [1] and [2] for more details.

Using multiple monitors with xdg-desktop-portal-wlr[編輯 | 編輯原始碼]

xdg-desktop-portal-wlr requires an external chooser to select the shared monitor. By default, it looks for slurp, wofi and bemenu in this order. When using slurp, after a request for screen sharing you will be presented with a crosshair cursor and you will need to click the screen you want to share. When using wofi or bemenu, you will be presented with a menu of available displays to share. If no choosers are available, xdg-desktop-portal-wlr will fallback to the first monitor found. For more information, see xdg-desktop-portal-wlr(5) § SCREENCAST OPTIONS.

Poor font rendering in GTK apps on KDE Plasma[編輯 | 編輯原始碼]

Some GTK apps require xdg-desktop-portal-gtk on Plasma in order to render font correctly. Install it and then run:

$ /usr/lib/xdg-desktop-portal --replace

See also[編輯 | 編輯原始碼]