Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions data/io.elementary.SettingsDaemon.AccountsService.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
</property>

<property name="AccentColor" type="i" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="1"/>
</property>

<property name="CursorBlink" type="b" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
</property>
Expand Down
28 changes: 25 additions & 3 deletions settings-portal/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ private interface Pantheon.AccountsService : Object {
public abstract int prefers_accent_color { owned get; set; }
}

[DBus (name = "io.elementary.SettingsDaemon.AccountsService")]
private interface SettingsDaemon.AccountsService : Object {
public abstract int accent_color { get; set; }
}

[DBus (name = "org.freedesktop.Accounts")]
interface FDO.Accounts : Object {
public abstract string find_user_by_name (string username) throws GLib.Error;
}

/* Copied from Granite.Settings */
private class AccountsServiceMonitor : GLib.Object {
private FDO.Accounts? accounts_service = null;
private Pantheon.AccountsService? pantheon_act = null;
private SettingsDaemon.AccountsService? settings_daemon_act = null;
private string user_path;

public int32 color_scheme { get; set; }
Expand All @@ -52,6 +57,7 @@ private class AccountsServiceMonitor : GLib.Object {
construct {
setup_user_path ();
setup_prefers_color_scheme ();
setup_prefers_accent_color ();
}

private void setup_user_path () {
Expand All @@ -78,15 +84,31 @@ private class AccountsServiceMonitor : GLib.Object {
);

color_scheme = pantheon_act.prefers_color_scheme;
accent_color = pantheon_act.prefers_accent_color;

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

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

accent_color = settings_daemon_act.accent_color;

value = changed.lookup_value ("PrefersAccentColor", new VariantType ("i"));
((GLib.DBusProxy) settings_daemon_act).g_properties_changed.connect ((changed, invalid) => {
var value = changed.lookup_value ("AccentColor", new VariantType ("i"));
if (value != null) {
accent_color = value.get_int32 ();
}
Expand Down
1 change: 1 addition & 0 deletions src/AccountsService.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public interface SettingsDaemon.AccountsService : Object {
public abstract bool touchpad_two_finger_scrolling { get; set; }

/* Interface */
public abstract int accent_color { get; set; }
public abstract bool cursor_blink { get; set; }
public abstract int cursor_blink_time { get; set; }
public abstract int cursor_blink_timeout { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public sealed class SettingsDaemon.Application : Gtk.Application {
try {
pantheon_service = yield connection.get_proxy (FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES);
prefers_color_scheme_settings = new Backends.PrefersColorSchemeSettings (pantheon_service);
accent_color_manager = new Backends.AccentColorManager (pantheon_service);
accent_color_manager = new Backends.AccentColorManager (pantheon_service, accounts_service);
} catch {
warning ("Unable to get pantheon's AccountsService proxy, color scheme preference may be incorrect");
}
Expand Down
73 changes: 45 additions & 28 deletions src/Backends/AccentColorManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

public class SettingsDaemon.Backends.AccentColorManager : Object {
public unowned Pantheon.AccountsService accounts_service { get; construct; }
public unowned Pantheon.AccountsService pantheon_accounts_service { get; construct; }
public unowned AccountsService accounts_service { get; construct; }

private Settings background_settings;
private Settings interface_settings;
Expand All @@ -15,6 +16,7 @@ public class SettingsDaemon.Backends.AccentColorManager : Object {
}

private struct Theme {
int index;
string name;
string stylesheet;
Gdk.RGBA color;
Expand All @@ -30,56 +32,74 @@ public class SettingsDaemon.Backends.AccentColorManager : Object {
}

private static Theme[] themes = {
{ "Blue", "io.elementary.stylesheet.blueberry", rgba_from_int (0x3689e6) }, // vala-lint=double-spaces
{ "Mint", "io.elementary.stylesheet.mint", rgba_from_int (0x28bca3) }, // vala-lint=double-spaces
{ "Green", "io.elementary.stylesheet.lime", rgba_from_int (0x68b723) }, // vala-lint=double-spaces
{ "Yellow", "io.elementary.stylesheet.banana", rgba_from_int (0xf9c440) }, // vala-lint=double-spaces
{ "Orange", "io.elementary.stylesheet.orange", rgba_from_int (0xffa154) }, // vala-lint=double-spaces
{ "Red", "io.elementary.stylesheet.strawberry", rgba_from_int (0xed5353) }, // vala-lint=double-spaces
{ "Pink", "io.elementary.stylesheet.bubblegum", rgba_from_int (0xde3e80) }, // vala-lint=double-spaces
{ "Purple", "io.elementary.stylesheet.grape", rgba_from_int (0xa56de2) }, // vala-lint=double-spaces
{ "Brown", "io.elementary.stylesheet.cocoa", rgba_from_int (0x8a715e) }, // vala-lint=double-spaces
{ "Gray", "io.elementary.stylesheet.slate", rgba_from_int (0x667885) } // vala-lint=double-spaces
{ 1, "Red", "io.elementary.stylesheet.strawberry", rgba_from_int (0xed5353) }, // vala-lint=double-spaces
{ 2, "Orange", "io.elementary.stylesheet.orange", rgba_from_int (0xffa154) }, // vala-lint=double-spaces
{ 3, "Yellow", "io.elementary.stylesheet.banana", rgba_from_int (0xf9c440) }, // vala-lint=double-spaces
{ 4, "Green", "io.elementary.stylesheet.lime", rgba_from_int (0x68b723) }, // vala-lint=double-spaces
{ 5, "Mint", "io.elementary.stylesheet.mint", rgba_from_int (0x28bca3) }, // vala-lint=double-spaces
{ 6, "Blue", "io.elementary.stylesheet.blueberry", rgba_from_int (0x3689e6) }, // vala-lint=double-spaces
{ 7, "Purple", "io.elementary.stylesheet.grape", rgba_from_int (0xa56de2) }, // vala-lint=double-spaces
{ 8, "Pink", "io.elementary.stylesheet.bubblegum", rgba_from_int (0xde3e80) }, // vala-lint=double-spaces
{ 9, "Brown", "io.elementary.stylesheet.cocoa", rgba_from_int (0x8a715e) }, // vala-lint=double-spaces
{ 10, "Gray", "io.elementary.stylesheet.slate", rgba_from_int (0x667885) } // vala-lint=double-spaces
};

public AccentColorManager (Pantheon.AccountsService accounts_service) {
Object (accounts_service: accounts_service);
public AccentColorManager (Pantheon.AccountsService pantheon_accounts_service, AccountsService accounts_service) {
Object (
pantheon_accounts_service: pantheon_accounts_service,
accounts_service: accounts_service
);
}

construct {
background_settings = new Settings ("org.gnome.desktop.background");
interface_settings = new Settings ("org.gnome.desktop.interface");

((DBusProxy) accounts_service).g_properties_changed.connect ((props) => {
int accent_color;
update_accent_color ();
if (pantheon_accounts_service.prefers_accent_color == 0) {
background_settings.changed["picture-options"].connect (update_accent_color);
background_settings.changed["picture-uri"].connect (update_accent_color);
background_settings.changed["primary-color"].connect (update_accent_color);
}

((DBusProxy) pantheon_accounts_service).g_properties_changed.connect ((props) => {
int accent_color;
if (!props.lookup ("PrefersAccentColor", "i", out accent_color)) {
return;
};

update_accent_color ();
if (accent_color == 0) {
background_settings.changed["picture-options"].connect (update_accent_color);
background_settings.changed["picture-uri"].connect (update_accent_color);
background_settings.changed["primary-color"].connect (update_accent_color);
update_accent_color ();
} else {
background_settings.changed["picture-options"].disconnect (update_accent_color);
background_settings.changed["picture-uri"].disconnect (update_accent_color);
background_settings.changed["primary-color"].disconnect (update_accent_color);
}
});
}

if (accounts_service.prefers_accent_color == 0) {
background_settings.changed["picture-options"].connect (update_accent_color);
background_settings.changed["picture-uri"].connect (update_accent_color);
background_settings.changed["primary-color"].connect (update_accent_color);
update_accent_color ();
private void update_accent_color () {
Theme? new_theme = null;
var prefers_accent_color = pantheon_accounts_service.prefers_accent_color;
if (prefers_accent_color == 0) {
new_theme = get_dynamic_accent_color_theme_name ();
} else if (prefers_accent_color < themes.length + 1) {
new_theme = themes[prefers_accent_color - 1];
} else {
critical ("Incorrect accent color in pantheon accounts service");
return;
}

interface_settings.set_string ("gtk-theme", new_theme.stylesheet);
debug ("New stylesheet: %s", new_theme.stylesheet);

accounts_service.accent_color = new_theme.index;
}

private void update_accent_color () {
var current_stylesheet = interface_settings.get_string ("gtk-theme");
debug ("Current stylesheet: %s", current_stylesheet);
private Theme get_dynamic_accent_color_theme_name () {
Theme? new_theme = null;

if (background_settings.get_enum ("picture-options") != BackgroundStyle.NONE) {
Expand All @@ -95,10 +115,7 @@ public class SettingsDaemon.Backends.AccentColorManager : Object {
new_theme = get_theme_for_primary_color (primary_color);
}

if (new_theme.stylesheet != current_stylesheet) {
debug ("New stylesheet: %s", new_theme.stylesheet);
interface_settings.set_string ("gtk-theme", new_theme.stylesheet);
}
return new_theme;
}

private Theme? get_theme_for_primary_color (string primary_color) {
Expand Down