55 */
66
77public class SettingsDaemon.Backends.AccentColorManager : Object {
8- public unowned Pantheon . AccountsService accounts_service { get ; construct; }
8+ public unowned Pantheon . AccountsService pantheon_accounts_service { get ; construct; }
9+ public unowned AccountsService accounts_service { get ; construct; }
910
1011 private Settings background_settings;
1112 private Settings interface_settings;
@@ -15,6 +16,7 @@ public class SettingsDaemon.Backends.AccentColorManager : Object {
1516 }
1617
1718 private struct Theme {
19+ int index;
1820 string name;
1921 string stylesheet;
2022 Gdk . RGBA color;
@@ -30,56 +32,74 @@ public class SettingsDaemon.Backends.AccentColorManager : Object {
3032 }
3133
3234 private static Theme [] themes = {
33- { " Blue " , " io.elementary.stylesheet.blueberry " , rgba_from_int (0x3689e6 ) }, // vala-lint=double-spaces
34- { " Mint " , " io.elementary.stylesheet.mint " , rgba_from_int (0x28bca3 ) }, // vala-lint=double-spaces
35- { " Green " , " io.elementary.stylesheet.lime " , rgba_from_int (0x68b723 ) }, // vala-lint=double-spaces
36- { " Yellow " , " io.elementary.stylesheet.banana " , rgba_from_int (0xf9c440 ) }, // vala-lint=double-spaces
37- { " Orange " , " io.elementary.stylesheet.orange " , rgba_from_int (0xffa154 ) }, // vala-lint=double-spaces
38- { " Red " , " io.elementary.stylesheet.strawberry " , rgba_from_int (0xed5353 ) }, // vala-lint=double-spaces
39- { " Pink " , " io.elementary.stylesheet.bubblegum " , rgba_from_int (0xde3e80 ) }, // vala-lint=double-spaces
40- { " Purple " , " io.elementary.stylesheet.grape " , rgba_from_int (0xa56de2 ) }, // vala-lint=double-spaces
41- { " Brown" , " io.elementary.stylesheet.cocoa" , rgba_from_int (0x8a715e ) }, // vala-lint=double-spaces
42- { " Gray" , " io.elementary.stylesheet.slate" , rgba_from_int (0x667885 ) } // vala-lint=double-spaces
35+ { 1 , " Red " , " io.elementary.stylesheet.strawberry " , rgba_from_int (0xed5353 ) }, // vala-lint=double-spaces
36+ { 2 , " Orange " , " io.elementary.stylesheet.orange " , rgba_from_int (0xffa154 ) }, // vala-lint=double-spaces
37+ { 3 , " Yellow " , " io.elementary.stylesheet.banana " , rgba_from_int (0xf9c440 ) }, // vala-lint=double-spaces
38+ { 4 , " Green " , " io.elementary.stylesheet.lime " , rgba_from_int (0x68b723 ) }, // vala-lint=double-spaces
39+ { 5 , " Mint " , " io.elementary.stylesheet.mint " , rgba_from_int (0x28bca3 ) }, // vala-lint=double-spaces
40+ { 6 , " Blue " , " io.elementary.stylesheet.blueberry " , rgba_from_int (0x3689e6 ) }, // vala-lint=double-spaces
41+ { 7 , " Purple " , " io.elementary.stylesheet.grape " , rgba_from_int (0xa56de2 ) }, // vala-lint=double-spaces
42+ { 8 , " Pink " , " io.elementary.stylesheet.bubblegum " , rgba_from_int (0xde3e80 ) }, // vala-lint=double-spaces
43+ { 9 , " Brown" , " io.elementary.stylesheet.cocoa" , rgba_from_int (0x8a715e ) }, // vala-lint=double-spaces
44+ { 10 , " Gray" , " io.elementary.stylesheet.slate" , rgba_from_int (0x667885 ) } // vala-lint=double-spaces
4345 };
4446
45- public AccentColorManager (Pantheon .AccountsService accounts_service ) {
46- Object (accounts_service: accounts_service);
47+ public AccentColorManager (Pantheon .AccountsService pantheon_accounts_service , AccountsService accounts_service ) {
48+ Object (
49+ pantheon_accounts_service: pantheon_accounts_service,
50+ accounts_service: accounts_service
51+ );
4752 }
4853
4954 construct {
5055 background_settings = new Settings (" org.gnome.desktop.background" );
5156 interface_settings = new Settings (" org.gnome.desktop.interface" );
5257
53- ((DBusProxy ) accounts_service). g_properties_changed. connect ((props) = > {
54- int accent_color;
58+ update_accent_color ();
59+ if (pantheon_accounts_service. prefers_accent_color == 0 ) {
60+ background_settings. changed[" picture-options" ]. connect (update_accent_color);
61+ background_settings. changed[" picture-uri" ]. connect (update_accent_color);
62+ background_settings. changed[" primary-color" ]. connect (update_accent_color);
63+ }
5564
65+ ((DBusProxy ) pantheon_accounts_service). g_properties_changed. connect ((props) = > {
66+ int accent_color;
5667 if (! props. lookup (" PrefersAccentColor" , " i" , out accent_color)) {
5768 return ;
5869 };
5970
71+ update_accent_color ();
6072 if (accent_color == 0 ) {
6173 background_settings. changed[" picture-options" ]. connect (update_accent_color);
6274 background_settings. changed[" picture-uri" ]. connect (update_accent_color);
6375 background_settings. changed[" primary-color" ]. connect (update_accent_color);
64- update_accent_color ();
6576 } else {
6677 background_settings. changed[" picture-options" ]. disconnect (update_accent_color);
6778 background_settings. changed[" picture-uri" ]. disconnect (update_accent_color);
6879 background_settings. changed[" primary-color" ]. disconnect (update_accent_color);
6980 }
7081 });
82+ }
7183
72- if (accounts_service. prefers_accent_color == 0 ) {
73- background_settings. changed[" picture-options" ]. connect (update_accent_color);
74- background_settings. changed[" picture-uri" ]. connect (update_accent_color);
75- background_settings. changed[" primary-color" ]. connect (update_accent_color);
76- update_accent_color ();
84+ private void update_accent_color () {
85+ Theme ? new_theme = null ;
86+ var prefers_accent_color = pantheon_accounts_service. prefers_accent_color;
87+ if (prefers_accent_color == 0 ) {
88+ new_theme = get_dynamic_accent_color_theme_name ();
89+ } else if (prefers_accent_color < themes. length + 1 ) {
90+ new_theme = themes[prefers_accent_color - 1 ];
91+ } else {
92+ critical (" Incorrect accent color in pantheon accounts service" );
93+ return ;
7794 }
95+
96+ interface_settings. set_string (" gtk-theme" , new_theme. stylesheet);
97+ debug (" New stylesheet: %s " , new_theme. stylesheet);
98+
99+ accounts_service. accent_color = new_theme. index;
78100 }
79101
80- private void update_accent_color () {
81- var current_stylesheet = interface_settings. get_string (" gtk-theme" );
82- debug (" Current stylesheet: %s " , current_stylesheet);
102+ private Theme get_dynamic_accent_color_theme_name () {
83103 Theme ? new_theme = null ;
84104
85105 if (background_settings. get_enum (" picture-options" ) != BackgroundStyle . NONE ) {
@@ -95,10 +115,7 @@ public class SettingsDaemon.Backends.AccentColorManager : Object {
95115 new_theme = get_theme_for_primary_color (primary_color);
96116 }
97117
98- if (new_theme. stylesheet != current_stylesheet) {
99- debug (" New stylesheet: %s " , new_theme. stylesheet);
100- interface_settings. set_string (" gtk-theme" , new_theme. stylesheet);
101- }
118+ return new_theme;
102119 }
103120
104121 private Theme ? get_theme_for_primary_color (string primary_color ) {
0 commit comments