Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add portals configuration file for desktop environments #955

Closed
wants to merge 19 commits into from

Conversation

ebassi
Copy link
Collaborator

@ebassi ebassi commented Jan 19, 2023

Replace the UseIn key in each portal implementation with a per-desktop configuration file.

Desktop environments (either upstream or downstream) are supposed to ship the configuration file to describe which portal implementation to use for each portal interface.

Fixes: #906

@ebassi
Copy link
Collaborator Author

ebassi commented Jan 19, 2023

Open questions:

  • deprecation policy for UseIn; add a warning, or just silently discard it?

The CI failure on 16.04 is unrelated, and seems to be an infrastructure issue.

@ebassi ebassi marked this pull request as ready for review January 19, 2023 16:51
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
Copy link
Contributor

@Sodivad Sodivad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work as I expect

[preferred]
default=kde
org.freedesktop.impl.portal.FileChooser=gtk

src/portal-impl.c Outdated Show resolved Hide resolved
@matthiasclasen
Copy link
Contributor

Open questions:

* deprecation policy for `UseIn`; add a warning, or just silently discard it?

I think a warning would be appropriate.

@matthiasclasen
Copy link
Contributor

I sadly don't find UseIn mentioned in any docs we ship, so portal configuration is probably entirely undocumented.

It might be nice to start changing that by including a manpage for the portals.conf file format.

@ebassi
Copy link
Collaborator Author

ebassi commented Feb 9, 2023

I think a warning would be appropriate.

Switched to a warning.

It might be nice to start changing that by including a manpage for the portals.conf file format.

Done. I've added an optional dependency on rst2man to generate the man page. I can also commit the generated man page.

Emmanuele Bassi added 13 commits May 4, 2023 15:52
Give some meaningful names to reused variables, and group portals that
depend on other portals together.
Use the same code GLib uses to ensure that the desktop names are
retrieved once, and are valid according to the Desktop Entry
specification.
Instead of having each portal define the preferred desktop to use its
interfaces in, we should have the desktops define the kind of portals to
use, depending on the interface.

This requires adding a new configuration file, shipped by the desktop
upstream (or by a downstream distributor) that defines the preferred
portal implementation(s) to use, with the ability to define the
implementation of each interface. The configuration file is in the
format "$DESKTOP-portals.conf", in order to match the
XDG_CURRENT_DESKTOP environment variable.

For environments that are not classified as "desktops", it's still
possible to define a "portals.conf" configuration file under
XDG_DATA_DIRS or XDG_DATA_HOME.

Fixes: flatpak#906
We use the environment variable to determine the portal configuration,
so we need to override it in the tests, to avoid loading the
configuration for the system's environment.
Make sure to dump all the debug messages in the test log.
We check under the `DATADIR` prefix for system installations, but we
should also check under `$XDG_CONFIG_HOME` for user overrides.
The UseIn key in the portal implementation configuration file is
deprecated, and is not a requirement any more.

We can still use it as a fallback mechanism while we get per-desktop
configuration files.
We need to look first in the user configuration directory, then in the
system's configuration directory.
- One argument per line
- Align argument type and names in two columns
- Use the right-most * to align pointer arguments
@rpigott
Copy link

rpigott commented Jul 24, 2023

Can I ask why XDG_DATA_HOME / XDG_DATA_DIRS was chosen for this config instead of XDG_CONFIG_HOME / XDG_CONFIG_DIRS? Isn't this a user configuration?

wentasah added a commit to wentasah/nix-conf that referenced this pull request Aug 15, 2023
This was an attempt to fix the problem with long start of gtk apps. I
hoped that it will disappear due to 1.17.0 containing
flatpak/xdg-desktop-portal#955, but gnome
portal is still loaded despite not being mentioned in
sway-portals.conf.

The next commit will have a solution that actually works for me.
columbarius added a commit to emersion/xdg-desktop-portal-wlr that referenced this pull request Aug 24, 2023
This is an example configuration for choosing the portal implementations
which should be used [1]. Compositors and distributions are expected to ship
their modified version according to their choice of components.

[1] flatpak/xdg-desktop-portal#955
@WhyNotHugo
Copy link
Contributor

With this merged in, if I'm using a portals.conf file to define which portals to use, I no longer need to set the XDG_CURRENT_DESKTOP variable for xdg-desktop-portal, right?

@Sodivad
Copy link
Contributor

Sodivad commented Sep 4, 2023

XDG_CURRENT_DESKTOP affects more than just portal backend selection

@ebassi
Copy link
Collaborator Author

ebassi commented Sep 4, 2023

You should not be setting XDG_CURRENT_DESKTOP yourself: it's up to whatever governs your session to do so.

The portals.conf file is a replacement for the UseIn key inside the portal implementation files; it is also a replacement for people disabling portal support.

If you don't have XDG_CURRENT_DESKTOP defined in your session, and if you don't have any session shipping a ${DESKTOP}-portals.conf then xdg-desktop-portal will read ${XDG_CONFIG_HOME}/xdg-desktop-portal/portals.conf.

