Skip to content

Commit

Permalink
settings: Implement the contrast settings
Browse files Browse the repository at this point in the history
See flatpak/xdg-desktop-portal#1175

Signed-off-by: Hubert Figuière <[email protected]>
  • Loading branch information
hfiguiere authored and TingPing committed Jan 28, 2024
1 parent 25e828d commit dcbc052
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/settings.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright © 2018 Igalia S.L.
* Copyright © 2024 GNOME Foundation Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -16,6 +17,7 @@
*
* Authors:
* Patrick Griffis <[email protected]>
* Hubert Figuière <[email protected]>
*/

#include "config.h"
Expand Down Expand Up @@ -102,6 +104,18 @@ get_color_scheme (void)
return g_variant_new_uint32 (color_scheme);
}

static GVariant *
get_contrast_value ()
{
SettingsBundle *bundle = g_hash_table_lookup (settings, "org.gnome.desktop.a11y.interface");
gboolean hc = FALSE;

if (bundle && g_settings_schema_has_key (bundle->schema, "high-contrast"))
hc = g_settings_get_boolean (bundle->settings, "high-contrast");

return g_variant_new_uint32 (hc ? 1 : 0);
}

static gboolean
settings_handle_read_all (XdpImplSettings *object,
GDBusMethodInvocation *invocation,
Expand Down Expand Up @@ -155,6 +169,7 @@ settings_handle_read_all (XdpImplSettings *object,

g_variant_dict_init (&dict, NULL);
g_variant_dict_insert_value (&dict, "color-scheme", get_color_scheme ());
g_variant_dict_insert_value (&dict, "contrast", get_contrast_value ());

g_variant_builder_add (builder, "{s@a{sv}}", "org.freedesktop.appearance", g_variant_dict_end (&dict));
}
Expand Down Expand Up @@ -184,12 +199,20 @@ settings_handle_read (XdpImplSettings *object,
return TRUE;
}
}
else if (strcmp (arg_namespace, "org.freedesktop.appearance") == 0 &&
strcmp (arg_key, "color-scheme") == 0)
else if (strcmp (arg_namespace, "org.freedesktop.appearance") == 0)
{
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(v)", get_color_scheme ()));
return TRUE;
if (strcmp (arg_key, "color-scheme") == 0)
{
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(v)", get_color_scheme ()));
return TRUE;
}
else if (strcmp (arg_key, "contrast") == 0)
{
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(v)", get_contrast_value ()));
return TRUE;
}
}
else if (strcmp (arg_namespace, "org.gnome.desktop.interface") == 0 &&
strcmp (arg_key, "enable-animations") == 0)
Expand Down Expand Up @@ -261,6 +284,16 @@ on_settings_changed (GSettings *settings,
xdp_impl_settings_emit_setting_changed (user_data->self,
"org.freedesktop.appearance", key,
g_variant_new ("v", get_color_scheme ()));
if (strcmp (user_data->namespace, "org.gnome.desktop.a11y.interface") == 0 &&
strcmp (key, "high-contrast") == 0 &&
g_variant_is_of_type (new_value, G_VARIANT_TYPE_BOOLEAN))
{
gboolean hc = g_variant_get_boolean (new_value);
xdp_impl_settings_emit_setting_changed (user_data->self,
"org.freedesktop.appearance",
"contrast",
g_variant_new ("v", g_variant_new_uint32 (hc ? 1 : 0)));
}
}

static void
Expand Down

0 comments on commit dcbc052

Please sign in to comment.