66 */
77
88public class Gala.Drawing.StyleManager : Object {
9+ private const string DBUS_DESKTOP_NAME = " org.freedesktop.portal.Desktop" ;
10+ private const string DBUS_DESKTOP_PATH = " /org/freedesktop/portal/desktop" ;
11+
912 public enum ColorScheme {
1013 NO_PREFERENCE ,
1114 DARK ,
1215 LIGHT
1316 }
1417
15- [DBus (name ="org.freedesktop. Accounts ")]
16- private interface Accounts : Object {
17- public abstract async string find_user_by_name (string name) throws IOError , DBusError ;
18- }
19-
20- [DBus (name ="io.elementary.pantheon. AccountsService ")]
21- private interface PantheonAccountsService : DBusProxy {
22- public abstract int prefers_color_scheme { get ; set ; }
23- public abstract int prefers_accent_color { get ; set ; }
24- }
18+ [DBus (name = "org.freedesktop.portal. Settings ")]
19+ private interface SettingsPortal : Object {
20+ public abstract HashTable<string, HashTable<string, Variant > > read_all (string [] namespaces) throws DBusError , IOError ;
21+ public abstract Variant read (string namespace, string key) throws DBusError , IOError ;
2522
26- [DBus (name ="io.elementary. SettingsDaemon .AccountsService ")]
27- private interface SettingsDaemonAccountsService : DBusProxy {
28- public abstract int accent_color { get ; set ; }
23+ public signal void setting_changed (string namespace, string key, Variant value );
2924 }
3025
31- private const string FDO_ACCOUNTS_NAME = " org.freedesktop.Accounts" ;
32- private const string FDO_ACCOUNTS_PATH = " /org/freedesktop/Accounts" ;
3326 private const uint8 ACCENT_COLOR_ALPHA = 64 ;
3427
3528 private static GLib . Once<StyleManager > instance;
@@ -39,106 +32,60 @@ public class Gala.Drawing.StyleManager : Object {
3932
4033 public ColorScheme prefers_color_scheme { get ; private set ; default = LIGHT ; }
4134#if ! HAS_MUTTER47
42- public Clutter . Color theme_accent_color { get ; private set ; default = { 0 , 0 , 0 , ACCENT_COLOR_ALPHA } ; }
35+ public Clutter . Color theme_accent_color { get ; private set ; default = Clutter . Color . from_string ( " #3689e6 " ) ; }
4336#else
44- public Cogl . Color theme_accent_color { get ; private set ; default = { 0 , 0 , 0 , ACCENT_COLOR_ALPHA } ; }
37+ public Cogl . Color theme_accent_color { get ; private set ; default = Cogl . Color . from_string ( " #3689e6 " ) ; }
4538#endif
4639
47- private PantheonAccountsService ? pantheon_proxy;
48- private SettingsDaemonAccountsService ? settings_daemon_proxy;
40+ private SettingsPortal ? settings_portal = null ;
4941
5042 construct {
5143 Bus . watch_name (
52- SYSTEM , FDO_ACCOUNTS_NAME , NONE ,
53- () = > connect_to_accounts_service. begin (),
54- () = > {
55- pantheon_proxy = null ;
56- settings_daemon_proxy = null ;
57- }
44+ SESSION , DBUS_DESKTOP_NAME , NONE ,
45+ () = > connect_to_settings_portal. begin (),
46+ () = > settings_portal = null
5847 );
5948 }
6049
61- private async void connect_to_accounts_service () {
50+ private async void connect_to_settings_portal () {
6251 try {
63- var accounts = yield Bus . get_proxy< Accounts > (SYSTEM , FDO_ACCOUNTS_NAME , FDO_ACCOUNTS_PATH );
64-
65- var path = yield accounts. find_user_by_name (Environment . get_user_name ());
66-
67- pantheon_proxy = yield Bus . get_proxy< PantheonAccountsService > (SYSTEM , FDO_ACCOUNTS_NAME , path, GET_INVALIDATED_PROPERTIES );
68- settings_daemon_proxy = yield Bus . get_proxy< SettingsDaemonAccountsService > (SYSTEM , FDO_ACCOUNTS_NAME , path, GET_INVALIDATED_PROPERTIES );
52+ settings_portal = yield Bus . get_proxy< SettingsPortal > (SESSION , DBUS_DESKTOP_NAME , DBUS_DESKTOP_PATH );
6953 } catch {
70- warning (" Could not connect to AccountsService . Default accent color will be used" );
54+ warning (" Could not connect to settings portal . Default accent color will be used" );
7155 return ;
7256 }
7357
74- update_color_scheme (pantheon_proxy. prefers_color_scheme);
75- update_color (settings_daemon_proxy. accent_color);
58+ try {
59+ update_color_scheme (settings_portal. read (" org.freedesktop.appearance" , " color-scheme" ). get_uint32 ());
60+ update_color (settings_portal. read (" org.freedesktop.appearance" , " accent-color" ). get_variant ());
61+ } catch (Error e) {
62+ warning (e. message);
63+ }
7664
77- pantheon_proxy. g_properties_changed. connect ((changed, invalid) = > {
78- var value = changed. lookup_value (" PrefersColorScheme" , new VariantType (" i" ));
79- if (value != null ) {
80- update_color_scheme (value . get_int32 ());
65+ settings_portal. setting_changed. connect ((scheme, key, variant) = > {
66+ if (scheme != " org.freedesktop.appearance" ) {
67+ return ;
8168 }
82- });
8369
84- settings_daemon_proxy. g_properties_changed. connect ((changed, invalid) = > {
85- var value = changed. lookup_value (" AccentColor" , new VariantType (" i" ));
86- if (value != null ) {
87- update_color (value . get_int32 ());
70+ switch (key) {
71+ case " color-scheme" :
72+ update_color_scheme (variant. get_uint32 ());
73+ break ;
74+ case " accent-color" :
75+ update_color (variant);
76+ break ;
8877 }
8978 });
9079 }
9180
92- private void update_color_scheme (int color_scheme ) {
81+ private void update_color_scheme (uint32 color_scheme ) {
9382 prefers_color_scheme = (ColorScheme ) color_scheme;
9483 }
9584
96- private void update_color (int color ) {
97- var rgb = get_color (color);
98-
99- var r = (uint8 ) ((rgb >> 16 ) & 255 );
100- var g = (uint8 ) ((rgb >> 8 ) & 255 );
101- var b = (uint8 ) (rgb & 255 );
102-
103- theme_accent_color = { r, g, b, ACCENT_COLOR_ALPHA };
104- }
105-
106- private int get_color (int color ) {
107- switch (color) {
108- case 1 : // Strawberry
109- return 0xed5353 ;
110-
111- case 2 : // Orange
112- return 0xffa154 ;
113-
114- case 3 : // Banana
115- return 0xf9c440 ;
116-
117- case 4 : // Lime
118- return 0x68b723 ;
119-
120- case 5 : // Mint
121- return 0x28bca3 ;
122-
123- case 6 : // Blueberry
124- return 0x3689e6 ;
125-
126- case 7 : // Grape
127- return 0xa56de2 ;
128-
129- case 8 : // Bubblegum
130- return 0xde3e80 ;
131-
132- case 9 : // Cocoa
133- return 0x8a715e ;
134-
135- case 10 : // Slate
136- return 0x667885 ;
137-
138- case 11 : // Latte
139- return 0xe7c591 ;
140- }
85+ private void update_color (Variant color ) {
86+ double r, g, b;
87+ color. get (" (ddd)" , out r, out g, out b);
14188
142- return 0 ;
89+ theme_accent_color = { ( uint8 ) (r * 255 ), ( uint8 ) (g * 255 ), ( uint8 ) (b * 255 ), ACCENT_COLOR_ALPHA } ;
14390 }
14491}
0 commit comments