For more information, xdg-desktop-portal ships a portals.conf(5) man page: https://github.com/flatpak/xdg-desktop-portal/blob/main/doc/portals-conf.rst

@WhyNotHugo
Copy link
Contributor

WhyNotHugo commented Sep 4, 2023 via email

@WhyNotHugo
Copy link
Contributor

You should not be setting XDG_CURRENT_DESKTOP yourself: it's up to whatever governs your session to do so.

I'm not using a session governor, so I have to set this manually.

With the new portals.conf in my $XDG_CONFIG_HOME, I'm wondering if I need to set $XDG_CURRENT_DESKTOP for anything else or if it would no longer be necessary.

@smcv
Copy link
Collaborator

smcv commented Sep 4, 2023

@rpigott:

Can I ask why XDG_DATA_HOME / XDG_DATA_DIRS was chosen for this config instead of XDG_CONFIG_HOME / XDG_CONFIG_DIRS? Isn't this a user configuration?

It's both. The original version in this PR only searched the configuration directories, and my followup #1082 added the data directories as a lower priority.

XDG_CONFIG_HOME / XDG_CONFIG_DIRS are read as the highest priority, so that user configuration overrides OS vendor or upstream defaults; but if there is no user or sysadmin configuration, the OS vendor or upstream project for the desktop environment needs to be able to provide reasonable defaults, and those should live in /usr.

This is exactly the same as mimeapps.list (and also Vulkan layers, and I expect that there are more specifications like this or will be soon). Some of the paths (like XDG_DATA_HOME) are only there for completeness and to be consistent with other specifications, and are not expected to be actually used or useful in practice.

@smcv
Copy link
Collaborator

smcv commented Sep 4, 2023

@WhyNotHugo:

I'm not using a session governor, so I have to set this manually.

If you are building a desktop environment out of individual pieces, then yes, it's up to you to be your own system integrator, because there is nobody else in that scenario who can take responsibility for doing this for you.

With the new portals.conf in my $XDG_CONFIG_HOME, I'm wondering if I need to set $XDG_CURRENT_DESKTOP for anything else or if it would no longer be necessary.

XDG_CURRENT_DESKTOP is not a new invention, and is used by several other freedesktop.org specifications. The ones I know about are mimeapps.list (desktop-specific defaults for MIME and URI handlers, so that by default you'll get GNOME apps in a GNOME session and KDE apps in a Plasma session if both are installed) and the OnlyShowIn/NotShowIn keys in the desktop entry specification (so apps that are inappropriate for a particular desktop environment won't show there). I'm sure there are others.

Again, if you're building a desktop environment out of individual pieces, then it's up to you to carry out the system-integrator role.

@Sodivad
Copy link
Contributor

Sodivad commented Sep 4, 2023

xdg-utils are also using XDG_CURRENT_DESKTOP to choose a strategy to fulfill what you requested a tool to do. Note that for instance there are also applications that don't implement the mimeapps.list spec themselves but just do xdg-open $file

@smcv
Copy link
Collaborator

smcv commented Sep 4, 2023

As a hint for system integrators who are assembling their own desktop environments, the usual way to set XDG_CURRENT_DESKTOP=Foo:Bar for your desktop session is to put DesktopNames=Foo;Bar; into /usr/share/xsessions/foo.desktop or /usr/share/wayland-sessions/foo.desktop, which will make many display managers (lightdm, gdm, sddm, probably others) set XDG_CURRENT_DESKTOP for the session.

Budgie (XDG_CURRENT_DESKTOP=Budgie:GNOME) is a good example of the non-trivial case where the desktop environment declares that it is a variant of something better-known, so that various specifications and components will use Budgie-specific behaviour if they know one, falling back to GNOME-specific behaviour or non-desktop-specific defaults otherwise.

@rpigott
Copy link

rpigott commented Sep 4, 2023

@WhyNotHugo See [1] for example, which filters desktop entries as intended by the spec. You should continue to set XDG_CURRENT_DESKTOP.

[1] https://codeberg.org/dnkl/fuzzel/pulls/235#issue-316968

@rpigott
Copy link

rpigott commented Sep 4, 2023

It's both. The original version in this PR only searched the configuration directories, and my followup #1082 added the data directories as a lower priority.

Ah, I didn't notice that the config dirs were checked. Thanks.

@WhyNotHugo
Copy link
Contributor

Thanks for all the detailed replies! :)

It's both. The original version in this PR only searched the configuration directories, and my follow-up #1082 added the data directories as a lower priority.

XDG_CONFIG_HOME / XDG_CONFIG_DIRS are read as the highest priority, so that user configuration overrides OS vendor or upstream defaults; but if there is no user or sysadmin configuration, the OS vendor or upstream project for the desktop environment needs to be able to provide reasonable defaults, and those should live in /usr.

This makes perfect sense. It can be configured by the distribution, overridden by the system administrator and overridden by the end-user in a way that's pretty standard.

