Skip to content

Commit

Permalink
portal-impl: Use fallback portals for Settings as well
Browse files Browse the repository at this point in the history
Since 1.18.2, we have a hardcoded fallback to xdg-desktop-portal-gtk as
a last resort if no other portal is defined by a configuration file.
This fallback mechanism, however, isn't implemented for the
org.freedesktop.impl.portal.Settings interface.

The consequence is that everything seems to work just fine, but user
preferences like color scheme are ignored in applications that use the
portal API to retrieve them (not just flatpak apps, also libadwaita
apps). That comes as a surprise to users; and since the portal stuff
otherwise works fine, it's not entirely straightforward to figure out
that configuring portal.conf would fix it.

I believe that if find_portal_implementation implements fallbacks, so
should find_all_portal_implementations, for consistency and to avoid
surprises.

The fallback logic this commit implements closely resembles the logic in
find_portal_implementation: we don't look for fallbacks if there is a
portal configured in portals.conf (or if portals.conf explicitly says
there should be none), and we only use the x-d-p-gtk as a last resort if
we haven't found any impl(s) using the legacy UseIn key.

(The above should be a self-contained description but there's some
additional thoughts at
#1199 (comment))

Fixes: d18c563 ("portal-impl: Hard-code x-d-p-gtk as a last-resort fallback")
Related: #1102
  • Loading branch information
liskin authored and GeorgesStavracas committed Oct 30, 2024
1 parent 6d85ca0 commit 9137e0e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/portal-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,10 @@ find_portal_implementation (const char *interface)
GPtrArray *
find_all_portal_implementations (const char *interface)
{
const char **desktops;
GPtrArray *impls;
GList *l;
int i;

impls = g_ptr_array_new ();

Expand All @@ -747,5 +750,56 @@ find_all_portal_implementations (const char *interface)
}
}

if (impls->len > 0)
return impls;

desktops = get_current_lowercase_desktops ();

/* Fallback to the old UseIn key */
for (i = 0; desktops[i] != NULL; i++)
{
for (l = implementations; l != NULL; l = l->next)
{
PortalImplementation *impl = l->data;

if (!portal_impl_supports_iface (impl, interface))
continue;

if (impl->use_in != NULL && g_strv_case_contains ((const char **)impl->use_in, desktops[i]))
{
g_warning ("Choosing %s.portal for %s via the deprecated UseIn key",
impl->source, interface);
warn_please_use_portals_conf ();
g_debug ("Using %s.portal for %s in %s (fallback)", impl->source, interface, desktops[i]);
g_ptr_array_add (impls, impl);
}
}
}

if (impls->len > 0)
return impls;

/* As a last resort, if nothing was selected for this desktop by
* ${desktop}-portals.conf or portals.conf, and no portal volunteered
* itself as suitable for this desktop via the legacy UseIn mechanism,
* try to fall back to x-d-p-gtk, which has historically been the portal
* UI backend used by desktop environments with no backend of their own.
* If it isn't installed, that is not an error: we just don't use it. */
for (l = implementations; l != NULL; l = l->next)
{
PortalImplementation *impl = l->data;

if (!g_str_equal (impl->dbus_name, "org.freedesktop.impl.portal.desktop.gtk"))
continue;

if (!portal_impl_supports_iface (impl, interface))
continue;

g_warning ("Choosing %s.portal for %s as a last-resort fallback",
impl->source, interface);
warn_please_use_portals_conf ();
g_ptr_array_add (impls, impl);
}

return impls;
}

0 comments on commit 9137e0e

Please sign in to comment.