Skip to content

Instantly share code, notes, and snippets.

@rodhfr
Last active March 14, 2025 14:23
Show Gist options
  • Save rodhfr/181a0bee00ad5f7a608bc3e1bd021be5 to your computer and use it in GitHub Desktop.
Save rodhfr/181a0bee00ad5f7a608bc3e1bd021be5 to your computer and use it in GitHub Desktop.

XDG Desktop Portals - Setup and Explanation

πŸ“Œ Main Reference

The best source of information on XDG Desktop Portals is the Arch Linux Wiki.

πŸ” What are XDG Desktop Portals?

xdg-desktop-portals act as bridges that allow Flatpaks (a type of container) to communicate with the host system.

Available Implementations

You can install multiple implementations without conflicts, such as:

  • xdg-desktop-portal-gtk
  • xdg-desktop-portal-wlr
  • xdg-desktop-portal (base implementation)

To check installed implementations, run:

ls /usr/share/xdg-desktop-portal/portals

The wlr.portal file already includes the following line by default: UseIn=wlroots;sway;Wayfire;river;phosh;Hyprland;

append this line to gtk.portal, instead of keeping it gnome-only, which is the default for xdg-desktop-portal-gtk.

#/usr/share/xdg-desktop-portal/portals/gtk.portal
UseIn=wlroots;sway;Wayfire;river;phosh;Hyprland;

put UseIn in the last line

And add the following lines to your ~/.bashrc:

#~/.bashrc
export XDG_CURRENT_DESKTOP=sway   # xdg-desktop-portal
export XDG_SESSION_DESKTOP=sway   # systemd
export XDG_SESSION_TYPE=wayland

This is for the flatpak app to recognize which desktop portal is needed

Also change your swayconfig appending

# cp /etc/sway/config ~/.config/sway/config # if not have your own config yet
#~/.config/sway/config
exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway

This is recommended in the xdg-desktop-portal-wlr repository.

  • xdg-desktop-portal-wlr β†’ Used only for screen capture.
  • xdg-desktop-portal-gtk β†’ Handles everything else, like file picker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment