Skip to content

Commit

Permalink
Add prefers_accent_color (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl authored Apr 20, 2021
1 parent 872d22b commit a95c546
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions lib/Widgets/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Granite {
[DBus (name = "io.elementary.pantheon.AccountsService")]
private interface Pantheon.AccountsService : Object {
public abstract int prefers_accent_color { owned get; set; }
public abstract int prefers_color_scheme { owned get; set; }
}

Expand All @@ -14,6 +15,56 @@ namespace Granite {
* Granite.Settings provides a way to share Pantheon desktop settings with applications.
*/
public class Settings : Object {
/**
* Possible accent color preferences expressed by the user
*/
public enum AccentColor {
/**
* The user has not expressed a accent color preference.
*/
NO_PREFERENCE,
/**
* The user prefers red as accent color.
*/
RED,
/**
* The user prefers orange as accent color.
*/
ORANGE,
/**
* The user prefers yellow as accent color.
*/
YELLOW,
/**
* The user prefers green as accent color.
*/
GREEN,
/**
* The user prefers mint as accent color.
*/
MINT,
/**
* The user prefers blue as accent color.
*/
BLUE,
/**
* The user prefers purple as accent color.
*/
PURPLE,
/**
* The user prefers pink as accent color.
*/
PINK,
/**
* The user prefers brown as accent color.
*/
BROWN,
/**
* The user prefers gray as accent color.
*/
GRAY
}

/**
* Possible color scheme preferences expressed by the user
*/
Expand All @@ -32,8 +83,24 @@ namespace Granite {
LIGHT
}

private AccentColor? _prefers_accent_color = null;
private ColorScheme? _prefers_color_scheme = null;

/**
* Accent color the user would prefer or if the user has expressed no preference.
*/
public AccentColor prefers_accent_color {
get {
if (_prefers_accent_color == null) {
setup_prefers_accent_color ();
}
return _prefers_accent_color;
}
private set {
_prefers_accent_color = value;
}
}

/**
* Whether the user would prefer if apps use a dark or light color scheme or if the user has expressed no preference.
*/
Expand Down Expand Up @@ -88,6 +155,28 @@ namespace Granite {
}
}

private void setup_prefers_accent_color () {
try {
pantheon_act = GLib.Bus.get_proxy_sync (
GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES
);

prefers_accent_color = (AccentColor) pantheon_act.prefers_accent_color;

((GLib.DBusProxy) pantheon_act).g_properties_changed.connect ((changed, invalid) => {
var accent_color = changed.lookup_value ("PrefersAccentColor", new VariantType ("i"));
if (accent_color != null) {
prefers_accent_color = (AccentColor) accent_color.get_int32 ();
}
});
} catch (Error e) {
critical (e.message);
}
}

private void setup_prefers_color_scheme () {
try {
pantheon_act = GLib.Bus.get_proxy_sync (
Expand Down

0 comments on commit a95c546

Please sign in to comment.