10 static constexpr
char kPortalName[] =
"org.freedesktop.portal.Desktop";
11 static constexpr
char kPortalPath[] =
"/org/freedesktop/portal/desktop";
24 G_VARIANT_TYPE_UINT32,
28 "org.gnome.desktop.a11y.interface";
32 G_VARIANT_TYPE_BOOLEAN,
39 G_VARIANT_TYPE_STRING,
44 G_VARIANT_TYPE_BOOLEAN,
49 G_VARIANT_TYPE_STRING,
53 "text-scaling-factor",
54 G_VARIANT_TYPE_DOUBLE,
79 G_IMPLEMENT_INTERFACE(fl_settings_get_type(),
82 static gchar* format_key(
const FlSetting* setting) {
83 return g_strconcat(setting->
ns,
"::", setting->
key,
nullptr);
89 g_autofree
const gchar* key = format_key(setting);
90 *
value = g_variant_dict_lookup_value(portal->values, key, setting->
type);
91 return *
value !=
nullptr;
97 g_autofree
const gchar* key = format_key(setting);
100 g_autoptr(GVariant) old_value =
101 g_variant_dict_lookup_value(portal->values, key,
nullptr);
102 if (old_value !=
nullptr &&
value !=
nullptr &&
103 g_variant_equal(old_value,
value)) {
107 g_variant_dict_insert_value(portal->values, key,
value);
117 g_autoptr(GError)
error =
nullptr;
118 g_autoptr(GVariant)
value =
119 g_dbus_proxy_call_sync(proxy,
"Read", g_variant_new(
"(ss)", ns, key),
120 G_DBUS_CALL_FLAGS_NONE, G_MAXINT,
nullptr, &
error);
123 if (
error->domain == G_DBUS_ERROR &&
124 error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) {
125 g_debug(
"XDG desktop portal unavailable: %s",
error->message);
129 if (
error->domain == G_DBUS_ERROR &&
130 error->code == G_DBUS_ERROR_UNKNOWN_METHOD) {
131 g_debug(
"XDG desktop portal settings unavailable: %s",
error->message);
135 g_critical(
"Failed to read XDG desktop portal settings: %s",
140 g_autoptr(GVariant) child =
nullptr;
141 g_variant_get(
value,
"(v)", &child);
142 g_variant_get(child,
"v", out);
148 const char* sender_name,
149 const char* signal_name,
150 GVariant* parameters,
152 FlSettingsPortal* portal = FL_SETTINGS_PORTAL(
user_data);
153 if (g_strcmp0(signal_name,
"SettingChanged")) {
158 g_autoptr(GVariant)
value =
nullptr;
159 g_variant_get(parameters,
"(&s&sv)", &setting.
ns, &setting.
key, &
value);
164 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(settings);
168 g_autoptr(GVariant)
value =
nullptr;
170 const gchar* clock_format_str = g_variant_get_string(
value,
nullptr);
180 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(settings);
184 g_autoptr(GVariant)
value =
nullptr;
190 const gchar* gtk_theme_str = g_variant_get_string(
value,
nullptr);
200 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(settings);
202 gboolean enable_animations =
true;
204 g_autoptr(GVariant)
value =
nullptr;
206 enable_animations = g_variant_get_boolean(
value);
209 return enable_animations;
213 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(settings);
215 gboolean high_contrast =
false;
217 g_autoptr(GVariant)
value =
nullptr;
219 high_contrast = g_variant_get_boolean(
value);
222 return high_contrast;
226 FlSettings* settings) {
227 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(settings);
229 gdouble scaling_factor = 1.0;
231 g_autoptr(GVariant)
value =
nullptr;
233 scaling_factor = g_variant_get_double(
value);
236 return scaling_factor;
240 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(
object);
242 g_clear_object(&self->dbus_proxy);
243 g_clear_pointer(&self->values, g_variant_dict_unref);
245 G_OBJECT_CLASS(fl_settings_portal_parent_class)->dispose(
object);
249 GObjectClass* object_class = G_OBJECT_CLASS(klass);
264 g_autoptr(GVariantDict) values = g_variant_dict_new(
nullptr);
269 g_return_val_if_fail(values !=
nullptr,
nullptr);
270 FlSettingsPortal* portal =
271 FL_SETTINGS_PORTAL(g_object_new(fl_settings_portal_get_type(),
nullptr));
272 portal->values = g_variant_dict_ref(values);
277 g_return_val_if_fail(FL_IS_SETTINGS_PORTAL(
self),
false);
278 g_return_val_if_fail(self->dbus_proxy ==
nullptr,
false);
280 self->dbus_proxy = g_dbus_proxy_new_for_bus_sync(
281 G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE,
nullptr,
kPortalName,
284 if (self->dbus_proxy ==
nullptr) {
289 g_autoptr(GVariant)
value =
nullptr;
296 g_signal_connect_object(self->dbus_proxy,
"g-signal",
298 static_cast<GConnectFlags
>(0));