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

settings: Implement the contrast settings #466

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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