Should upstream compositors ship the configuration for their portals? Portals like xdg-desktop-portal-wlr are used by multiple compositors. Is the expectation that each compositor ships the corresponding portal file?

From what I can tell, for general purpose portals (e.g.: darkman, a dark mode / light mode daemon that exposes its value via the settings portal, or xdp-access-portal, a standalone org.freedesktop.impl.portal.Access implementation) there's no correct place to ship any configuration, and it is entirely the responsibility of the user to configure it.

However, given that only the first matching configuration file is used, the user would have to copy their existing one (e.g.: from /etc or /usr) and append any customisations into that (also making sure to keep their copy in sync in future).

Wouldn't it be best to read all configuration files, and each one overrides the previous one? So that users can append configurations easily?

rcalixte added a commit to rcalixte/labwc that referenced this pull request Apr 15, 2024
The previous 'UseIn' key was deprecated in xdg-desktop-portal 1.17/1.18.
It has been superceded by the portals.conf structure so that each
desktop can configure the precise desired structure for portals. In
addition, support was added to the Desktop Entry Specifications to
support a `DesktopNames` key that login managers will use to set
XDG_CURRENT_DESKTOP.

* [portals.conf
  Documentation](https://github.com/flatpak/xdg-desktop-portal/blob/main/doc/portals.conf.rst.in)
* [Example
  sway-portals.conf](https://salsa.debian.org/swaywm-team/sway/-/blob/debian/sid/debian/sway-portals.conf)
* [Desktop Entry
  Specifications](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html)

Ref: flatpak/xdg-desktop-portal#955
rcalixte added a commit to rcalixte/labwc that referenced this pull request Apr 15, 2024
The previous `UseIn` key was deprecated in xdg-desktop-portal 1.17/1.18.
It has been superceded by the portals.conf structure so that each
desktop can configure the precise desired structure for portals. In
addition, support was added to the Desktop Entry Specifications to
support a `DesktopNames` key that login managers will use to set
XDG_CURRENT_DESKTOP.

* [portals.conf
  Documentation](https://github.com/flatpak/xdg-desktop-portal/blob/main/doc/portals.conf.rst.in)
* [Example
  sway-portals.conf](https://salsa.debian.org/swaywm-team/sway/-/blob/debian/sid/debian/sway-portals.conf)
* [Desktop Entry
  Specifications](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html)

Ref: flatpak/xdg-desktop-portal#955
rcalixte added a commit to rcalixte/labwc that referenced this pull request Apr 15, 2024
The previous `UseIn` key was deprecated in xdg-desktop-portal 1.17/1.18.
It has been superceded by the portals.conf structure so that each
desktop can configure the precise desired structure for portals. In
addition, support was added to the Desktop Entry Specifications to
support a `DesktopNames` key that login managers will use to set
XDG_CURRENT_DESKTOP.

* [portals.conf
  Documentation](https://github.com/flatpak/xdg-desktop-portal/blob/main/doc/portals.conf.rst.in)
* [Example
  sway-portals.conf](https://salsa.debian.org/swaywm-team/sway/-/blob/debian/sid/debian/sway-portals.conf)
* [Desktop Entry
  Specifications](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html)

Ref: flatpak/xdg-desktop-portal#955
rcalixte added a commit to rcalixte/labwc that referenced this pull request Apr 15, 2024
The previous `UseIn` key was deprecated in xdg-desktop-portal 1.17/1.18.
It has been superceded by the portals.conf structure so that each
desktop can configure the precise desired structure for portals. In
addition, support was added to the Desktop Entry Specifications to
support a `DesktopNames` key that login managers will use to set
XDG_CURRENT_DESKTOP.

* [portals.conf
  Documentation](https://github.com/flatpak/xdg-desktop-portal/blob/main/doc/portals.conf.rst.in)
* [Example
  sway-portals.conf](https://salsa.debian.org/swaywm-team/sway/-/blob/debian/sid/debian/sway-portals.conf)
* [Desktop Entry
  Specifications](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html)

Ref: flatpak/xdg-desktop-portal#955
rcalixte added a commit to rcalixte/labwc that referenced this pull request Apr 15, 2024
The previous `UseIn` key was deprecated in xdg-desktop-portal 1.17/1.18.
It has been superceded by the portals.conf structure so that each
desktop can configure the precise desired structure for portals. In
addition, support was added to the Desktop Entry Specifications to
support a `DesktopNames` key that login managers will use to set
XDG_CURRENT_DESKTOP.

* [portals.conf
  Documentation](https://github.com/flatpak/xdg-desktop-portal/blob/main/doc/portals.conf.rst.in)
* [Example
  sway-portals.conf](https://salsa.debian.org/swaywm-team/sway/-/blob/debian/sid/debian/sway-portals.conf)
* [Desktop Entry
  Specifications](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html)

Ref: flatpak/xdg-desktop-portal#955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace UseIn with more descriptive declarative keys
7 participants